Completed
Pull Request — master (#42)
by
unknown
01:14
created
ecrire/inc/filtres.php 3 patches
Spacing   +130 added lines, -131 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 
98 98
 	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
99
+	foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) {
100 100
 		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101 101
 		// fonction ou name\space\fonction
102 102
 		if (is_callable($f)) {
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	// affichage "GIT [master: abcdef]"
224 224
 	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
225 225
 	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
226
+		$commit = $desc['branch'].': '.$commit;
227 227
 	}
228 228
 	return "{$desc['vcs']} [$commit]";
229 229
 }
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 	}
243 243
 
244 244
 	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
245
+	if (lire_fichier($dir.'/.git/HEAD', $c)) {
246 246
 		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
247
+		if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) {
248 248
 			return [
249 249
 				'vcs' => 'GIT',
250 250
 				'branch' => basename($currentHead),
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 		$dir = '.';
272 272
 	}
273 273
 	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
274
+	if (file_exists($dir.'/.svn/wc.db') && class_exists('SQLite3')) {
275
+		$db = new SQLite3($dir.'/.svn/wc.db');
276 276
 		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277 277
 		if ($result) {
278 278
 			$row = $result->fetchArray();
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
292 292
 // et laisser passer les fonctions personnelles baptisees image_...
293
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
294
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
295
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
296
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
297
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
298
-$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php';
293
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
294
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
295
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
296
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
297
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
298
+$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php';
299 299
 
300 300
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
301 301
 $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php';
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456 456
 	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
457
+		is_null($key) ? '' : (var_export($key, true).' = ')
458
+		).var_export($val, true);
459 459
 
460 460
 	include_spip('inc/autoriser');
461 461
 	if (autoriser('webmestre')) {
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 		$is_file = false;
510 510
 	}
511 511
 	if ($is_file) {
512
-		$is_local_file = function ($path) {
512
+		$is_local_file = function($path) {
513 513
 			if (strpos($path, '?') !== false) {
514 514
 				$path = supprimer_timestamp($path);
515 515
 				// remove ?24px added by find_in_theme on .svg files
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562 562
 							$srcover = $match[1];
563 563
 							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
564
+							array_unshift($args, "<img src='".$match[1]."' />");
565 565
 							$srcover_filter = call_user_func_array($filtre, $args);
566 566
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567 567
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 	// " -> &quot; et tout ce genre de choses
926 926
 	$u = $GLOBALS['meta']['pcre_u'];
927 927
 	$texte = str_replace('&nbsp;', ' ', $texte);
928
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
928
+	$texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte);
929 929
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
930 930
 	$texte = entites_html($texte, false, false);
931 931
 	// mais bien echapper les double quotes !
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
  **/
986 986
 function supprimer_numero($texte) {
987 987
 	return preg_replace(
988
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
988
+		',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
989 989
 		'',
990 990
 		$texte
991 991
 	);
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 function recuperer_numero($texte) {
1014 1014
 	if (
1015 1015
 		preg_match(
1016
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1016
+			',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1017 1017
 			$texte,
1018 1018
 			$regs
1019 1019
 		)
@@ -1101,8 +1101,8 @@  discard block
 block discarded – undo
1101 1101
  **/
1102 1102
 function textebrut($texte) {
1103 1103
 	$u = $GLOBALS['meta']['pcre_u'];
1104
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1105
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1104
+	$texte = preg_replace('/\s+/S'.$u, ' ', $texte);
1105
+	$texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte);
1106 1106
 	$texte = preg_replace("/^\n+/", '', $texte);
1107 1107
 	$texte = preg_replace("/\n+$/", '', $texte);
1108 1108
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
 		)
1137 1137
 	) {
1138 1138
 		foreach ($liens[0] as $a) {
1139
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1139
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1140 1140
 			$ablank = inserer_attribut($a, 'rel', $rel);
1141 1141
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1142 1142
 			$texte = str_replace($a, $ablank, $texte);
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 		foreach ($regs[0] as $a) {
1162 1162
 			$rel = extraire_attribut($a, 'rel');
1163 1163
 			if (strpos($rel, 'nofollow') === false) {
1164
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1164
+				$rel = 'nofollow'.($rel ? " $rel" : '');
1165 1165
 				$anofollow = inserer_attribut($a, 'rel', $rel);
1166 1166
 				$texte = str_replace($a, $anofollow, $texte);
1167 1167
 			}
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 	$u = $GLOBALS['meta']['pcre_u'];
1191 1191
 	$texte = preg_replace('@</p>@iS', "\n", $texte);
1192 1192
 	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1193
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1193
+	$texte = preg_replace('@^\s*<br />@S'.$u, '', $texte);
1194 1194
 
1195 1195
 	return $texte;
1196 1196
 }
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
 		return $texte;
1222 1222
 	}
1223 1223
 	include_spip('inc/texte');
1224
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1224
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1225 1225
 		'div' : 'span';
1226 1226
 
1227 1227
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
 function attribut_html($texte, $textebrut = true) {
1331 1331
 	$u = $GLOBALS['meta']['pcre_u'];
1332 1332
 	if ($textebrut) {
1333
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1333
+		$texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte));
1334 1334
 	}
1335 1335
 	$texte = texte_backend($texte);
1336 1336
 	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
@@ -1362,7 +1362,7 @@  discard block
 block discarded – undo
1362 1362
 	# un message pour abs_url
1363 1363
 	$GLOBALS['mode_abs_url'] = 'url';
1364 1364
 	$url = trim($url);
1365
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1365
+	$r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS';
1366 1366
 
1367 1367
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1368 1368
 }
@@ -1564,14 +1564,14 @@  discard block
 block discarded – undo
1564 1564
 	if (strpos($texte, '<') !== false) {
1565 1565
 		include_spip('inc/lien');
1566 1566
 		if (defined('_PREG_MODELE')) {
1567
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1567
+			$preg_modeles = '@'._PREG_MODELE.'@imsS';
1568 1568
 			$texte = echappe_html($texte, '', true, $preg_modeles);
1569 1569
 		}
1570 1570
 	}
1571 1571
 
1572 1572
 	$debut = '';
1573 1573
 	$suite = $texte;
1574
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1574
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1575 1575
 		$debut .= substr($suite, 0, $t - 1);
1576 1576
 		$suite = substr($suite, $t);
1577 1577
 		$car = substr($suite, 0, 1);
@@ -1589,11 +1589,11 @@  discard block
 block discarded – undo
1589 1589
 			$suite = substr($suite, strlen($regs[0]));
1590 1590
 		}
1591 1591
 	}
1592
-	$texte = $debut . $suite;
1592
+	$texte = $debut.$suite;
1593 1593
 
1594 1594
 	$texte = echappe_retour($texte);
1595 1595
 
1596
-	return $texte . $fin;
1596
+	return $texte.$fin;
1597 1597
 }
1598 1598
 
1599 1599
 
@@ -1655,7 +1655,7 @@  discard block
 block discarded – undo
1655 1655
 		}
1656 1656
 
1657 1657
 		foreach ($regs as $reg) {
1658
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1658
+			$cle = ($reg[1] ? $reg[1].':' : '').$reg[2];
1659 1659
 			$desc = $traduire($cle, $lang, true);
1660 1660
 			$l = $desc->langue;
1661 1661
 			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
@@ -1769,9 +1769,9 @@  discard block
 block discarded – undo
1769 1769
 					// il ne faut pas echapper en div si propre produit un seul paragraphe
1770 1770
 					include_spip('inc/texte');
1771 1771
 					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1772
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1772
+					$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1773 1773
 					if ($mode === 'div') {
1774
-						$trad = rtrim($trad) . "\n\n";
1774
+						$trad = rtrim($trad)."\n\n";
1775 1775
 					}
1776 1776
 					$trad = code_echappement($trad, 'multi', false, $mode);
1777 1777
 					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
@@ -1965,7 +1965,7 @@  discard block
 block discarded – undo
1965 1965
 	if (is_array($balise)) {
1966 1966
 		array_walk(
1967 1967
 			$balise,
1968
-			function (&$a, $key, $t) {
1968
+			function(&$a, $key, $t) {
1969 1969
 				$a = extraire_attribut($a, $t);
1970 1970
 			},
1971 1971
 			$attribut
@@ -2055,14 +2055,14 @@  discard block
 block discarded – undo
2055 2055
 
2056 2056
 	if ($old !== null) {
2057 2057
 		// Remplacer l'ancien attribut du meme nom
2058
-		$balise = $r[1] . $insert . $r[5];
2058
+		$balise = $r[1].$insert.$r[5];
2059 2059
 	} else {
2060 2060
 		// preferer une balise " />" (comme <img />)
2061 2061
 		if (preg_match(',/>,', $balise)) {
2062
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2062
+			$balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1);
2063 2063
 		} // sinon une balise <a ...> ... </a>
2064 2064
 		else {
2065
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2065
+			$balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1);
2066 2066
 		}
2067 2067
 	}
2068 2068
 
@@ -2116,7 +2116,7 @@  discard block
 block discarded – undo
2116 2116
 				$is_class_presente = false;
2117 2117
 				if (
2118 2118
 					strpos($class_courante, $c) !== false
2119
-					and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2119
+					and preg_match('/(^|\s)'.preg_quote($c).'($|\s)/', $class_courante)
2120 2120
 				) {
2121 2121
 					$is_class_presente = true;
2122 2122
 				}
@@ -2124,13 +2124,13 @@  discard block
 block discarded – undo
2124 2124
 					in_array($operation, ['ajouter', 'commuter'])
2125 2125
 					and !$is_class_presente
2126 2126
 				) {
2127
-					$class_new = rtrim($class_new) . ' ' . $c;
2127
+					$class_new = rtrim($class_new).' '.$c;
2128 2128
 				}
2129 2129
 				elseif (
2130 2130
 					in_array($operation, ['supprimer', 'commuter'])
2131 2131
 					and $is_class_presente
2132 2132
 				) {
2133
-					$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2133
+					$class_new = trim(preg_replace('/(^|\s)'.preg_quote($c).'($|\s)/', "\\1", $class_new));
2134 2134
 				}
2135 2135
 			}
2136 2136
 		}
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
 // Quelques fonctions de calcul arithmetique
2197 2197
 //
2198 2198
 function floatstr($a) {
2199
- return str_replace(',', '.', (string)floatval($a));
2199
+ return str_replace(',', '.', (string) floatval($a));
2200 2200
 }
2201 2201
 function strize($f, $a, $b) {
2202 2202
  return floatstr($f(floatstr($a), floatstr($b)));
@@ -2330,13 +2330,13 @@  discard block
 block discarded – undo
2330 2330
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2331 2331
 		define('_TAGS_NOM_AUTEUR', '');
2332 2332
 	}
2333
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2333
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2334 2334
 	foreach ($tags_acceptes as $tag) {
2335 2335
 		if (strlen($tag)) {
2336
-			$remp1[] = '<' . trim($tag) . '>';
2337
-			$remp1[] = '</' . trim($tag) . '>';
2338
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2339
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2336
+			$remp1[] = '<'.trim($tag).'>';
2337
+			$remp1[] = '</'.trim($tag).'>';
2338
+			$remp2[] = '\x60'.trim($tag).'\x61';
2339
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2340 2340
 		}
2341 2341
 	}
2342 2342
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2390,7 +2390,7 @@  discard block
 block discarded – undo
2390 2390
 				. http_img_pack(
2391 2391
 					'attachment-16.png',
2392 2392
 					$t,
2393
-					'title="' . attribut_html($t) . '"'
2393
+					'title="'.attribut_html($t).'"'
2394 2394
 				)
2395 2395
 				. '</a>',
2396 2396
 				$tag
@@ -2454,10 +2454,10 @@  discard block
 block discarded – undo
2454 2454
 	$fichier = basename($url);
2455 2455
 
2456 2456
 	return '<a rel="enclosure"'
2457
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2458
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2459
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2460
-	. '>' . $fichier . '</a>';
2457
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2458
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2459
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2460
+	. '>'.$fichier.'</a>';
2461 2461
 }
2462 2462
 
2463 2463
 /**
@@ -2485,9 +2485,9 @@  discard block
 block discarded – undo
2485 2485
 			} # vieux data
2486 2486
 			$fichier = basename($url);
2487 2487
 			$enclosures[] = '<enclosure'
2488
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2489
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2490
-				. ($length ? ' length="' . $length . '"' : '')
2488
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2489
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2490
+				. ($length ? ' length="'.$length.'"' : '')
2491 2491
 				. ' />';
2492 2492
 		}
2493 2493
 	}
@@ -2513,7 +2513,7 @@  discard block
 block discarded – undo
2513 2513
 		if (extraire_attribut($e, 'rel') == 'tag') {
2514 2514
 			$subjects .= '<dc:subject>'
2515 2515
 				. texte_backend(textebrut($e))
2516
-				. '</dc:subject>' . "\n";
2516
+				. '</dc:subject>'."\n";
2517 2517
 		}
2518 2518
 	}
2519 2519
 
@@ -2549,7 +2549,7 @@  discard block
 block discarded – undo
2549 2549
 	if (is_array($texte)) {
2550 2550
 		array_walk(
2551 2551
 			$texte,
2552
-			function (&$a, $key, $t) {
2552
+			function(&$a, $key, $t) {
2553 2553
 				$a = extraire_balise($a, $t);
2554 2554
 			},
2555 2555
 			$tag
@@ -2597,7 +2597,7 @@  discard block
 block discarded – undo
2597 2597
 	if (is_array($texte)) {
2598 2598
 		array_walk(
2599 2599
 			$texte,
2600
-			function (&$a, $key, $t) {
2600
+			function(&$a, $key, $t) {
2601 2601
 				$a = extraire_balises($a, $t);
2602 2602
 			},
2603 2603
 			$tag
@@ -2729,7 +2729,7 @@  discard block
 block discarded – undo
2729 2729
 		if ($fond != '404') {
2730 2730
 			$contexte = array_shift($p);
2731 2731
 			$contexte['page'] = $fond;
2732
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2732
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2733 2733
 		}
2734 2734
 	}
2735 2735
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2784,9 +2784,9 @@  discard block
 block discarded – undo
2784 2784
 			. '"'
2785 2785
 			. (is_null($val)
2786 2786
 				? ''
2787
-				: ' value="' . entites_html($val) . '"'
2787
+				: ' value="'.entites_html($val).'"'
2788 2788
 			)
2789
-			. ' type="hidden"' . "\n/>";
2789
+			. ' type="hidden"'."\n/>";
2790 2790
 	}
2791 2791
 
2792 2792
 	return join('', $hidden);
@@ -2896,8 +2896,8 @@  discard block
 block discarded – undo
2896 2896
 
2897 2897
 	return preg_replace_callback(
2898 2898
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2899
-		function ($x) use ($path) {
2900
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2899
+		function($x) use ($path) {
2900
+			return "url('".suivre_lien($path, $x[1])."')";
2901 2901
 		},
2902 2902
 		$contenu
2903 2903
 	);
@@ -2959,14 +2959,14 @@  discard block
 block discarded – undo
2959 2959
 	) {
2960 2960
 		$distant = true;
2961 2961
 		$cssf = parse_url($css);
2962
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2962
+		$cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : '');
2963 2963
 		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2964 2964
 	} else {
2965 2965
 		$distant = false;
2966 2966
 		$cssf = $css;
2967 2967
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2968 2968
 		//propose (rien a faire dans ce cas)
2969
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2969
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2970 2970
 		if (@file_exists($f)) {
2971 2971
 			return $f;
2972 2972
 		}
@@ -2976,7 +2976,7 @@  discard block
 block discarded – undo
2976 2976
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2977 2977
 	$f = $dir_var
2978 2978
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2979
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2979
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2980 2980
 
2981 2981
 	// la css peut etre distante (url absolue !)
2982 2982
 	if ($distant) {
@@ -3022,8 +3022,8 @@  discard block
 block discarded – undo
3022 3022
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3023 3023
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3024 3024
 			$css_direction = substr($css_direction, strlen($dir_var));
3025
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3026
-			$css_direction = '/@@@@@@/' . $css_direction;
3025
+			$src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction;
3026
+			$css_direction = '/@@@@@@/'.$css_direction;
3027 3027
 		}
3028 3028
 		$src[] = $regs[0][$k];
3029 3029
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -3072,7 +3072,7 @@  discard block
 block discarded – undo
3072 3072
 
3073 3073
 	$f = basename($css, '.css');
3074 3074
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3075
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3075
+		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
3076 3076
 		. '.css';
3077 3077
 
3078 3078
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -3082,7 +3082,7 @@  discard block
 block discarded – undo
3082 3082
 	if ($url_absolue_css == $css) {
3083 3083
 		if (
3084 3084
 			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3085
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3085
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
3086 3086
 		) {
3087 3087
 			include_spip('inc/distant');
3088 3088
 			$contenu = recuperer_url($css);
@@ -3194,7 +3194,7 @@  discard block
 block discarded – undo
3194 3194
 	$expression = str_replace('\/', '/', $expression);
3195 3195
 	$expression = str_replace('/', '\/', $expression);
3196 3196
 
3197
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3197
+	if (preg_match('/'.$expression.'/'.$modif, $texte, $r)) {
3198 3198
 		if (isset($r[$capte])) {
3199 3199
 			return $r[$capte];
3200 3200
 		} else {
@@ -3232,7 +3232,7 @@  discard block
 block discarded – undo
3232 3232
 	$expression = str_replace('\/', '/', $expression);
3233 3233
 	$expression = str_replace('/', '\/', $expression);
3234 3234
 
3235
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3235
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3236 3236
 }
3237 3237
 
3238 3238
 
@@ -3251,7 +3251,7 @@  discard block
 block discarded – undo
3251 3251
 function traiter_doublons_documents(&$doublons, $letexte) {
3252 3252
 
3253 3253
 	// Verifier dans le texte & les notes (pas beau, helas)
3254
-	$t = $letexte . $GLOBALS['les_notes'];
3254
+	$t = $letexte.$GLOBALS['les_notes'];
3255 3255
 
3256 3256
 	if (
3257 3257
 		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
@@ -3265,7 +3265,7 @@  discard block
 block discarded – undo
3265 3265
 		if (!isset($doublons['documents'])) {
3266 3266
 			$doublons['documents'] = '';
3267 3267
 		}
3268
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3268
+		$doublons['documents'] .= ','.join(',', $matches[1]);
3269 3269
 	}
3270 3270
 
3271 3271
 	return $letexte;
@@ -3322,7 +3322,7 @@  discard block
 block discarded – undo
3322 3322
 	if ($env) {
3323 3323
 		foreach ($env as $i => $j) {
3324 3324
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3325
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3325
+				$texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />";
3326 3326
 			}
3327 3327
 		}
3328 3328
 	}
@@ -3361,7 +3361,7 @@  discard block
 block discarded – undo
3361 3361
 	if ($env) {
3362 3362
 		foreach ($env as $i => $j) {
3363 3363
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3364
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3364
+				$texte .= attribut_html($i)."='".attribut_html($j)."' ";
3365 3365
 			}
3366 3366
 		}
3367 3367
 	}
@@ -3435,10 +3435,10 @@  discard block
 block discarded – undo
3435 3435
 	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3436 3436
 	if (
3437 3437
 		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3438
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3438
+		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg'
3439 3439
 		and file_exists($variante_svg_generique)
3440 3440
 	) {
3441
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3441
+		if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) {
3442 3442
 			$img_file = $variante_svg_size;
3443 3443
 		}
3444 3444
 		else {
@@ -3496,7 +3496,7 @@  discard block
 block discarded – undo
3496 3496
 				return '';
3497 3497
 			}
3498 3498
 		}
3499
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3499
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3500 3500
 	}
3501 3501
 
3502 3502
 	if (file_exists($img_file)) {
@@ -3506,14 +3506,14 @@  discard block
 block discarded – undo
3506 3506
 		$alt = '';
3507 3507
 	}
3508 3508
 	elseif ($alt or $alt === '') {
3509
-		$alt = " alt='" . attribut_html($alt) . "'";
3509
+		$alt = " alt='".attribut_html($alt)."'";
3510 3510
 	}
3511 3511
 	else {
3512
-		$alt = " alt='" . attribut_html($title) . "'";
3512
+		$alt = " alt='".attribut_html($title)."'";
3513 3513
 	}
3514 3514
 	return "<img src='$img_file'$alt"
3515
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3516
-	. ' ' . ltrim($atts)
3515
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3516
+	. ' '.ltrim($atts)
3517 3517
 	. ' />';
3518 3518
 }
3519 3519
 
@@ -3527,10 +3527,10 @@  discard block
 block discarded – undo
3527 3527
  */
3528 3528
 function http_style_background($img, $att = '', $size = null) {
3529 3529
 	if ($size and is_numeric($size)) {
3530
-		$size = trim($size) . 'px';
3530
+		$size = trim($size).'px';
3531 3531
 	}
3532
-	return " style='background" .
3533
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3532
+	return " style='background".
3533
+		($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';'
3534 3534
 		. ($size ? "background-size:{$size};" : '')
3535 3535
 		. "'";
3536 3536
 }
@@ -3645,7 +3645,7 @@  discard block
 block discarded – undo
3645 3645
 		$img = http_img_pack(
3646 3646
 			$img,
3647 3647
 			$alt,
3648
-			$class ? " class='" . attribut_html($class) . "'" : '',
3648
+			$class ? " class='".attribut_html($class)."'" : '',
3649 3649
 			'',
3650 3650
 			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3651 3651
 		);
@@ -3717,7 +3717,7 @@  discard block
 block discarded – undo
3717 3717
 	$balise_svg_source = $balise_svg;
3718 3718
 
3719 3719
 	// entete XML à supprimer
3720
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3720
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3721 3721
 
3722 3722
 	// IE est toujours mon ami
3723 3723
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
@@ -3735,9 +3735,9 @@  discard block
 block discarded – undo
3735 3735
 	// regler le alt
3736 3736
 	if ($alt) {
3737 3737
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3738
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3738
+		$id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4);
3739 3739
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3740
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3740
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3741 3741
 		$balise_svg .= $title;
3742 3742
 	}
3743 3743
 	else {
@@ -3785,7 +3785,7 @@  discard block
 block discarded – undo
3785 3785
 	if (is_array($tableau)) {
3786 3786
 		foreach ($tableau as $k => $v) {
3787 3787
 			$res = recuperer_fond(
3788
-				'modeles/' . $modele,
3788
+				'modeles/'.$modele,
3789 3789
 				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3790 3790
 			);
3791 3791
 			$texte .= $res;
@@ -3969,7 +3969,7 @@  discard block
 block discarded – undo
3969 3969
 	}
3970 3970
 
3971 3971
 	$c = serialize($c);
3972
-	$cle = calculer_cle_action($form . $c);
3972
+	$cle = calculer_cle_action($form.$c);
3973 3973
 	$c = "$cle:$c";
3974 3974
 
3975 3975
 	// on ne stocke pas les contextes dans des fichiers en cache
@@ -4027,15 +4027,15 @@  discard block
 block discarded – undo
4027 4027
 	}
4028 4028
 	// toujours encoder l'url source dans le bloc ajax
4029 4029
 	$r = self();
4030
-	$r = ' data-origin="' . $r . '"';
4030
+	$r = ' data-origin="'.$r.'"';
4031 4031
 	$class = 'ajaxbloc';
4032 4032
 	if ($ajaxid and is_string($ajaxid)) {
4033 4033
 		// ajaxid est normalement conforme a un nom de classe css
4034 4034
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4035
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4035
+		$class .= ' ajax-id-'.entites_html($ajaxid);
4036 4036
 	}
4037 4037
 
4038
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4038
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4039 4039
 }
4040 4040
 
4041 4041
 /**
@@ -4079,7 +4079,7 @@  discard block
 block discarded – undo
4079 4079
 		$cle = substr($c, 0, $p);
4080 4080
 		$c = substr($c, $p + 1);
4081 4081
 
4082
-		if ($cle == calculer_cle_action($form . $c)) {
4082
+		if ($cle == calculer_cle_action($form.$c)) {
4083 4083
 			$env = @unserialize($c);
4084 4084
 			return $env;
4085 4085
 		}
@@ -4200,13 +4200,13 @@  discard block
 block discarded – undo
4200 4200
 				}
4201 4201
 			}
4202 4202
 		}
4203
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4203
+		$att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"';
4204 4204
 	} else {
4205 4205
 		$bal = 'a';
4206 4206
 		$att = "href='$url'"
4207
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4208
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4209
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4207
+			. ($title ? " title='".attribut_html($title)."'" : '')
4208
+			. ($class ? " class='".attribut_html($class)."'" : '')
4209
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
4210 4210
 			. $evt;
4211 4211
 	}
4212 4212
 	if ($libelle === null) {
@@ -4345,7 +4345,7 @@  discard block
 block discarded – undo
4345 4345
 
4346 4346
 	// Icône
4347 4347
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4348
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4348
+	$icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>";
4349 4349
 
4350 4350
 	// Markup final
4351 4351
 	if ($type == 'lien') {
@@ -4622,20 +4622,20 @@  discard block
 block discarded – undo
4622 4622
 		$class_form = 'ajax';
4623 4623
 		$class = str_replace('ajax', '', $class);
4624 4624
 	}
4625
-	$class_btn = 'submit ' . trim($class);
4625
+	$class_btn = 'submit '.trim($class);
4626 4626
 
4627 4627
 	if ($confirm) {
4628
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4628
+		$confirm = 'confirm("'.attribut_html($confirm).'")';
4629 4629
 		if ($callback) {
4630 4630
 			$callback = "$confirm?($callback):false";
4631 4631
 		} else {
4632 4632
 			$callback = $confirm;
4633 4633
 		}
4634 4634
 	}
4635
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4635
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : '';
4636 4636
 	$title = $title ? " title='$title'" : '';
4637 4637
 
4638
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4638
+	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url)
4639 4639
 	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4640 4640
 }
4641 4641
 
@@ -4700,14 +4700,14 @@  discard block
 block discarded – undo
4700 4700
 		$champ_titre = '';
4701 4701
 		if ($demande_titre) {
4702 4702
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4703
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4703
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4704 4704
 		}
4705 4705
 		include_spip('base/abstract_sql');
4706 4706
 		include_spip('base/connect_sql');
4707 4707
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4708
-			'*' . $champ_titre,
4708
+			'*'.$champ_titre,
4709 4709
 			$desc['table_sql'],
4710
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4710
+			id_table_objet($type_objet).' = '.intval($id_objet)
4711 4711
 		);
4712 4712
 
4713 4713
 		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
@@ -4785,8 +4785,7 @@  discard block
 block discarded – undo
4785 4785
 	if (isset($ligne_sql['chapo'])) {
4786 4786
 		$chapo = $ligne_sql['chapo'];
4787 4787
 		$texte = strlen($descriptif) ?
4788
-			'' :
4789
-			"$chapo \n\n $texte";
4788
+			'' : "$chapo \n\n $texte";
4790 4789
 	}
4791 4790
 
4792 4791
 	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
@@ -4853,7 +4852,7 @@  discard block
 block discarded – undo
4853 4852
 		return $texte;
4854 4853
 	}
4855 4854
 
4856
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4855
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4857 4856
 
4858 4857
 	// Fournir $connect et $Pile[0] au traitement si besoin
4859 4858
 	$Pile = [0 => $env];
@@ -4887,7 +4886,7 @@  discard block
 block discarded – undo
4887 4886
 	}
4888 4887
 	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4889 4888
 
4890
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4889
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>';
4891 4890
 }
4892 4891
 
4893 4892
 
@@ -4906,10 +4905,10 @@  discard block
 block discarded – undo
4906 4905
 function wrap($texte, $wrap) {
4907 4906
 	$balises = extraire_balises($wrap);
4908 4907
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4909
-		$texte = $wrap . $texte;
4908
+		$texte = $wrap.$texte;
4910 4909
 		$regs = array_reverse($regs[1]);
4911
-		$wrap = '</' . implode('></', $regs) . '>';
4912
-		$texte = $texte . $wrap;
4910
+		$wrap = '</'.implode('></', $regs).'>';
4911
+		$texte = $texte.$wrap;
4913 4912
 	}
4914 4913
 
4915 4914
 	return $texte;
@@ -4940,7 +4939,7 @@  discard block
 block discarded – undo
4940 4939
 
4941 4940
 	// caster $u en array si besoin
4942 4941
 	if (is_object($u)) {
4943
-		$u = (array)$u;
4942
+		$u = (array) $u;
4944 4943
 	}
4945 4944
 
4946 4945
 	if (is_array($u)) {
@@ -4962,7 +4961,7 @@  discard block
 block discarded – undo
4962 4961
 		// sinon on passe a la ligne et on indente
4963 4962
 		$i_str = str_pad('', $indent, ' ');
4964 4963
 		foreach ($u as $k => $v) {
4965
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4964
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
4966 4965
 		}
4967 4966
 
4968 4967
 		return $out;
@@ -5016,7 +5015,7 @@  discard block
 block discarded – undo
5016 5015
  * @return string
5017 5016
  */
5018 5017
 function objet_icone($objet, $taille = 24, $class = '') {
5019
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5018
+	$icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png';
5020 5019
 	$icone = chemin_image($icone);
5021 5020
 	$balise_img = charger_filtre('balise_img');
5022 5021
 
@@ -5042,7 +5041,7 @@  discard block
 block discarded – undo
5042 5041
  */
5043 5042
 function objet_T($objet, $chaine, $args = [], $options = []) {
5044 5043
 	$chaine = explode(':', $chaine);
5045
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5044
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) {
5046 5045
 		return $t;
5047 5046
 	}
5048 5047
 	$chaine = implode(':', $chaine);
@@ -5108,7 +5107,7 @@  discard block
 block discarded – undo
5108 5107
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5109 5108
 
5110 5109
 	// calculer le nom de la css
5111
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5110
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
5112 5111
 	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5113 5112
 	$contexte_implicite = calculer_contexte_implicite();
5114 5113
 
@@ -5116,14 +5115,14 @@  discard block
 block discarded – undo
5116 5115
 	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5117 5116
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5118 5117
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5119
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5118
+		$hash = md5($contexte_implicite['host'].'::'.$cache);
5120 5119
 	}
5121 5120
 	else {
5122 5121
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5123 5122
 		ksort($contexte);
5124
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5123
+		$hash = md5($fond.json_encode($contexte_implicite).json_encode($contexte).$connect);
5125 5124
 	}
5126
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5125
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension";
5127 5126
 
5128 5127
 	// mettre a jour le fichier si il n'existe pas
5129 5128
 	// ou trop ancien
@@ -5131,8 +5130,8 @@  discard block
 block discarded – undo
5131 5130
 	// et recopie sur le fichier cible uniquement si il change
5132 5131
 	if (
5133 5132
 		!file_exists($filename)
5134
-		or !file_exists($filename . '.last')
5135
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5133
+		or !file_exists($filename.'.last')
5134
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified'])
5136 5135
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5137 5136
 	) {
5138 5137
 		$contenu = $cache['texte'];
@@ -5153,10 +5152,10 @@  discard block
 block discarded – undo
5153 5152
 			}
5154 5153
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5155 5154
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5156
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5155
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
5157 5156
 		}
5158 5157
 		// et ecrire le fichier si il change
5159
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5158
+		ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true);
5160 5159
 	}
5161 5160
 
5162 5161
 	return timestamp($filename);
@@ -5382,7 +5381,7 @@  discard block
 block discarded – undo
5382 5381
 	if ($e > 0 and strlen($mid) > 8) {
5383 5382
 		$mid = '***...***';
5384 5383
 	}
5385
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5384
+	return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : '');
5386 5385
 }
5387 5386
 
5388 5387
 
@@ -5444,7 +5443,7 @@  discard block
 block discarded – undo
5444 5443
 		case 'id':
5445 5444
 		case 'anchor':
5446 5445
 			if (preg_match(',^\d,', $texte)) {
5447
-				$texte = substr($type, 0, 1) . $texte;
5446
+				$texte = substr($type, 0, 1).$texte;
5448 5447
 			}
5449 5448
 	}
5450 5449
 
@@ -5454,9 +5453,9 @@  discard block
 block discarded – undo
5454 5453
 
5455 5454
 	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5456 5455
 		if (preg_match(',^\d,', $texte)) {
5457
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5456
+			$texte = ($type ? substr($type, 0, 1) : 's').$texte;
5458 5457
 		}
5459
-		$texte .= $separateur . md5($original);
5458
+		$texte .= $separateur.md5($original);
5460 5459
 		$texte = substr($texte, 0, $longueur_mini);
5461 5460
 	}
5462 5461
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -24 removed lines patch added patch discarded remove patch
@@ -631,8 +631,7 @@  discard block
 block discarded – undo
631 631
 			if (!$srcHeight) {
632 632
 				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633 633
 			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
634
+		} elseif (strpos($src, '<svg') !== false) {
636 635
 			include_spip('inc/svg');
637 636
 			if ($attrs = svg_lire_attributs($src)) {
638 637
 				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
@@ -2125,8 +2124,7 @@  discard block
 block discarded – undo
2125 2124
 					and !$is_class_presente
2126 2125
 				) {
2127 2126
 					$class_new = rtrim($class_new) . ' ' . $c;
2128
-				}
2129
-				elseif (
2127
+				} elseif (
2130 2128
 					in_array($operation, ['supprimer', 'commuter'])
2131 2129
 					and $is_class_presente
2132 2130
 				) {
@@ -2138,8 +2136,7 @@  discard block
 block discarded – undo
2138 2136
 		if ($class_new !== $class_courante) {
2139 2137
 			if (strlen($class_new)) {
2140 2138
 				$balise = inserer_attribut($balise, 'class', $class_new);
2141
-			}
2142
-			elseif ($class_courante) {
2139
+			} elseif ($class_courante) {
2143 2140
 				$balise = vider_attribut($balise, 'class');
2144 2141
 			}
2145 2142
 		}
@@ -3440,8 +3437,7 @@  discard block
 block discarded – undo
3440 3437
 	) {
3441 3438
 		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3442 3439
 			$img_file = $variante_svg_size;
3443
-		}
3444
-		else {
3440
+		} else {
3445 3441
 			$img_file = $variante_svg_generique;
3446 3442
 		}
3447 3443
 	}
@@ -3473,8 +3469,7 @@  discard block
 block discarded – undo
3473 3469
 	}
3474 3470
 	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3475 3471
 		$img_file = chemin_image($img);
3476
-	}
3477
-	else {
3472
+	} else {
3478 3473
 		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3479 3474
 			$img_file = http_img_variante_svg_si_possible($img_file);
3480 3475
 		}
@@ -3504,11 +3499,9 @@  discard block
 block discarded – undo
3504 3499
 	}
3505 3500
 	if ($alt === false) {
3506 3501
 		$alt = '';
3507
-	}
3508
-	elseif ($alt or $alt === '') {
3502
+	} elseif ($alt or $alt === '') {
3509 3503
 		$alt = " alt='" . attribut_html($alt) . "'";
3510
-	}
3511
-	else {
3504
+	} else {
3512 3505
 		$alt = " alt='" . attribut_html($title) . "'";
3513 3506
 	}
3514 3507
 	return "<img src='$img_file'$alt"
@@ -3635,13 +3628,11 @@  discard block
 block discarded – undo
3635 3628
 		if (!is_null($class)) {
3636 3629
 			if (strlen($class)) {
3637 3630
 				$img = inserer_attribut($img, 'class', $class);
3638
-			}
3639
-			else {
3631
+			} else {
3640 3632
 				$img = vider_attribut($img, 'class');
3641 3633
 			}
3642 3634
 		}
3643
-	}
3644
-	else {
3635
+	} else {
3645 3636
 		$img = http_img_pack(
3646 3637
 			$img,
3647 3638
 			$alt,
@@ -3726,8 +3717,7 @@  discard block
 block discarded – undo
3726 3717
 	if (!is_null($class)) {
3727 3718
 		if (strlen($class)) {
3728 3719
 			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3729
-		}
3730
-		else {
3720
+		} else {
3731 3721
 			$balise_svg = vider_attribut($balise_svg, 'class');
3732 3722
 		}
3733 3723
 	}
@@ -3739,8 +3729,7 @@  discard block
 block discarded – undo
3739 3729
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3740 3730
 		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3741 3731
 		$balise_svg .= $title;
3742
-	}
3743
-	else {
3732
+	} else {
3744 3733
 		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3745 3734
 	}
3746 3735
 
@@ -5117,8 +5106,7 @@  discard block
 block discarded – undo
5117 5106
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5118 5107
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5119 5108
 		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5120
-	}
5121
-	else {
5109
+	} else {
5122 5110
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5123 5111
 		ksort($contexte);
5124 5112
 		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
Please login to merge, or discard this patch.
Indentation   +2399 added lines, -2399 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
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string Texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,38 +77,38 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		// fonction ou name\space\fonction
102
-		if (is_callable($f)) {
103
-			return $f;
104
-		}
105
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
-		elseif (false === strpos($f, '::') and is_callable([$f])) {
107
-			return $f;
108
-		}
109
-	}
110
-
111
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        // fonction ou name\space\fonction
102
+        if (is_callable($f)) {
103
+            return $f;
104
+        }
105
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
+        elseif (false === strpos($f, '::') and is_callable([$f])) {
107
+            return $f;
108
+        }
109
+    }
110
+
111
+    return $default;
112 112
 }
113 113
 
114 114
 /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  *     Chaîne vide sinon.
153 153
  **/
154 154
 function appliquer_filtre($arg, $filtre) {
155
-	$args = func_get_args();
156
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
155
+    $args = func_get_args();
156
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
157 157
 }
158 158
 
159 159
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  *     Texte d'origine sinon
179 179
  **/
180 180
 function appliquer_si_filtre($arg, $filtre) {
181
-	$args = func_get_args();
182
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181
+    $args = func_get_args();
182
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
183 183
 }
184 184
 
185 185
 /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
  *     Version de SPIP
196 196
  **/
197 197
 function spip_version() {
198
-	$version = $GLOBALS['spip_version_affichee'];
199
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
-		$version .= " $vcs_version";
201
-	}
198
+    $version = $GLOBALS['spip_version_affichee'];
199
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
+        $version .= " $vcs_version";
201
+    }
202 202
 
203
-	return $version;
203
+    return $version;
204 204
 }
205 205
 
206 206
 /**
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
  *    - string|null si $raw = false
214 214
  */
215 215
 function version_vcs_courante($dir, $raw = false) {
216
-	$desc = decrire_version_git($dir);
217
-	if ($desc === null) {
218
-		$desc = decrire_version_svn($dir);
219
-	}
220
-	if ($desc === null or $raw) {
221
-		return $desc;
222
-	}
223
-	// affichage "GIT [master: abcdef]"
224
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
225
-	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
227
-	}
228
-	return "{$desc['vcs']} [$commit]";
216
+    $desc = decrire_version_git($dir);
217
+    if ($desc === null) {
218
+        $desc = decrire_version_svn($dir);
219
+    }
220
+    if ($desc === null or $raw) {
221
+        return $desc;
222
+    }
223
+    // affichage "GIT [master: abcdef]"
224
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
225
+    if ($desc['branch']) {
226
+        $commit = $desc['branch'] . ': ' . $commit;
227
+    }
228
+    return "{$desc['vcs']} [$commit]";
229 229
 }
230 230
 
231 231
 /**
@@ -237,24 +237,24 @@  discard block
 block discarded – undo
237 237
  *      array ['branch' => xx, 'commit' => yy] sinon.
238 238
  **/
239 239
 function decrire_version_git($dir) {
240
-	if (!$dir) {
241
-		$dir = '.';
242
-	}
240
+    if (!$dir) {
241
+        $dir = '.';
242
+    }
243 243
 
244
-	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
-		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
-			return [
249
-				'vcs' => 'GIT',
250
-				'branch' => basename($currentHead),
251
-				'commit' => trim($hash),
252
-				'commit_short' => substr(trim($hash), 0, 8),
253
-			];
254
-		}
255
-	}
244
+    // version installee par GIT
245
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
+        $currentHead = trim(substr($c, 4));
247
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
+            return [
249
+                'vcs' => 'GIT',
250
+                'branch' => basename($currentHead),
251
+                'commit' => trim($hash),
252
+                'commit_short' => substr(trim($hash), 0, 8),
253
+            ];
254
+        }
255
+    }
256 256
 
257
-	return null;
257
+    return null;
258 258
 }
259 259
 
260 260
 
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
268 268
  **/
269 269
 function decrire_version_svn($dir) {
270
-	if (!$dir) {
271
-		$dir = '.';
272
-	}
273
-	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
276
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
-		if ($result) {
278
-			$row = $result->fetchArray();
279
-			if ($row['changed_revision'] != '') {
280
-				return [
281
-					'vcs' => 'SVN',
282
-					'branch' => '',
283
-					'commit' => $row['changed_revision'],
284
-				];
285
-			}
286
-		}
287
-	}
288
-	return null;
270
+    if (!$dir) {
271
+        $dir = '.';
272
+    }
273
+    // version installee par SVN
274
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
+        $db = new SQLite3($dir . '/.svn/wc.db');
276
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
+        if ($result) {
278
+            $row = $result->fetchArray();
279
+            if ($row['changed_revision'] != '') {
280
+                return [
281
+                    'vcs' => 'SVN',
282
+                    'branch' => '',
283
+                    'commit' => $row['changed_revision'],
284
+                ];
285
+            }
286
+        }
287
+    }
288
+    return null;
289 289
 }
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
  *     Code HTML retourné par le filtre
333 333
  **/
334 334
 function filtrer($filtre) {
335
-	$tous = func_get_args();
336
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
-		return image_filtrer($tous);
338
-	} elseif ($f = chercher_filtre($filtre)) {
339
-		array_shift($tous);
340
-		return call_user_func_array($f, $tous);
341
-	} else {
342
-		// le filtre n'existe pas, on provoque une erreur
343
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
-		erreur_squelette($msg);
345
-		return '';
346
-	}
335
+    $tous = func_get_args();
336
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
+        return image_filtrer($tous);
338
+    } elseif ($f = chercher_filtre($filtre)) {
339
+        array_shift($tous);
340
+        return call_user_func_array($f, $tous);
341
+    } else {
342
+        // le filtre n'existe pas, on provoque une erreur
343
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
+        erreur_squelette($msg);
345
+        return '';
346
+    }
347 347
 }
348 348
 
349 349
 /**
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
361 361
  */
362 362
 function trouver_filtre_matrice($filtre) {
363
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
-		find_in_path($f, '', true);
365
-		$GLOBALS['spip_matrice'][$filtre] = true;
366
-	}
367
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
363
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
+        find_in_path($f, '', true);
365
+        $GLOBALS['spip_matrice'][$filtre] = true;
366
+    }
367
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
368 368
 }
369 369
 
370 370
 
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
  * @return mixed
393 393
  */
394 394
 function filtre_set(&$Pile, $val, $key, $continue = null) {
395
-	$Pile['vars'][$key] = $val;
396
-	return $continue ? $val : '';
395
+    $Pile['vars'][$key] = $val;
396
+    return $continue ? $val : '';
397 397
 }
398 398
 
399 399
 /**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
420 420
  */
421 421
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
422
-	$Pile[0][$key] = $val;
423
-	return $continue ? $val : '';
422
+    $Pile[0][$key] = $val;
423
+    return $continue ? $val : '';
424 424
 }
425 425
 
426 426
 /**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
  * @return string
430 430
  */
431 431
 function filtre_sanitize_env(&$Pile, $keys) {
432
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
-	return '';
432
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
+    return '';
434 434
 }
435 435
 
436 436
 
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
  * @return mixed Retourne la valeur (sans la modifier).
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456
-	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
456
+    $debug = (
457
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
458
+        ) . var_export($val, true);
459 459
 
460
-	include_spip('inc/autoriser');
461
-	if (autoriser('webmestre')) {
462
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
-	}
460
+    include_spip('inc/autoriser');
461
+    if (autoriser('webmestre')) {
462
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
+    }
464 464
 
465
-	spip_log($debug, 'debug');
465
+    spip_log($debug, 'debug');
466 466
 
467
-	return $val;
467
+    return $val;
468 468
 }
469 469
 
470 470
 
@@ -492,89 +492,89 @@  discard block
 block discarded – undo
492 492
  *     Texte qui a reçu les filtres
493 493
  **/
494 494
 function image_filtrer($args) {
495
-	$filtre = array_shift($args); # enlever $filtre
496
-	$texte = array_shift($args);
497
-	if (!strlen($texte)) {
498
-		return;
499
-	}
500
-	find_in_path('filtres_images_mini.php', 'inc/', true);
501
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
-	// Cas du nom de fichier local
503
-	$is_file = trim($texte);
504
-	if (
505
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
-		  or strpbrk($is_file, "<>\n\r\t") !== false
507
-		  or strpos($is_file, '/') === 0
508
-	) {
509
-		$is_file = false;
510
-	}
511
-	if ($is_file) {
512
-		$is_local_file = function ($path) {
513
-			if (strpos($path, '?') !== false) {
514
-				$path = supprimer_timestamp($path);
515
-				// remove ?24px added by find_in_theme on .svg files
516
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
-			}
518
-			return file_exists($path);
519
-		};
520
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
-			array_unshift($args, "<img src='$is_file' />");
522
-			$res = call_user_func_array($filtre, $args);
523
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
-			return $res;
525
-		}
526
-	}
527
-
528
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
529
-	if (
530
-		preg_match_all(
531
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
-			$texte,
533
-			$tags,
534
-			PREG_SET_ORDER
535
-		)
536
-	) {
537
-		foreach ($tags as $tag) {
538
-			$class = extraire_attribut($tag[3], 'class');
539
-			if (
540
-				!$class or
541
-				(strpos($class, 'filtre_inactif') === false
542
-					// compat historique a virer en 3.2
543
-					and strpos($class, 'no_image_filtrer') === false)
544
-			) {
545
-				array_unshift($args, $tag[3]);
546
-				if ($reduit = call_user_func_array($filtre, $args)) {
547
-					// En cas de span spip_documents, modifier le style=...width:
548
-					if ($tag[1]) {
549
-						$w = extraire_attribut($reduit, 'width');
550
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
-							$w = $regs[1];
552
-						}
553
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
-							$replace = inserer_attribut($tag[1], 'style', $style);
556
-							$texte = str_replace($tag[1], $replace, $texte);
557
-						}
558
-					}
559
-					// traiter aussi un eventuel mouseover
560
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
-							$srcover = $match[1];
563
-							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
565
-							$srcover_filter = call_user_func_array($filtre, $args);
566
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
568
-						}
569
-					}
570
-					$texte = str_replace($tag[3], $reduit, $texte);
571
-				}
572
-				array_shift($args);
573
-			}
574
-		}
575
-	}
576
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
-	return $texte;
495
+    $filtre = array_shift($args); # enlever $filtre
496
+    $texte = array_shift($args);
497
+    if (!strlen($texte)) {
498
+        return;
499
+    }
500
+    find_in_path('filtres_images_mini.php', 'inc/', true);
501
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
+    // Cas du nom de fichier local
503
+    $is_file = trim($texte);
504
+    if (
505
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
+          or strpbrk($is_file, "<>\n\r\t") !== false
507
+          or strpos($is_file, '/') === 0
508
+    ) {
509
+        $is_file = false;
510
+    }
511
+    if ($is_file) {
512
+        $is_local_file = function ($path) {
513
+            if (strpos($path, '?') !== false) {
514
+                $path = supprimer_timestamp($path);
515
+                // remove ?24px added by find_in_theme on .svg files
516
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
+            }
518
+            return file_exists($path);
519
+        };
520
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
+            array_unshift($args, "<img src='$is_file' />");
522
+            $res = call_user_func_array($filtre, $args);
523
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
+            return $res;
525
+        }
526
+    }
527
+
528
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
529
+    if (
530
+        preg_match_all(
531
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
+            $texte,
533
+            $tags,
534
+            PREG_SET_ORDER
535
+        )
536
+    ) {
537
+        foreach ($tags as $tag) {
538
+            $class = extraire_attribut($tag[3], 'class');
539
+            if (
540
+                !$class or
541
+                (strpos($class, 'filtre_inactif') === false
542
+                    // compat historique a virer en 3.2
543
+                    and strpos($class, 'no_image_filtrer') === false)
544
+            ) {
545
+                array_unshift($args, $tag[3]);
546
+                if ($reduit = call_user_func_array($filtre, $args)) {
547
+                    // En cas de span spip_documents, modifier le style=...width:
548
+                    if ($tag[1]) {
549
+                        $w = extraire_attribut($reduit, 'width');
550
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
+                            $w = $regs[1];
552
+                        }
553
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
+                            $replace = inserer_attribut($tag[1], 'style', $style);
556
+                            $texte = str_replace($tag[1], $replace, $texte);
557
+                        }
558
+                    }
559
+                    // traiter aussi un eventuel mouseover
560
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
+                            $srcover = $match[1];
563
+                            array_shift($args);
564
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
565
+                            $srcover_filter = call_user_func_array($filtre, $args);
566
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
567
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
568
+                        }
569
+                    }
570
+                    $texte = str_replace($tag[3], $reduit, $texte);
571
+                }
572
+                array_shift($args);
573
+            }
574
+        }
575
+    }
576
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
+    return $texte;
578 578
 }
579 579
 
580 580
 /**
@@ -589,78 +589,78 @@  discard block
 block discarded – undo
589 589
  **/
590 590
 function taille_image($img, $force_refresh = false) {
591 591
 
592
-	static $largeur_img = [], $hauteur_img = [];
593
-	$srcWidth = 0;
594
-	$srcHeight = 0;
595
-
596
-	$src = extraire_attribut($img, 'src');
597
-
598
-	if (!$src) {
599
-		$src = $img;
600
-	} else {
601
-		$srcWidth = extraire_attribut($img, 'width');
602
-		$srcHeight = extraire_attribut($img, 'height');
603
-	}
604
-
605
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
606
-	// la copie locale a toutes les chances d'etre la ou de resservir
607
-	if (tester_url_absolue($src)) {
608
-		include_spip('inc/distant');
609
-		$fichier = copie_locale($src);
610
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
611
-	}
612
-	if (($p = strpos($src, '?')) !== false) {
613
-		$src = substr($src, 0, $p);
614
-	}
615
-
616
-	$srcsize = false;
617
-	if (isset($largeur_img[$src]) and !$force_refresh) {
618
-		$srcWidth = $largeur_img[$src];
619
-	}
620
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
621
-		$srcHeight = $hauteur_img[$src];
622
-	}
623
-	if (!$srcWidth or !$srcHeight) {
624
-		if (
625
-			file_exists($src)
626
-			and $srcsize = spip_getimagesize($src)
627
-		) {
628
-			if (!$srcWidth) {
629
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
630
-			}
631
-			if (!$srcHeight) {
632
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633
-			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
636
-			include_spip('inc/svg');
637
-			if ($attrs = svg_lire_attributs($src)) {
638
-				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
-				if (!$srcWidth) {
640
-					$largeur_img[$src] = $srcWidth = $width;
641
-				}
642
-				if (!$srcHeight) {
643
-					$hauteur_img[$src] = $srcHeight = $height;
644
-				}
645
-			}
646
-		}
647
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
-		elseif (
650
-			@file_exists($f = "$src.src")
651
-			and lire_fichier($f, $valeurs)
652
-			and $valeurs = unserialize($valeurs)
653
-		) {
654
-			if (!$srcWidth) {
655
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
-			}
657
-			if (!$srcHeight) {
658
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
-			}
660
-		}
661
-	}
662
-
663
-	return [$srcHeight, $srcWidth];
592
+    static $largeur_img = [], $hauteur_img = [];
593
+    $srcWidth = 0;
594
+    $srcHeight = 0;
595
+
596
+    $src = extraire_attribut($img, 'src');
597
+
598
+    if (!$src) {
599
+        $src = $img;
600
+    } else {
601
+        $srcWidth = extraire_attribut($img, 'width');
602
+        $srcHeight = extraire_attribut($img, 'height');
603
+    }
604
+
605
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
606
+    // la copie locale a toutes les chances d'etre la ou de resservir
607
+    if (tester_url_absolue($src)) {
608
+        include_spip('inc/distant');
609
+        $fichier = copie_locale($src);
610
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
611
+    }
612
+    if (($p = strpos($src, '?')) !== false) {
613
+        $src = substr($src, 0, $p);
614
+    }
615
+
616
+    $srcsize = false;
617
+    if (isset($largeur_img[$src]) and !$force_refresh) {
618
+        $srcWidth = $largeur_img[$src];
619
+    }
620
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
621
+        $srcHeight = $hauteur_img[$src];
622
+    }
623
+    if (!$srcWidth or !$srcHeight) {
624
+        if (
625
+            file_exists($src)
626
+            and $srcsize = spip_getimagesize($src)
627
+        ) {
628
+            if (!$srcWidth) {
629
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
630
+            }
631
+            if (!$srcHeight) {
632
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
633
+            }
634
+        }
635
+        elseif (strpos($src, '<svg') !== false) {
636
+            include_spip('inc/svg');
637
+            if ($attrs = svg_lire_attributs($src)) {
638
+                list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
+                if (!$srcWidth) {
640
+                    $largeur_img[$src] = $srcWidth = $width;
641
+                }
642
+                if (!$srcHeight) {
643
+                    $hauteur_img[$src] = $srcHeight = $height;
644
+                }
645
+            }
646
+        }
647
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
+        elseif (
650
+            @file_exists($f = "$src.src")
651
+            and lire_fichier($f, $valeurs)
652
+            and $valeurs = unserialize($valeurs)
653
+        ) {
654
+            if (!$srcWidth) {
655
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
+            }
657
+            if (!$srcHeight) {
658
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
+            }
660
+        }
661
+    }
662
+
663
+    return [$srcHeight, $srcWidth];
664 664
 }
665 665
 
666 666
 
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
  *     Largeur en pixels, NULL ou 0 si aucune image.
679 679
  **/
680 680
 function largeur($img) {
681
-	if (!$img) {
682
-		return;
683
-	}
684
-	list($h, $l) = taille_image($img);
681
+    if (!$img) {
682
+        return;
683
+    }
684
+    list($h, $l) = taille_image($img);
685 685
 
686
-	return $l;
686
+    return $l;
687 687
 }
688 688
 
689 689
 /**
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
  *     Hauteur en pixels, NULL ou 0 si aucune image.
701 701
  **/
702 702
 function hauteur($img) {
703
-	if (!$img) {
704
-		return;
705
-	}
706
-	list($h, $l) = taille_image($img);
703
+    if (!$img) {
704
+        return;
705
+    }
706
+    list($h, $l) = taille_image($img);
707 707
 
708
-	return $h;
708
+    return $h;
709 709
 }
710 710
 
711 711
 
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
  * @return string
726 726
  **/
727 727
 function corriger_entites_html($texte) {
728
-	if (strpos($texte, '&amp;') === false) {
729
-		return $texte;
730
-	}
728
+    if (strpos($texte, '&amp;') === false) {
729
+        return $texte;
730
+    }
731 731
 
732
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
732
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
733 733
 }
734 734
 
735 735
 /**
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
  * @return string
745 745
  **/
746 746
 function corriger_toutes_entites_html($texte) {
747
-	if (strpos($texte, '&amp;') === false) {
748
-		return $texte;
749
-	}
747
+    if (strpos($texte, '&amp;') === false) {
748
+        return $texte;
749
+    }
750 750
 
751
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
751
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
752 752
 }
753 753
 
754 754
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return string
759 759
  **/
760 760
 function proteger_amp($texte) {
761
-	return str_replace('&', '&amp;', $texte);
761
+    return str_replace('&', '&amp;', $texte);
762 762
 }
763 763
 
764 764
 
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
  * @return mixed|string
790 790
  */
791 791
 function entites_html($texte, $tout = false, $quote = true) {
792
-	if (
793
-		!is_string($texte) or !$texte
794
-		or strpbrk($texte, "&\"'<>") == false
795
-	) {
796
-		return $texte;
797
-	}
798
-	include_spip('inc/texte');
799
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
-	$flags |= ENT_HTML401;
801
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
-	if ($tout) {
803
-		return corriger_toutes_entites_html($texte);
804
-	} else {
805
-		return corriger_entites_html($texte);
806
-	}
792
+    if (
793
+        !is_string($texte) or !$texte
794
+        or strpbrk($texte, "&\"'<>") == false
795
+    ) {
796
+        return $texte;
797
+    }
798
+    include_spip('inc/texte');
799
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
+    $flags |= ENT_HTML401;
801
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
+    if ($tout) {
803
+        return corriger_toutes_entites_html($texte);
804
+    } else {
805
+        return corriger_entites_html($texte);
806
+    }
807 807
 }
808 808
 
809 809
 /**
@@ -822,37 +822,37 @@  discard block
 block discarded – undo
822 822
  *     Texte converti
823 823
  **/
824 824
 function filtrer_entites($texte) {
825
-	if (strpos($texte, '&') === false) {
826
-		return $texte;
827
-	}
828
-	// filtrer
829
-	$texte = html2unicode($texte);
830
-	// remettre le tout dans le charset cible
831
-	$texte = unicode2charset($texte);
832
-	// cas particulier des " et ' qu'il faut filtrer aussi
833
-	// (on le faisait deja avec un &quot;)
834
-	if (strpos($texte, '&#') !== false) {
835
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
-	}
825
+    if (strpos($texte, '&') === false) {
826
+        return $texte;
827
+    }
828
+    // filtrer
829
+    $texte = html2unicode($texte);
830
+    // remettre le tout dans le charset cible
831
+    $texte = unicode2charset($texte);
832
+    // cas particulier des " et ' qu'il faut filtrer aussi
833
+    // (on le faisait deja avec un &quot;)
834
+    if (strpos($texte, '&#') !== false) {
835
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
+    }
837 837
 
838
-	return $texte;
838
+    return $texte;
839 839
 }
840 840
 
841 841
 
842 842
 if (!function_exists('filtre_filtrer_entites_dist')) {
843
-	/**
844
-	 * Version sécurisée de filtrer_entites
845
-	 *
846
-	 * @uses interdire_scripts()
847
-	 * @uses filtrer_entites()
848
-	 *
849
-	 * @param string $t
850
-	 * @return string
851
-	 */
852
-	function filtre_filtrer_entites_dist($t) {
853
-		include_spip('inc/texte');
854
-		return interdire_scripts(filtrer_entites($t));
855
-	}
843
+    /**
844
+     * Version sécurisée de filtrer_entites
845
+     *
846
+     * @uses interdire_scripts()
847
+     * @uses filtrer_entites()
848
+     *
849
+     * @param string $t
850
+     * @return string
851
+     */
852
+    function filtre_filtrer_entites_dist($t) {
853
+        include_spip('inc/texte');
854
+        return interdire_scripts(filtrer_entites($t));
855
+    }
856 856
 }
857 857
 
858 858
 
@@ -867,18 +867,18 @@  discard block
 block discarded – undo
867 867
  * @return string|array
868 868
  **/
869 869
 function supprimer_caracteres_illegaux($texte) {
870
-	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";
871
-	static $to = null;
870
+    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";
871
+    static $to = null;
872 872
 
873
-	if (is_array($texte)) {
874
-		return array_map('supprimer_caracteres_illegaux', $texte);
875
-	}
873
+    if (is_array($texte)) {
874
+        return array_map('supprimer_caracteres_illegaux', $texte);
875
+    }
876 876
 
877
-	if (!$to) {
878
-		$to = str_repeat('-', strlen($from));
879
-	}
877
+    if (!$to) {
878
+        $to = str_repeat('-', strlen($from));
879
+    }
880 880
 
881
-	return strtr($texte, $from, $to);
881
+    return strtr($texte, $from, $to);
882 882
 }
883 883
 
884 884
 /**
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
  * @return string|array
891 891
  **/
892 892
 function corriger_caracteres($texte) {
893
-	$texte = corriger_caracteres_windows($texte);
894
-	$texte = supprimer_caracteres_illegaux($texte);
893
+    $texte = corriger_caracteres_windows($texte);
894
+    $texte = supprimer_caracteres_illegaux($texte);
895 895
 
896
-	return $texte;
896
+    return $texte;
897 897
 }
898 898
 
899 899
 /**
@@ -911,40 +911,40 @@  discard block
 block discarded – undo
911 911
  */
912 912
 function texte_backend($texte) {
913 913
 
914
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
914
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
915 915
 
916
-	// si on a des liens ou des images, les passer en absolu
917
-	$texte = liens_absolus($texte);
916
+    // si on a des liens ou des images, les passer en absolu
917
+    $texte = liens_absolus($texte);
918 918
 
919
-	// echapper les tags &gt; &lt;
920
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
919
+    // echapper les tags &gt; &lt;
920
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
921 921
 
922
-	// importer les &eacute;
923
-	$texte = filtrer_entites($texte);
922
+    // importer les &eacute;
923
+    $texte = filtrer_entites($texte);
924 924
 
925
-	// " -> &quot; et tout ce genre de choses
926
-	$u = $GLOBALS['meta']['pcre_u'];
927
-	$texte = str_replace('&nbsp;', ' ', $texte);
928
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
929
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
930
-	$texte = entites_html($texte, false, false);
931
-	// mais bien echapper les double quotes !
932
-	$texte = str_replace('"', '&#034;', $texte);
925
+    // " -> &quot; et tout ce genre de choses
926
+    $u = $GLOBALS['meta']['pcre_u'];
927
+    $texte = str_replace('&nbsp;', ' ', $texte);
928
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
929
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
930
+    $texte = entites_html($texte, false, false);
931
+    // mais bien echapper les double quotes !
932
+    $texte = str_replace('"', '&#034;', $texte);
933 933
 
934
-	// verifier le charset
935
-	$texte = charset2unicode($texte);
934
+    // verifier le charset
935
+    $texte = charset2unicode($texte);
936 936
 
937
-	// Caracteres problematiques en iso-latin 1
938
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
939
-		$texte = str_replace(chr(156), '&#156;', $texte);
940
-		$texte = str_replace(chr(140), '&#140;', $texte);
941
-		$texte = str_replace(chr(159), '&#159;', $texte);
942
-	}
937
+    // Caracteres problematiques en iso-latin 1
938
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
939
+        $texte = str_replace(chr(156), '&#156;', $texte);
940
+        $texte = str_replace(chr(140), '&#140;', $texte);
941
+        $texte = str_replace(chr(159), '&#159;', $texte);
942
+    }
943 943
 
944
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
945
-	// et le caractere apostrophe alourdit les squelettes avec PHP
946
-	// ==> on les remplace par l'entite HTML
947
-	return str_replace($apostrophe, "'", $texte);
944
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
945
+    // et le caractere apostrophe alourdit les squelettes avec PHP
946
+    // ==> on les remplace par l'entite HTML
947
+    return str_replace($apostrophe, "'", $texte);
948 948
 }
949 949
 
950 950
 /**
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
  *     Texte encodé et quote pour XML
962 962
  */
963 963
 function texte_backendq($texte) {
964
-	return addslashes(texte_backend($texte));
964
+    return addslashes(texte_backend($texte));
965 965
 }
966 966
 
967 967
 
@@ -984,11 +984,11 @@  discard block
 block discarded – undo
984 984
  *     Numéro de titre, sinon chaîne vide
985 985
  **/
986 986
 function supprimer_numero($texte) {
987
-	return preg_replace(
988
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
989
-		'',
990
-		$texte
991
-	);
987
+    return preg_replace(
988
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
989
+        '',
990
+        $texte
991
+    );
992 992
 }
993 993
 
994 994
 /**
@@ -1011,17 +1011,17 @@  discard block
 block discarded – undo
1011 1011
  *     Numéro de titre, sinon chaîne vide
1012 1012
  **/
1013 1013
 function recuperer_numero($texte) {
1014
-	if (
1015
-		preg_match(
1016
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1017
-			$texte,
1018
-			$regs
1019
-		)
1020
-	) {
1021
-		return strval($regs[1]);
1022
-	} else {
1023
-		return '';
1024
-	}
1014
+    if (
1015
+        preg_match(
1016
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1017
+            $texte,
1018
+            $regs
1019
+        )
1020
+    ) {
1021
+        return strval($regs[1]);
1022
+    } else {
1023
+        return '';
1024
+    }
1025 1025
 }
1026 1026
 
1027 1027
 /**
@@ -1048,13 +1048,13 @@  discard block
 block discarded – undo
1048 1048
  *     Texte converti
1049 1049
  **/
1050 1050
 function supprimer_tags($texte, $rempl = '') {
1051
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1052
-	// ne pas oublier un < final non ferme car coupe
1053
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1054
-	// mais qui peut aussi etre un simple signe plus petit que
1055
-	$texte = str_replace('<', '&lt;', $texte);
1051
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1052
+    // ne pas oublier un < final non ferme car coupe
1053
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1054
+    // mais qui peut aussi etre un simple signe plus petit que
1055
+    $texte = str_replace('<', '&lt;', $texte);
1056 1056
 
1057
-	return $texte;
1057
+    return $texte;
1058 1058
 }
1059 1059
 
1060 1060
 /**
@@ -1077,9 +1077,9 @@  discard block
 block discarded – undo
1077 1077
  *     Texte converti
1078 1078
  **/
1079 1079
 function echapper_tags($texte, $rempl = '') {
1080
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1080
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1081 1081
 
1082
-	return $texte;
1082
+    return $texte;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1100,18 +1100,18 @@  discard block
 block discarded – undo
1100 1100
  *     Texte converti
1101 1101
  **/
1102 1102
 function textebrut($texte) {
1103
-	$u = $GLOBALS['meta']['pcre_u'];
1104
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1105
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1106
-	$texte = preg_replace("/^\n+/", '', $texte);
1107
-	$texte = preg_replace("/\n+$/", '', $texte);
1108
-	$texte = preg_replace("/\n +/", "\n", $texte);
1109
-	$texte = supprimer_tags($texte);
1110
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1111
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1112
-	$texte = str_replace('&#8217;', "'", $texte);
1103
+    $u = $GLOBALS['meta']['pcre_u'];
1104
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1105
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1106
+    $texte = preg_replace("/^\n+/", '', $texte);
1107
+    $texte = preg_replace("/\n+$/", '', $texte);
1108
+    $texte = preg_replace("/\n +/", "\n", $texte);
1109
+    $texte = supprimer_tags($texte);
1110
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1111
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1112
+    $texte = str_replace('&#8217;', "'", $texte);
1113 1113
 
1114
-	return $texte;
1114
+    return $texte;
1115 1115
 }
1116 1116
 
1117 1117
 
@@ -1127,23 +1127,23 @@  discard block
 block discarded – undo
1127 1127
  *     Texte avec liens ouvrants
1128 1128
  **/
1129 1129
 function liens_ouvrants($texte) {
1130
-	if (
1131
-		preg_match_all(
1132
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1133
-			$texte,
1134
-			$liens,
1135
-			PREG_PATTERN_ORDER
1136
-		)
1137
-	) {
1138
-		foreach ($liens[0] as $a) {
1139
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1140
-			$ablank = inserer_attribut($a, 'rel', $rel);
1141
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1142
-			$texte = str_replace($a, $ablank, $texte);
1143
-		}
1144
-	}
1145
-
1146
-	return $texte;
1130
+    if (
1131
+        preg_match_all(
1132
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1133
+            $texte,
1134
+            $liens,
1135
+            PREG_PATTERN_ORDER
1136
+        )
1137
+    ) {
1138
+        foreach ($liens[0] as $a) {
1139
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1140
+            $ablank = inserer_attribut($a, 'rel', $rel);
1141
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1142
+            $texte = str_replace($a, $ablank, $texte);
1143
+        }
1144
+    }
1145
+
1146
+    return $texte;
1147 1147
 }
1148 1148
 
1149 1149
 /**
@@ -1153,22 +1153,22 @@  discard block
 block discarded – undo
1153 1153
  * @return string
1154 1154
  */
1155 1155
 function liens_nofollow($texte) {
1156
-	if (stripos($texte, '<a') === false) {
1157
-		return $texte;
1158
-	}
1156
+    if (stripos($texte, '<a') === false) {
1157
+        return $texte;
1158
+    }
1159 1159
 
1160
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1161
-		foreach ($regs[0] as $a) {
1162
-			$rel = extraire_attribut($a, 'rel');
1163
-			if (strpos($rel, 'nofollow') === false) {
1164
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1165
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1166
-				$texte = str_replace($a, $anofollow, $texte);
1167
-			}
1168
-		}
1169
-	}
1160
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1161
+        foreach ($regs[0] as $a) {
1162
+            $rel = extraire_attribut($a, 'rel');
1163
+            if (strpos($rel, 'nofollow') === false) {
1164
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1165
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1166
+                $texte = str_replace($a, $anofollow, $texte);
1167
+            }
1168
+        }
1169
+    }
1170 1170
 
1171
-	return $texte;
1171
+    return $texte;
1172 1172
 }
1173 1173
 
1174 1174
 /**
@@ -1187,12 +1187,12 @@  discard block
 block discarded – undo
1187 1187
  *     Texte sans paraghaphes
1188 1188
  **/
1189 1189
 function PtoBR($texte) {
1190
-	$u = $GLOBALS['meta']['pcre_u'];
1191
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1192
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1193
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1190
+    $u = $GLOBALS['meta']['pcre_u'];
1191
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1192
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1193
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1194 1194
 
1195
-	return $texte;
1195
+    return $texte;
1196 1196
 }
1197 1197
 
1198 1198
 
@@ -1217,14 +1217,14 @@  discard block
 block discarded – undo
1217 1217
  * @return string Texte encadré du style CSS
1218 1218
  */
1219 1219
 function lignes_longues($texte) {
1220
-	if (!strlen(trim($texte))) {
1221
-		return $texte;
1222
-	}
1223
-	include_spip('inc/texte');
1224
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1225
-		'div' : 'span';
1220
+    if (!strlen(trim($texte))) {
1221
+        return $texte;
1222
+    }
1223
+    include_spip('inc/texte');
1224
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1225
+        'div' : 'span';
1226 1226
 
1227
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1227
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1228 1228
 }
1229 1229
 
1230 1230
 /**
@@ -1243,30 +1243,30 @@  discard block
 block discarded – undo
1243 1243
  * @return string Texte en majuscule
1244 1244
  */
1245 1245
 function majuscules($texte) {
1246
-	if (!strlen($texte)) {
1247
-		return '';
1248
-	}
1246
+    if (!strlen($texte)) {
1247
+        return '';
1248
+    }
1249 1249
 
1250
-	// Cas du turc
1251
-	if ($GLOBALS['spip_lang'] == 'tr') {
1252
-		# remplacer hors des tags et des entites
1253
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1254
-			foreach ($regs as $n => $match) {
1255
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1256
-			}
1257
-		}
1250
+    // Cas du turc
1251
+    if ($GLOBALS['spip_lang'] == 'tr') {
1252
+        # remplacer hors des tags et des entites
1253
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1254
+            foreach ($regs as $n => $match) {
1255
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1256
+            }
1257
+        }
1258 1258
 
1259
-		$texte = str_replace('i', '&#304;', $texte);
1259
+        $texte = str_replace('i', '&#304;', $texte);
1260 1260
 
1261
-		if ($regs) {
1262
-			foreach ($regs as $n => $match) {
1263
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1264
-			}
1265
-		}
1266
-	}
1261
+        if ($regs) {
1262
+            foreach ($regs as $n => $match) {
1263
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1264
+            }
1265
+        }
1266
+    }
1267 1267
 
1268
-	// Cas general
1269
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1268
+    // Cas general
1269
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1270 1270
 }
1271 1271
 
1272 1272
 /**
@@ -1284,29 +1284,29 @@  discard block
 block discarded – undo
1284 1284
  * @return string
1285 1285
  **/
1286 1286
 function taille_en_octets($taille) {
1287
-	if (!defined('_KILOBYTE')) {
1288
-		/**
1289
-		 * Définit le nombre d'octets dans un Kilobyte
1290
-		 *
1291
-		 * @var int
1292
-		 **/
1293
-		define('_KILOBYTE', 1024);
1294
-	}
1287
+    if (!defined('_KILOBYTE')) {
1288
+        /**
1289
+         * Définit le nombre d'octets dans un Kilobyte
1290
+         *
1291
+         * @var int
1292
+         **/
1293
+        define('_KILOBYTE', 1024);
1294
+    }
1295 1295
 
1296
-	if ($taille < 1) {
1297
-		return '';
1298
-	}
1299
-	if ($taille < _KILOBYTE) {
1300
-		$taille = _T('taille_octets', ['taille' => $taille]);
1301
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1302
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1303
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1304
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1305
-	} else {
1306
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1307
-	}
1296
+    if ($taille < 1) {
1297
+        return '';
1298
+    }
1299
+    if ($taille < _KILOBYTE) {
1300
+        $taille = _T('taille_octets', ['taille' => $taille]);
1301
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1302
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1303
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1304
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1305
+    } else {
1306
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1307
+    }
1308 1308
 
1309
-	return $taille;
1309
+    return $taille;
1310 1310
 }
1311 1311
 
1312 1312
 
@@ -1328,18 +1328,18 @@  discard block
 block discarded – undo
1328 1328
  *     Texte prêt pour être utilisé en attribut HTML
1329 1329
  **/
1330 1330
 function attribut_html($texte, $textebrut = true) {
1331
-	$u = $GLOBALS['meta']['pcre_u'];
1332
-	if ($textebrut) {
1333
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1334
-	}
1335
-	$texte = texte_backend($texte);
1336
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1331
+    $u = $GLOBALS['meta']['pcre_u'];
1332
+    if ($textebrut) {
1333
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1334
+    }
1335
+    $texte = texte_backend($texte);
1336
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1337 1337
 
1338
-	return preg_replace(
1339
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1340
-		['&', '&#38;'],
1341
-		$texte
1342
-	);
1338
+    return preg_replace(
1339
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1340
+        ['&', '&#38;'],
1341
+        $texte
1342
+    );
1343 1343
 }
1344 1344
 
1345 1345
 
@@ -1359,12 +1359,12 @@  discard block
 block discarded – undo
1359 1359
  *     URL ou chaîne vide
1360 1360
  **/
1361 1361
 function vider_url($url, $entites = true) {
1362
-	# un message pour abs_url
1363
-	$GLOBALS['mode_abs_url'] = 'url';
1364
-	$url = trim($url);
1365
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1362
+    # un message pour abs_url
1363
+    $GLOBALS['mode_abs_url'] = 'url';
1364
+    $url = trim($url);
1365
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1366 1366
 
1367
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1367
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1368 1368
 }
1369 1369
 
1370 1370
 
@@ -1379,10 +1379,10 @@  discard block
 block discarded – undo
1379 1379
  * @return string Adresse email maquillée
1380 1380
  **/
1381 1381
 function antispam($texte) {
1382
-	include_spip('inc/acces');
1383
-	$masque = creer_pass_aleatoire(3);
1382
+    include_spip('inc/acces');
1383
+    $masque = creer_pass_aleatoire(3);
1384 1384
 
1385
-	return preg_replace('/@/', " $masque ", $texte);
1385
+    return preg_replace('/@/', " $masque ", $texte);
1386 1386
 }
1387 1387
 
1388 1388
 /**
@@ -1414,12 +1414,12 @@  discard block
 block discarded – undo
1414 1414
  *     True si on a le droit d'accès, false sinon.
1415 1415
  **/
1416 1416
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1417
-	include_spip('inc/acces');
1418
-	if ($op) {
1419
-		$dir .= " $op $args";
1420
-	}
1417
+    include_spip('inc/acces');
1418
+    if ($op) {
1419
+        $dir .= " $op $args";
1420
+    }
1421 1421
 
1422
-	return verifier_low_sec($id_auteur, $cle, $dir);
1422
+    return verifier_low_sec($id_auteur, $cle, $dir);
1423 1423
 }
1424 1424
 
1425 1425
 /**
@@ -1444,11 +1444,11 @@  discard block
 block discarded – undo
1444 1444
  *     Retourne $texte, sinon $sinon.
1445 1445
  **/
1446 1446
 function sinon($texte, $sinon = '') {
1447
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1448
-		return $texte;
1449
-	} else {
1450
-		return $sinon;
1451
-	}
1447
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1448
+        return $texte;
1449
+    } else {
1450
+        return $sinon;
1451
+    }
1452 1452
 }
1453 1453
 
1454 1454
 /**
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
  * @return mixed
1473 1473
  **/
1474 1474
 function choixsivide($a, $vide, $pasvide) {
1475
-	return $a ? $pasvide : $vide;
1475
+    return $a ? $pasvide : $vide;
1476 1476
 }
1477 1477
 
1478 1478
 /**
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
  * @return mixed
1497 1497
  **/
1498 1498
 function choixsiegal($a1, $a2, $v, $f) {
1499
-	return ($a1 == $a2) ? $v : $f;
1499
+    return ($a1 == $a2) ? $v : $f;
1500 1500
 }
1501 1501
 
1502 1502
 //
@@ -1515,13 +1515,13 @@  discard block
 block discarded – undo
1515 1515
  * @return string
1516 1516
  **/
1517 1517
 function filtrer_ical($texte) {
1518
-	#include_spip('inc/charsets');
1519
-	$texte = html2unicode($texte);
1520
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1521
-	$texte = preg_replace("/\n/", ' ', $texte);
1522
-	$texte = preg_replace('/,/', '\,', $texte);
1518
+    #include_spip('inc/charsets');
1519
+    $texte = html2unicode($texte);
1520
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1521
+    $texte = preg_replace("/\n/", ' ', $texte);
1522
+    $texte = preg_replace('/,/', '\,', $texte);
1523 1523
 
1524
-	return $texte;
1524
+    return $texte;
1525 1525
 }
1526 1526
 
1527 1527
 
@@ -1546,54 +1546,54 @@  discard block
 block discarded – undo
1546 1546
  * @return string
1547 1547
  **/
1548 1548
 function post_autobr($texte, $delim = "\n_ ") {
1549
-	if (!function_exists('echappe_html')) {
1550
-		include_spip('inc/texte_mini');
1551
-	}
1552
-	$texte = str_replace("\r\n", "\r", $texte);
1553
-	$texte = str_replace("\r", "\n", $texte);
1554
-
1555
-	if (preg_match(",\n+$,", $texte, $fin)) {
1556
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1557
-	} else {
1558
-		$fin = '';
1559
-	}
1560
-
1561
-	$texte = echappe_html($texte, '', true);
1562
-
1563
-	// echapper les modeles
1564
-	if (strpos($texte, '<') !== false) {
1565
-		include_spip('inc/lien');
1566
-		if (defined('_PREG_MODELE')) {
1567
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1568
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1569
-		}
1570
-	}
1571
-
1572
-	$debut = '';
1573
-	$suite = $texte;
1574
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1575
-		$debut .= substr($suite, 0, $t - 1);
1576
-		$suite = substr($suite, $t);
1577
-		$car = substr($suite, 0, 1);
1578
-		if (
1579
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1580
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1581
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1582
-		) {
1583
-			$debut .= $delim;
1584
-		} else {
1585
-			$debut .= "\n";
1586
-		}
1587
-		if (preg_match(",^\n+,", $suite, $regs)) {
1588
-			$debut .= $regs[0];
1589
-			$suite = substr($suite, strlen($regs[0]));
1590
-		}
1591
-	}
1592
-	$texte = $debut . $suite;
1593
-
1594
-	$texte = echappe_retour($texte);
1595
-
1596
-	return $texte . $fin;
1549
+    if (!function_exists('echappe_html')) {
1550
+        include_spip('inc/texte_mini');
1551
+    }
1552
+    $texte = str_replace("\r\n", "\r", $texte);
1553
+    $texte = str_replace("\r", "\n", $texte);
1554
+
1555
+    if (preg_match(",\n+$,", $texte, $fin)) {
1556
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1557
+    } else {
1558
+        $fin = '';
1559
+    }
1560
+
1561
+    $texte = echappe_html($texte, '', true);
1562
+
1563
+    // echapper les modeles
1564
+    if (strpos($texte, '<') !== false) {
1565
+        include_spip('inc/lien');
1566
+        if (defined('_PREG_MODELE')) {
1567
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1568
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1569
+        }
1570
+    }
1571
+
1572
+    $debut = '';
1573
+    $suite = $texte;
1574
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1575
+        $debut .= substr($suite, 0, $t - 1);
1576
+        $suite = substr($suite, $t);
1577
+        $car = substr($suite, 0, 1);
1578
+        if (
1579
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1580
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1581
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1582
+        ) {
1583
+            $debut .= $delim;
1584
+        } else {
1585
+            $debut .= "\n";
1586
+        }
1587
+        if (preg_match(",^\n+,", $suite, $regs)) {
1588
+            $debut .= $regs[0];
1589
+            $suite = substr($suite, strlen($regs[0]));
1590
+        }
1591
+    }
1592
+    $texte = $debut . $suite;
1593
+
1594
+    $texte = echappe_retour($texte);
1595
+
1596
+    return $texte . $fin;
1597 1597
 }
1598 1598
 
1599 1599
 
@@ -1634,47 +1634,47 @@  discard block
 block discarded – undo
1634 1634
  * @return string
1635 1635
  **/
1636 1636
 function extraire_idiome($letexte, $lang = null, $options = []) {
1637
-	static $traduire = false;
1638
-	if (
1639
-		$letexte
1640
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1641
-	) {
1642
-		if (!$traduire) {
1643
-			$traduire = charger_fonction('traduire', 'inc');
1644
-			include_spip('inc/lang');
1645
-		}
1646
-		if (!$lang) {
1647
-			$lang = $GLOBALS['spip_lang'];
1648
-		}
1649
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1650
-		if (is_bool($options)) {
1651
-			$options = ['echappe_span' => $options];
1652
-		}
1653
-		if (!isset($options['echappe_span'])) {
1654
-			$options = array_merge($options, ['echappe_span' => false]);
1655
-		}
1656
-
1657
-		foreach ($regs as $reg) {
1658
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1659
-			$desc = $traduire($cle, $lang, true);
1660
-			$l = $desc->langue;
1661
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1662
-			if (strlen($desc->texte)) {
1663
-				$trad = code_echappement($desc->texte, 'idiome', false);
1664
-				if ($l !== $lang) {
1665
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1666
-				}
1667
-				if (lang_dir($l) !== lang_dir($lang)) {
1668
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1669
-				}
1670
-				if (!$options['echappe_span']) {
1671
-					$trad = echappe_retour($trad, 'idiome');
1672
-				}
1673
-				$letexte = str_replace($reg[0], $trad, $letexte);
1674
-			}
1675
-		}
1676
-	}
1677
-	return $letexte;
1637
+    static $traduire = false;
1638
+    if (
1639
+        $letexte
1640
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1641
+    ) {
1642
+        if (!$traduire) {
1643
+            $traduire = charger_fonction('traduire', 'inc');
1644
+            include_spip('inc/lang');
1645
+        }
1646
+        if (!$lang) {
1647
+            $lang = $GLOBALS['spip_lang'];
1648
+        }
1649
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1650
+        if (is_bool($options)) {
1651
+            $options = ['echappe_span' => $options];
1652
+        }
1653
+        if (!isset($options['echappe_span'])) {
1654
+            $options = array_merge($options, ['echappe_span' => false]);
1655
+        }
1656
+
1657
+        foreach ($regs as $reg) {
1658
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1659
+            $desc = $traduire($cle, $lang, true);
1660
+            $l = $desc->langue;
1661
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1662
+            if (strlen($desc->texte)) {
1663
+                $trad = code_echappement($desc->texte, 'idiome', false);
1664
+                if ($l !== $lang) {
1665
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1666
+                }
1667
+                if (lang_dir($l) !== lang_dir($lang)) {
1668
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1669
+                }
1670
+                if (!$options['echappe_span']) {
1671
+                    $trad = echappe_retour($trad, 'idiome');
1672
+                }
1673
+                $letexte = str_replace($reg[0], $trad, $letexte);
1674
+            }
1675
+        }
1676
+    }
1677
+    return $letexte;
1678 1678
 }
1679 1679
 
1680 1680
 /**
@@ -1726,68 +1726,68 @@  discard block
 block discarded – undo
1726 1726
  **/
1727 1727
 function extraire_multi($letexte, $lang = null, $options = []) {
1728 1728
 
1729
-	if (
1730
-		$letexte
1731
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1732
-	) {
1733
-		if (!$lang) {
1734
-			$lang = $GLOBALS['spip_lang'];
1735
-		}
1736
-
1737
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1738
-		if (is_bool($options)) {
1739
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1740
-		}
1741
-		if (!isset($options['echappe_span'])) {
1742
-			$options = array_merge($options, ['echappe_span' => false]);
1743
-		}
1744
-		if (!isset($options['lang_defaut'])) {
1745
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1746
-		}
1747
-
1748
-		include_spip('inc/lang');
1749
-		foreach ($regs as $reg) {
1750
-			// chercher la version de la langue courante
1751
-			$trads = extraire_trads($reg[1]);
1752
-			if ($l = approcher_langue($trads, $lang)) {
1753
-				$trad = $trads[$l];
1754
-			} else {
1755
-				if ($options['lang_defaut'] == 'aucune') {
1756
-					$trad = '';
1757
-				} else {
1758
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1759
-					// ou la premiere dispo
1760
-					// mais typographier le texte selon les regles de celle-ci
1761
-					// Attention aux blocs multi sur plusieurs lignes
1762
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1763
-						$l = key($trads);
1764
-					}
1765
-					$trad = $trads[$l];
1766
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1767
-					$trad = $typographie($trad);
1768
-					// Tester si on echappe en span ou en div
1769
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1770
-					include_spip('inc/texte');
1771
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1772
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1773
-					if ($mode === 'div') {
1774
-						$trad = rtrim($trad) . "\n\n";
1775
-					}
1776
-					$trad = code_echappement($trad, 'multi', false, $mode);
1777
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1778
-					if (lang_dir($l) !== lang_dir($lang)) {
1779
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1780
-					}
1781
-					if (!$options['echappe_span']) {
1782
-						$trad = echappe_retour($trad, 'multi');
1783
-					}
1784
-				}
1785
-			}
1786
-			$letexte = str_replace($reg[0], $trad, $letexte);
1787
-		}
1788
-	}
1789
-
1790
-	return $letexte;
1729
+    if (
1730
+        $letexte
1731
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1732
+    ) {
1733
+        if (!$lang) {
1734
+            $lang = $GLOBALS['spip_lang'];
1735
+        }
1736
+
1737
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1738
+        if (is_bool($options)) {
1739
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1740
+        }
1741
+        if (!isset($options['echappe_span'])) {
1742
+            $options = array_merge($options, ['echappe_span' => false]);
1743
+        }
1744
+        if (!isset($options['lang_defaut'])) {
1745
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1746
+        }
1747
+
1748
+        include_spip('inc/lang');
1749
+        foreach ($regs as $reg) {
1750
+            // chercher la version de la langue courante
1751
+            $trads = extraire_trads($reg[1]);
1752
+            if ($l = approcher_langue($trads, $lang)) {
1753
+                $trad = $trads[$l];
1754
+            } else {
1755
+                if ($options['lang_defaut'] == 'aucune') {
1756
+                    $trad = '';
1757
+                } else {
1758
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1759
+                    // ou la premiere dispo
1760
+                    // mais typographier le texte selon les regles de celle-ci
1761
+                    // Attention aux blocs multi sur plusieurs lignes
1762
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1763
+                        $l = key($trads);
1764
+                    }
1765
+                    $trad = $trads[$l];
1766
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1767
+                    $trad = $typographie($trad);
1768
+                    // Tester si on echappe en span ou en div
1769
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1770
+                    include_spip('inc/texte');
1771
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1772
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1773
+                    if ($mode === 'div') {
1774
+                        $trad = rtrim($trad) . "\n\n";
1775
+                    }
1776
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1777
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1778
+                    if (lang_dir($l) !== lang_dir($lang)) {
1779
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1780
+                    }
1781
+                    if (!$options['echappe_span']) {
1782
+                        $trad = echappe_retour($trad, 'multi');
1783
+                    }
1784
+                }
1785
+            }
1786
+            $letexte = str_replace($reg[0], $trad, $letexte);
1787
+        }
1788
+    }
1789
+
1790
+    return $letexte;
1791 1791
 }
1792 1792
 
1793 1793
 /**
@@ -1803,20 +1803,20 @@  discard block
 block discarded – undo
1803 1803
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1804 1804
  **/
1805 1805
 function extraire_trads($bloc) {
1806
-	$lang = '';
1806
+    $lang = '';
1807 1807
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1808 1808
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1809
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1810
-		$texte = trim($regs[1]);
1811
-		if ($texte or $lang) {
1812
-			$trads[$lang] = $texte;
1813
-		}
1814
-		$bloc = substr($bloc, strlen($regs[0]));
1815
-		$lang = $regs[2];
1816
-	}
1817
-	$trads[$lang] = $bloc;
1809
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1810
+        $texte = trim($regs[1]);
1811
+        if ($texte or $lang) {
1812
+            $trads[$lang] = $texte;
1813
+        }
1814
+        $bloc = substr($bloc, strlen($regs[0]));
1815
+        $lang = $regs[2];
1816
+    }
1817
+    $trads[$lang] = $bloc;
1818 1818
 
1819
-	return $trads;
1819
+    return $trads;
1820 1820
 }
1821 1821
 
1822 1822
 
@@ -1827,7 +1827,7 @@  discard block
 block discarded – undo
1827 1827
  * @return string L'initiale en majuscule
1828 1828
  */
1829 1829
 function filtre_initiale($nom) {
1830
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1830
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1831 1831
 }
1832 1832
 
1833 1833
 
@@ -1872,33 +1872,33 @@  discard block
 block discarded – undo
1872 1872
  *      - null (interne) : si on empile
1873 1873
  **/
1874 1874
 function unique($donnee, $famille = '', $cpt = false) {
1875
-	static $mem = [];
1876
-	// permettre de vider la pile et de la restaurer
1877
-	// pour le calcul de introduction...
1878
-	if ($famille == '_spip_raz_') {
1879
-		$tmp = $mem;
1880
-		$mem = [];
1881
-
1882
-		return $tmp;
1883
-	} elseif ($famille == '_spip_set_') {
1884
-		$mem = $donnee;
1885
-
1886
-		return;
1887
-	}
1888
-	// eviter une notice
1889
-	if (!isset($mem[$famille])) {
1890
-		$mem[$famille] = [];
1891
-	}
1892
-	if ($cpt) {
1893
-		return count($mem[$famille]);
1894
-	}
1895
-	// eviter une notice
1896
-	if (!isset($mem[$famille][$donnee])) {
1897
-		$mem[$famille][$donnee] = 0;
1898
-	}
1899
-	if (!($mem[$famille][$donnee]++)) {
1900
-		return $donnee;
1901
-	}
1875
+    static $mem = [];
1876
+    // permettre de vider la pile et de la restaurer
1877
+    // pour le calcul de introduction...
1878
+    if ($famille == '_spip_raz_') {
1879
+        $tmp = $mem;
1880
+        $mem = [];
1881
+
1882
+        return $tmp;
1883
+    } elseif ($famille == '_spip_set_') {
1884
+        $mem = $donnee;
1885
+
1886
+        return;
1887
+    }
1888
+    // eviter une notice
1889
+    if (!isset($mem[$famille])) {
1890
+        $mem[$famille] = [];
1891
+    }
1892
+    if ($cpt) {
1893
+        return count($mem[$famille]);
1894
+    }
1895
+    // eviter une notice
1896
+    if (!isset($mem[$famille][$donnee])) {
1897
+        $mem[$famille][$donnee] = 0;
1898
+    }
1899
+    if (!($mem[$famille][$donnee]++)) {
1900
+        return $donnee;
1901
+    }
1902 1902
 }
1903 1903
 
1904 1904
 
@@ -1928,16 +1928,16 @@  discard block
 block discarded – undo
1928 1928
  *     Une des valeurs en fonction du compteur.
1929 1929
  **/
1930 1930
 function alterner($i, ...$args) {
1931
-	// recuperer les arguments (attention fonctions un peu space)
1932
-	$num = count($args);
1931
+    // recuperer les arguments (attention fonctions un peu space)
1932
+    $num = count($args);
1933 1933
 
1934
-	if ($num === 1 && is_array($args[0])) {
1935
-		$args = $args[0];
1936
-		$num = count($args);
1937
-	}
1934
+    if ($num === 1 && is_array($args[0])) {
1935
+        $args = $args[0];
1936
+        $num = count($args);
1937
+    }
1938 1938
 
1939
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1940
-	return $args[(intval($i) - 1) % $num];
1939
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1940
+    return $args[(intval($i) - 1) % $num];
1941 1941
 }
1942 1942
 
1943 1943
 
@@ -1962,49 +1962,49 @@  discard block
 block discarded – undo
1962 1962
  *     - Tableau complet (si 2e argument)
1963 1963
  **/
1964 1964
 function extraire_attribut($balise, $attribut, $complet = false) {
1965
-	if (is_array($balise)) {
1966
-		array_walk(
1967
-			$balise,
1968
-			function (&$a, $key, $t) {
1969
-				$a = extraire_attribut($a, $t);
1970
-			},
1971
-			$attribut
1972
-		);
1973
-
1974
-		return $balise;
1975
-	}
1976
-	if (
1977
-		preg_match(
1978
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1979
-			. $attribut
1980
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1981
-			$balise,
1982
-			$r
1983
-		)
1984
-	) {
1985
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1986
-			$r[4] = substr($r[3], 1, -1);
1987
-			$r[3] = $r[3][0];
1988
-		} elseif ($r[3] !== '') {
1989
-			$r[4] = $r[3];
1990
-			$r[3] = '';
1991
-		} else {
1992
-			$r[4] = trim($r[2]);
1993
-		}
1994
-		$att = $r[4];
1995
-		if (strpos($att, '&#') !== false) {
1996
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1997
-		}
1998
-		$att = filtrer_entites($att);
1999
-	} else {
2000
-		$att = null;
2001
-	}
2002
-
2003
-	if ($complet) {
2004
-		return [$att, $r];
2005
-	} else {
2006
-		return $att;
2007
-	}
1965
+    if (is_array($balise)) {
1966
+        array_walk(
1967
+            $balise,
1968
+            function (&$a, $key, $t) {
1969
+                $a = extraire_attribut($a, $t);
1970
+            },
1971
+            $attribut
1972
+        );
1973
+
1974
+        return $balise;
1975
+    }
1976
+    if (
1977
+        preg_match(
1978
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1979
+            . $attribut
1980
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1981
+            $balise,
1982
+            $r
1983
+        )
1984
+    ) {
1985
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1986
+            $r[4] = substr($r[3], 1, -1);
1987
+            $r[3] = $r[3][0];
1988
+        } elseif ($r[3] !== '') {
1989
+            $r[4] = $r[3];
1990
+            $r[3] = '';
1991
+        } else {
1992
+            $r[4] = trim($r[2]);
1993
+        }
1994
+        $att = $r[4];
1995
+        if (strpos($att, '&#') !== false) {
1996
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1997
+        }
1998
+        $att = filtrer_entites($att);
1999
+    } else {
2000
+        $att = null;
2001
+    }
2002
+
2003
+    if ($complet) {
2004
+        return [$att, $r];
2005
+    } else {
2006
+        return $att;
2007
+    }
2008 2008
 }
2009 2009
 
2010 2010
 /**
@@ -2036,37 +2036,37 @@  discard block
 block discarded – undo
2036 2036
  *     Code html modifié
2037 2037
  **/
2038 2038
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
2039
-	// preparer l'attribut
2040
-	// supprimer les &nbsp; etc mais pas les balises html
2041
-	// qui ont un sens dans un attribut value d'un input
2042
-	if ($proteger) {
2043
-		$val = attribut_html($val, false);
2044
-	}
2045
-
2046
-	// echapper les ' pour eviter tout bug
2047
-	$val = str_replace("'", '&#039;', $val);
2048
-	if ($vider and strlen($val) == 0) {
2049
-		$insert = '';
2050
-	} else {
2051
-		$insert = " $attribut='$val'";
2052
-	}
2053
-
2054
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
2055
-
2056
-	if ($old !== null) {
2057
-		// Remplacer l'ancien attribut du meme nom
2058
-		$balise = $r[1] . $insert . $r[5];
2059
-	} else {
2060
-		// preferer une balise " />" (comme <img />)
2061
-		if (preg_match(',/>,', $balise)) {
2062
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2063
-		} // sinon une balise <a ...> ... </a>
2064
-		else {
2065
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2066
-		}
2067
-	}
2068
-
2069
-	return $balise;
2039
+    // preparer l'attribut
2040
+    // supprimer les &nbsp; etc mais pas les balises html
2041
+    // qui ont un sens dans un attribut value d'un input
2042
+    if ($proteger) {
2043
+        $val = attribut_html($val, false);
2044
+    }
2045
+
2046
+    // echapper les ' pour eviter tout bug
2047
+    $val = str_replace("'", '&#039;', $val);
2048
+    if ($vider and strlen($val) == 0) {
2049
+        $insert = '';
2050
+    } else {
2051
+        $insert = " $attribut='$val'";
2052
+    }
2053
+
2054
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
2055
+
2056
+    if ($old !== null) {
2057
+        // Remplacer l'ancien attribut du meme nom
2058
+        $balise = $r[1] . $insert . $r[5];
2059
+    } else {
2060
+        // preferer une balise " />" (comme <img />)
2061
+        if (preg_match(',/>,', $balise)) {
2062
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2063
+        } // sinon une balise <a ...> ... </a>
2064
+        else {
2065
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2066
+        }
2067
+    }
2068
+
2069
+    return $balise;
2070 2070
 }
2071 2071
 
2072 2072
 /**
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
  * @return string Code HTML sans l'attribut
2085 2085
  **/
2086 2086
 function vider_attribut($balise, $attribut) {
2087
-	return inserer_attribut($balise, $attribut, '', false, true);
2087
+    return inserer_attribut($balise, $attribut, '', false, true);
2088 2088
 }
2089 2089
 
2090 2090
 /**
@@ -2096,56 +2096,56 @@  discard block
 block discarded – undo
2096 2096
  * @return string
2097 2097
  */
2098 2098
 function modifier_class($balise, $class, $operation = 'ajouter') {
2099
-	if (is_string($class)) {
2100
-		$class = explode(' ', trim($class));
2101
-	}
2102
-	$class = array_filter($class);
2103
-
2104
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2105
-	if (preg_match(',[^\w-],', implode('', $class))) {
2106
-		return $balise;
2107
-	}
2108
-
2109
-	if ($class) {
2110
-		$class = array_unique($class);
2111
-		$class_courante = extraire_attribut($balise, 'class');
2112
-
2113
-		$class_new = $class_courante;
2114
-		foreach ($class as $c) {
2115
-			if ($c) {
2116
-				$is_class_presente = false;
2117
-				if (
2118
-					strpos($class_courante, $c) !== false
2119
-					and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2120
-				) {
2121
-					$is_class_presente = true;
2122
-				}
2123
-				if (
2124
-					in_array($operation, ['ajouter', 'commuter'])
2125
-					and !$is_class_presente
2126
-				) {
2127
-					$class_new = rtrim($class_new) . ' ' . $c;
2128
-				}
2129
-				elseif (
2130
-					in_array($operation, ['supprimer', 'commuter'])
2131
-					and $is_class_presente
2132
-				) {
2133
-					$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2134
-				}
2135
-			}
2136
-		}
2137
-
2138
-		if ($class_new !== $class_courante) {
2139
-			if (strlen($class_new)) {
2140
-				$balise = inserer_attribut($balise, 'class', $class_new);
2141
-			}
2142
-			elseif ($class_courante) {
2143
-				$balise = vider_attribut($balise, 'class');
2144
-			}
2145
-		}
2146
-	}
2147
-
2148
-	return $balise;
2099
+    if (is_string($class)) {
2100
+        $class = explode(' ', trim($class));
2101
+    }
2102
+    $class = array_filter($class);
2103
+
2104
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2105
+    if (preg_match(',[^\w-],', implode('', $class))) {
2106
+        return $balise;
2107
+    }
2108
+
2109
+    if ($class) {
2110
+        $class = array_unique($class);
2111
+        $class_courante = extraire_attribut($balise, 'class');
2112
+
2113
+        $class_new = $class_courante;
2114
+        foreach ($class as $c) {
2115
+            if ($c) {
2116
+                $is_class_presente = false;
2117
+                if (
2118
+                    strpos($class_courante, $c) !== false
2119
+                    and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2120
+                ) {
2121
+                    $is_class_presente = true;
2122
+                }
2123
+                if (
2124
+                    in_array($operation, ['ajouter', 'commuter'])
2125
+                    and !$is_class_presente
2126
+                ) {
2127
+                    $class_new = rtrim($class_new) . ' ' . $c;
2128
+                }
2129
+                elseif (
2130
+                    in_array($operation, ['supprimer', 'commuter'])
2131
+                    and $is_class_presente
2132
+                ) {
2133
+                    $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2134
+                }
2135
+            }
2136
+        }
2137
+
2138
+        if ($class_new !== $class_courante) {
2139
+            if (strlen($class_new)) {
2140
+                $balise = inserer_attribut($balise, 'class', $class_new);
2141
+            }
2142
+            elseif ($class_courante) {
2143
+                $balise = vider_attribut($balise, 'class');
2144
+            }
2145
+        }
2146
+    }
2147
+
2148
+    return $balise;
2149 2149
 }
2150 2150
 
2151 2151
 /**
@@ -2155,7 +2155,7 @@  discard block
 block discarded – undo
2155 2155
  * @return string
2156 2156
  */
2157 2157
 function ajouter_class($balise, $class) {
2158
-	return modifier_class($balise, $class, 'ajouter');
2158
+    return modifier_class($balise, $class, 'ajouter');
2159 2159
 }
2160 2160
 
2161 2161
 /**
@@ -2165,7 +2165,7 @@  discard block
 block discarded – undo
2165 2165
  * @return string
2166 2166
  */
2167 2167
 function supprimer_class($balise, $class) {
2168
-	return modifier_class($balise, $class, 'supprimer');
2168
+    return modifier_class($balise, $class, 'supprimer');
2169 2169
 }
2170 2170
 
2171 2171
 /**
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
  * @return string
2177 2177
  */
2178 2178
 function commuter_class($balise, $class) {
2179
-	return modifier_class($balise, $class, 'commuter');
2179
+    return modifier_class($balise, $class, 'commuter');
2180 2180
 }
2181 2181
 
2182 2182
 /**
@@ -2187,19 +2187,19 @@  discard block
 block discarded – undo
2187 2187
  * @return string
2188 2188
  */
2189 2189
 function tester_config($id, $mode = '') {
2190
-	include_spip('action/inscrire_auteur');
2190
+    include_spip('action/inscrire_auteur');
2191 2191
 
2192
-	return tester_statut_inscription($mode, $id);
2192
+    return tester_statut_inscription($mode, $id);
2193 2193
 }
2194 2194
 
2195 2195
 //
2196 2196
 // Quelques fonctions de calcul arithmetique
2197 2197
 //
2198 2198
 function floatstr($a) {
2199
- return str_replace(',', '.', (string)floatval($a));
2199
+    return str_replace(',', '.', (string)floatval($a));
2200 2200
 }
2201 2201
 function strize($f, $a, $b) {
2202
- return floatstr($f(floatstr($a), floatstr($b)));
2202
+    return floatstr($f(floatstr($a), floatstr($b)));
2203 2203
 }
2204 2204
 
2205 2205
 /**
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
  * @return int $a+$b
2219 2219
  **/
2220 2220
 function plus($a, $b) {
2221
-	return $a + $b;
2221
+    return $a + $b;
2222 2222
 }
2223 2223
 function strplus($a, $b) {
2224 2224
 return strize('plus', $a, $b);
@@ -2239,7 +2239,7 @@  discard block
 block discarded – undo
2239 2239
  * @return int $a-$b
2240 2240
  **/
2241 2241
 function moins($a, $b) {
2242
-	return $a - $b;
2242
+    return $a - $b;
2243 2243
 }
2244 2244
 function strmoins($a, $b) {
2245 2245
 return strize('moins', $a, $b);
@@ -2262,7 +2262,7 @@  discard block
 block discarded – undo
2262 2262
  * @return int $a*$b
2263 2263
  **/
2264 2264
 function mult($a, $b) {
2265
-	return $a * $b;
2265
+    return $a * $b;
2266 2266
 }
2267 2267
 function strmult($a, $b) {
2268 2268
 return strize('mult', $a, $b);
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
  * @return int $a/$b (ou 0 si $b est nul)
2286 2286
  **/
2287 2287
 function div($a, $b) {
2288
-	return $b ? $a / $b : 0;
2288
+    return $b ? $a / $b : 0;
2289 2289
 }
2290 2290
 function strdiv($a, $b) {
2291 2291
 return strize('div', $a, $b);
@@ -2309,7 +2309,7 @@  discard block
 block discarded – undo
2309 2309
  * @return int ($nb % $mod) + $add
2310 2310
  **/
2311 2311
 function modulo($nb, $mod, $add = 0) {
2312
-	return ($mod ? $nb % $mod : 0) + $add;
2312
+    return ($mod ? $nb % $mod : 0) + $add;
2313 2313
 }
2314 2314
 
2315 2315
 
@@ -2324,24 +2324,24 @@  discard block
 block discarded – undo
2324 2324
  *      - true sinon
2325 2325
  **/
2326 2326
 function nom_acceptable($nom) {
2327
-	if (!is_string($nom)) {
2328
-		return false;
2329
-	}
2330
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2331
-		define('_TAGS_NOM_AUTEUR', '');
2332
-	}
2333
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2334
-	foreach ($tags_acceptes as $tag) {
2335
-		if (strlen($tag)) {
2336
-			$remp1[] = '<' . trim($tag) . '>';
2337
-			$remp1[] = '</' . trim($tag) . '>';
2338
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2339
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2340
-		}
2341
-	}
2342
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2327
+    if (!is_string($nom)) {
2328
+        return false;
2329
+    }
2330
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2331
+        define('_TAGS_NOM_AUTEUR', '');
2332
+    }
2333
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2334
+    foreach ($tags_acceptes as $tag) {
2335
+        if (strlen($tag)) {
2336
+            $remp1[] = '<' . trim($tag) . '>';
2337
+            $remp1[] = '</' . trim($tag) . '>';
2338
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2339
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2340
+        }
2341
+    }
2342
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2343 2343
 
2344
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2344
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2345 2345
 }
2346 2346
 
2347 2347
 
@@ -2357,14 +2357,14 @@  discard block
 block discarded – undo
2357 2357
  *      - renvoie un tableau si l'entree est un tableau
2358 2358
  **/
2359 2359
 function email_valide($adresses) {
2360
-	if (is_array($adresses)) {
2361
-		$adresses = array_map('email_valide', $adresses);
2362
-		$adresses = array_filter($adresses);
2363
-		return $adresses;
2364
-	}
2360
+    if (is_array($adresses)) {
2361
+        $adresses = array_map('email_valide', $adresses);
2362
+        $adresses = array_filter($adresses);
2363
+        return $adresses;
2364
+    }
2365 2365
 
2366
-	$email_valide = charger_fonction('email_valide', 'inc');
2367
-	return $email_valide($adresses);
2366
+    $email_valide = charger_fonction('email_valide', 'inc');
2367
+    return $email_valide($adresses);
2368 2368
 }
2369 2369
 
2370 2370
 /**
@@ -2378,27 +2378,27 @@  discard block
 block discarded – undo
2378 2378
  * @return string Texte
2379 2379
  **/
2380 2380
 function afficher_enclosures($tags) {
2381
-	$s = [];
2382
-	foreach (extraire_balises($tags, 'a') as $tag) {
2383
-		if (
2384
-			extraire_attribut($tag, 'rel') == 'enclosure'
2385
-			and $t = extraire_attribut($tag, 'href')
2386
-		) {
2387
-			$s[] = preg_replace(
2388
-				',>[^<]+</a>,S',
2389
-				'>'
2390
-				. http_img_pack(
2391
-					'attachment-16.png',
2392
-					$t,
2393
-					'title="' . attribut_html($t) . '"'
2394
-				)
2395
-				. '</a>',
2396
-				$tag
2397
-			);
2398
-		}
2399
-	}
2400
-
2401
-	return join('&nbsp;', $s);
2381
+    $s = [];
2382
+    foreach (extraire_balises($tags, 'a') as $tag) {
2383
+        if (
2384
+            extraire_attribut($tag, 'rel') == 'enclosure'
2385
+            and $t = extraire_attribut($tag, 'href')
2386
+        ) {
2387
+            $s[] = preg_replace(
2388
+                ',>[^<]+</a>,S',
2389
+                '>'
2390
+                . http_img_pack(
2391
+                    'attachment-16.png',
2392
+                    $t,
2393
+                    'title="' . attribut_html($t) . '"'
2394
+                )
2395
+                . '</a>',
2396
+                $tag
2397
+            );
2398
+        }
2399
+    }
2400
+
2401
+    return join('&nbsp;', $s);
2402 2402
 }
2403 2403
 
2404 2404
 /**
@@ -2413,15 +2413,15 @@  discard block
 block discarded – undo
2413 2413
  * @return string Liens trouvés
2414 2414
  **/
2415 2415
 function afficher_tags($tags, $rels = 'tag,directory') {
2416
-	$s = [];
2417
-	foreach (extraire_balises($tags, 'a') as $tag) {
2418
-		$rel = extraire_attribut($tag, 'rel');
2419
-		if (strstr(",$rels,", ",$rel,")) {
2420
-			$s[] = $tag;
2421
-		}
2422
-	}
2416
+    $s = [];
2417
+    foreach (extraire_balises($tags, 'a') as $tag) {
2418
+        $rel = extraire_attribut($tag, 'rel');
2419
+        if (strstr(",$rels,", ",$rel,")) {
2420
+            $s[] = $tag;
2421
+        }
2422
+    }
2423 2423
 
2424
-	return join(', ', $s);
2424
+    return join(', ', $s);
2425 2425
 }
2426 2426
 
2427 2427
 
@@ -2443,21 +2443,21 @@  discard block
 block discarded – undo
2443 2443
  * @return string Tag HTML `<a>` avec microformat.
2444 2444
  **/
2445 2445
 function enclosure2microformat($e) {
2446
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2447
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2448
-	}
2449
-	$type = extraire_attribut($e, 'type');
2450
-	if (!$length = extraire_attribut($e, 'length')) {
2451
-		# <media:content : longeur dans fileSize. On tente.
2452
-		$length = extraire_attribut($e, 'fileSize');
2453
-	}
2454
-	$fichier = basename($url);
2446
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2447
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2448
+    }
2449
+    $type = extraire_attribut($e, 'type');
2450
+    if (!$length = extraire_attribut($e, 'length')) {
2451
+        # <media:content : longeur dans fileSize. On tente.
2452
+        $length = extraire_attribut($e, 'fileSize');
2453
+    }
2454
+    $fichier = basename($url);
2455 2455
 
2456
-	return '<a rel="enclosure"'
2457
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2458
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2459
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2460
-	. '>' . $fichier . '</a>';
2456
+    return '<a rel="enclosure"'
2457
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2458
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2459
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2460
+    . '>' . $fichier . '</a>';
2461 2461
 }
2462 2462
 
2463 2463
 /**
@@ -2475,24 +2475,24 @@  discard block
 block discarded – undo
2475 2475
  * @return string Tags RSS `<enclosure>`.
2476 2476
  **/
2477 2477
 function microformat2enclosure($tags) {
2478
-	$enclosures = [];
2479
-	foreach (extraire_balises($tags, 'a') as $e) {
2480
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2481
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2482
-			$type = extraire_attribut($e, 'type');
2483
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2484
-				$length = intval(extraire_attribut($e, 'length'));
2485
-			} # vieux data
2486
-			$fichier = basename($url);
2487
-			$enclosures[] = '<enclosure'
2488
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2489
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2490
-				. ($length ? ' length="' . $length . '"' : '')
2491
-				. ' />';
2492
-		}
2493
-	}
2478
+    $enclosures = [];
2479
+    foreach (extraire_balises($tags, 'a') as $e) {
2480
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2481
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2482
+            $type = extraire_attribut($e, 'type');
2483
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2484
+                $length = intval(extraire_attribut($e, 'length'));
2485
+            } # vieux data
2486
+            $fichier = basename($url);
2487
+            $enclosures[] = '<enclosure'
2488
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2489
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2490
+                . ($length ? ' length="' . $length . '"' : '')
2491
+                . ' />';
2492
+        }
2493
+    }
2494 2494
 
2495
-	return join("\n", $enclosures);
2495
+    return join("\n", $enclosures);
2496 2496
 }
2497 2497
 
2498 2498
 
@@ -2508,16 +2508,16 @@  discard block
 block discarded – undo
2508 2508
  * @return string Tags RSS Atom `<dc:subject>`.
2509 2509
  **/
2510 2510
 function tags2dcsubject($tags) {
2511
-	$subjects = '';
2512
-	foreach (extraire_balises($tags, 'a') as $e) {
2513
-		if (extraire_attribut($e, 'rel') == 'tag') {
2514
-			$subjects .= '<dc:subject>'
2515
-				. texte_backend(textebrut($e))
2516
-				. '</dc:subject>' . "\n";
2517
-		}
2518
-	}
2511
+    $subjects = '';
2512
+    foreach (extraire_balises($tags, 'a') as $e) {
2513
+        if (extraire_attribut($e, 'rel') == 'tag') {
2514
+            $subjects .= '<dc:subject>'
2515
+                . texte_backend(textebrut($e))
2516
+                . '</dc:subject>' . "\n";
2517
+        }
2518
+    }
2519 2519
 
2520
-	return $subjects;
2520
+    return $subjects;
2521 2521
 }
2522 2522
 
2523 2523
 /**
@@ -2546,27 +2546,27 @@  discard block
 block discarded – undo
2546 2546
  *     - Tableau de résultats, si tableau en entrée.
2547 2547
  **/
2548 2548
 function extraire_balise($texte, $tag = 'a') {
2549
-	if (is_array($texte)) {
2550
-		array_walk(
2551
-			$texte,
2552
-			function (&$a, $key, $t) {
2553
-				$a = extraire_balise($a, $t);
2554
-			},
2555
-			$tag
2556
-		);
2557
-
2558
-		return $texte;
2559
-	}
2560
-
2561
-	if (
2562
-		preg_match(
2563
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2564
-			$texte,
2565
-			$regs
2566
-		)
2567
-	) {
2568
-		return $regs[0];
2569
-	}
2549
+    if (is_array($texte)) {
2550
+        array_walk(
2551
+            $texte,
2552
+            function (&$a, $key, $t) {
2553
+                $a = extraire_balise($a, $t);
2554
+            },
2555
+            $tag
2556
+        );
2557
+
2558
+        return $texte;
2559
+    }
2560
+
2561
+    if (
2562
+        preg_match(
2563
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2564
+            $texte,
2565
+            $regs
2566
+        )
2567
+    ) {
2568
+        return $regs[0];
2569
+    }
2570 2570
 }
2571 2571
 
2572 2572
 /**
@@ -2594,30 +2594,30 @@  discard block
 block discarded – undo
2594 2594
  *     - Tableau de résultats, si tableau en entrée.
2595 2595
  **/
2596 2596
 function extraire_balises($texte, $tag = 'a') {
2597
-	if (is_array($texte)) {
2598
-		array_walk(
2599
-			$texte,
2600
-			function (&$a, $key, $t) {
2601
-				$a = extraire_balises($a, $t);
2602
-			},
2603
-			$tag
2604
-		);
2605
-
2606
-		return $texte;
2607
-	}
2608
-
2609
-	if (
2610
-		preg_match_all(
2611
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2612
-			$texte,
2613
-			$regs,
2614
-			PREG_PATTERN_ORDER
2615
-		)
2616
-	) {
2617
-		return $regs[0];
2618
-	} else {
2619
-		return [];
2620
-	}
2597
+    if (is_array($texte)) {
2598
+        array_walk(
2599
+            $texte,
2600
+            function (&$a, $key, $t) {
2601
+                $a = extraire_balises($a, $t);
2602
+            },
2603
+            $tag
2604
+        );
2605
+
2606
+        return $texte;
2607
+    }
2608
+
2609
+    if (
2610
+        preg_match_all(
2611
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2612
+            $texte,
2613
+            $regs,
2614
+            PREG_PATTERN_ORDER
2615
+        )
2616
+    ) {
2617
+        return $regs[0];
2618
+    } else {
2619
+        return [];
2620
+    }
2621 2621
 }
2622 2622
 
2623 2623
 /**
@@ -2646,11 +2646,11 @@  discard block
 block discarded – undo
2646 2646
  *     - `$def` si on n'a pas transmis de tableau
2647 2647
  **/
2648 2648
 function in_any($val, $vals, $def = '') {
2649
-	if (!is_array($vals) and $v = unserialize($vals)) {
2650
-		$vals = $v;
2651
-	}
2649
+    if (!is_array($vals) and $v = unserialize($vals)) {
2650
+        $vals = $v;
2651
+    }
2652 2652
 
2653
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2653
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2654 2654
 }
2655 2655
 
2656 2656
 
@@ -2671,12 +2671,12 @@  discard block
 block discarded – undo
2671 2671
  *     Résultat du calcul
2672 2672
  **/
2673 2673
 function valeur_numerique($expr) {
2674
-	$a = 0;
2675
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2676
-		eval("\$a = $expr;");
2677
-	}
2674
+    $a = 0;
2675
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2676
+        eval("\$a = $expr;");
2677
+    }
2678 2678
 
2679
-	return intval($a);
2679
+    return intval($a);
2680 2680
 }
2681 2681
 
2682 2682
 /**
@@ -2695,7 +2695,7 @@  discard block
 block discarded – undo
2695 2695
  *      Retourne `$a*$b/$c`
2696 2696
  **/
2697 2697
 function regledetrois($a, $b, $c) {
2698
-	return round($a * $b / $c);
2698
+    return round($a * $b / $c);
2699 2699
 }
2700 2700
 
2701 2701
 
@@ -2719,77 +2719,77 @@  discard block
 block discarded – undo
2719 2719
  **/
2720 2720
 function form_hidden($action) {
2721 2721
 
2722
-	$contexte = [];
2723
-	include_spip('inc/urls');
2724
-	if (
2725
-		$p = urls_decoder_url($action, '')
2726
-		and reset($p)
2727
-	) {
2728
-		$fond = array_shift($p);
2729
-		if ($fond != '404') {
2730
-			$contexte = array_shift($p);
2731
-			$contexte['page'] = $fond;
2732
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2733
-		}
2734
-	}
2735
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2736
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2737
-		unset($contexte['type']);
2738
-	}
2739
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2740
-		unset($contexte['type-page']);
2741
-	}
2742
-
2743
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2744
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2745
-	$values = [];
2746
-
2747
-	// d'abord avec celles de l'url
2748
-	if (false !== ($p = strpos($action, '?'))) {
2749
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2750
-			$c = explode('=', $c, 2);
2751
-			$var = array_shift($c);
2752
-			$val = array_shift($c);
2753
-			if ($var) {
2754
-				$val = rawurldecode($val);
2755
-				$var = rawurldecode($var); // decoder les [] eventuels
2756
-				if (preg_match(',\[\]$,S', $var)) {
2757
-					$values[] = [$var, $val];
2758
-				} else {
2759
-					if (!isset($values[$var])) {
2760
-						$values[$var] = [$var, $val];
2761
-					}
2762
-				}
2763
-			}
2764
-		}
2765
-	}
2766
-
2767
-	// ensuite avec celles du contexte, sans doublonner !
2768
-	foreach ($contexte as $var => $val) {
2769
-		if (preg_match(',\[\]$,S', $var)) {
2770
-			$values[] = [$var, $val];
2771
-		} else {
2772
-			if (!isset($values[$var])) {
2773
-				$values[$var] = [$var, $val];
2774
-			}
2775
-		}
2776
-	}
2777
-
2778
-	// puis on rassemble le tout
2779
-	$hidden = [];
2780
-	foreach ($values as $value) {
2781
-		list($var, $val) = $value;
2782
-		$hidden[] = '<input name="'
2783
-			. entites_html($var)
2784
-			. '"'
2785
-			. (is_null($val)
2786
-				? ''
2787
-				: ' value="' . entites_html($val) . '"'
2788
-			)
2789
-			. ' type="hidden"' . "\n/>";
2790
-	}
2791
-
2792
-	return join('', $hidden);
2722
+    $contexte = [];
2723
+    include_spip('inc/urls');
2724
+    if (
2725
+        $p = urls_decoder_url($action, '')
2726
+        and reset($p)
2727
+    ) {
2728
+        $fond = array_shift($p);
2729
+        if ($fond != '404') {
2730
+            $contexte = array_shift($p);
2731
+            $contexte['page'] = $fond;
2732
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2733
+        }
2734
+    }
2735
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2736
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2737
+        unset($contexte['type']);
2738
+    }
2739
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2740
+        unset($contexte['type-page']);
2741
+    }
2742
+
2743
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2744
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2745
+    $values = [];
2746
+
2747
+    // d'abord avec celles de l'url
2748
+    if (false !== ($p = strpos($action, '?'))) {
2749
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2750
+            $c = explode('=', $c, 2);
2751
+            $var = array_shift($c);
2752
+            $val = array_shift($c);
2753
+            if ($var) {
2754
+                $val = rawurldecode($val);
2755
+                $var = rawurldecode($var); // decoder les [] eventuels
2756
+                if (preg_match(',\[\]$,S', $var)) {
2757
+                    $values[] = [$var, $val];
2758
+                } else {
2759
+                    if (!isset($values[$var])) {
2760
+                        $values[$var] = [$var, $val];
2761
+                    }
2762
+                }
2763
+            }
2764
+        }
2765
+    }
2766
+
2767
+    // ensuite avec celles du contexte, sans doublonner !
2768
+    foreach ($contexte as $var => $val) {
2769
+        if (preg_match(',\[\]$,S', $var)) {
2770
+            $values[] = [$var, $val];
2771
+        } else {
2772
+            if (!isset($values[$var])) {
2773
+                $values[$var] = [$var, $val];
2774
+            }
2775
+        }
2776
+    }
2777
+
2778
+    // puis on rassemble le tout
2779
+    $hidden = [];
2780
+    foreach ($values as $value) {
2781
+        list($var, $val) = $value;
2782
+        $hidden[] = '<input name="'
2783
+            . entites_html($var)
2784
+            . '"'
2785
+            . (is_null($val)
2786
+                ? ''
2787
+                : ' value="' . entites_html($val) . '"'
2788
+            )
2789
+            . ' type="hidden"' . "\n/>";
2790
+    }
2791
+
2792
+    return join('', $hidden);
2793 2793
 }
2794 2794
 
2795 2795
 
@@ -2811,7 +2811,7 @@  discard block
 block discarded – undo
2811 2811
  *    - la première valeur du tableau sinon.
2812 2812
  **/
2813 2813
 function filtre_reset($array) {
2814
-	return !is_array($array) ? null : reset($array);
2814
+    return !is_array($array) ? null : reset($array);
2815 2815
 }
2816 2816
 
2817 2817
 /**
@@ -2832,7 +2832,7 @@  discard block
 block discarded – undo
2832 2832
  *    - la dernière valeur du tableau sinon.
2833 2833
  **/
2834 2834
 function filtre_end($array) {
2835
-	return !is_array($array) ? null : end($array);
2835
+    return !is_array($array) ? null : end($array);
2836 2836
 }
2837 2837
 
2838 2838
 /**
@@ -2852,11 +2852,11 @@  discard block
 block discarded – undo
2852 2852
  *
2853 2853
  **/
2854 2854
 function filtre_push($array, $val) {
2855
-	if (!is_array($array) or !array_push($array, $val)) {
2856
-		return '';
2857
-	}
2855
+    if (!is_array($array) or !array_push($array, $val)) {
2856
+        return '';
2857
+    }
2858 2858
 
2859
-	return $array;
2859
+    return $array;
2860 2860
 }
2861 2861
 
2862 2862
 /**
@@ -2875,7 +2875,7 @@  discard block
 block discarded – undo
2875 2875
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2876 2876
  **/
2877 2877
 function filtre_find($array, $val) {
2878
-	return (is_array($array) and in_array($val, $array));
2878
+    return (is_array($array) and in_array($val, $array));
2879 2879
 }
2880 2880
 
2881 2881
 
@@ -2892,15 +2892,15 @@  discard block
 block discarded – undo
2892 2892
  *     Contenu avec urls en absolus
2893 2893
  **/
2894 2894
 function urls_absolues_css($contenu, $source) {
2895
-	$path = suivre_lien(url_absolue($source), './');
2895
+    $path = suivre_lien(url_absolue($source), './');
2896 2896
 
2897
-	return preg_replace_callback(
2898
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2899
-		function ($x) use ($path) {
2900
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2901
-		},
2902
-		$contenu
2903
-	);
2897
+    return preg_replace_callback(
2898
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2899
+        function ($x) use ($path) {
2900
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2901
+        },
2902
+        $contenu
2903
+    );
2904 2904
 }
2905 2905
 
2906 2906
 
@@ -2929,119 +2929,119 @@  discard block
 block discarded – undo
2929 2929
  *     Chemin du fichier CSS inversé
2930 2930
  **/
2931 2931
 function direction_css($css, $voulue = '') {
2932
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2933
-		return $css;
2934
-	}
2935
-	include_spip('inc/lang');
2936
-	// si on a precise le sens voulu en argument, le prendre en compte
2937
-	if ($voulue = strtolower($voulue)) {
2938
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2939
-			$voulue = lang_dir($voulue);
2940
-		}
2941
-	} else {
2942
-		$voulue = lang_dir();
2943
-	}
2944
-
2945
-	$r = count($r) > 1;
2946
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2947
-	$dir = $r ? 'rtl' : 'ltr';
2948
-	$ndir = $r ? 'ltr' : 'rtl';
2949
-
2950
-	if ($voulue == $dir) {
2951
-		return $css;
2952
-	}
2953
-
2954
-	if (
2955
-		// url absolue
2956
-		preg_match(',^https?:,i', $css)
2957
-		// ou qui contient un ?
2958
-		or (($p = strpos($css, '?')) !== false)
2959
-	) {
2960
-		$distant = true;
2961
-		$cssf = parse_url($css);
2962
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2963
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2964
-	} else {
2965
-		$distant = false;
2966
-		$cssf = $css;
2967
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2968
-		//propose (rien a faire dans ce cas)
2969
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2970
-		if (@file_exists($f)) {
2971
-			return $f;
2972
-		}
2973
-	}
2974
-
2975
-	// 2.
2976
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2977
-	$f = $dir_var
2978
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2979
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2980
-
2981
-	// la css peut etre distante (url absolue !)
2982
-	if ($distant) {
2983
-		include_spip('inc/distant');
2984
-		$res = recuperer_url($css);
2985
-		if (!$res or !$contenu = $res['page']) {
2986
-			return $css;
2987
-		}
2988
-	} else {
2989
-		if (
2990
-			(@filemtime($f) > @filemtime($css))
2991
-			and (_VAR_MODE != 'recalcul')
2992
-		) {
2993
-			return $f;
2994
-		}
2995
-		if (!lire_fichier($css, $contenu)) {
2996
-			return $css;
2997
-		}
2998
-	}
2999
-
3000
-
3001
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3002
-	include_spip('lib/csstidy/class.csstidy');
3003
-	$parser = new csstidy();
3004
-	$parser->set_cfg('optimise_shorthands', 0);
3005
-	$parser->set_cfg('reverse_left_and_right', true);
3006
-	$parser->parse($contenu);
3007
-
3008
-	$contenu = $parser->print->plain();
3009
-
3010
-
3011
-	// reperer les @import auxquels il faut propager le direction_css
3012
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3013
-	$src = [];
3014
-	$src_direction_css = [];
3015
-	$src_faux_abs = [];
3016
-	$d = dirname($css);
3017
-	foreach ($regs[1] as $k => $import_css) {
3018
-		$css_direction = direction_css("$d/$import_css", $voulue);
3019
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3020
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3021
-			$css_direction = substr($css_direction, strlen($d) + 1);
3022
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3023
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3024
-			$css_direction = substr($css_direction, strlen($dir_var));
3025
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3026
-			$css_direction = '/@@@@@@/' . $css_direction;
3027
-		}
3028
-		$src[] = $regs[0][$k];
3029
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3030
-	}
3031
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3032
-
3033
-	$contenu = urls_absolues_css($contenu, $css);
3034
-
3035
-	// virer les fausses url absolues que l'on a mis dans les import
3036
-	if (count($src_faux_abs)) {
3037
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3038
-	}
3039
-
3040
-	if (!ecrire_fichier($f, $contenu)) {
3041
-		return $css;
3042
-	}
3043
-
3044
-	return $f;
2932
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2933
+        return $css;
2934
+    }
2935
+    include_spip('inc/lang');
2936
+    // si on a precise le sens voulu en argument, le prendre en compte
2937
+    if ($voulue = strtolower($voulue)) {
2938
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2939
+            $voulue = lang_dir($voulue);
2940
+        }
2941
+    } else {
2942
+        $voulue = lang_dir();
2943
+    }
2944
+
2945
+    $r = count($r) > 1;
2946
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2947
+    $dir = $r ? 'rtl' : 'ltr';
2948
+    $ndir = $r ? 'ltr' : 'rtl';
2949
+
2950
+    if ($voulue == $dir) {
2951
+        return $css;
2952
+    }
2953
+
2954
+    if (
2955
+        // url absolue
2956
+        preg_match(',^https?:,i', $css)
2957
+        // ou qui contient un ?
2958
+        or (($p = strpos($css, '?')) !== false)
2959
+    ) {
2960
+        $distant = true;
2961
+        $cssf = parse_url($css);
2962
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2963
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2964
+    } else {
2965
+        $distant = false;
2966
+        $cssf = $css;
2967
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2968
+        //propose (rien a faire dans ce cas)
2969
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2970
+        if (@file_exists($f)) {
2971
+            return $f;
2972
+        }
2973
+    }
2974
+
2975
+    // 2.
2976
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2977
+    $f = $dir_var
2978
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2979
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2980
+
2981
+    // la css peut etre distante (url absolue !)
2982
+    if ($distant) {
2983
+        include_spip('inc/distant');
2984
+        $res = recuperer_url($css);
2985
+        if (!$res or !$contenu = $res['page']) {
2986
+            return $css;
2987
+        }
2988
+    } else {
2989
+        if (
2990
+            (@filemtime($f) > @filemtime($css))
2991
+            and (_VAR_MODE != 'recalcul')
2992
+        ) {
2993
+            return $f;
2994
+        }
2995
+        if (!lire_fichier($css, $contenu)) {
2996
+            return $css;
2997
+        }
2998
+    }
2999
+
3000
+
3001
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3002
+    include_spip('lib/csstidy/class.csstidy');
3003
+    $parser = new csstidy();
3004
+    $parser->set_cfg('optimise_shorthands', 0);
3005
+    $parser->set_cfg('reverse_left_and_right', true);
3006
+    $parser->parse($contenu);
3007
+
3008
+    $contenu = $parser->print->plain();
3009
+
3010
+
3011
+    // reperer les @import auxquels il faut propager le direction_css
3012
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3013
+    $src = [];
3014
+    $src_direction_css = [];
3015
+    $src_faux_abs = [];
3016
+    $d = dirname($css);
3017
+    foreach ($regs[1] as $k => $import_css) {
3018
+        $css_direction = direction_css("$d/$import_css", $voulue);
3019
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3020
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3021
+            $css_direction = substr($css_direction, strlen($d) + 1);
3022
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3023
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3024
+            $css_direction = substr($css_direction, strlen($dir_var));
3025
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3026
+            $css_direction = '/@@@@@@/' . $css_direction;
3027
+        }
3028
+        $src[] = $regs[0][$k];
3029
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3030
+    }
3031
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3032
+
3033
+    $contenu = urls_absolues_css($contenu, $css);
3034
+
3035
+    // virer les fausses url absolues que l'on a mis dans les import
3036
+    if (count($src_faux_abs)) {
3037
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3038
+    }
3039
+
3040
+    if (!ecrire_fichier($f, $contenu)) {
3041
+        return $css;
3042
+    }
3043
+
3044
+    return $f;
3045 3045
 }
3046 3046
 
3047 3047
 
@@ -3064,46 +3064,46 @@  discard block
 block discarded – undo
3064 3064
  *     - Chemin ou URL du fichier CSS source sinon.
3065 3065
  **/
3066 3066
 function url_absolue_css($css) {
3067
-	if (!preg_match(',\.css$,i', $css, $r)) {
3068
-		return $css;
3069
-	}
3067
+    if (!preg_match(',\.css$,i', $css, $r)) {
3068
+        return $css;
3069
+    }
3070 3070
 
3071
-	$url_absolue_css = url_absolue($css);
3071
+    $url_absolue_css = url_absolue($css);
3072 3072
 
3073
-	$f = basename($css, '.css');
3074
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3075
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3076
-		. '.css';
3073
+    $f = basename($css, '.css');
3074
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3075
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3076
+        . '.css';
3077 3077
 
3078
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3079
-		return $f;
3080
-	}
3078
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3079
+        return $f;
3080
+    }
3081 3081
 
3082
-	if ($url_absolue_css == $css) {
3083
-		if (
3084
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3085
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3086
-		) {
3087
-			include_spip('inc/distant');
3088
-			$contenu = recuperer_url($css);
3089
-			$contenu = $contenu['page'] ?? '';
3090
-			if (!$contenu) {
3091
-				return $css;
3092
-			}
3093
-		}
3094
-	} elseif (!lire_fichier($css, $contenu)) {
3095
-		return $css;
3096
-	}
3082
+    if ($url_absolue_css == $css) {
3083
+        if (
3084
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3085
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3086
+        ) {
3087
+            include_spip('inc/distant');
3088
+            $contenu = recuperer_url($css);
3089
+            $contenu = $contenu['page'] ?? '';
3090
+            if (!$contenu) {
3091
+                return $css;
3092
+            }
3093
+        }
3094
+    } elseif (!lire_fichier($css, $contenu)) {
3095
+        return $css;
3096
+    }
3097 3097
 
3098
-	// passer les url relatives a la css d'origine en url absolues
3099
-	$contenu = urls_absolues_css($contenu, $css);
3098
+    // passer les url relatives a la css d'origine en url absolues
3099
+    $contenu = urls_absolues_css($contenu, $css);
3100 3100
 
3101
-	// ecrire la css
3102
-	if (!ecrire_fichier($f, $contenu)) {
3103
-		return $css;
3104
-	}
3101
+    // ecrire la css
3102
+    if (!ecrire_fichier($f, $contenu)) {
3103
+        return $css;
3104
+    }
3105 3105
 
3106
-	return $f;
3106
+    return $f;
3107 3107
 }
3108 3108
 
3109 3109
 
@@ -3137,24 +3137,24 @@  discard block
 block discarded – undo
3137 3137
  *     Valeur trouvée ou valeur par défaut.
3138 3138
  **/
3139 3139
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3140
-	foreach (explode('/', $cle) as $k) {
3141
-		$table = (is_string($table) ? @unserialize($table) : $table);
3140
+    foreach (explode('/', $cle) as $k) {
3141
+        $table = (is_string($table) ? @unserialize($table) : $table);
3142 3142
 
3143
-		if (is_object($table)) {
3144
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3145
-		} elseif (is_array($table)) {
3146
-			if ($conserver_null) {
3147
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3148
-			} else {
3149
-				$table = ($table[$k] ?? $defaut);
3150
-			}
3151
-		} else {
3152
-			$table = $defaut;
3153
-			break;
3154
-		}
3155
-	}
3143
+        if (is_object($table)) {
3144
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3145
+        } elseif (is_array($table)) {
3146
+            if ($conserver_null) {
3147
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3148
+            } else {
3149
+                $table = ($table[$k] ?? $defaut);
3150
+            }
3151
+        } else {
3152
+            $table = $defaut;
3153
+            break;
3154
+        }
3155
+    }
3156 3156
 
3157
-	return $table;
3157
+    return $table;
3158 3158
 }
3159 3159
 
3160 3160
 /**
@@ -3187,22 +3187,22 @@  discard block
 block discarded – undo
3187 3187
  *     - string : expression trouvée.
3188 3188
  **/
3189 3189
 function filtre_match_dist($texte, $expression, $modif = 'UimsS', $capte = 0) {
3190
-	if (intval($modif) and $capte == 0) {
3191
-		$capte = $modif;
3192
-		$modif = 'UimsS';
3193
-	}
3194
-	$expression = str_replace('\/', '/', $expression);
3195
-	$expression = str_replace('/', '\/', $expression);
3190
+    if (intval($modif) and $capte == 0) {
3191
+        $capte = $modif;
3192
+        $modif = 'UimsS';
3193
+    }
3194
+    $expression = str_replace('\/', '/', $expression);
3195
+    $expression = str_replace('/', '\/', $expression);
3196 3196
 
3197
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3198
-		if (isset($r[$capte])) {
3199
-			return $r[$capte];
3200
-		} else {
3201
-			return true;
3202
-		}
3203
-	}
3197
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3198
+        if (isset($r[$capte])) {
3199
+            return $r[$capte];
3200
+        } else {
3201
+            return true;
3202
+        }
3203
+    }
3204 3204
 
3205
-	return false;
3205
+    return false;
3206 3206
 }
3207 3207
 
3208 3208
 
@@ -3229,10 +3229,10 @@  discard block
 block discarded – undo
3229 3229
  *     Texte
3230 3230
  **/
3231 3231
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3232
-	$expression = str_replace('\/', '/', $expression);
3233
-	$expression = str_replace('/', '\/', $expression);
3232
+    $expression = str_replace('\/', '/', $expression);
3233
+    $expression = str_replace('/', '\/', $expression);
3234 3234
 
3235
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3235
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3236 3236
 }
3237 3237
 
3238 3238
 
@@ -3250,25 +3250,25 @@  discard block
 block discarded – undo
3250 3250
  **/
3251 3251
 function traiter_doublons_documents(&$doublons, $letexte) {
3252 3252
 
3253
-	// Verifier dans le texte & les notes (pas beau, helas)
3254
-	$t = $letexte . $GLOBALS['les_notes'];
3253
+    // Verifier dans le texte & les notes (pas beau, helas)
3254
+    $t = $letexte . $GLOBALS['les_notes'];
3255 3255
 
3256
-	if (
3257
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3258
-		and preg_match_all(
3259
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3260
-			$t,
3261
-			$matches,
3262
-			PREG_PATTERN_ORDER
3263
-		)
3264
-	) {
3265
-		if (!isset($doublons['documents'])) {
3266
-			$doublons['documents'] = '';
3267
-		}
3268
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3269
-	}
3256
+    if (
3257
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3258
+        and preg_match_all(
3259
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3260
+            $t,
3261
+            $matches,
3262
+            PREG_PATTERN_ORDER
3263
+        )
3264
+    ) {
3265
+        if (!isset($doublons['documents'])) {
3266
+            $doublons['documents'] = '';
3267
+        }
3268
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3269
+    }
3270 3270
 
3271
-	return $letexte;
3271
+    return $letexte;
3272 3272
 }
3273 3273
 
3274 3274
 /**
@@ -3282,7 +3282,7 @@  discard block
 block discarded – undo
3282 3282
  * @return string Chaîne vide
3283 3283
  **/
3284 3284
 function vide($texte) {
3285
-	return '';
3285
+    return '';
3286 3286
 }
3287 3287
 
3288 3288
 //
@@ -3311,23 +3311,23 @@  discard block
 block discarded – undo
3311 3311
  *      Code HTML résultant
3312 3312
  **/
3313 3313
 function env_to_params($env, $ignore_params = []) {
3314
-	$ignore_params = array_merge(
3315
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
-		$ignore_params
3317
-	);
3318
-	if (!is_array($env)) {
3319
-		$env = unserialize($env);
3320
-	}
3321
-	$texte = '';
3322
-	if ($env) {
3323
-		foreach ($env as $i => $j) {
3324
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3325
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3326
-			}
3327
-		}
3328
-	}
3329
-
3330
-	return $texte;
3314
+    $ignore_params = array_merge(
3315
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
+        $ignore_params
3317
+    );
3318
+    if (!is_array($env)) {
3319
+        $env = unserialize($env);
3320
+    }
3321
+    $texte = '';
3322
+    if ($env) {
3323
+        foreach ($env as $i => $j) {
3324
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3325
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3326
+            }
3327
+        }
3328
+    }
3329
+
3330
+    return $texte;
3331 3331
 }
3332 3332
 
3333 3333
 /**
@@ -3350,23 +3350,23 @@  discard block
 block discarded – undo
3350 3350
  *      Code HTML résultant
3351 3351
  **/
3352 3352
 function env_to_attributs($env, $ignore_params = []) {
3353
-	$ignore_params = array_merge(
3354
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3355
-		$ignore_params
3356
-	);
3357
-	if (!is_array($env)) {
3358
-		$env = unserialize($env);
3359
-	}
3360
-	$texte = '';
3361
-	if ($env) {
3362
-		foreach ($env as $i => $j) {
3363
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3364
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3365
-			}
3366
-		}
3367
-	}
3353
+    $ignore_params = array_merge(
3354
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3355
+        $ignore_params
3356
+    );
3357
+    if (!is_array($env)) {
3358
+        $env = unserialize($env);
3359
+    }
3360
+    $texte = '';
3361
+    if ($env) {
3362
+        foreach ($env as $i => $j) {
3363
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3364
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3365
+            }
3366
+        }
3367
+    }
3368 3368
 
3369
-	return $texte;
3369
+    return $texte;
3370 3370
 }
3371 3371
 
3372 3372
 
@@ -3384,7 +3384,7 @@  discard block
 block discarded – undo
3384 3384
  * @return string Chaînes concaténés
3385 3385
  **/
3386 3386
 function concat(...$args): string {
3387
-	return join('', $args);
3387
+    return join('', $args);
3388 3388
 }
3389 3389
 
3390 3390
 
@@ -3404,23 +3404,23 @@  discard block
 block discarded – undo
3404 3404
  *     Contenu du ou des fichiers, concaténé
3405 3405
  **/
3406 3406
 function charge_scripts($files, $script = true) {
3407
-	$flux = '';
3408
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3409
-		if (!is_string($file)) {
3410
-			continue;
3411
-		}
3412
-		if ($script) {
3413
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3414
-		}
3415
-		if ($file) {
3416
-			$path = find_in_path($file);
3417
-			if ($path) {
3418
-				$flux .= spip_file_get_contents($path);
3419
-			}
3420
-		}
3421
-	}
3422
-
3423
-	return $flux;
3407
+    $flux = '';
3408
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3409
+        if (!is_string($file)) {
3410
+            continue;
3411
+        }
3412
+        if ($script) {
3413
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3414
+        }
3415
+        if ($file) {
3416
+            $path = find_in_path($file);
3417
+            if ($path) {
3418
+                $flux .= spip_file_get_contents($path);
3419
+            }
3420
+        }
3421
+    }
3422
+
3423
+    return $flux;
3424 3424
 }
3425 3425
 
3426 3426
 /**
@@ -3431,22 +3431,22 @@  discard block
 block discarded – undo
3431 3431
  * @return string
3432 3432
  */
3433 3433
 function http_img_variante_svg_si_possible($img_file) {
3434
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3435
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3436
-	if (
3437
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3438
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3439
-		and file_exists($variante_svg_generique)
3440
-	) {
3441
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3442
-			$img_file = $variante_svg_size;
3443
-		}
3444
-		else {
3445
-			$img_file = $variante_svg_generique;
3446
-		}
3447
-	}
3434
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3435
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3436
+    if (
3437
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3438
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3439
+        and file_exists($variante_svg_generique)
3440
+    ) {
3441
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3442
+            $img_file = $variante_svg_size;
3443
+        }
3444
+        else {
3445
+            $img_file = $variante_svg_generique;
3446
+        }
3447
+    }
3448 3448
 
3449
-	return $img_file;
3449
+    return $img_file;
3450 3450
 }
3451 3451
 
3452 3452
 /**
@@ -3467,54 +3467,54 @@  discard block
 block discarded – undo
3467 3467
  */
3468 3468
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3469 3469
 
3470
-	$img_file = $img;
3471
-	if ($p = strpos($img_file, '?')) {
3472
-		$img_file = substr($img_file, 0, $p);
3473
-	}
3474
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3475
-		$img_file = chemin_image($img);
3476
-	}
3477
-	else {
3478
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3479
-			$img_file = http_img_variante_svg_si_possible($img_file);
3480
-		}
3481
-	}
3482
-	if (stripos($atts, 'width') === false) {
3483
-		// utiliser directement l'info de taille presente dans le nom
3484
-		if (
3485
-			(!isset($options['utiliser_suffixe_size'])
3486
-				or $options['utiliser_suffixe_size'] == true
3487
-			  or strpos($img_file, '-xx.svg') !== false)
3488
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3489
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3490
-		) {
3491
-			$largeur = $hauteur = intval($regs[1]);
3492
-		} else {
3493
-			$taille = taille_image($img_file);
3494
-			list($hauteur, $largeur) = $taille;
3495
-			if (!$hauteur or !$largeur) {
3496
-				return '';
3497
-			}
3498
-		}
3499
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3500
-	}
3501
-
3502
-	if (file_exists($img_file)) {
3503
-		$img_file = timestamp($img_file);
3504
-	}
3505
-	if ($alt === false) {
3506
-		$alt = '';
3507
-	}
3508
-	elseif ($alt or $alt === '') {
3509
-		$alt = " alt='" . attribut_html($alt) . "'";
3510
-	}
3511
-	else {
3512
-		$alt = " alt='" . attribut_html($title) . "'";
3513
-	}
3514
-	return "<img src='$img_file'$alt"
3515
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3516
-	. ' ' . ltrim($atts)
3517
-	. ' />';
3470
+    $img_file = $img;
3471
+    if ($p = strpos($img_file, '?')) {
3472
+        $img_file = substr($img_file, 0, $p);
3473
+    }
3474
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3475
+        $img_file = chemin_image($img);
3476
+    }
3477
+    else {
3478
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3479
+            $img_file = http_img_variante_svg_si_possible($img_file);
3480
+        }
3481
+    }
3482
+    if (stripos($atts, 'width') === false) {
3483
+        // utiliser directement l'info de taille presente dans le nom
3484
+        if (
3485
+            (!isset($options['utiliser_suffixe_size'])
3486
+                or $options['utiliser_suffixe_size'] == true
3487
+              or strpos($img_file, '-xx.svg') !== false)
3488
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3489
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3490
+        ) {
3491
+            $largeur = $hauteur = intval($regs[1]);
3492
+        } else {
3493
+            $taille = taille_image($img_file);
3494
+            list($hauteur, $largeur) = $taille;
3495
+            if (!$hauteur or !$largeur) {
3496
+                return '';
3497
+            }
3498
+        }
3499
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3500
+    }
3501
+
3502
+    if (file_exists($img_file)) {
3503
+        $img_file = timestamp($img_file);
3504
+    }
3505
+    if ($alt === false) {
3506
+        $alt = '';
3507
+    }
3508
+    elseif ($alt or $alt === '') {
3509
+        $alt = " alt='" . attribut_html($alt) . "'";
3510
+    }
3511
+    else {
3512
+        $alt = " alt='" . attribut_html($title) . "'";
3513
+    }
3514
+    return "<img src='$img_file'$alt"
3515
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3516
+    . ' ' . ltrim($atts)
3517
+    . ' />';
3518 3518
 }
3519 3519
 
3520 3520
 /**
@@ -3526,70 +3526,70 @@  discard block
 block discarded – undo
3526 3526
  * @return string
3527 3527
  */
3528 3528
 function http_style_background($img, $att = '', $size = null) {
3529
-	if ($size and is_numeric($size)) {
3530
-		$size = trim($size) . 'px';
3531
-	}
3532
-	return " style='background" .
3533
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3534
-		. ($size ? "background-size:{$size};" : '')
3535
-		. "'";
3529
+    if ($size and is_numeric($size)) {
3530
+        $size = trim($size) . 'px';
3531
+    }
3532
+    return " style='background" .
3533
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3534
+        . ($size ? "background-size:{$size};" : '')
3535
+        . "'";
3536 3536
 }
3537 3537
 
3538 3538
 
3539 3539
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3540
-	$args = [$alt_or_size, $class_or_size, $size];
3541
-	while (is_null(end($args)) and count($args)) {
3542
-		array_pop($args);
3543
-	}
3544
-	if (!count($args)) {
3545
-		return [null, null, null];
3546
-	}
3547
-	if (count($args) < 3) {
3548
-		$maybe_size = array_pop($args);
3549
-		// @2x
3550
-		// @1.5x
3551
-		// 512
3552
-		// 512x*
3553
-		// 512x300
3554
-		if (
3555
-			!strlen($maybe_size)
3556
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3557
-		) {
3558
-			$args[] = $maybe_size;
3559
-			$maybe_size = null;
3560
-		}
3561
-		while (count($args) < 2) {
3562
-			$args[] = null; // default alt or class
3563
-		}
3564
-		$args[] = $maybe_size;
3565
-	}
3566
-	return $args;
3540
+    $args = [$alt_or_size, $class_or_size, $size];
3541
+    while (is_null(end($args)) and count($args)) {
3542
+        array_pop($args);
3543
+    }
3544
+    if (!count($args)) {
3545
+        return [null, null, null];
3546
+    }
3547
+    if (count($args) < 3) {
3548
+        $maybe_size = array_pop($args);
3549
+        // @2x
3550
+        // @1.5x
3551
+        // 512
3552
+        // 512x*
3553
+        // 512x300
3554
+        if (
3555
+            !strlen($maybe_size)
3556
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3557
+        ) {
3558
+            $args[] = $maybe_size;
3559
+            $maybe_size = null;
3560
+        }
3561
+        while (count($args) < 2) {
3562
+            $args[] = null; // default alt or class
3563
+        }
3564
+        $args[] = $maybe_size;
3565
+    }
3566
+    return $args;
3567 3567
 }
3568 3568
 
3569 3569
 function helper_filtre_balise_img_svg_size($img, $size) {
3570
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3571
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3572
-		$coef = floatval(substr($size, 1, -1));
3573
-		list($h, $w) = taille_image($img);
3574
-		$height = intval(round($h / $coef));
3575
-		$width = intval(round($w / $coef));
3576
-	}
3577
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3578
-	else {
3579
-		$size = explode('x', $size, 2);
3580
-		$size = array_map('trim', $size);
3581
-		$height = $width = intval(array_shift($size));
3582
-
3583
-		if (count($size) and reset($size)) {
3584
-			$height = array_shift($size);
3585
-			if ($height === '*') {
3586
-				list($h, $w) = taille_image($img);
3587
-				$height = intval(round($h * $width / $w));
3588
-			}
3589
-		}
3590
-	}
3591
-
3592
-	return [$width, $height];
3570
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3571
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3572
+        $coef = floatval(substr($size, 1, -1));
3573
+        list($h, $w) = taille_image($img);
3574
+        $height = intval(round($h / $coef));
3575
+        $width = intval(round($w / $coef));
3576
+    }
3577
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3578
+    else {
3579
+        $size = explode('x', $size, 2);
3580
+        $size = array_map('trim', $size);
3581
+        $height = $width = intval(array_shift($size));
3582
+
3583
+        if (count($size) and reset($size)) {
3584
+            $height = array_shift($size);
3585
+            if ($height === '*') {
3586
+                list($h, $w) = taille_image($img);
3587
+                $height = intval(round($h * $width / $w));
3588
+            }
3589
+        }
3590
+    }
3591
+
3592
+    return [$width, $height];
3593 3593
 }
3594 3594
 
3595 3595
 /**
@@ -3625,43 +3625,43 @@  discard block
 block discarded – undo
3625 3625
  */
3626 3626
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3627 3627
 
3628
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3629
-
3630
-	$img = trim($img);
3631
-	if (strpos($img, '<img') === 0) {
3632
-		if (!is_null($alt)) {
3633
-			$img = inserer_attribut($img, 'alt', $alt);
3634
-		}
3635
-		if (!is_null($class)) {
3636
-			if (strlen($class)) {
3637
-				$img = inserer_attribut($img, 'class', $class);
3638
-			}
3639
-			else {
3640
-				$img = vider_attribut($img, 'class');
3641
-			}
3642
-		}
3643
-	}
3644
-	else {
3645
-		$img = http_img_pack(
3646
-			$img,
3647
-			$alt,
3648
-			$class ? " class='" . attribut_html($class) . "'" : '',
3649
-			'',
3650
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3651
-		);
3652
-		if (is_null($alt)) {
3653
-			$img = vider_attribut($img, 'alt');
3654
-		}
3655
-	}
3656
-
3657
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3658
-		list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3659
-
3660
-		$img = inserer_attribut($img, 'width', $width);
3661
-		$img = inserer_attribut($img, 'height', $height);
3662
-	}
3663
-
3664
-	return $img;
3628
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3629
+
3630
+    $img = trim($img);
3631
+    if (strpos($img, '<img') === 0) {
3632
+        if (!is_null($alt)) {
3633
+            $img = inserer_attribut($img, 'alt', $alt);
3634
+        }
3635
+        if (!is_null($class)) {
3636
+            if (strlen($class)) {
3637
+                $img = inserer_attribut($img, 'class', $class);
3638
+            }
3639
+            else {
3640
+                $img = vider_attribut($img, 'class');
3641
+            }
3642
+        }
3643
+    }
3644
+    else {
3645
+        $img = http_img_pack(
3646
+            $img,
3647
+            $alt,
3648
+            $class ? " class='" . attribut_html($class) . "'" : '',
3649
+            '',
3650
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3651
+        );
3652
+        if (is_null($alt)) {
3653
+            $img = vider_attribut($img, 'alt');
3654
+        }
3655
+    }
3656
+
3657
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3658
+        list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3659
+
3660
+        $img = inserer_attribut($img, 'width', $width);
3661
+        $img = inserer_attribut($img, 'height', $height);
3662
+    }
3663
+
3664
+    return $img;
3665 3665
 }
3666 3666
 
3667 3667
 
@@ -3695,67 +3695,67 @@  discard block
 block discarded – undo
3695 3695
  */
3696 3696
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3697 3697
 
3698
-	$img = trim($img);
3699
-	$img_file = $img;
3700
-	if (strpos($img, '<svg') === false) {
3701
-		if ($p = strpos($img_file, '?')) {
3702
-			$img_file = substr($img_file, 0, $p);
3703
-		}
3698
+    $img = trim($img);
3699
+    $img_file = $img;
3700
+    if (strpos($img, '<svg') === false) {
3701
+        if ($p = strpos($img_file, '?')) {
3702
+            $img_file = substr($img_file, 0, $p);
3703
+        }
3704 3704
 
3705
-		if (!$img_file or !$svg = file_get_contents($img_file)) {
3706
-			return '';
3707
-		}
3708
-	}
3705
+        if (!$img_file or !$svg = file_get_contents($img_file)) {
3706
+            return '';
3707
+        }
3708
+    }
3709 3709
 
3710
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3711
-		return '';
3712
-	}
3710
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3711
+        return '';
3712
+    }
3713 3713
 
3714
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3714
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3715 3715
 
3716
-	$balise_svg = $match[0];
3717
-	$balise_svg_source = $balise_svg;
3716
+    $balise_svg = $match[0];
3717
+    $balise_svg_source = $balise_svg;
3718 3718
 
3719
-	// entete XML à supprimer
3720
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3719
+    // entete XML à supprimer
3720
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3721 3721
 
3722
-	// IE est toujours mon ami
3723
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3722
+    // IE est toujours mon ami
3723
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3724 3724
 
3725
-	// regler la classe
3726
-	if (!is_null($class)) {
3727
-		if (strlen($class)) {
3728
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3729
-		}
3730
-		else {
3731
-			$balise_svg = vider_attribut($balise_svg, 'class');
3732
-		}
3733
-	}
3725
+    // regler la classe
3726
+    if (!is_null($class)) {
3727
+        if (strlen($class)) {
3728
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3729
+        }
3730
+        else {
3731
+            $balise_svg = vider_attribut($balise_svg, 'class');
3732
+        }
3733
+    }
3734 3734
 
3735
-	// regler le alt
3736
-	if ($alt) {
3737
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3738
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3739
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3740
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3741
-		$balise_svg .= $title;
3742
-	}
3743
-	else {
3744
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3745
-	}
3735
+    // regler le alt
3736
+    if ($alt) {
3737
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3738
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3739
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3740
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3741
+        $balise_svg .= $title;
3742
+    }
3743
+    else {
3744
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3745
+    }
3746 3746
 
3747
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3747
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3748 3748
 
3749
-	if (!is_null($size) and strlen($size = trim($size))) {
3750
-		list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3749
+    if (!is_null($size) and strlen($size = trim($size))) {
3750
+        list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3751 3751
 
3752
-		if (!function_exists('svg_redimensionner')) {
3753
-			include_spip('inc/svg');
3754
-		}
3755
-		$svg = svg_redimensionner($svg, $width, $height);
3756
-	}
3752
+        if (!function_exists('svg_redimensionner')) {
3753
+            include_spip('inc/svg');
3754
+        }
3755
+        $svg = svg_redimensionner($svg, $width, $height);
3756
+    }
3757 3757
 
3758
-	return $svg;
3758
+    return $svg;
3759 3759
 }
3760 3760
 
3761 3761
 
@@ -3781,18 +3781,18 @@  discard block
 block discarded – undo
3781 3781
  *     Code HTML résultant
3782 3782
  **/
3783 3783
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3784
-	$texte = '';
3785
-	if (is_array($tableau)) {
3786
-		foreach ($tableau as $k => $v) {
3787
-			$res = recuperer_fond(
3788
-				'modeles/' . $modele,
3789
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3790
-			);
3791
-			$texte .= $res;
3792
-		}
3793
-	}
3784
+    $texte = '';
3785
+    if (is_array($tableau)) {
3786
+        foreach ($tableau as $k => $v) {
3787
+            $res = recuperer_fond(
3788
+                'modeles/' . $modele,
3789
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3790
+            );
3791
+            $texte .= $res;
3792
+        }
3793
+    }
3794 3794
 
3795
-	return $texte;
3795
+    return $texte;
3796 3796
 }
3797 3797
 
3798 3798
 
@@ -3817,37 +3817,37 @@  discard block
 block discarded – undo
3817 3817
  *         - tout : retourne toutes les informations du plugin actif
3818 3818
  **/
3819 3819
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3820
-	include_spip('inc/plugin');
3821
-	$plugin = strtoupper($plugin);
3822
-	$plugins_actifs = liste_plugin_actifs();
3823
-
3824
-	if (!$plugin) {
3825
-		return serialize(array_keys($plugins_actifs));
3826
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3827
-		return '';
3828
-	} elseif (($type_info == 'est_actif') and !$reload) {
3829
-		return $plugins_actifs[$plugin] ? 1 : 0;
3830
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3831
-		return $plugins_actifs[$plugin][$type_info];
3832
-	} else {
3833
-		$get_infos = charger_fonction('get_infos', 'plugins');
3834
-		// On prend en compte les extensions
3835
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3836
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3837
-		} else {
3838
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3839
-		}
3840
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3841
-			return '';
3842
-		}
3843
-		if ($type_info == 'tout') {
3844
-			return $infos;
3845
-		} elseif ($type_info == 'est_actif') {
3846
-			return $infos ? 1 : 0;
3847
-		} else {
3848
-			return strval($infos[$type_info]);
3849
-		}
3850
-	}
3820
+    include_spip('inc/plugin');
3821
+    $plugin = strtoupper($plugin);
3822
+    $plugins_actifs = liste_plugin_actifs();
3823
+
3824
+    if (!$plugin) {
3825
+        return serialize(array_keys($plugins_actifs));
3826
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3827
+        return '';
3828
+    } elseif (($type_info == 'est_actif') and !$reload) {
3829
+        return $plugins_actifs[$plugin] ? 1 : 0;
3830
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3831
+        return $plugins_actifs[$plugin][$type_info];
3832
+    } else {
3833
+        $get_infos = charger_fonction('get_infos', 'plugins');
3834
+        // On prend en compte les extensions
3835
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3836
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3837
+        } else {
3838
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3839
+        }
3840
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3841
+            return '';
3842
+        }
3843
+        if ($type_info == 'tout') {
3844
+            return $infos;
3845
+        } elseif ($type_info == 'est_actif') {
3846
+            return $infos ? 1 : 0;
3847
+        } else {
3848
+            return strval($infos[$type_info]);
3849
+        }
3850
+    }
3851 3851
 }
3852 3852
 
3853 3853
 
@@ -3874,9 +3874,9 @@  discard block
 block discarded – undo
3874 3874
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3875 3875
  */
3876 3876
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3877
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3877
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3878 3878
 
3879
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3879
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3880 3880
 }
3881 3881
 
3882 3882
 
@@ -3906,19 +3906,19 @@  discard block
 block discarded – undo
3906 3906
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3907 3907
  */
3908 3908
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3909
-	static $puce_statut = null;
3910
-	if (!$puce_statut) {
3911
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3912
-	}
3909
+    static $puce_statut = null;
3910
+    if (!$puce_statut) {
3911
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3912
+    }
3913 3913
 
3914
-	return $puce_statut(
3915
-		$id_objet,
3916
-		$statut,
3917
-		$id_parent,
3918
-		$objet,
3919
-		false,
3920
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3921
-	);
3914
+    return $puce_statut(
3915
+        $id_objet,
3916
+        $statut,
3917
+        $id_parent,
3918
+        $objet,
3919
+        false,
3920
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3921
+    );
3922 3922
 }
3923 3923
 
3924 3924
 
@@ -3945,97 +3945,97 @@  discard block
 block discarded – undo
3945 3945
  *   hash du contexte
3946 3946
  */
3947 3947
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3948
-	if (
3949
-		is_string($c)
3950
-		and @unserialize($c) !== false
3951
-	) {
3952
-		$c = unserialize($c);
3953
-	}
3954
-
3955
-	// supprimer les parametres debut_x
3956
-	// pour que la pagination ajax ne soit pas plantee
3957
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3958
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3959
-	if (is_array($c)) {
3960
-		foreach ($c as $k => $v) {
3961
-			if (strpos($k, 'debut_') === 0) {
3962
-				unset($c[$k]);
3963
-			}
3964
-		}
3965
-	}
3966
-
3967
-	if (!function_exists('calculer_cle_action')) {
3968
-		include_spip('inc/securiser_action');
3969
-	}
3970
-
3971
-	$c = serialize($c);
3972
-	$cle = calculer_cle_action($form . $c);
3973
-	$c = "$cle:$c";
3974
-
3975
-	// on ne stocke pas les contextes dans des fichiers en cache
3976
-	// par defaut, sauf si cette configuration a été forcée
3977
-	// OU que la longueur de l’argument géneré est plus long
3978
-	// que ce qui est toléré.
3979
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3980
-	if (!$cache_contextes_ajax) {
3981
-		$env = $c;
3982
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3983
-			$env = gzdeflate($env);
3984
-		}
3985
-		$env = _xor($env);
3986
-		$env = base64_encode($env);
3987
-		$len = strlen($env);
3988
-		// Si l’url est trop longue pour le navigateur
3989
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3990
-		if ($len > $max_len) {
3991
-			$cache_contextes_ajax = true;
3992
-			spip_log(
3993
-				'Contextes AJAX forces en fichiers !'
3994
-				. ' Cela arrive lorsque la valeur du contexte'
3995
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3996
-				_LOG_AVERTISSEMENT
3997
-			);
3998
-		}
3999
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4000
-		elseif (
4001
-			$max_len = @ini_get('suhosin.get.max_value_length')
4002
-			and $max_len < $len
4003
-		) {
4004
-			$cache_contextes_ajax = true;
4005
-			spip_log('Contextes AJAX forces en fichiers !'
4006
-				. ' Cela arrive lorsque la valeur du contexte'
4007
-				. ' depasse la longueur maximale autorisee par Suhosin'
4008
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4009
-				. ' Vous devriez modifier les parametres de Suhosin'
4010
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4011
-		}
4012
-	}
4013
-
4014
-	if ($cache_contextes_ajax) {
4015
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4016
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4017
-		$md5 = md5($c);
4018
-		ecrire_fichier("$dir/c$md5", $c);
4019
-		$env = $md5;
4020
-	}
4021
-
4022
-	if ($emboite === null) {
4023
-		return $env;
4024
-	}
4025
-	if (!trim($emboite)) {
4026
-		return '';
4027
-	}
4028
-	// toujours encoder l'url source dans le bloc ajax
4029
-	$r = self();
4030
-	$r = ' data-origin="' . $r . '"';
4031
-	$class = 'ajaxbloc';
4032
-	if ($ajaxid and is_string($ajaxid)) {
4033
-		// ajaxid est normalement conforme a un nom de classe css
4034
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4035
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4036
-	}
4037
-
4038
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3948
+    if (
3949
+        is_string($c)
3950
+        and @unserialize($c) !== false
3951
+    ) {
3952
+        $c = unserialize($c);
3953
+    }
3954
+
3955
+    // supprimer les parametres debut_x
3956
+    // pour que la pagination ajax ne soit pas plantee
3957
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3958
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3959
+    if (is_array($c)) {
3960
+        foreach ($c as $k => $v) {
3961
+            if (strpos($k, 'debut_') === 0) {
3962
+                unset($c[$k]);
3963
+            }
3964
+        }
3965
+    }
3966
+
3967
+    if (!function_exists('calculer_cle_action')) {
3968
+        include_spip('inc/securiser_action');
3969
+    }
3970
+
3971
+    $c = serialize($c);
3972
+    $cle = calculer_cle_action($form . $c);
3973
+    $c = "$cle:$c";
3974
+
3975
+    // on ne stocke pas les contextes dans des fichiers en cache
3976
+    // par defaut, sauf si cette configuration a été forcée
3977
+    // OU que la longueur de l’argument géneré est plus long
3978
+    // que ce qui est toléré.
3979
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3980
+    if (!$cache_contextes_ajax) {
3981
+        $env = $c;
3982
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3983
+            $env = gzdeflate($env);
3984
+        }
3985
+        $env = _xor($env);
3986
+        $env = base64_encode($env);
3987
+        $len = strlen($env);
3988
+        // Si l’url est trop longue pour le navigateur
3989
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3990
+        if ($len > $max_len) {
3991
+            $cache_contextes_ajax = true;
3992
+            spip_log(
3993
+                'Contextes AJAX forces en fichiers !'
3994
+                . ' Cela arrive lorsque la valeur du contexte'
3995
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3996
+                _LOG_AVERTISSEMENT
3997
+            );
3998
+        }
3999
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4000
+        elseif (
4001
+            $max_len = @ini_get('suhosin.get.max_value_length')
4002
+            and $max_len < $len
4003
+        ) {
4004
+            $cache_contextes_ajax = true;
4005
+            spip_log('Contextes AJAX forces en fichiers !'
4006
+                . ' Cela arrive lorsque la valeur du contexte'
4007
+                . ' depasse la longueur maximale autorisee par Suhosin'
4008
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4009
+                . ' Vous devriez modifier les parametres de Suhosin'
4010
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4011
+        }
4012
+    }
4013
+
4014
+    if ($cache_contextes_ajax) {
4015
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4016
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4017
+        $md5 = md5($c);
4018
+        ecrire_fichier("$dir/c$md5", $c);
4019
+        $env = $md5;
4020
+    }
4021
+
4022
+    if ($emboite === null) {
4023
+        return $env;
4024
+    }
4025
+    if (!trim($emboite)) {
4026
+        return '';
4027
+    }
4028
+    // toujours encoder l'url source dans le bloc ajax
4029
+    $r = self();
4030
+    $r = ' data-origin="' . $r . '"';
4031
+    $class = 'ajaxbloc';
4032
+    if ($ajaxid and is_string($ajaxid)) {
4033
+        // ajaxid est normalement conforme a un nom de classe css
4034
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4035
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4036
+    }
4037
+
4038
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4039 4039
 }
4040 4040
 
4041 4041
 /**
@@ -4055,37 +4055,37 @@  discard block
 block discarded – undo
4055 4055
  *   - false : erreur de décodage
4056 4056
  */
4057 4057
 function decoder_contexte_ajax($c, $form = '') {
4058
-	if (!function_exists('calculer_cle_action')) {
4059
-		include_spip('inc/securiser_action');
4060
-	}
4061
-	if (
4062
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4063
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4064
-		and lire_fichier("$dir/c$c", $contexte)
4065
-	) {
4066
-		$c = $contexte;
4067
-	} else {
4068
-		$c = @base64_decode($c);
4069
-		$c = _xor($c);
4070
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4071
-			$c = @gzinflate($c);
4072
-		}
4073
-	}
4074
-
4075
-	// extraire la signature en debut de contexte
4076
-	// et la verifier avant de deserializer
4077
-	// format : signature:donneesserializees
4078
-	if ($p = strpos($c, ':')) {
4079
-		$cle = substr($c, 0, $p);
4080
-		$c = substr($c, $p + 1);
4081
-
4082
-		if ($cle == calculer_cle_action($form . $c)) {
4083
-			$env = @unserialize($c);
4084
-			return $env;
4085
-		}
4086
-	}
4087
-
4088
-	return false;
4058
+    if (!function_exists('calculer_cle_action')) {
4059
+        include_spip('inc/securiser_action');
4060
+    }
4061
+    if (
4062
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4063
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4064
+        and lire_fichier("$dir/c$c", $contexte)
4065
+    ) {
4066
+        $c = $contexte;
4067
+    } else {
4068
+        $c = @base64_decode($c);
4069
+        $c = _xor($c);
4070
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4071
+            $c = @gzinflate($c);
4072
+        }
4073
+    }
4074
+
4075
+    // extraire la signature en debut de contexte
4076
+    // et la verifier avant de deserializer
4077
+    // format : signature:donneesserializees
4078
+    if ($p = strpos($c, ':')) {
4079
+        $cle = substr($c, 0, $p);
4080
+        $c = substr($c, $p + 1);
4081
+
4082
+        if ($cle == calculer_cle_action($form . $c)) {
4083
+            $env = @unserialize($c);
4084
+            return $env;
4085
+        }
4086
+    }
4087
+
4088
+    return false;
4089 4089
 }
4090 4090
 
4091 4091
 
@@ -4103,20 +4103,20 @@  discard block
 block discarded – undo
4103 4103
  *    Message décrypté ou encrypté
4104 4104
  **/
4105 4105
 function _xor($message, $key = null) {
4106
-	if (is_null($key)) {
4107
-		if (!function_exists('calculer_cle_action')) {
4108
-			include_spip('inc/securiser_action');
4109
-		}
4110
-		$key = pack('H*', calculer_cle_action('_xor'));
4111
-	}
4106
+    if (is_null($key)) {
4107
+        if (!function_exists('calculer_cle_action')) {
4108
+            include_spip('inc/securiser_action');
4109
+        }
4110
+        $key = pack('H*', calculer_cle_action('_xor'));
4111
+    }
4112 4112
 
4113
-	$keylen = strlen($key);
4114
-	$messagelen = strlen($message);
4115
-	for ($i = 0; $i < $messagelen; $i++) {
4116
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4117
-	}
4113
+    $keylen = strlen($key);
4114
+    $messagelen = strlen($message);
4115
+    for ($i = 0; $i < $messagelen; $i++) {
4116
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4117
+    }
4118 4118
 
4119
-	return $message;
4119
+    return $message;
4120 4120
 }
4121 4121
 
4122 4122
 /**
@@ -4130,7 +4130,7 @@  discard block
 block discarded – undo
4130 4130
  * @return string
4131 4131
  */
4132 4132
 function url_reponse_forum($texte) {
4133
- return $texte;
4133
+    return $texte;
4134 4134
 }
4135 4135
 
4136 4136
 /**
@@ -4144,7 +4144,7 @@  discard block
 block discarded – undo
4144 4144
  * @return string
4145 4145
  */
4146 4146
 function url_rss_forum($texte) {
4147
- return $texte;
4147
+    return $texte;
4148 4148
 }
4149 4149
 
4150 4150
 
@@ -4183,37 +4183,37 @@  discard block
 block discarded – undo
4183 4183
  *   Code HTML
4184 4184
  */
4185 4185
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4186
-	if ($on) {
4187
-		$bal = 'strong';
4188
-		$class = '';
4189
-		$att = '';
4190
-		// si $on passe la balise et optionnelement une ou ++classe
4191
-		// a.active span.selected.active etc....
4192
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4193
-			$on = explode('.', $on);
4194
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4195
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4196
-				$bal = array_shift($on);
4197
-				$class = implode(' ', $on);
4198
-				if ($bal == 'a') {
4199
-					$att = 'href="#" ';
4200
-				}
4201
-			}
4202
-		}
4203
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4204
-	} else {
4205
-		$bal = 'a';
4206
-		$att = "href='$url'"
4207
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4208
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4209
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4210
-			. $evt;
4211
-	}
4212
-	if ($libelle === null) {
4213
-		$libelle = $url;
4214
-	}
4215
-
4216
-	return "<$bal $att>$libelle</$bal>";
4186
+    if ($on) {
4187
+        $bal = 'strong';
4188
+        $class = '';
4189
+        $att = '';
4190
+        // si $on passe la balise et optionnelement une ou ++classe
4191
+        // a.active span.selected.active etc....
4192
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4193
+            $on = explode('.', $on);
4194
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4195
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4196
+                $bal = array_shift($on);
4197
+                $class = implode(' ', $on);
4198
+                if ($bal == 'a') {
4199
+                    $att = 'href="#" ';
4200
+                }
4201
+            }
4202
+        }
4203
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4204
+    } else {
4205
+        $bal = 'a';
4206
+        $att = "href='$url'"
4207
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4208
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4209
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4210
+            . $evt;
4211
+    }
4212
+    if ($libelle === null) {
4213
+        $libelle = $url;
4214
+    }
4215
+
4216
+    return "<$bal $att>$libelle</$bal>";
4217 4217
 }
4218 4218
 
4219 4219
 
@@ -4230,39 +4230,39 @@  discard block
 block discarded – undo
4230 4230
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4231 4231
  */
4232 4232
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4233
-	static $local_singulier_ou_pluriel = [];
4234
-
4235
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4236
-	if (!is_numeric($nb) or $nb == 0) {
4237
-		return '';
4238
-	}
4239
-	if (!is_array($vars)) {
4240
-		return '';
4241
-	}
4242
-
4243
-	$langue = $GLOBALS['spip_lang'];
4244
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4245
-		$local_singulier_ou_pluriel[$langue] = false;
4246
-		if (
4247
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4248
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4249
-		) {
4250
-			$local_singulier_ou_pluriel[$langue] = $f;
4251
-		}
4252
-	}
4253
-
4254
-	// si on a une surcharge on l'utilise
4255
-	if ($local_singulier_ou_pluriel[$langue]) {
4256
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4257
-	}
4258
-
4259
-	// sinon traitement par defaut
4260
-	$vars[$var] = $nb;
4261
-	if ($nb >= 2) {
4262
-		return _T($chaine_plusieurs, $vars);
4263
-	} else {
4264
-		return _T($chaine_un, $vars);
4265
-	}
4233
+    static $local_singulier_ou_pluriel = [];
4234
+
4235
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4236
+    if (!is_numeric($nb) or $nb == 0) {
4237
+        return '';
4238
+    }
4239
+    if (!is_array($vars)) {
4240
+        return '';
4241
+    }
4242
+
4243
+    $langue = $GLOBALS['spip_lang'];
4244
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4245
+        $local_singulier_ou_pluriel[$langue] = false;
4246
+        if (
4247
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4248
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4249
+        ) {
4250
+            $local_singulier_ou_pluriel[$langue] = $f;
4251
+        }
4252
+    }
4253
+
4254
+    // si on a une surcharge on l'utilise
4255
+    if ($local_singulier_ou_pluriel[$langue]) {
4256
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4257
+    }
4258
+
4259
+    // sinon traitement par defaut
4260
+    $vars[$var] = $nb;
4261
+    if ($nb >= 2) {
4262
+        return _T($chaine_plusieurs, $vars);
4263
+    } else {
4264
+        return _T($chaine_un, $vars);
4265
+    }
4266 4266
 }
4267 4267
 
4268 4268
 
@@ -4290,73 +4290,73 @@  discard block
 block discarded – undo
4290 4290
  */
4291 4291
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4292 4292
 
4293
-	$class_lien = $class_bouton = $class;
4294
-
4295
-	// Normaliser la fonction et compléter la classe en fonction
4296
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4297
-		$class_lien .= ' danger';
4298
-		$class_bouton .= ' btn_danger';
4299
-	} elseif ($fonction == 'rien.gif') {
4300
-		$fonction = '';
4301
-	} elseif ($fonction == 'delsafe') {
4302
-		$fonction = 'del';
4303
-	}
4304
-
4305
-	$fond_origine = $fond;
4306
-	// Remappage des icone : article-24.png+new => article-new-24.png
4307
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4308
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4309
-	}
4310
-
4311
-	// Ajouter le type d'objet dans la classe
4312
-	$objet_type = substr(basename($fond), 0, -4);
4313
-	$class_lien .= " $objet_type";
4314
-	$class_bouton .= " $objet_type";
4315
-
4316
-	// Texte
4317
-	$alt = attribut_html($texte);
4318
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4319
-
4320
-	// Liens : préparer les classes ajax
4321
-	$ajax = '';
4322
-	if ($type === 'lien') {
4323
-		if (strpos($class_lien, 'ajax') !== false) {
4324
-			$ajax = 'ajax';
4325
-			if (strpos($class_lien, 'preload') !== false) {
4326
-				$ajax .= ' preload';
4327
-			}
4328
-			if (strpos($class_lien, 'nocache') !== false) {
4329
-				$ajax .= ' nocache';
4330
-			}
4331
-			$ajax = " class='$ajax'";
4332
-		}
4333
-	}
4334
-
4335
-	// Repérer la taille et l'ajouter dans la classe
4336
-	$size = 24;
4337
-	if (
4338
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4339
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4340
-	) {
4341
-		$size = $match[1];
4342
-	}
4343
-	$class_lien .= " s$size";
4344
-	$class_bouton .= " s$size";
4345
-
4346
-	// Icône
4347
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4348
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4349
-
4350
-	// Markup final
4351
-	if ($type == 'lien') {
4352
-		return "<span class='icone $class_lien'>"
4353
-		. "<a href='$lien'$title$ajax$javascript>"
4354
-		. $icone
4355
-		. "<b>$texte</b>"
4356
-		. "</a></span>\n";
4357
-	} else {
4358
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4359
-	}
4293
+    $class_lien = $class_bouton = $class;
4294
+
4295
+    // Normaliser la fonction et compléter la classe en fonction
4296
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4297
+        $class_lien .= ' danger';
4298
+        $class_bouton .= ' btn_danger';
4299
+    } elseif ($fonction == 'rien.gif') {
4300
+        $fonction = '';
4301
+    } elseif ($fonction == 'delsafe') {
4302
+        $fonction = 'del';
4303
+    }
4304
+
4305
+    $fond_origine = $fond;
4306
+    // Remappage des icone : article-24.png+new => article-new-24.png
4307
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4308
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4309
+    }
4310
+
4311
+    // Ajouter le type d'objet dans la classe
4312
+    $objet_type = substr(basename($fond), 0, -4);
4313
+    $class_lien .= " $objet_type";
4314
+    $class_bouton .= " $objet_type";
4315
+
4316
+    // Texte
4317
+    $alt = attribut_html($texte);
4318
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4319
+
4320
+    // Liens : préparer les classes ajax
4321
+    $ajax = '';
4322
+    if ($type === 'lien') {
4323
+        if (strpos($class_lien, 'ajax') !== false) {
4324
+            $ajax = 'ajax';
4325
+            if (strpos($class_lien, 'preload') !== false) {
4326
+                $ajax .= ' preload';
4327
+            }
4328
+            if (strpos($class_lien, 'nocache') !== false) {
4329
+                $ajax .= ' nocache';
4330
+            }
4331
+            $ajax = " class='$ajax'";
4332
+        }
4333
+    }
4334
+
4335
+    // Repérer la taille et l'ajouter dans la classe
4336
+    $size = 24;
4337
+    if (
4338
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4339
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4340
+    ) {
4341
+        $size = $match[1];
4342
+    }
4343
+    $class_lien .= " s$size";
4344
+    $class_bouton .= " s$size";
4345
+
4346
+    // Icône
4347
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4348
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4349
+
4350
+    // Markup final
4351
+    if ($type == 'lien') {
4352
+        return "<span class='icone $class_lien'>"
4353
+        . "<a href='$lien'$title$ajax$javascript>"
4354
+        . $icone
4355
+        . "<b>$texte</b>"
4356
+        . "</a></span>\n";
4357
+    } else {
4358
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4359
+    }
4360 4360
 }
4361 4361
 
4362 4362
 /**
@@ -4380,7 +4380,7 @@  discard block
 block discarded – undo
4380 4380
  *     Code HTML du lien
4381 4381
  **/
4382 4382
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4383
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4383
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4384 4384
 }
4385 4385
 
4386 4386
 /**
@@ -4415,7 +4415,7 @@  discard block
 block discarded – undo
4415 4415
  *     Code HTML du lien
4416 4416
  **/
4417 4417
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4418
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4418
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4419 4419
 }
4420 4420
 
4421 4421
 /**
@@ -4460,7 +4460,7 @@  discard block
 block discarded – undo
4460 4460
  *     Code HTML du lien
4461 4461
  **/
4462 4462
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4463
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4463
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4464 4464
 }
4465 4465
 
4466 4466
 /**
@@ -4491,7 +4491,7 @@  discard block
 block discarded – undo
4491 4491
  *     Code HTML du lien
4492 4492
  **/
4493 4493
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4494
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4494
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4495 4495
 }
4496 4496
 
4497 4497
 /**
@@ -4522,7 +4522,7 @@  discard block
 block discarded – undo
4522 4522
  *     Code HTML du lien
4523 4523
  */
4524 4524
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4525
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4525
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4526 4526
 }
4527 4527
 
4528 4528
 
@@ -4544,7 +4544,7 @@  discard block
 block discarded – undo
4544 4544
  * @return array Liste des éléments
4545 4545
  */
4546 4546
 function filtre_explode_dist($a, $b) {
4547
- return explode($b, $a);
4547
+    return explode($b, $a);
4548 4548
 }
4549 4549
 
4550 4550
 /**
@@ -4565,7 +4565,7 @@  discard block
 block discarded – undo
4565 4565
  * @return string Texte
4566 4566
  */
4567 4567
 function filtre_implode_dist($a, $b) {
4568
- return is_array($a) ? implode($b, $a) : $a;
4568
+    return is_array($a) ? implode($b, $a) : $a;
4569 4569
 }
4570 4570
 
4571 4571
 /**
@@ -4574,24 +4574,24 @@  discard block
 block discarded – undo
4574 4574
  * @return string Code CSS
4575 4575
  */
4576 4576
 function bando_images_background() {
4577
-	include_spip('inc/bandeau');
4578
-	// recuperer tous les boutons et leurs images
4579
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4577
+    include_spip('inc/bandeau');
4578
+    // recuperer tous les boutons et leurs images
4579
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4580 4580
 
4581
-	$res = '';
4582
-	foreach ($boutons as $page => $detail) {
4583
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4584
-		if (is_array($detail->sousmenu)) {
4585
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4586
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4587
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4588
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4589
-				}
4590
-			}
4591
-		}
4592
-	}
4581
+    $res = '';
4582
+    foreach ($boutons as $page => $detail) {
4583
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4584
+        if (is_array($detail->sousmenu)) {
4585
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4586
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4587
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4588
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4589
+                }
4590
+            }
4591
+        }
4592
+    }
4593 4593
 
4594
-	return $res;
4594
+    return $res;
4595 4595
 }
4596 4596
 
4597 4597
 /**
@@ -4616,27 +4616,27 @@  discard block
 block discarded – undo
4616 4616
  */
4617 4617
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4618 4618
 
4619
-	// Classes : dispatcher `ajax` sur le formulaire
4620
-	$class_form = '';
4621
-	if (strpos($class, 'ajax') !== false) {
4622
-		$class_form = 'ajax';
4623
-		$class = str_replace('ajax', '', $class);
4624
-	}
4625
-	$class_btn = 'submit ' . trim($class);
4619
+    // Classes : dispatcher `ajax` sur le formulaire
4620
+    $class_form = '';
4621
+    if (strpos($class, 'ajax') !== false) {
4622
+        $class_form = 'ajax';
4623
+        $class = str_replace('ajax', '', $class);
4624
+    }
4625
+    $class_btn = 'submit ' . trim($class);
4626 4626
 
4627
-	if ($confirm) {
4628
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4629
-		if ($callback) {
4630
-			$callback = "$confirm?($callback):false";
4631
-		} else {
4632
-			$callback = $confirm;
4633
-		}
4634
-	}
4635
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4636
-	$title = $title ? " title='$title'" : '';
4627
+    if ($confirm) {
4628
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4629
+        if ($callback) {
4630
+            $callback = "$confirm?($callback):false";
4631
+        } else {
4632
+            $callback = $confirm;
4633
+        }
4634
+    }
4635
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4636
+    $title = $title ? " title='$title'" : '';
4637 4637
 
4638
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4639
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4638
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4639
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4640 4640
 }
4641 4641
 
4642 4642
 /**
@@ -4659,94 +4659,94 @@  discard block
 block discarded – undo
4659 4659
  * @return string
4660 4660
  */
4661 4661
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4662
-	static $trouver_table = null;
4663
-	static $objets;
4664
-
4665
-	// On verifie qu'on a tout ce qu'il faut
4666
-	$id_objet = intval($id_objet);
4667
-	if (!($id_objet and $type_objet and $info)) {
4668
-		return '';
4669
-	}
4670
-
4671
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4672
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4673
-		return '';
4674
-	}
4675
-
4676
-	// Si on demande l'url, on retourne direct la fonction
4677
-	if ($info == 'url') {
4678
-		return generer_url_entite($id_objet, $type_objet, ...$params);
4679
-	}
4680
-
4681
-	// Sinon on va tout chercher dans la table et on garde en memoire
4682
-	$demande_titre = ($info === 'titre');
4683
-	$demande_introduction = ($info === 'introduction');
4684
-
4685
-	// 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
4686
-	if (
4687
-		!isset($objets[$type_objet][$id_objet])
4688
-		or
4689
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4690
-	) {
4691
-		if (!$trouver_table) {
4692
-			$trouver_table = charger_fonction('trouver_table', 'base');
4693
-		}
4694
-		$desc = $trouver_table(table_objet_sql($type_objet));
4695
-		if (!$desc) {
4696
-			return $objets[$type_objet] = false;
4697
-		}
4698
-
4699
-		// Si on demande le titre, on le gere en interne
4700
-		$champ_titre = '';
4701
-		if ($demande_titre) {
4702
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4703
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4704
-		}
4705
-		include_spip('base/abstract_sql');
4706
-		include_spip('base/connect_sql');
4707
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4708
-			'*' . $champ_titre,
4709
-			$desc['table_sql'],
4710
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4711
-		);
4712
-
4713
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4714
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4715
-	}
4716
-
4717
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4718
-	// ajouter la longueur au début des params supplémentaires
4719
-	if ($demande_introduction) {
4720
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4721
-		array_unshift($params, $introduction_longueur);
4722
-	}
4723
-
4724
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4725
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4726
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4727
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4728
-	else {
4729
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4730
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4731
-		} // Sinon on prend directement le champ SQL tel quel
4732
-		else {
4733
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4734
-		}
4735
-	}
4736
-
4737
-	// On va ensuite appliquer les traitements automatiques si besoin
4738
-	if (!$etoile) {
4739
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4740
-		// mais ce fonctionnement est a ameliorer !
4741
-		$info_generee = appliquer_traitement_champ(
4742
-			$info_generee,
4743
-			$info,
4744
-			table_objet($type_objet),
4745
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4746
-		);
4747
-	}
4748
-
4749
-	return $info_generee;
4662
+    static $trouver_table = null;
4663
+    static $objets;
4664
+
4665
+    // On verifie qu'on a tout ce qu'il faut
4666
+    $id_objet = intval($id_objet);
4667
+    if (!($id_objet and $type_objet and $info)) {
4668
+        return '';
4669
+    }
4670
+
4671
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4672
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4673
+        return '';
4674
+    }
4675
+
4676
+    // Si on demande l'url, on retourne direct la fonction
4677
+    if ($info == 'url') {
4678
+        return generer_url_entite($id_objet, $type_objet, ...$params);
4679
+    }
4680
+
4681
+    // Sinon on va tout chercher dans la table et on garde en memoire
4682
+    $demande_titre = ($info === 'titre');
4683
+    $demande_introduction = ($info === 'introduction');
4684
+
4685
+    // 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
4686
+    if (
4687
+        !isset($objets[$type_objet][$id_objet])
4688
+        or
4689
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4690
+    ) {
4691
+        if (!$trouver_table) {
4692
+            $trouver_table = charger_fonction('trouver_table', 'base');
4693
+        }
4694
+        $desc = $trouver_table(table_objet_sql($type_objet));
4695
+        if (!$desc) {
4696
+            return $objets[$type_objet] = false;
4697
+        }
4698
+
4699
+        // Si on demande le titre, on le gere en interne
4700
+        $champ_titre = '';
4701
+        if ($demande_titre) {
4702
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4703
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4704
+        }
4705
+        include_spip('base/abstract_sql');
4706
+        include_spip('base/connect_sql');
4707
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4708
+            '*' . $champ_titre,
4709
+            $desc['table_sql'],
4710
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4711
+        );
4712
+
4713
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4714
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4715
+    }
4716
+
4717
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4718
+    // ajouter la longueur au début des params supplémentaires
4719
+    if ($demande_introduction) {
4720
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4721
+        array_unshift($params, $introduction_longueur);
4722
+    }
4723
+
4724
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4725
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4726
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4727
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4728
+    else {
4729
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4730
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4731
+        } // Sinon on prend directement le champ SQL tel quel
4732
+        else {
4733
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4734
+        }
4735
+    }
4736
+
4737
+    // On va ensuite appliquer les traitements automatiques si besoin
4738
+    if (!$etoile) {
4739
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4740
+        // mais ce fonctionnement est a ameliorer !
4741
+        $info_generee = appliquer_traitement_champ(
4742
+            $info_generee,
4743
+            $info,
4744
+            table_objet($type_objet),
4745
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4746
+        );
4747
+    }
4748
+
4749
+    return $info_generee;
4750 4750
 }
4751 4751
 
4752 4752
 /**
@@ -4779,36 +4779,36 @@  discard block
 block discarded – undo
4779 4779
  */
4780 4780
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, $connect = '') {
4781 4781
 
4782
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4783
-	$texte = $ligne_sql['texte'] ?? '';
4784
-	// En absence de descriptif, on se rabat sur chapo + texte
4785
-	if (isset($ligne_sql['chapo'])) {
4786
-		$chapo = $ligne_sql['chapo'];
4787
-		$texte = strlen($descriptif) ?
4788
-			'' :
4789
-			"$chapo \n\n $texte";
4790
-	}
4782
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4783
+    $texte = $ligne_sql['texte'] ?? '';
4784
+    // En absence de descriptif, on se rabat sur chapo + texte
4785
+    if (isset($ligne_sql['chapo'])) {
4786
+        $chapo = $ligne_sql['chapo'];
4787
+        $texte = strlen($descriptif) ?
4788
+            '' :
4789
+            "$chapo \n\n $texte";
4790
+    }
4791 4791
 
4792
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4793
-	if (!intval($longueur_ou_suite)) {
4794
-		$longueur = intval($introduction_longueur ?: 600);
4795
-	} else {
4796
-		$longueur = intval($longueur_ou_suite);
4797
-	}
4792
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4793
+    if (!intval($longueur_ou_suite)) {
4794
+        $longueur = intval($introduction_longueur ?: 600);
4795
+    } else {
4796
+        $longueur = intval($longueur_ou_suite);
4797
+    }
4798 4798
 
4799
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4800
-	// Ex : #INTRODUCTION{...}
4801
-	if (
4802
-		is_null($suite)
4803
-		and !intval($longueur_ou_suite)
4804
-	) {
4805
-		$suite = $longueur_ou_suite;
4806
-	}
4799
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4800
+    // Ex : #INTRODUCTION{...}
4801
+    if (
4802
+        is_null($suite)
4803
+        and !intval($longueur_ou_suite)
4804
+    ) {
4805
+        $suite = $longueur_ou_suite;
4806
+    }
4807 4807
 
4808
-	$f = chercher_filtre('introduction');
4809
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4808
+    $f = chercher_filtre('introduction');
4809
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4810 4810
 
4811
-	return $introduction;
4811
+    return $introduction;
4812 4812
 }
4813 4813
 
4814 4814
 /**
@@ -4822,44 +4822,44 @@  discard block
 block discarded – undo
4822 4822
  * @return string
4823 4823
  */
4824 4824
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], $connect = '') {
4825
-	if (!$champ) {
4826
-		return $texte;
4827
-	}
4825
+    if (!$champ) {
4826
+        return $texte;
4827
+    }
4828 4828
 
4829
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4830
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4831
-	include_fichiers_fonctions();
4829
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4830
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4831
+    include_fichiers_fonctions();
4832 4832
 
4833
-	$champ = strtoupper($champ);
4834
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4835
-	if (!$traitements or !is_array($traitements)) {
4836
-		return $texte;
4837
-	}
4833
+    $champ = strtoupper($champ);
4834
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4835
+    if (!$traitements or !is_array($traitements)) {
4836
+        return $texte;
4837
+    }
4838 4838
 
4839
-	$traitement = '';
4840
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4841
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4842
-		$table_objet = table_objet($table_objet);
4843
-		if (isset($traitements[$table_objet])) {
4844
-			$traitement = $traitements[$table_objet];
4845
-		}
4846
-	}
4847
-	if (!$traitement and isset($traitements[0])) {
4848
-		$traitement = $traitements[0];
4849
-	}
4850
-	// (sinon prendre le premier de la liste par defaut ?)
4839
+    $traitement = '';
4840
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4841
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4842
+        $table_objet = table_objet($table_objet);
4843
+        if (isset($traitements[$table_objet])) {
4844
+            $traitement = $traitements[$table_objet];
4845
+        }
4846
+    }
4847
+    if (!$traitement and isset($traitements[0])) {
4848
+        $traitement = $traitements[0];
4849
+    }
4850
+    // (sinon prendre le premier de la liste par defaut ?)
4851 4851
 
4852
-	if (!$traitement) {
4853
-		return $texte;
4854
-	}
4852
+    if (!$traitement) {
4853
+        return $texte;
4854
+    }
4855 4855
 
4856
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4856
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4857 4857
 
4858
-	// Fournir $connect et $Pile[0] au traitement si besoin
4859
-	$Pile = [0 => $env];
4860
-	eval("\$texte = $traitement;");
4858
+    // Fournir $connect et $Pile[0] au traitement si besoin
4859
+    $Pile = [0 => $env];
4860
+    eval("\$texte = $traitement;");
4861 4861
 
4862
-	return $texte;
4862
+    return $texte;
4863 4863
 }
4864 4864
 
4865 4865
 
@@ -4873,21 +4873,21 @@  discard block
 block discarded – undo
4873 4873
  * @return string
4874 4874
  */
4875 4875
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4876
-	include_spip('inc/liens');
4877
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4878
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4879
-	// le raccourcis n'est plus valide
4880
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4881
-	// on essaye avec generer_info_entite ?
4882
-	if (!strlen($titre) and !$connect) {
4883
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4884
-	}
4885
-	if (!strlen($titre)) {
4886
-		$titre = _T('info_sans_titre');
4887
-	}
4888
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4876
+    include_spip('inc/liens');
4877
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4878
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4879
+    // le raccourcis n'est plus valide
4880
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4881
+    // on essaye avec generer_info_entite ?
4882
+    if (!strlen($titre) and !$connect) {
4883
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4884
+    }
4885
+    if (!strlen($titre)) {
4886
+        $titre = _T('info_sans_titre');
4887
+    }
4888
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4889 4889
 
4890
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4890
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4891 4891
 }
4892 4892
 
4893 4893
 
@@ -4904,15 +4904,15 @@  discard block
 block discarded – undo
4904 4904
  * @return string
4905 4905
  */
4906 4906
 function wrap($texte, $wrap) {
4907
-	$balises = extraire_balises($wrap);
4908
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4909
-		$texte = $wrap . $texte;
4910
-		$regs = array_reverse($regs[1]);
4911
-		$wrap = '</' . implode('></', $regs) . '>';
4912
-		$texte = $texte . $wrap;
4913
-	}
4907
+    $balises = extraire_balises($wrap);
4908
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4909
+        $texte = $wrap . $texte;
4910
+        $regs = array_reverse($regs[1]);
4911
+        $wrap = '</' . implode('></', $regs) . '>';
4912
+        $texte = $texte . $wrap;
4913
+    }
4914 4914
 
4915
-	return $texte;
4915
+    return $texte;
4916 4916
 }
4917 4917
 
4918 4918
 
@@ -4932,44 +4932,44 @@  discard block
 block discarded – undo
4932 4932
  * @return array|mixed|string
4933 4933
  */
4934 4934
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4935
-	if (is_string($u)) {
4936
-		$u = typo($u);
4935
+    if (is_string($u)) {
4936
+        $u = typo($u);
4937 4937
 
4938
-		return $u;
4939
-	}
4938
+        return $u;
4939
+    }
4940 4940
 
4941
-	// caster $u en array si besoin
4942
-	if (is_object($u)) {
4943
-		$u = (array)$u;
4944
-	}
4941
+    // caster $u en array si besoin
4942
+    if (is_object($u)) {
4943
+        $u = (array)$u;
4944
+    }
4945 4945
 
4946
-	if (is_array($u)) {
4947
-		$out = '';
4948
-		// toutes les cles sont numeriques ?
4949
-		// et aucun enfant n'est un tableau
4950
-		// liste simple separee par des virgules
4951
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4952
-		$array_values = array_map('is_array', $u);
4953
-		$object_values = array_map('is_object', $u);
4954
-		if (
4955
-			array_sum($numeric_keys) == count($numeric_keys)
4956
-			and !array_sum($array_values)
4957
-			and !array_sum($object_values)
4958
-		) {
4959
-			return join(', ', array_map('filtre_print_dist', $u));
4960
-		}
4946
+    if (is_array($u)) {
4947
+        $out = '';
4948
+        // toutes les cles sont numeriques ?
4949
+        // et aucun enfant n'est un tableau
4950
+        // liste simple separee par des virgules
4951
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4952
+        $array_values = array_map('is_array', $u);
4953
+        $object_values = array_map('is_object', $u);
4954
+        if (
4955
+            array_sum($numeric_keys) == count($numeric_keys)
4956
+            and !array_sum($array_values)
4957
+            and !array_sum($object_values)
4958
+        ) {
4959
+            return join(', ', array_map('filtre_print_dist', $u));
4960
+        }
4961 4961
 
4962
-		// sinon on passe a la ligne et on indente
4963
-		$i_str = str_pad('', $indent, ' ');
4964
-		foreach ($u as $k => $v) {
4965
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4966
-		}
4962
+        // sinon on passe a la ligne et on indente
4963
+        $i_str = str_pad('', $indent, ' ');
4964
+        foreach ($u as $k => $v) {
4965
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4966
+        }
4967 4967
 
4968
-		return $out;
4969
-	}
4968
+        return $out;
4969
+    }
4970 4970
 
4971
-	// on sait pas quoi faire...
4972
-	return $u;
4971
+    // on sait pas quoi faire...
4972
+    return $u;
4973 4973
 }
4974 4974
 
4975 4975
 
@@ -4982,10 +4982,10 @@  discard block
 block discarded – undo
4982 4982
  * @return string|array
4983 4983
  */
4984 4984
 function objet_info($objet, $info) {
4985
-	$table = table_objet_sql($objet);
4986
-	$infos = lister_tables_objets_sql($table);
4985
+    $table = table_objet_sql($objet);
4986
+    $infos = lister_tables_objets_sql($table);
4987 4987
 
4988
-	return (isset($infos[$info]) ? $infos[$info] : '');
4988
+    return (isset($infos[$info]) ? $infos[$info] : '');
4989 4989
 }
4990 4990
 
4991 4991
 /**
@@ -5000,11 +5000,11 @@  discard block
 block discarded – undo
5000 5000
  *     Texte traduit du comptage, tel que '3 articles'
5001 5001
  */
5002 5002
 function objet_afficher_nb($nb, $objet) {
5003
-	if (!$nb) {
5004
-		return _T(objet_info($objet, 'info_aucun_objet'));
5005
-	} else {
5006
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5007
-	}
5003
+    if (!$nb) {
5004
+        return _T(objet_info($objet, 'info_aucun_objet'));
5005
+    } else {
5006
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5007
+    }
5008 5008
 }
5009 5009
 
5010 5010
 /**
@@ -5016,11 +5016,11 @@  discard block
 block discarded – undo
5016 5016
  * @return string
5017 5017
  */
5018 5018
 function objet_icone($objet, $taille = 24, $class = '') {
5019
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5020
-	$icone = chemin_image($icone);
5021
-	$balise_img = charger_filtre('balise_img');
5019
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5020
+    $icone = chemin_image($icone);
5021
+    $balise_img = charger_filtre('balise_img');
5022 5022
 
5023
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5023
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5024 5024
 }
5025 5025
 
5026 5026
 /**
@@ -5041,12 +5041,12 @@  discard block
 block discarded – undo
5041 5041
  * @return string
5042 5042
  */
5043 5043
 function objet_T($objet, $chaine, $args = [], $options = []) {
5044
-	$chaine = explode(':', $chaine);
5045
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5046
-		return $t;
5047
-	}
5048
-	$chaine = implode(':', $chaine);
5049
-	return _T($chaine, $args, $options);
5044
+    $chaine = explode(':', $chaine);
5045
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5046
+        return $t;
5047
+    }
5048
+    $chaine = implode(':', $chaine);
5049
+    return _T($chaine, $args, $options);
5050 5050
 }
5051 5051
 
5052 5052
 /**
@@ -5060,18 +5060,18 @@  discard block
 block discarded – undo
5060 5060
  * @return string      Code HTML
5061 5061
  */
5062 5062
 function insert_head_css_conditionnel($flux) {
5063
-	if (
5064
-		strpos($flux, '<!-- insert_head_css -->') === false
5065
-		and $p = strpos($flux, '<!-- insert_head -->')
5066
-	) {
5067
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5068
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5069
-			$p = $p1;
5070
-		}
5071
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5072
-	}
5063
+    if (
5064
+        strpos($flux, '<!-- insert_head_css -->') === false
5065
+        and $p = strpos($flux, '<!-- insert_head -->')
5066
+    ) {
5067
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5068
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5069
+            $p = $p1;
5070
+        }
5071
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5072
+    }
5073 5073
 
5074
-	return $flux;
5074
+    return $flux;
5075 5075
 }
5076 5076
 
5077 5077
 /**
@@ -5094,72 +5094,72 @@  discard block
 block discarded – undo
5094 5094
  * @return string
5095 5095
  */
5096 5096
 function produire_fond_statique($fond, $contexte = [], $options = [], $connect = '') {
5097
-	if (isset($contexte['format'])) {
5098
-		$extension = $contexte['format'];
5099
-		unset($contexte['format']);
5100
-	} else {
5101
-		$extension = 'html';
5102
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5103
-			$extension = $m[1];
5104
-		}
5105
-	}
5106
-	// recuperer le contenu produit par le squelette
5107
-	$options['raw'] = true;
5108
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5109
-
5110
-	// calculer le nom de la css
5111
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5112
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5113
-	$contexte_implicite = calculer_contexte_implicite();
5114
-
5115
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5116
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5117
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5118
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5119
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5120
-	}
5121
-	else {
5122
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5123
-		ksort($contexte);
5124
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5125
-	}
5126
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5127
-
5128
-	// mettre a jour le fichier si il n'existe pas
5129
-	// ou trop ancien
5130
-	// le dernier fichier produit est toujours suffixe par .last
5131
-	// et recopie sur le fichier cible uniquement si il change
5132
-	if (
5133
-		!file_exists($filename)
5134
-		or !file_exists($filename . '.last')
5135
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5136
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5137
-	) {
5138
-		$contenu = $cache['texte'];
5139
-		// passer les urls en absolu si c'est une css
5140
-		if ($extension == 'css') {
5141
-			$contenu = urls_absolues_css(
5142
-				$contenu,
5143
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5144
-			);
5145
-		}
5146
-
5147
-		$comment = '';
5148
-		// ne pas insérer de commentaire sur certains formats
5149
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5150
-			$comment = "/* #PRODUIRE{fond=$fond";
5151
-			foreach ($contexte as $k => $v) {
5152
-				$comment .= ",$k=$v";
5153
-			}
5154
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5155
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5156
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5157
-		}
5158
-		// et ecrire le fichier si il change
5159
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5160
-	}
5161
-
5162
-	return timestamp($filename);
5097
+    if (isset($contexte['format'])) {
5098
+        $extension = $contexte['format'];
5099
+        unset($contexte['format']);
5100
+    } else {
5101
+        $extension = 'html';
5102
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5103
+            $extension = $m[1];
5104
+        }
5105
+    }
5106
+    // recuperer le contenu produit par le squelette
5107
+    $options['raw'] = true;
5108
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5109
+
5110
+    // calculer le nom de la css
5111
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5112
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5113
+    $contexte_implicite = calculer_contexte_implicite();
5114
+
5115
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5116
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5117
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5118
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5119
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5120
+    }
5121
+    else {
5122
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5123
+        ksort($contexte);
5124
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5125
+    }
5126
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5127
+
5128
+    // mettre a jour le fichier si il n'existe pas
5129
+    // ou trop ancien
5130
+    // le dernier fichier produit est toujours suffixe par .last
5131
+    // et recopie sur le fichier cible uniquement si il change
5132
+    if (
5133
+        !file_exists($filename)
5134
+        or !file_exists($filename . '.last')
5135
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5136
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5137
+    ) {
5138
+        $contenu = $cache['texte'];
5139
+        // passer les urls en absolu si c'est une css
5140
+        if ($extension == 'css') {
5141
+            $contenu = urls_absolues_css(
5142
+                $contenu,
5143
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5144
+            );
5145
+        }
5146
+
5147
+        $comment = '';
5148
+        // ne pas insérer de commentaire sur certains formats
5149
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5150
+            $comment = "/* #PRODUIRE{fond=$fond";
5151
+            foreach ($contexte as $k => $v) {
5152
+                $comment .= ",$k=$v";
5153
+            }
5154
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5155
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5156
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5157
+        }
5158
+        // et ecrire le fichier si il change
5159
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5160
+    }
5161
+
5162
+    return timestamp($filename);
5163 5163
 }
5164 5164
 
5165 5165
 /**
@@ -5172,15 +5172,15 @@  discard block
 block discarded – undo
5172 5172
  *    $fichier auquel on a ajouté le timestamp
5173 5173
  */
5174 5174
 function timestamp($fichier) {
5175
-	if (
5176
-		!$fichier
5177
-		or !file_exists($fichier)
5178
-		or !$m = filemtime($fichier)
5179
-	) {
5180
-		return $fichier;
5181
-	}
5175
+    if (
5176
+        !$fichier
5177
+        or !file_exists($fichier)
5178
+        or !$m = filemtime($fichier)
5179
+    ) {
5180
+        return $fichier;
5181
+    }
5182 5182
 
5183
-	return "$fichier?$m";
5183
+    return "$fichier?$m";
5184 5184
 }
5185 5185
 
5186 5186
 /**
@@ -5190,11 +5190,11 @@  discard block
 block discarded – undo
5190 5190
  * @return string
5191 5191
  */
5192 5192
 function supprimer_timestamp($url) {
5193
-	if (strpos($url, '?') === false) {
5194
-		return $url;
5195
-	}
5193
+    if (strpos($url, '?') === false) {
5194
+        return $url;
5195
+    }
5196 5196
 
5197
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5197
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5198 5198
 }
5199 5199
 
5200 5200
 /**
@@ -5209,9 +5209,9 @@  discard block
 block discarded – undo
5209 5209
  * @return string
5210 5210
  */
5211 5211
 function filtre_nettoyer_titre_email_dist($titre) {
5212
-	include_spip('inc/envoyer_mail');
5212
+    include_spip('inc/envoyer_mail');
5213 5213
 
5214
-	return nettoyer_titre_email($titre);
5214
+    return nettoyer_titre_email($titre);
5215 5215
 }
5216 5216
 
5217 5217
 /**
@@ -5233,27 +5233,27 @@  discard block
 block discarded – undo
5233 5233
  * @return string
5234 5234
  */
5235 5235
 function filtre_chercher_rubrique_dist(
5236
-	$titre,
5237
-	$id_objet,
5238
-	$id_parent,
5239
-	$objet,
5240
-	$id_secteur,
5241
-	$restreint,
5242
-	$actionable = false,
5243
-	$retour_sans_cadre = false
5236
+    $titre,
5237
+    $id_objet,
5238
+    $id_parent,
5239
+    $objet,
5240
+    $id_secteur,
5241
+    $restreint,
5242
+    $actionable = false,
5243
+    $retour_sans_cadre = false
5244 5244
 ) {
5245
-	include_spip('inc/filtres_ecrire');
5245
+    include_spip('inc/filtres_ecrire');
5246 5246
 
5247
-	return chercher_rubrique(
5248
-		$titre,
5249
-		$id_objet,
5250
-		$id_parent,
5251
-		$objet,
5252
-		$id_secteur,
5253
-		$restreint,
5254
-		$actionable,
5255
-		$retour_sans_cadre
5256
-	);
5247
+    return chercher_rubrique(
5248
+        $titre,
5249
+        $id_objet,
5250
+        $id_parent,
5251
+        $objet,
5252
+        $id_secteur,
5253
+        $restreint,
5254
+        $actionable,
5255
+        $retour_sans_cadre
5256
+    );
5257 5257
 }
5258 5258
 
5259 5259
 /**
@@ -5282,56 +5282,56 @@  discard block
 block discarded – undo
5282 5282
  *     Chaîne vide si l'accès est autorisé
5283 5283
  */
5284 5284
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5285
-	if ($ok) {
5286
-		return '';
5287
-	}
5288
-
5289
-	// Vider tous les tampons
5290
-	$level = @ob_get_level();
5291
-	while ($level--) {
5292
-		@ob_end_clean();
5293
-	}
5294
-
5295
-	include_spip('inc/headers');
5296
-
5297
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5298
-	if ($url) {
5299
-		redirige_par_entete($url, '', $statut);
5300
-	}
5301
-
5302
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5303
-	if (!is_numeric($statut) and is_null($message)) {
5304
-		$message = $statut;
5305
-		$statut = 0;
5306
-	}
5307
-	if (!$message) {
5308
-		$message = '';
5309
-	}
5310
-	$statut = intval($statut);
5311
-
5312
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5313
-	if (test_espace_prive()) {
5314
-		if (!$statut or !in_array($statut, [404, 403])) {
5315
-			$statut = 403;
5316
-		}
5317
-		http_response_code(403);
5318
-		$echec = charger_fonction('403', 'exec');
5319
-		$echec($message);
5320
-	} else {
5321
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5322
-		if (!$statut) {
5323
-			$statut = 404;
5324
-		}
5325
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5326
-		http_response_code($statut);
5327
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5328
-		if ($statut >= 400) {
5329
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5330
-		}
5331
-	}
5332
-
5333
-
5334
-	exit;
5285
+    if ($ok) {
5286
+        return '';
5287
+    }
5288
+
5289
+    // Vider tous les tampons
5290
+    $level = @ob_get_level();
5291
+    while ($level--) {
5292
+        @ob_end_clean();
5293
+    }
5294
+
5295
+    include_spip('inc/headers');
5296
+
5297
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5298
+    if ($url) {
5299
+        redirige_par_entete($url, '', $statut);
5300
+    }
5301
+
5302
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5303
+    if (!is_numeric($statut) and is_null($message)) {
5304
+        $message = $statut;
5305
+        $statut = 0;
5306
+    }
5307
+    if (!$message) {
5308
+        $message = '';
5309
+    }
5310
+    $statut = intval($statut);
5311
+
5312
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5313
+    if (test_espace_prive()) {
5314
+        if (!$statut or !in_array($statut, [404, 403])) {
5315
+            $statut = 403;
5316
+        }
5317
+        http_response_code(403);
5318
+        $echec = charger_fonction('403', 'exec');
5319
+        $echec($message);
5320
+    } else {
5321
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5322
+        if (!$statut) {
5323
+            $statut = 404;
5324
+        }
5325
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5326
+        http_response_code($statut);
5327
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5328
+        if ($statut >= 400) {
5329
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5330
+        }
5331
+    }
5332
+
5333
+
5334
+    exit;
5335 5335
 }
5336 5336
 
5337 5337
 /**
@@ -5342,11 +5342,11 @@  discard block
 block discarded – undo
5342 5342
  * @return string
5343 5343
  */
5344 5344
 function filtre_compacte_dist($source, $format = null) {
5345
-	if (function_exists('compacte')) {
5346
-		return compacte($source, $format);
5347
-	}
5345
+    if (function_exists('compacte')) {
5346
+        return compacte($source, $format);
5347
+    }
5348 5348
 
5349
-	return $source;
5349
+    return $source;
5350 5350
 }
5351 5351
 
5352 5352
 
@@ -5358,31 +5358,31 @@  discard block
 block discarded – undo
5358 5358
  * @return string
5359 5359
  */
5360 5360
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5361
-	$l = strlen($passe);
5362
-
5363
-	if ($l <= 8 or !$afficher_partiellement) {
5364
-		if (!$l) {
5365
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5366
-		}
5367
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5368
-	}
5369
-
5370
-	if (is_null($portion_pourcent)) {
5371
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5372
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5373
-		}
5374
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5375
-	}
5376
-	if ($portion_pourcent >= 100) {
5377
-		return $passe;
5378
-	}
5379
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5380
-	$e = max($e, 0);
5381
-	$mid = str_pad('', $l - 2 * $e, '*');
5382
-	if ($e > 0 and strlen($mid) > 8) {
5383
-		$mid = '***...***';
5384
-	}
5385
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5361
+    $l = strlen($passe);
5362
+
5363
+    if ($l <= 8 or !$afficher_partiellement) {
5364
+        if (!$l) {
5365
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5366
+        }
5367
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5368
+    }
5369
+
5370
+    if (is_null($portion_pourcent)) {
5371
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5372
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5373
+        }
5374
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5375
+    }
5376
+    if ($portion_pourcent >= 100) {
5377
+        return $passe;
5378
+    }
5379
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5380
+    $e = max($e, 0);
5381
+    $mid = str_pad('', $l - 2 * $e, '*');
5382
+    if ($e > 0 and strlen($mid) > 8) {
5383
+        $mid = '***...***';
5384
+    }
5385
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5386 5386
 }
5387 5387
 
5388 5388
 
@@ -5403,64 +5403,64 @@  discard block
 block discarded – undo
5403 5403
  */
5404 5404
 function identifiant_slug($texte, $type = '', $options = []) {
5405 5405
 
5406
-	$original = $texte;
5407
-	$separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5408
-	$longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5409
-	$longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5406
+    $original = $texte;
5407
+    $separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5408
+    $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5409
+    $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5410 5410
 
5411
-	if (!function_exists('translitteration')) {
5412
-		include_spip('inc/charsets');
5413
-	}
5411
+    if (!function_exists('translitteration')) {
5412
+        include_spip('inc/charsets');
5413
+    }
5414 5414
 
5415
-	// pas de balise html
5416
-	if (strpos($texte, '<') !== false) {
5417
-		$texte = strip_tags($texte);
5418
-	}
5419
-	if (strpos($texte, '&') !== false) {
5420
-		$texte = unicode2charset($texte);
5421
-	}
5422
-	// On enlève les espaces indésirables
5423
-	$texte = trim($texte);
5415
+    // pas de balise html
5416
+    if (strpos($texte, '<') !== false) {
5417
+        $texte = strip_tags($texte);
5418
+    }
5419
+    if (strpos($texte, '&') !== false) {
5420
+        $texte = unicode2charset($texte);
5421
+    }
5422
+    // On enlève les espaces indésirables
5423
+    $texte = trim($texte);
5424 5424
 
5425
-	// On enlève les accents et cie
5426
-	$texte = translitteration($texte);
5425
+    // On enlève les accents et cie
5426
+    $texte = translitteration($texte);
5427 5427
 
5428
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5429
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5428
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5429
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5430 5430
 
5431
-	// nettoyer les doubles occurences du separateur si besoin
5432
-	while (strpos($texte, "$separateur$separateur") !== false) {
5433
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5434
-	}
5431
+    // nettoyer les doubles occurences du separateur si besoin
5432
+    while (strpos($texte, "$separateur$separateur") !== false) {
5433
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5434
+    }
5435 5435
 
5436
-	// pas de separateur au debut ni a la fin
5437
-	$texte = trim($texte, $separateur);
5436
+    // pas de separateur au debut ni a la fin
5437
+    $texte = trim($texte, $separateur);
5438 5438
 
5439
-	// en minuscules
5440
-	$texte = strtolower($texte);
5439
+    // en minuscules
5440
+    $texte = strtolower($texte);
5441 5441
 
5442
-	switch ($type) {
5443
-		case 'class':
5444
-		case 'id':
5445
-		case 'anchor':
5446
-			if (preg_match(',^\d,', $texte)) {
5447
-				$texte = substr($type, 0, 1) . $texte;
5448
-			}
5449
-	}
5442
+    switch ($type) {
5443
+        case 'class':
5444
+        case 'id':
5445
+        case 'anchor':
5446
+            if (preg_match(',^\d,', $texte)) {
5447
+                $texte = substr($type, 0, 1) . $texte;
5448
+            }
5449
+    }
5450 5450
 
5451
-	if (strlen($texte) > $longueur_maxi) {
5452
-		$texte = substr($texte, 0, $longueur_maxi);
5453
-	}
5451
+    if (strlen($texte) > $longueur_maxi) {
5452
+        $texte = substr($texte, 0, $longueur_maxi);
5453
+    }
5454 5454
 
5455
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5456
-		if (preg_match(',^\d,', $texte)) {
5457
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5458
-		}
5459
-		$texte .= $separateur . md5($original);
5460
-		$texte = substr($texte, 0, $longueur_mini);
5461
-	}
5455
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5456
+        if (preg_match(',^\d,', $texte)) {
5457
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5458
+        }
5459
+        $texte .= $separateur . md5($original);
5460
+        $texte = substr($texte, 0, $longueur_mini);
5461
+    }
5462 5462
 
5463
-	return $texte;
5463
+    return $texte;
5464 5464
 }
5465 5465
 
5466 5466
 
@@ -5481,11 +5481,11 @@  discard block
 block discarded – undo
5481 5481
  * @exemple `<:info_maximum|label_nettoyer:>`
5482 5482
  */
5483 5483
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5484
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5485
-	if ($ucfirst) {
5486
-		$label = spip_ucfirst($label);
5487
-	}
5488
-	return $label;
5484
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5485
+    if ($ucfirst) {
5486
+        $label = spip_ucfirst($label);
5487
+    }
5488
+    return $label;
5489 5489
 }
5490 5490
 
5491 5491
 /**
@@ -5498,8 +5498,8 @@  discard block
 block discarded – undo
5498 5498
  * @exemple `<:info_maximum|label_ponctuer:>`
5499 5499
  */
5500 5500
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5501
-	$label = label_nettoyer($text, $ucfirst);
5502
-	return _T('label_ponctuer', ['label' => $label]);
5501
+    $label = label_nettoyer($text, $ucfirst);
5502
+    return _T('label_ponctuer', ['label' => $label]);
5503 5503
 }
5504 5504
 
5505 5505
 
@@ -5512,19 +5512,19 @@  discard block
 block discarded – undo
5512 5512
  * @return array
5513 5513
  */
5514 5514
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5515
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5516
-		return [];
5517
-	}
5515
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5516
+        return [];
5517
+    }
5518 5518
 
5519
-	// compatibilite signature inversee
5520
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5521
-		list($objet, $id_objet) = [$id_objet, $objet];
5522
-	}
5519
+    // compatibilite signature inversee
5520
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5521
+        list($objet, $id_objet) = [$id_objet, $objet];
5522
+    }
5523 5523
 
5524
-	if (!function_exists($fonction)) {
5525
-		include_spip('base/objets');
5526
-	}
5527
-	return $fonction($objet, $id_objet);
5524
+    if (!function_exists($fonction)) {
5525
+        include_spip('base/objets');
5526
+    }
5527
+    return $fonction($objet, $id_objet);
5528 5528
 }
5529 5529
 
5530 5530
 
@@ -5539,7 +5539,7 @@  discard block
 block discarded – undo
5539 5539
  * @return array
5540 5540
  */
5541 5541
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5542
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5542
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5543 5543
 }
5544 5544
 
5545 5545
 /**
@@ -5553,7 +5553,7 @@  discard block
 block discarded – undo
5553 5553
  * @return array
5554 5554
  */
5555 5555
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5556
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5556
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5557 5557
 }
5558 5558
 
5559 5559
 /**
@@ -5567,7 +5567,7 @@  discard block
 block discarded – undo
5567 5567
  * @return array
5568 5568
  */
5569 5569
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5570
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5570
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5571 5571
 }
5572 5572
 
5573 5573
 /**
@@ -5581,5 +5581,5 @@  discard block
 block discarded – undo
5581 5581
  * @return array
5582 5582
  */
5583 5583
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5584
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5584
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5585 5585
 }
Please login to merge, or discard this patch.
ecrire/inc/preselectionner_parent_nouvel_objet.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 if (!defined('_AUTO_SELECTION_RUBRIQUE')) {
17
-	define('_AUTO_SELECTION_RUBRIQUE', false);
17
+    define('_AUTO_SELECTION_RUBRIQUE', false);
18 18
 }
19 19
 
20 20
 
@@ -28,39 +28,39 @@  discard block
 block discarded – undo
28 28
  * @return string
29 29
  */
30 30
 function inc_preselectionner_parent_nouvel_objet_dist($objet, $row) {
31
-	if (!_AUTO_SELECTION_RUBRIQUE) {
32
-		return '';
33
-	}
31
+    if (!_AUTO_SELECTION_RUBRIQUE) {
32
+        return '';
33
+    }
34 34
 
35
-	if (!isset($row['id_rubrique'])) {
36
-		return '';
37
-	}
35
+    if (!isset($row['id_rubrique'])) {
36
+        return '';
37
+    }
38 38
 
39
-	$id_rubrique = '';
40
-	if ($GLOBALS['connect_id_rubrique']) {
41
-		// si admin restreint : sa rubrique
42
-		$id_rubrique = $GLOBALS['connect_id_rubrique'][0];
43
-	} elseif (
44
-		is_int(_AUTO_SELECTION_RUBRIQUE)
45
-		and sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . intval(_AUTO_SELECTION_RUBRIQUE))
46
-	) {
47
-		$id_rubrique = _AUTO_SELECTION_RUBRIQUE;
48
-	} else {
49
-		// sinon la derniere rubrique cree
50
-		$row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1');
51
-		$id_rubrique = $row_rub['id_rubrique'];
52
-	}
53
-	// si le choix ne convient pas, on cherche dans un secteur
54
-	if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) {
55
-		$id_rubrique = '';
56
-		// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
57
-		$res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
58
-		while (!$id_rubrique and $row_rub = sql_fetch($res)) {
59
-			if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) {
60
-				$id_rubrique = $row_rub['id_rubrique'];
61
-			}
62
-		}
63
-	}
39
+    $id_rubrique = '';
40
+    if ($GLOBALS['connect_id_rubrique']) {
41
+        // si admin restreint : sa rubrique
42
+        $id_rubrique = $GLOBALS['connect_id_rubrique'][0];
43
+    } elseif (
44
+        is_int(_AUTO_SELECTION_RUBRIQUE)
45
+        and sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . intval(_AUTO_SELECTION_RUBRIQUE))
46
+    ) {
47
+        $id_rubrique = _AUTO_SELECTION_RUBRIQUE;
48
+    } else {
49
+        // sinon la derniere rubrique cree
50
+        $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1');
51
+        $id_rubrique = $row_rub['id_rubrique'];
52
+    }
53
+    // si le choix ne convient pas, on cherche dans un secteur
54
+    if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) {
55
+        $id_rubrique = '';
56
+        // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
57
+        $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
58
+        while (!$id_rubrique and $row_rub = sql_fetch($res)) {
59
+            if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) {
60
+                $id_rubrique = $row_rub['id_rubrique'];
61
+            }
62
+        }
63
+    }
64 64
 
65
-	return $id_rubrique;
65
+    return $id_rubrique;
66 66
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 		$id_rubrique = $GLOBALS['connect_id_rubrique'][0];
43 43
 	} elseif (
44 44
 		is_int(_AUTO_SELECTION_RUBRIQUE)
45
-		and sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . intval(_AUTO_SELECTION_RUBRIQUE))
45
+		and sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique='.intval(_AUTO_SELECTION_RUBRIQUE))
46 46
 	) {
47 47
 		$id_rubrique = _AUTO_SELECTION_RUBRIQUE;
48 48
 	} else {
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
 		$id_rubrique = $row_rub['id_rubrique'];
52 52
 	}
53 53
 	// si le choix ne convient pas, on cherche dans un secteur
54
-	if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) {
54
+	if (!autoriser('creer'.$objet.'dans', 'rubrique', $id_rubrique)) {
55 55
 		$id_rubrique = '';
56 56
 		// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
57 57
 		$res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
58 58
 		while (!$id_rubrique and $row_rub = sql_fetch($res)) {
59
-			if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) {
59
+			if (autoriser('creer'.$objet.'dans', 'rubrique', $row_rub['id_rubrique'])) {
60 60
 				$id_rubrique = $row_rub['id_rubrique'];
61 61
 			}
62 62
 		}
Please login to merge, or discard this patch.
ecrire/inc/filtres_selecteur_generique.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  **/
8 8
 
9 9
 if (!defined('_ECRIRE_INC_VERSION')) {
10
-	return;
10
+    return;
11 11
 }
12 12
 
13 13
 /**
@@ -28,51 +28,51 @@  discard block
 block discarded – undo
28 28
  *     - afficher : tableau des objets à afficher (mais pas forcément sélectionnables)
29 29
  */
30 30
 function selecteur_lister_objets($whitelist = [], $blacklist = []) {
31
-	static $liste_selecteurs, $liste_parents;
32
-
33
-	if (!$liste_selecteurs) {
34
-		$liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$');
35
-	}
36
-	$objets_selectionner = [];
37
-	foreach ($liste_selecteurs as $fichier => $chemin) {
38
-		$objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier);
39
-	}
40
-
41
-	// S'il y a une whitelist on ne garde que ce qui est dedans
42
-	if (!empty($whitelist)) {
43
-		$whitelist = array_map('table_objet', $whitelist);
44
-		$objets_selectionner = array_intersect($objets_selectionner, $whitelist);
45
-	}
46
-	// On supprime ce qui est dans la blacklist
47
-	$blacklist = array_map('table_objet', $blacklist);
48
-	// On enlève toujours la racine
49
-	$blacklist[] = 'racine';
50
-	$objets_selectionner = array_diff($objets_selectionner, $blacklist);
51
-
52
-	// Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner
53
-	$objets_afficher = $objets_selectionner;
54
-
55
-	// Il faut alors chercher d'éventuels parents obligatoires en plus :
56
-	// lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules"
57
-	if (!$liste_parents) {
58
-		$liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$');
59
-	}
60
-	foreach ($liste_parents as $fichier => $chemin) {
61
-		preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures);
62
-		$parent = $captures[1];
63
-		$type = $captures[2];
64
-		// Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage
65
-		if (in_array($type, $objets_afficher)) {
66
-			$objets_afficher[] = $parent;
67
-		}
68
-	}
69
-
70
-	$objets = [
71
-		'selectionner' => array_unique($objets_selectionner),
72
-		'afficher' => array_unique($objets_afficher),
73
-	];
74
-
75
-	return $objets;
31
+    static $liste_selecteurs, $liste_parents;
32
+
33
+    if (!$liste_selecteurs) {
34
+        $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$');
35
+    }
36
+    $objets_selectionner = [];
37
+    foreach ($liste_selecteurs as $fichier => $chemin) {
38
+        $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier);
39
+    }
40
+
41
+    // S'il y a une whitelist on ne garde que ce qui est dedans
42
+    if (!empty($whitelist)) {
43
+        $whitelist = array_map('table_objet', $whitelist);
44
+        $objets_selectionner = array_intersect($objets_selectionner, $whitelist);
45
+    }
46
+    // On supprime ce qui est dans la blacklist
47
+    $blacklist = array_map('table_objet', $blacklist);
48
+    // On enlève toujours la racine
49
+    $blacklist[] = 'racine';
50
+    $objets_selectionner = array_diff($objets_selectionner, $blacklist);
51
+
52
+    // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner
53
+    $objets_afficher = $objets_selectionner;
54
+
55
+    // Il faut alors chercher d'éventuels parents obligatoires en plus :
56
+    // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules"
57
+    if (!$liste_parents) {
58
+        $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$');
59
+    }
60
+    foreach ($liste_parents as $fichier => $chemin) {
61
+        preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures);
62
+        $parent = $captures[1];
63
+        $type = $captures[2];
64
+        // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage
65
+        if (in_array($type, $objets_afficher)) {
66
+            $objets_afficher[] = $parent;
67
+        }
68
+    }
69
+
70
+    $objets = [
71
+        'selectionner' => array_unique($objets_selectionner),
72
+        'afficher' => array_unique($objets_afficher),
73
+    ];
74
+
75
+    return $objets;
76 76
 }
77 77
 
78 78
 /**
@@ -99,31 +99,31 @@  discard block
 block discarded – undo
99 99
  *     liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet.
100 100
  **/
101 101
 function picker_selected($selected, $type = '') {
102
-	$select = [];
103
-	$type = preg_replace(',\W,', '', $type);
104
-
105
-	if ($selected and !is_array($selected)) {
106
-		$selected = explode(',', $selected);
107
-	}
108
-
109
-	if (is_array($selected)) {
110
-		foreach ($selected as $value) {
111
-			// Si c'est le bon format déjà
112
-			if (preg_match('/^([\w]+)[|]([0-9]+)$/', $value, $captures)) {
113
-				$objet = $captures[1];
114
-				$id_objet = intval($captures[2]);
115
-
116
-				// Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants
117
-				if (is_string($type) and $type == $objet and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
118
-					$select[] = $id_objet;
119
-				} elseif (!$type and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
120
-					$select[] = ['objet' => $objet, 'id_objet' => $id_objet];
121
-				}
122
-			}
123
-		}
124
-	}
125
-
126
-	return $select;
102
+    $select = [];
103
+    $type = preg_replace(',\W,', '', $type);
104
+
105
+    if ($selected and !is_array($selected)) {
106
+        $selected = explode(',', $selected);
107
+    }
108
+
109
+    if (is_array($selected)) {
110
+        foreach ($selected as $value) {
111
+            // Si c'est le bon format déjà
112
+            if (preg_match('/^([\w]+)[|]([0-9]+)$/', $value, $captures)) {
113
+                $objet = $captures[1];
114
+                $id_objet = intval($captures[2]);
115
+
116
+                // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants
117
+                if (is_string($type) and $type == $objet and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
118
+                    $select[] = $id_objet;
119
+                } elseif (!$type and ($id_objet or in_array($objet, ['racine', 'rubrique']))) {
120
+                    $select[] = ['objet' => $objet, 'id_objet' => $id_objet];
121
+                }
122
+            }
123
+        }
124
+    }
125
+
126
+    return $select;
127 127
 }
128 128
 
129 129
 /**
@@ -140,49 +140,49 @@  discard block
 block discarded – undo
140 140
  *     Booléen indiquant si les articles sont sélectionnables
141 141
  */
142 142
 function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) {
143
-	include_spip('inc/json');
144
-	include_spip('inc/lien');
145
-
146
-	// On construit un tableau des objets sélectionnables suivant les paramètres
147
-	$objets = [];
148
-	if ($rubriques_ou_objets and is_array($rubriques_ou_objets)) {
149
-		$objets = $rubriques_ou_objets;
150
-	} else {
151
-		if ($rubriques_ou_objets) {
152
-			$objets[] = 'rubriques';
153
-		}
154
-		if ($articles) {
155
-			$objets[] = 'articles';
156
-		}
157
-	}
158
-
159
-	// si id numerique et un seul objet possible, pas d'ambiguite
160
-	if (is_numeric($ref) and count($objets) === 1) {
161
-		$ref = reset($objets) . $ref;
162
-	}
163
-
164
-	// Si la référence ne correspond à rien, c'est fini
165
-	if (!($match = typer_raccourci($ref))) {
166
-		return json_export(false);
167
-	}
168
-	// Sinon on récupère les infos utiles
169
-	@list($type, , $id, , , , ) = $match;
170
-
171
-	// On regarde si le type trouvé fait partie des objets sélectionnables
172
-	if (!in_array(table_objet($type), $objets)) {
173
-		return json_export(false);
174
-	}
175
-
176
-	// Maintenant que tout est bon, on cherche les informations sur cet objet
177
-	include_spip('inc/filtres');
178
-	if (!$titre = generer_info_entite($id, $type, 'titre')) {
179
-		return json_export(false);
180
-	}
181
-
182
-	// On simplifie le texte
183
-	$titre = attribut_html($titre);
184
-
185
-	return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]);
143
+    include_spip('inc/json');
144
+    include_spip('inc/lien');
145
+
146
+    // On construit un tableau des objets sélectionnables suivant les paramètres
147
+    $objets = [];
148
+    if ($rubriques_ou_objets and is_array($rubriques_ou_objets)) {
149
+        $objets = $rubriques_ou_objets;
150
+    } else {
151
+        if ($rubriques_ou_objets) {
152
+            $objets[] = 'rubriques';
153
+        }
154
+        if ($articles) {
155
+            $objets[] = 'articles';
156
+        }
157
+    }
158
+
159
+    // si id numerique et un seul objet possible, pas d'ambiguite
160
+    if (is_numeric($ref) and count($objets) === 1) {
161
+        $ref = reset($objets) . $ref;
162
+    }
163
+
164
+    // Si la référence ne correspond à rien, c'est fini
165
+    if (!($match = typer_raccourci($ref))) {
166
+        return json_export(false);
167
+    }
168
+    // Sinon on récupère les infos utiles
169
+    @list($type, , $id, , , , ) = $match;
170
+
171
+    // On regarde si le type trouvé fait partie des objets sélectionnables
172
+    if (!in_array(table_objet($type), $objets)) {
173
+        return json_export(false);
174
+    }
175
+
176
+    // Maintenant que tout est bon, on cherche les informations sur cet objet
177
+    include_spip('inc/filtres');
178
+    if (!$titre = generer_info_entite($id, $type, 'titre')) {
179
+        return json_export(false);
180
+    }
181
+
182
+    // On simplifie le texte
183
+    $titre = attribut_html($titre);
184
+
185
+    return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]);
186 186
 }
187 187
 
188 188
 /**
@@ -205,34 +205,34 @@  discard block
 block discarded – undo
205 205
  *     Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon.
206 206
  */
207 207
 function test_enfants_rubrique($id_rubrique, $types = []) {
208
-	static $has_child = [];
209
-
210
-	if (!isset($has_child[$id_rubrique])) {
211
-		$types = (is_array($types) ? array_filter($types) : []);
212
-
213
-		// recuperer tous les freres et soeurs de la rubrique visee
214
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
215
-		$fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent));
216
-		$fratrie = array_column($fratrie, 'id_rubrique');
217
-		$has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
218
-		$has = array_column($has, 'id_parent');
219
-		$fratrie = array_diff($fratrie, $has);
220
-
221
-		while (count($fratrie) and is_array($types) and count($types)) {
222
-			$type = array_shift($types);
223
-			$h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie));
224
-			$h = array_column($h, 'id_rubrique');
225
-			$has = array_merge($has, $h);
226
-			$fratrie = array_diff($fratrie, $h);
227
-		}
228
-
229
-		if (count($has)) {
230
-			$has_child = $has_child + array_combine($has, array_pad([], count($has), true));
231
-		}
232
-		if (count($fratrie)) {
233
-			$has_child = $has_child + array_combine($fratrie, array_pad([], count($fratrie), false));
234
-		}
235
-	}
236
-
237
-	return $has_child[$id_rubrique] ? ' ' : '';
208
+    static $has_child = [];
209
+
210
+    if (!isset($has_child[$id_rubrique])) {
211
+        $types = (is_array($types) ? array_filter($types) : []);
212
+
213
+        // recuperer tous les freres et soeurs de la rubrique visee
214
+        $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
215
+        $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent));
216
+        $fratrie = array_column($fratrie, 'id_rubrique');
217
+        $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
218
+        $has = array_column($has, 'id_parent');
219
+        $fratrie = array_diff($fratrie, $has);
220
+
221
+        while (count($fratrie) and is_array($types) and count($types)) {
222
+            $type = array_shift($types);
223
+            $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie));
224
+            $h = array_column($h, 'id_rubrique');
225
+            $has = array_merge($has, $h);
226
+            $fratrie = array_diff($fratrie, $h);
227
+        }
228
+
229
+        if (count($has)) {
230
+            $has_child = $has_child + array_combine($has, array_pad([], count($has), true));
231
+        }
232
+        if (count($fratrie)) {
233
+            $has_child = $has_child + array_combine($fratrie, array_pad([], count($fratrie), false));
234
+        }
235
+    }
236
+
237
+    return $has_child[$id_rubrique] ? ' ' : '';
238 238
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
 	// si id numerique et un seul objet possible, pas d'ambiguite
160 160
 	if (is_numeric($ref) and count($objets) === 1) {
161
-		$ref = reset($objets) . $ref;
161
+		$ref = reset($objets).$ref;
162 162
 	}
163 163
 
164 164
 	// Si la référence ne correspond à rien, c'est fini
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 		return json_export(false);
167 167
 	}
168 168
 	// Sinon on récupère les infos utiles
169
-	@list($type, , $id, , , , ) = $match;
169
+	@list($type,, $id,,,,) = $match;
170 170
 
171 171
 	// On regarde si le type trouvé fait partie des objets sélectionnables
172 172
 	if (!in_array(table_objet($type), $objets)) {
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 		$types = (is_array($types) ? array_filter($types) : []);
212 212
 
213 213
 		// recuperer tous les freres et soeurs de la rubrique visee
214
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
215
-		$fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent));
214
+		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique));
215
+		$fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent='.intval($id_parent));
216 216
 		$fratrie = array_column($fratrie, 'id_rubrique');
217 217
 		$has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
218 218
 		$has = array_column($has, 'id_parent');
Please login to merge, or discard this patch.
ecrire/inc/session.php 2 patches
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
  * @return bool|null|void
41 41
  */
42 42
 function inc_session_dist($auteur = false) {
43
-	if (is_numeric($auteur)) {
44
-		return supprimer_sessions($auteur, $auteur > 0);
45
-	} else {
46
-		if (is_array($auteur)) {
47
-			return ajouter_session($auteur);
48
-		} else {
49
-			return verifier_session($auteur);
50
-		}
51
-	}
43
+    if (is_numeric($auteur)) {
44
+        return supprimer_sessions($auteur, $auteur > 0);
45
+    } else {
46
+        if (is_array($auteur)) {
47
+            return ajouter_session($auteur);
48
+        } else {
49
+            return verifier_session($auteur);
50
+        }
51
+    }
52 52
 }
53 53
 
54 54
 
@@ -77,36 +77,36 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function supprimer_sessions($id_auteur, $toutes = true, $actives = true) {
79 79
 
80
-	$nb_files = 0;
81
-	$nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000);
82
-	spip_log("supprimer sessions auteur $id_auteur", 'session');
83
-	if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) {
84
-		if ($dir = opendir(_DIR_SESSIONS)) {
85
-			$t = $_SERVER['REQUEST_TIME']  - (4 * _RENOUVELLE_ALEA); // 48h par defaut
86
-			$t_short = $_SERVER['REQUEST_TIME']  - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut
87
-			$t = time() - (4 * _RENOUVELLE_ALEA);
88
-			while (($f = readdir($dir)) !== false) {
89
-				$nb_files++;
90
-				if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) {
91
-					$f = _DIR_SESSIONS . $f;
92
-					if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) {
93
-						spip_unlink($f);
94
-					}
95
-					// si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H
96
-					// cf http://core.spip.org/issues/3276
97
-					elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) {
98
-						spip_unlink($f);
99
-					}
100
-				}
101
-			}
102
-		}
103
-	} else {
104
-		verifier_session();
105
-		spip_unlink(fichier_session('alea_ephemere', true));
106
-	}
107
-
108
-	// forcer le recalcul de la session courante
109
-	spip_session(true);
80
+    $nb_files = 0;
81
+    $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000);
82
+    spip_log("supprimer sessions auteur $id_auteur", 'session');
83
+    if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) {
84
+        if ($dir = opendir(_DIR_SESSIONS)) {
85
+            $t = $_SERVER['REQUEST_TIME']  - (4 * _RENOUVELLE_ALEA); // 48h par defaut
86
+            $t_short = $_SERVER['REQUEST_TIME']  - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut
87
+            $t = time() - (4 * _RENOUVELLE_ALEA);
88
+            while (($f = readdir($dir)) !== false) {
89
+                $nb_files++;
90
+                if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) {
91
+                    $f = _DIR_SESSIONS . $f;
92
+                    if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) {
93
+                        spip_unlink($f);
94
+                    }
95
+                    // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H
96
+                    // cf http://core.spip.org/issues/3276
97
+                    elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) {
98
+                        spip_unlink($f);
99
+                    }
100
+                }
101
+            }
102
+        }
103
+    } else {
104
+        verifier_session();
105
+        spip_unlink(fichier_session('alea_ephemere', true));
106
+    }
107
+
108
+    // forcer le recalcul de la session courante
109
+    spip_session(true);
110 110
 }
111 111
 
112 112
 /**
@@ -124,125 +124,125 @@  discard block
 block discarded – undo
124 124
  * @return bool|string
125 125
  */
126 126
 function ajouter_session($auteur) {
127
-	// Si le client a deja une session valide pour son id_auteur
128
-	// on conserve le meme fichier
129
-
130
-	// Attention un visiteur peut avoir une session et un id=0,
131
-	// => ne pas melanger les sessions des differents visiteurs
132
-	$id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0;
133
-
134
-	// Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session)
135
-	// on va vérifier s'il y a vraiment des choses à écrire
136
-	if (!$id_auteur) {
137
-		// On supprime les données de base pour voir le contenu réel de la session
138
-		$auteur_verif = $auteur;
139
-		if (isset($auteur_verif['id_auteur'])) {
140
-			unset($auteur_verif['id_auteur']);
141
-		}
142
-		if (isset($auteur_verif['hash_env'])) {
143
-			unset($auteur_verif['hash_env']);
144
-		}
145
-		if (isset($auteur_verif['ip_change'])) {
146
-			unset($auteur_verif['ip_change']);
147
-		}
148
-		if (isset($auteur_verif['date_session'])) {
149
-			unset($auteur_verif['date_session']);
150
-		}
151
-
152
-		// Les variables vraiment nulle ne sont pas à prendre en compte non plus
153
-		foreach ($auteur_verif as $variable => $valeur) {
154
-			if ($valeur === null) {
155
-				unset($auteur_verif[$variable]);
156
-			}
157
-		}
158
-
159
-		// Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là
160
-		if (!$auteur_verif) {
161
-			if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) {
162
-				unset($_SESSION[$_COOKIE['spip_session']]);
163
-			}
164
-			if (isset($_COOKIE['spip_session'])) {
165
-				unset($_COOKIE['spip_session']);
166
-			}
167
-
168
-			return false;
169
-		}
170
-	}
171
-
172
-	if (
173
-		!isset($_COOKIE['spip_session'])
174
-		or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session'])
175
-	) {
176
-		$_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(rand(), true));
177
-	}
178
-
179
-	// Maintenant on sait qu'on a des choses à écrire
180
-	// On s'assure d'avoir au moins ces valeurs
181
-	$auteur['id_auteur'] = $id_auteur;
182
-	if (!isset($auteur['hash_env'])) {
183
-		$auteur['hash_env'] = hash_env();
184
-	}
185
-	if (!isset($auteur['ip_change'])) {
186
-		$auteur['ip_change'] = false;
187
-	}
188
-
189
-	if (!isset($auteur['date_session'])) {
190
-		$auteur['date_session'] = time();
191
-	}
192
-	if (
193
-		isset($auteur['prefs'])
194
-		and is_string($auteur['prefs'])
195
-		and $prefs = @unserialize($auteur['prefs'])
196
-	) {
197
-		$auteur['prefs'] = $prefs;
198
-	}
199
-
200
-	$fichier_session = '';
201
-
202
-	// les sessions anonymes sont stockees dans $_SESSION
203
-	if (!$id_auteur) {
204
-		spip_php_session_start();
205
-		$_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur);
206
-	} else {
207
-		$fichier_session = fichier_session('alea_ephemere');
208
-		if (!ecrire_fichier_session($fichier_session, $auteur)) {
209
-			spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS);
210
-			include_spip('inc/minipres');
211
-			echo minipres();
212
-			exit;
213
-		}
214
-		// verifier et limiter le nombre maxi de sessions
215
-		// https://core.spip.net/issues/3807
216
-		lister_sessions_auteur($id_auteur);
217
-	}
218
-
219
-	// poser le cookie de session SPIP
220
-	include_spip('inc/cookie');
221
-	$duree = definir_duree_cookie_session($auteur);
222
-	spip_setcookie('spip_session', $_COOKIE['spip_session'], [
223
-		'expires' => time() + $duree
224
-	]);
225
-	spip_log("ajoute session $fichier_session cookie $duree", 'session');
226
-
227
-	// Si on est admin, poser le cookie de correspondance
228
-	if (!function_exists('autoriser')) {
229
-		include_spip('inc/autoriser');
230
-	}
231
-	if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) {
232
-		spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [
233
-			'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree)
234
-		]);
235
-	} // sinon le supprimer ...
236
-	else {
237
-		spip_setcookie('spip_admin', '', [
238
-			'expires' => 1
239
-		]);
240
-	}
241
-
242
-	# on en profite pour purger les vieilles sessions anonymes abandonnees
243
-	# supprimer_sessions(0, true, false);
244
-
245
-	return $_COOKIE['spip_session'];
127
+    // Si le client a deja une session valide pour son id_auteur
128
+    // on conserve le meme fichier
129
+
130
+    // Attention un visiteur peut avoir une session et un id=0,
131
+    // => ne pas melanger les sessions des differents visiteurs
132
+    $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0;
133
+
134
+    // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session)
135
+    // on va vérifier s'il y a vraiment des choses à écrire
136
+    if (!$id_auteur) {
137
+        // On supprime les données de base pour voir le contenu réel de la session
138
+        $auteur_verif = $auteur;
139
+        if (isset($auteur_verif['id_auteur'])) {
140
+            unset($auteur_verif['id_auteur']);
141
+        }
142
+        if (isset($auteur_verif['hash_env'])) {
143
+            unset($auteur_verif['hash_env']);
144
+        }
145
+        if (isset($auteur_verif['ip_change'])) {
146
+            unset($auteur_verif['ip_change']);
147
+        }
148
+        if (isset($auteur_verif['date_session'])) {
149
+            unset($auteur_verif['date_session']);
150
+        }
151
+
152
+        // Les variables vraiment nulle ne sont pas à prendre en compte non plus
153
+        foreach ($auteur_verif as $variable => $valeur) {
154
+            if ($valeur === null) {
155
+                unset($auteur_verif[$variable]);
156
+            }
157
+        }
158
+
159
+        // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là
160
+        if (!$auteur_verif) {
161
+            if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) {
162
+                unset($_SESSION[$_COOKIE['spip_session']]);
163
+            }
164
+            if (isset($_COOKIE['spip_session'])) {
165
+                unset($_COOKIE['spip_session']);
166
+            }
167
+
168
+            return false;
169
+        }
170
+    }
171
+
172
+    if (
173
+        !isset($_COOKIE['spip_session'])
174
+        or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session'])
175
+    ) {
176
+        $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(rand(), true));
177
+    }
178
+
179
+    // Maintenant on sait qu'on a des choses à écrire
180
+    // On s'assure d'avoir au moins ces valeurs
181
+    $auteur['id_auteur'] = $id_auteur;
182
+    if (!isset($auteur['hash_env'])) {
183
+        $auteur['hash_env'] = hash_env();
184
+    }
185
+    if (!isset($auteur['ip_change'])) {
186
+        $auteur['ip_change'] = false;
187
+    }
188
+
189
+    if (!isset($auteur['date_session'])) {
190
+        $auteur['date_session'] = time();
191
+    }
192
+    if (
193
+        isset($auteur['prefs'])
194
+        and is_string($auteur['prefs'])
195
+        and $prefs = @unserialize($auteur['prefs'])
196
+    ) {
197
+        $auteur['prefs'] = $prefs;
198
+    }
199
+
200
+    $fichier_session = '';
201
+
202
+    // les sessions anonymes sont stockees dans $_SESSION
203
+    if (!$id_auteur) {
204
+        spip_php_session_start();
205
+        $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur);
206
+    } else {
207
+        $fichier_session = fichier_session('alea_ephemere');
208
+        if (!ecrire_fichier_session($fichier_session, $auteur)) {
209
+            spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS);
210
+            include_spip('inc/minipres');
211
+            echo minipres();
212
+            exit;
213
+        }
214
+        // verifier et limiter le nombre maxi de sessions
215
+        // https://core.spip.net/issues/3807
216
+        lister_sessions_auteur($id_auteur);
217
+    }
218
+
219
+    // poser le cookie de session SPIP
220
+    include_spip('inc/cookie');
221
+    $duree = definir_duree_cookie_session($auteur);
222
+    spip_setcookie('spip_session', $_COOKIE['spip_session'], [
223
+        'expires' => time() + $duree
224
+    ]);
225
+    spip_log("ajoute session $fichier_session cookie $duree", 'session');
226
+
227
+    // Si on est admin, poser le cookie de correspondance
228
+    if (!function_exists('autoriser')) {
229
+        include_spip('inc/autoriser');
230
+    }
231
+    if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) {
232
+        spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [
233
+            'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree)
234
+        ]);
235
+    } // sinon le supprimer ...
236
+    else {
237
+        spip_setcookie('spip_admin', '', [
238
+            'expires' => 1
239
+        ]);
240
+    }
241
+
242
+    # on en profite pour purger les vieilles sessions anonymes abandonnees
243
+    # supprimer_sessions(0, true, false);
244
+
245
+    return $_COOKIE['spip_session'];
246 246
 }
247 247
 
248 248
 /**
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
  *     Durée en secondes
263 263
 **/
264 264
 function definir_duree_cookie_session($auteur) {
265
-	$coef = 2;
266
-	if (isset($auteur['cookie'])) {
267
-		if (is_numeric($auteur['cookie'])) {
268
-			$coef = $auteur['cookie'];
269
-		} else {
270
-			$coef = 20;
271
-		}
272
-	}
273
-	return (int)(_RENOUVELLE_ALEA * $coef);
265
+    $coef = 2;
266
+    if (isset($auteur['cookie'])) {
267
+        if (is_numeric($auteur['cookie'])) {
268
+            $coef = $auteur['cookie'];
269
+        } else {
270
+            $coef = 20;
271
+        }
272
+    }
273
+    return (int)(_RENOUVELLE_ALEA * $coef);
274 274
 }
275 275
 
276 276
 /**
@@ -290,91 +290,91 @@  discard block
 block discarded – undo
290 290
  * @return bool|int|null
291 291
  */
292 292
 function verifier_session($change = false) {
293
-	// si pas de cookie, c'est fichu
294
-	if (!isset($_COOKIE['spip_session'])) {
295
-		return false;
296
-	}
297
-
298
-	$fichier_session = '';
299
-
300
-	// est-ce une session anonyme ?
301
-	if (!intval($_COOKIE['spip_session'])) {
302
-		spip_php_session_start();
303
-		if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) {
304
-			return false;
305
-		}
306
-		$GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']];
307
-	} else {
308
-		// Tester avec alea courant
309
-		$fichier_session = fichier_session('alea_ephemere', true);
310
-		if ($fichier_session and @file_exists($fichier_session)) {
311
-			include($fichier_session);
312
-		} else {
313
-			// Sinon, tester avec alea precedent
314
-			$fichier_session = fichier_session('alea_ephemere_ancien', true);
315
-			if (!$fichier_session or !@file_exists($fichier_session)) {
316
-				return false;
317
-			}
318
-
319
-			// Renouveler la session avec l'alea courant
320
-			include($fichier_session);
321
-			spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session');
322
-			spip_unlink($fichier_session);
323
-			ajouter_session($GLOBALS['visiteur_session']);
324
-		}
325
-	}
326
-
327
-	// Compatibilite ascendante : auteur_session est visiteur_session si
328
-	// c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut
329
-	// n'etre qu'identifie, sans aucune authentification).
330
-
331
-	if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) {
332
-		$GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session'];
333
-	}
334
-
335
-
336
-	// Si l'adresse IP change, inc/presentation mettra une balise image
337
-	// avec un URL de rappel demandant a changer le nom de la session.
338
-	// Seul celui qui a l'IP d'origine est rejoue
339
-	// ainsi un eventuel voleur de cookie ne pourrait pas deconnecter
340
-	// sa victime, mais se ferait deconnecter par elle.
341
-	if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) {
342
-		if (!$GLOBALS['visiteur_session']['ip_change']) {
343
-			define('_SESSION_REJOUER', true);
344
-			$GLOBALS['visiteur_session']['ip_change'] = true;
345
-			ajouter_session($GLOBALS['visiteur_session']);
346
-		} else {
347
-			if ($change) {
348
-				spip_log('session non rejouee, vol de cookie ?', 'session');
349
-			}
350
-		}
351
-	} else {
352
-		if ($change) {
353
-			spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session');
354
-			if ($fichier_session) {
355
-				spip_unlink($fichier_session);
356
-			}
357
-			$GLOBALS['visiteur_session']['ip_change'] = false;
358
-			unset($_COOKIE['spip_session']);
359
-			ajouter_session($GLOBALS['visiteur_session']);
360
-		}
361
-	}
362
-
363
-	// Si la session a ete initiee il y a trop longtemps, elle est annulee
364
-	if (
365
-		isset($GLOBALS['visiteur_session'])
366
-		and defined('_AGE_SESSION_MAX')
367
-		and _AGE_SESSION_MAX > 0
368
-		and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX
369
-	) {
370
-		unset($GLOBALS['visiteur_session']);
371
-
372
-		return false;
373
-	}
374
-
375
-	return is_numeric($GLOBALS['visiteur_session']['id_auteur'])
376
-		? $GLOBALS['visiteur_session']['id_auteur']
377
-		: null;
293
+    // si pas de cookie, c'est fichu
294
+    if (!isset($_COOKIE['spip_session'])) {
295
+        return false;
296
+    }
297
+
298
+    $fichier_session = '';
299
+
300
+    // est-ce une session anonyme ?
301
+    if (!intval($_COOKIE['spip_session'])) {
302
+        spip_php_session_start();
303
+        if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) {
304
+            return false;
305
+        }
306
+        $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']];
307
+    } else {
308
+        // Tester avec alea courant
309
+        $fichier_session = fichier_session('alea_ephemere', true);
310
+        if ($fichier_session and @file_exists($fichier_session)) {
311
+            include($fichier_session);
312
+        } else {
313
+            // Sinon, tester avec alea precedent
314
+            $fichier_session = fichier_session('alea_ephemere_ancien', true);
315
+            if (!$fichier_session or !@file_exists($fichier_session)) {
316
+                return false;
317
+            }
318
+
319
+            // Renouveler la session avec l'alea courant
320
+            include($fichier_session);
321
+            spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session');
322
+            spip_unlink($fichier_session);
323
+            ajouter_session($GLOBALS['visiteur_session']);
324
+        }
325
+    }
326
+
327
+    // Compatibilite ascendante : auteur_session est visiteur_session si
328
+    // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut
329
+    // n'etre qu'identifie, sans aucune authentification).
330
+
331
+    if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) {
332
+        $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session'];
333
+    }
334
+
335
+
336
+    // Si l'adresse IP change, inc/presentation mettra une balise image
337
+    // avec un URL de rappel demandant a changer le nom de la session.
338
+    // Seul celui qui a l'IP d'origine est rejoue
339
+    // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter
340
+    // sa victime, mais se ferait deconnecter par elle.
341
+    if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) {
342
+        if (!$GLOBALS['visiteur_session']['ip_change']) {
343
+            define('_SESSION_REJOUER', true);
344
+            $GLOBALS['visiteur_session']['ip_change'] = true;
345
+            ajouter_session($GLOBALS['visiteur_session']);
346
+        } else {
347
+            if ($change) {
348
+                spip_log('session non rejouee, vol de cookie ?', 'session');
349
+            }
350
+        }
351
+    } else {
352
+        if ($change) {
353
+            spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session');
354
+            if ($fichier_session) {
355
+                spip_unlink($fichier_session);
356
+            }
357
+            $GLOBALS['visiteur_session']['ip_change'] = false;
358
+            unset($_COOKIE['spip_session']);
359
+            ajouter_session($GLOBALS['visiteur_session']);
360
+        }
361
+    }
362
+
363
+    // Si la session a ete initiee il y a trop longtemps, elle est annulee
364
+    if (
365
+        isset($GLOBALS['visiteur_session'])
366
+        and defined('_AGE_SESSION_MAX')
367
+        and _AGE_SESSION_MAX > 0
368
+        and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX
369
+    ) {
370
+        unset($GLOBALS['visiteur_session']);
371
+
372
+        return false;
373
+    }
374
+
375
+    return is_numeric($GLOBALS['visiteur_session']['id_auteur'])
376
+        ? $GLOBALS['visiteur_session']['id_auteur']
377
+        : null;
378 378
 }
379 379
 
380 380
 /**
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
  *     Valeur, si trouvée, `null` sinon.
390 390
  */
391 391
 function session_get($nom) {
392
-	return isset($GLOBALS['visiteur_session'][$nom]) ? $GLOBALS['visiteur_session'][$nom] : null;
392
+    return isset($GLOBALS['visiteur_session'][$nom]) ? $GLOBALS['visiteur_session'][$nom] : null;
393 393
 }
394 394
 
395 395
 
@@ -405,32 +405,32 @@  discard block
 block discarded – undo
405 405
  * @return void|array
406 406
  */
407 407
 function session_set($nom, $val = null) {
408
-	static $remove = [];
409
-	static $actualiser_sessions = false;
410
-	if ($nom === false) {
411
-		return $remove;
412
-	}
413
-	if (is_null($val)) {
414
-		// rien a faire
415
-		if (!isset($GLOBALS['visiteur_session'][$nom])) {
416
-			return;
417
-		}
418
-		unset($GLOBALS['visiteur_session'][$nom]);
419
-		$remove[] = $nom;
420
-	} else {
421
-		// On ajoute la valeur dans la globale
422
-		$GLOBALS['visiteur_session'][$nom] = $val;
423
-		if ($remove) {
424
-			$remove = array_diff($remove, [$nom]);
425
-		}
426
-	}
427
-	if (!$actualiser_sessions) {
428
-		// il faut creer la session si on en a pas, la premiere fois
429
-		ajouter_session($GLOBALS['visiteur_session']);
430
-		// in register la fonction qui mettra a jour toutes les sessions en fin de hit
431
-		register_shutdown_function('terminer_actualiser_sessions');
432
-		$actualiser_sessions = true;
433
-	}
408
+    static $remove = [];
409
+    static $actualiser_sessions = false;
410
+    if ($nom === false) {
411
+        return $remove;
412
+    }
413
+    if (is_null($val)) {
414
+        // rien a faire
415
+        if (!isset($GLOBALS['visiteur_session'][$nom])) {
416
+            return;
417
+        }
418
+        unset($GLOBALS['visiteur_session'][$nom]);
419
+        $remove[] = $nom;
420
+    } else {
421
+        // On ajoute la valeur dans la globale
422
+        $GLOBALS['visiteur_session'][$nom] = $val;
423
+        if ($remove) {
424
+            $remove = array_diff($remove, [$nom]);
425
+        }
426
+    }
427
+    if (!$actualiser_sessions) {
428
+        // il faut creer la session si on en a pas, la premiere fois
429
+        ajouter_session($GLOBALS['visiteur_session']);
430
+        // in register la fonction qui mettra a jour toutes les sessions en fin de hit
431
+        register_shutdown_function('terminer_actualiser_sessions');
432
+        $actualiser_sessions = true;
433
+    }
434 434
 }
435 435
 
436 436
 /**
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
  * @uses actualiser_sessions()
440 440
  */
441 441
 function terminer_actualiser_sessions() {
442
-	// se remettre dans le dossier de travail au cas ou Apache a change
443
-	chdir(_ROOT_CWD);
444
-	// recuperer les variables a effacer
445
-	$remove = session_set(false);
446
-	// mettre a jour toutes les sessions
447
-	actualiser_sessions($GLOBALS['visiteur_session'], $remove);
442
+    // se remettre dans le dossier de travail au cas ou Apache a change
443
+    chdir(_ROOT_CWD);
444
+    // recuperer les variables a effacer
445
+    $remove = session_set(false);
446
+    // mettre a jour toutes les sessions
447
+    actualiser_sessions($GLOBALS['visiteur_session'], $remove);
448 448
 }
449 449
 
450 450
 
@@ -469,83 +469,83 @@  discard block
 block discarded – undo
469 469
  */
470 470
 function actualiser_sessions($auteur, $supprimer_cles = []) {
471 471
 
472
-	$id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0;
473
-	$id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0;
474
-
475
-	// si l'auteur est celui de la session courante, verifier/creer la session si besoin
476
-	$fichier_session_courante = '';
477
-	if ($id_auteur == $id_auteur_courant) {
478
-		$auteur = array_merge($GLOBALS['visiteur_session'], $auteur);
479
-		ajouter_session($auteur);
480
-		if ($id_auteur) {
481
-			$fichier_session_courante = fichier_session('alea_ephemere');
482
-		}
483
-	}
484
-
485
-	// si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees
486
-	if (!$id_auteur) {
487
-		return;
488
-	}
489
-
490
-	// les préférences sont désérialisées, toujours.
491
-	// [fixme] Le champ 'prefs' sert aussi à l’inscription
492
-	if (isset($auteur['prefs']) and is_string($auteur['prefs'])) {
493
-		$auteur['prefs'] = @unserialize($auteur['prefs']);
494
-		if (!is_array($auteur['prefs'])) {
495
-			$auteur['prefs'] = [];
496
-		}
497
-	}
498
-
499
-	// memoriser l'auteur courant (celui qui modifie la fiche)
500
-	$sauve = $GLOBALS['visiteur_session'];
501
-
502
-	// .. mettre a jour les sessions de l'auteur cible
503
-	// attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire
504
-	// cree par une ecriture concurente d'une session (fichier atomique temporaire)
505
-	$sessions = lister_sessions_auteur($id_auteur);
506
-
507
-	// 1ere passe : lire et fusionner les sessions
508
-	foreach ($sessions as $session) {
509
-		$GLOBALS['visiteur_session'] = [];
510
-		// a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence)
511
-		if (
512
-			$session !== $fichier_session_courante
513
-			and @file_exists($session)
514
-		) {
515
-			include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible
516
-
517
-			$auteur = array_merge($GLOBALS['visiteur_session'], $auteur);
518
-		}
519
-	}
520
-
521
-	// supprimer les eventuelles cles dont on ne veut plus
522
-	foreach ($supprimer_cles as $cle) {
523
-		unset($auteur[$cle]);
524
-	}
525
-
526
-	$auteur_session = preparer_ecriture_session($auteur);
527
-
528
-	// seconde passe : ecrire les sessions qui ne sont pas a jour
529
-	foreach ($sessions as $session) {
530
-		$GLOBALS['visiteur_session'] = [];
531
-		// a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence)
532
-		if (@file_exists($session)) {
533
-			include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible
534
-
535
-			// est-ce que cette session est a mettre a jour ?
536
-			if ($auteur_session != $GLOBALS['visiteur_session']) {
537
-				ecrire_fichier_session($session, $auteur);
538
-			}
539
-		}
540
-	}
541
-
542
-	if ($id_auteur == $id_auteur_courant) {
543
-		$GLOBALS['visiteur_session'] = $auteur;
544
-		$GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session'];
545
-	} else {
546
-		// restaurer l'auteur courant
547
-		$GLOBALS['visiteur_session'] = $sauve;
548
-	}
472
+    $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0;
473
+    $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0;
474
+
475
+    // si l'auteur est celui de la session courante, verifier/creer la session si besoin
476
+    $fichier_session_courante = '';
477
+    if ($id_auteur == $id_auteur_courant) {
478
+        $auteur = array_merge($GLOBALS['visiteur_session'], $auteur);
479
+        ajouter_session($auteur);
480
+        if ($id_auteur) {
481
+            $fichier_session_courante = fichier_session('alea_ephemere');
482
+        }
483
+    }
484
+
485
+    // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees
486
+    if (!$id_auteur) {
487
+        return;
488
+    }
489
+
490
+    // les préférences sont désérialisées, toujours.
491
+    // [fixme] Le champ 'prefs' sert aussi à l’inscription
492
+    if (isset($auteur['prefs']) and is_string($auteur['prefs'])) {
493
+        $auteur['prefs'] = @unserialize($auteur['prefs']);
494
+        if (!is_array($auteur['prefs'])) {
495
+            $auteur['prefs'] = [];
496
+        }
497
+    }
498
+
499
+    // memoriser l'auteur courant (celui qui modifie la fiche)
500
+    $sauve = $GLOBALS['visiteur_session'];
501
+
502
+    // .. mettre a jour les sessions de l'auteur cible
503
+    // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire
504
+    // cree par une ecriture concurente d'une session (fichier atomique temporaire)
505
+    $sessions = lister_sessions_auteur($id_auteur);
506
+
507
+    // 1ere passe : lire et fusionner les sessions
508
+    foreach ($sessions as $session) {
509
+        $GLOBALS['visiteur_session'] = [];
510
+        // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence)
511
+        if (
512
+            $session !== $fichier_session_courante
513
+            and @file_exists($session)
514
+        ) {
515
+            include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible
516
+
517
+            $auteur = array_merge($GLOBALS['visiteur_session'], $auteur);
518
+        }
519
+    }
520
+
521
+    // supprimer les eventuelles cles dont on ne veut plus
522
+    foreach ($supprimer_cles as $cle) {
523
+        unset($auteur[$cle]);
524
+    }
525
+
526
+    $auteur_session = preparer_ecriture_session($auteur);
527
+
528
+    // seconde passe : ecrire les sessions qui ne sont pas a jour
529
+    foreach ($sessions as $session) {
530
+        $GLOBALS['visiteur_session'] = [];
531
+        // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence)
532
+        if (@file_exists($session)) {
533
+            include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible
534
+
535
+            // est-ce que cette session est a mettre a jour ?
536
+            if ($auteur_session != $GLOBALS['visiteur_session']) {
537
+                ecrire_fichier_session($session, $auteur);
538
+            }
539
+        }
540
+    }
541
+
542
+    if ($id_auteur == $id_auteur_courant) {
543
+        $GLOBALS['visiteur_session'] = $auteur;
544
+        $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session'];
545
+    } else {
546
+        // restaurer l'auteur courant
547
+        $GLOBALS['visiteur_session'] = $sauve;
548
+    }
549 549
 }
550 550
 
551 551
 /**
@@ -559,48 +559,48 @@  discard block
 block discarded – undo
559 559
  */
560 560
 function lister_sessions_auteur($id_auteur, $nb_max = null) {
561 561
 
562
-	if (is_null($nb_max)) {
563
-		if (!defined('_NB_SESSIONS_MAX')) {
564
-			define('_NB_SESSIONS_MAX', 100);
565
-		}
566
-		$nb_max = _NB_SESSIONS_MAX;
567
-	}
568
-
569
-	// liste des sessions
570
-	$sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$');
571
-
572
-	// si on en a plus que la limite, supprimer les plus vieilles
573
-	// si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes
574
-	if (
575
-		$id_auteur
576
-		and count($sessions) > $nb_max
577
-	) {
578
-		// limiter le nombre de sessions ouvertes par un auteur
579
-		// filemtime sur les sessions
580
-		$sessions = array_flip($sessions);
581
-
582
-		// 1ere passe : lire les filemtime
583
-		foreach ($sessions as $session => $z) {
584
-			if (
585
-				$d = @filemtime($session)
586
-			) {
587
-				$sessions[$session] = $d;
588
-			} else {
589
-				$sessions[$session] = 0;
590
-			}
591
-		}
592
-
593
-		// les plus anciennes en premier
594
-		asort($sessions);
595
-
596
-		$sessions = array_keys($sessions);
597
-		while (count($sessions) > $nb_max) {
598
-			$session = array_shift($sessions);
599
-			@unlink($session);
600
-		}
601
-	}
602
-
603
-	return $sessions;
562
+    if (is_null($nb_max)) {
563
+        if (!defined('_NB_SESSIONS_MAX')) {
564
+            define('_NB_SESSIONS_MAX', 100);
565
+        }
566
+        $nb_max = _NB_SESSIONS_MAX;
567
+    }
568
+
569
+    // liste des sessions
570
+    $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$');
571
+
572
+    // si on en a plus que la limite, supprimer les plus vieilles
573
+    // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes
574
+    if (
575
+        $id_auteur
576
+        and count($sessions) > $nb_max
577
+    ) {
578
+        // limiter le nombre de sessions ouvertes par un auteur
579
+        // filemtime sur les sessions
580
+        $sessions = array_flip($sessions);
581
+
582
+        // 1ere passe : lire les filemtime
583
+        foreach ($sessions as $session => $z) {
584
+            if (
585
+                $d = @filemtime($session)
586
+            ) {
587
+                $sessions[$session] = $d;
588
+            } else {
589
+                $sessions[$session] = 0;
590
+            }
591
+        }
592
+
593
+        // les plus anciennes en premier
594
+        asort($sessions);
595
+
596
+        $sessions = array_keys($sessions);
597
+        while (count($sessions) > $nb_max) {
598
+            $session = array_shift($sessions);
599
+            @unlink($session);
600
+        }
601
+    }
602
+
603
+    return $sessions;
604 604
 }
605 605
 
606 606
 
@@ -614,26 +614,26 @@  discard block
 block discarded – undo
614 614
  * @return array
615 615
  */
616 616
 function preparer_ecriture_session($auteur) {
617
-	$row = $auteur;
618
-
619
-	// ne pas enregistrer ces elements de securite
620
-	// dans le fichier de session
621
-	unset($auteur['pass']);
622
-	unset($auteur['htpass']);
623
-	unset($auteur['low_sec']);
624
-	unset($auteur['alea_actuel']);
625
-	unset($auteur['alea_futur']);
626
-
627
-	$auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]);
628
-
629
-	// ne pas enregistrer les valeurs vraiment nulle dans le fichier
630
-	foreach ($auteur as $variable => $valeur) {
631
-		if ($valeur === null) {
632
-			unset($auteur[$variable]);
633
-		}
634
-	}
635
-
636
-	return $auteur;
617
+    $row = $auteur;
618
+
619
+    // ne pas enregistrer ces elements de securite
620
+    // dans le fichier de session
621
+    unset($auteur['pass']);
622
+    unset($auteur['htpass']);
623
+    unset($auteur['low_sec']);
624
+    unset($auteur['alea_actuel']);
625
+    unset($auteur['alea_futur']);
626
+
627
+    $auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]);
628
+
629
+    // ne pas enregistrer les valeurs vraiment nulle dans le fichier
630
+    foreach ($auteur as $variable => $valeur) {
631
+        if ($valeur === null) {
632
+            unset($auteur[$variable]);
633
+        }
634
+    }
635
+
636
+    return $auteur;
637 637
 }
638 638
 
639 639
 /**
@@ -645,17 +645,17 @@  discard block
 block discarded – undo
645 645
  */
646 646
 function ecrire_fichier_session($fichier, $auteur) {
647 647
 
648
-	$auteur = preparer_ecriture_session($auteur);
648
+    $auteur = preparer_ecriture_session($auteur);
649 649
 
650
-	// enregistrer les autres donnees du visiteur
651
-	$texte = '<' . "?php\n";
652
-	foreach ($auteur as $var => $val) {
653
-		$texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = '
654
-			. var_export($val, true) . ";\n";
655
-	}
656
-	$texte .= '?' . ">\n";
650
+    // enregistrer les autres donnees du visiteur
651
+    $texte = '<' . "?php\n";
652
+    foreach ($auteur as $var => $val) {
653
+        $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = '
654
+            . var_export($val, true) . ";\n";
655
+    }
656
+    $texte .= '?' . ">\n";
657 657
 
658
-	return ecrire_fichier($fichier, $texte);
658
+    return ecrire_fichier($fichier, $texte);
659 659
 }
660 660
 
661 661
 
@@ -668,23 +668,23 @@  discard block
 block discarded – undo
668 668
  */
669 669
 function fichier_session($alea, $tantpis = false) {
670 670
 
671
-	include_spip('inc/acces');
672
-	charger_aleas();
671
+    include_spip('inc/acces');
672
+    charger_aleas();
673 673
 
674
-	if (empty($GLOBALS['meta'][$alea])) {
675
-		if (!$tantpis) {
676
-			spip_log("fichier session ($tantpis): $alea indisponible", 'session');
677
-			include_spip('inc/minipres');
678
-			echo minipres();
679
-		}
674
+    if (empty($GLOBALS['meta'][$alea])) {
675
+        if (!$tantpis) {
676
+            spip_log("fichier session ($tantpis): $alea indisponible", 'session');
677
+            include_spip('inc/minipres');
678
+            echo minipres();
679
+        }
680 680
 
681
-		return ''; // echec mais $tanpis
682
-	} else {
683
-		$repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis);
684
-		$c = $_COOKIE['spip_session'];
681
+        return ''; // echec mais $tanpis
682
+    } else {
683
+        $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis);
684
+        $c = $_COOKIE['spip_session'];
685 685
 
686
-		return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php';
687
-	}
686
+        return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php';
687
+    }
688 688
 }
689 689
 
690 690
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
  * @return string
702 702
  */
703 703
 function rejouer_session() {
704
-	return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />';
704
+    return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />';
705 705
 }
706 706
 
707 707
 
@@ -711,12 +711,12 @@  discard block
 block discarded – undo
711 711
  * @return string
712 712
  */
713 713
 function hash_env() {
714
-	static $res = '';
715
-	if ($res) {
716
-		return $res;
717
-	}
714
+    static $res = '';
715
+    if ($res) {
716
+        return $res;
717
+    }
718 718
 
719
-	return $res = md5($GLOBALS['ip'] . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''));
719
+    return $res = md5($GLOBALS['ip'] . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''));
720 720
 }
721 721
 
722 722
 
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
  * @return bool True si une session PHP est ouverte.
729 729
  **/
730 730
 function spip_php_session_start() {
731
-	if (!is_php_session_started()) {
732
-		return session_start();
733
-	}
731
+    if (!is_php_session_started()) {
732
+        return session_start();
733
+    }
734 734
 
735
-	return true;
735
+    return true;
736 736
 }
737 737
 
738 738
 /**
@@ -742,9 +742,9 @@  discard block
 block discarded – undo
742 742
  * @return bool true si une session PHP est active
743 743
  **/
744 744
 function is_php_session_started() {
745
-	if (php_sapi_name() !== 'cli') {
746
-		return session_status() === PHP_SESSION_ACTIVE ? true : false;
747
-	}
745
+    if (php_sapi_name() !== 'cli') {
746
+        return session_status() === PHP_SESSION_ACTIVE ? true : false;
747
+    }
748 748
 
749
-	return false;
749
+    return false;
750 750
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
 	spip_log("supprimer sessions auteur $id_auteur", 'session');
83 83
 	if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) {
84 84
 		if ($dir = opendir(_DIR_SESSIONS)) {
85
-			$t = $_SERVER['REQUEST_TIME']  - (4 * _RENOUVELLE_ALEA); // 48h par defaut
86
-			$t_short = $_SERVER['REQUEST_TIME']  - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut
85
+			$t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut
86
+			$t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut
87 87
 			$t = time() - (4 * _RENOUVELLE_ALEA);
88 88
 			while (($f = readdir($dir)) !== false) {
89 89
 				$nb_files++;
90 90
 				if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) {
91
-					$f = _DIR_SESSIONS . $f;
91
+					$f = _DIR_SESSIONS.$f;
92 92
 					if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) {
93 93
 						spip_unlink($f);
94 94
 					}
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
 
172 172
 	if (
173 173
 		!isset($_COOKIE['spip_session'])
174
-		or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session'])
174
+		or !preg_match(',^'.$id_auteur.'_,', $_COOKIE['spip_session'])
175 175
 	) {
176
-		$_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(rand(), true));
176
+		$_COOKIE['spip_session'] = $id_auteur.'_'.md5(uniqid(rand(), true));
177 177
 	}
178 178
 
179 179
 	// Maintenant on sait qu'on a des choses à écrire
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	} else {
207 207
 		$fichier_session = fichier_session('alea_ephemere');
208 208
 		if (!ecrire_fichier_session($fichier_session, $auteur)) {
209
-			spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS);
209
+			spip_log('Echec ecriture fichier session '.$fichier_session, 'session'._LOG_HS);
210 210
 			include_spip('inc/minipres');
211 211
 			echo minipres();
212 212
 			exit;
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		include_spip('inc/autoriser');
230 230
 	}
231 231
 	if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) {
232
-		spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [
232
+		spip_setcookie('spip_admin', '@'.($auteur['email'] ?: $auteur['login']), [
233 233
 			'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree)
234 234
 		]);
235 235
 	} // sinon le supprimer ...
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 			$coef = 20;
271 271
 		}
272 272
 	}
273
-	return (int)(_RENOUVELLE_ALEA * $coef);
273
+	return (int) (_RENOUVELLE_ALEA * $coef);
274 274
 }
275 275
 
276 276
 /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 
319 319
 			// Renouveler la session avec l'alea courant
320 320
 			include($fichier_session);
321
-			spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session');
321
+			spip_log('renouvelle session '.$GLOBALS['visiteur_session']['id_auteur'], 'session');
322 322
 			spip_unlink($fichier_session);
323 323
 			ajouter_session($GLOBALS['visiteur_session']);
324 324
 		}
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 		}
351 351
 	} else {
352 352
 		if ($change) {
353
-			spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session');
353
+			spip_log("rejoue session $fichier_session ".$_COOKIE['spip_session'], 'session');
354 354
 			if ($fichier_session) {
355 355
 				spip_unlink($fichier_session);
356 356
 			}
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 	}
568 568
 
569 569
 	// liste des sessions
570
-	$sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$');
570
+	$sessions = preg_files(_DIR_SESSIONS, '/'.$id_auteur.'_.*\.php$');
571 571
 
572 572
 	// si on en a plus que la limite, supprimer les plus vieilles
573 573
 	// si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes
@@ -648,12 +648,12 @@  discard block
 block discarded – undo
648 648
 	$auteur = preparer_ecriture_session($auteur);
649 649
 
650 650
 	// enregistrer les autres donnees du visiteur
651
-	$texte = '<' . "?php\n";
651
+	$texte = '<'."?php\n";
652 652
 	foreach ($auteur as $var => $val) {
653
-		$texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = '
654
-			. var_export($val, true) . ";\n";
653
+		$texte .= '$GLOBALS[\'visiteur_session\']['.var_export($var, true).'] = '
654
+			. var_export($val, true).";\n";
655 655
 	}
656
-	$texte .= '?' . ">\n";
656
+	$texte .= '?'.">\n";
657 657
 
658 658
 	return ecrire_fichier($fichier, $texte);
659 659
 }
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 		$repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis);
684 684
 		$c = $_COOKIE['spip_session'];
685 685
 
686
-		return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php';
686
+		return $repertoire.intval($c).'_'.md5($c.' '.$GLOBALS['meta'][$alea]).'.php';
687 687
 	}
688 688
 }
689 689
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
  * @return string
702 702
  */
703 703
 function rejouer_session() {
704
-	return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />';
704
+	return '<img src="'.generer_url_action('cookie', 'change_session=oui', true).'" width="0" height="0" alt="" />';
705 705
 }
706 706
 
707 707
 
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 		return $res;
717 717
 	}
718 718
 
719
-	return $res = md5($GLOBALS['ip'] . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''));
719
+	return $res = md5($GLOBALS['ip'].(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''));
720 720
 }
721 721
 
722 722
 
Please login to merge, or discard this patch.
ecrire/inc/envoyer_mail.php 3 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Mail
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function nettoyer_titre_email($titre) {
35
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
36 36
 }
37 37
 
38 38
 /**
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function nettoyer_caracteres_mail($t) {
50 50
 
51
-	$t = filtrer_entites($t);
51
+    $t = filtrer_entites($t);
52 52
 
53
-	if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
-		$t = str_replace(
55
-			['&#8217;', '&#8220;', '&#8221;'],
56
-			["'", '"', '"'],
57
-			$t
58
-		);
59
-	}
53
+    if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
+        $t = str_replace(
55
+            ['&#8217;', '&#8220;', '&#8221;'],
56
+            ["'", '"', '"'],
57
+            $t
58
+        );
59
+    }
60 60
 
61
-	$t = str_replace(
62
-		['&mdash;', '&endash;'],
63
-		['--', '-'],
64
-		$t
65
-	);
61
+    $t = str_replace(
62
+        ['&mdash;', '&endash;'],
63
+        ['--', '-'],
64
+        $t
65
+    );
66 66
 
67
-	return $t;
67
+    return $t;
68 68
 }
69 69
 
70 70
 /**
@@ -97,86 +97,86 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
99 99
 
100
-	if (!email_valide($destinataire)) {
101
-		return false;
102
-	}
103
-	if ($destinataire == _T('info_mail_fournisseur')) {
104
-		return false;
105
-	} // tres fort
106
-
107
-	// Fournir si possible un Message-Id: conforme au RFC1036,
108
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
-
110
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
111
-	if (!email_valide($email_envoi)) {
112
-		spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
-		$email_envoi = $destinataire;
114
-	}
115
-
116
-	$parts = '';
117
-	if (is_array($corps)) {
118
-		$texte = $corps['texte'];
119
-		$from = (isset($corps['from']) ? $corps['from'] : $from);
120
-		$headers = (isset($corps['headers']) ? $corps['headers'] : $headers);
121
-		if (is_array($headers)) {
122
-			$headers = implode("\n", $headers);
123
-		}
124
-		if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) {
125
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
-		}
127
-	} else {
128
-		$texte = $corps;
129
-	}
130
-
131
-	if (!$from) {
132
-		$from = $email_envoi;
133
-	}
134
-
135
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
-	}
139
-
140
-	// nettoyer les &eacute; &#8217, &emdash; etc...
141
-	// les 'cliquer ici' etc sont a eviter;  voir:
142
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
-	$texte = nettoyer_caracteres_mail($texte);
144
-	$sujet = nettoyer_caracteres_mail($sujet);
145
-
146
-	// encoder le sujet si possible selon la RFC
147
-	if (init_mb_string()) {
148
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
-		$charset = $GLOBALS['meta']['charset'];
151
-		mb_internal_encoding($charset);
152
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
-		mb_internal_encoding('utf-8');
154
-	}
155
-
156
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
157
-		$texte = wordwrap($texte);
158
-	}
159
-
160
-	list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
161
-
162
-	if (_OS_SERVEUR == 'windows') {
163
-		$texte = preg_replace("@\r*\n@", "\r\n", $texte);
164
-		$headers = preg_replace("@\r*\n@", "\r\n", $headers);
165
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
166
-	}
167
-
168
-	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
169
-	// mode TEST : forcer l'email
170
-	if (defined('_TEST_EMAIL_DEST')) {
171
-		if (!_TEST_EMAIL_DEST) {
172
-			return false;
173
-		} else {
174
-			$texte = "Dest : $destinataire\r\n" . $texte;
175
-			$destinataire = _TEST_EMAIL_DEST;
176
-		}
177
-	}
178
-
179
-	return @mail($destinataire, $sujet, $texte, $headers);
100
+    if (!email_valide($destinataire)) {
101
+        return false;
102
+    }
103
+    if ($destinataire == _T('info_mail_fournisseur')) {
104
+        return false;
105
+    } // tres fort
106
+
107
+    // Fournir si possible un Message-Id: conforme au RFC1036,
108
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
+
110
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
111
+    if (!email_valide($email_envoi)) {
112
+        spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
+        $email_envoi = $destinataire;
114
+    }
115
+
116
+    $parts = '';
117
+    if (is_array($corps)) {
118
+        $texte = $corps['texte'];
119
+        $from = (isset($corps['from']) ? $corps['from'] : $from);
120
+        $headers = (isset($corps['headers']) ? $corps['headers'] : $headers);
121
+        if (is_array($headers)) {
122
+            $headers = implode("\n", $headers);
123
+        }
124
+        if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) {
125
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
+        }
127
+    } else {
128
+        $texte = $corps;
129
+    }
130
+
131
+    if (!$from) {
132
+        $from = $email_envoi;
133
+    }
134
+
135
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
+    }
139
+
140
+    // nettoyer les &eacute; &#8217, &emdash; etc...
141
+    // les 'cliquer ici' etc sont a eviter;  voir:
142
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
+    $texte = nettoyer_caracteres_mail($texte);
144
+    $sujet = nettoyer_caracteres_mail($sujet);
145
+
146
+    // encoder le sujet si possible selon la RFC
147
+    if (init_mb_string()) {
148
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
+        $charset = $GLOBALS['meta']['charset'];
151
+        mb_internal_encoding($charset);
152
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
+        mb_internal_encoding('utf-8');
154
+    }
155
+
156
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
157
+        $texte = wordwrap($texte);
158
+    }
159
+
160
+    list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
161
+
162
+    if (_OS_SERVEUR == 'windows') {
163
+        $texte = preg_replace("@\r*\n@", "\r\n", $texte);
164
+        $headers = preg_replace("@\r*\n@", "\r\n", $headers);
165
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
166
+    }
167
+
168
+    spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
169
+    // mode TEST : forcer l'email
170
+    if (defined('_TEST_EMAIL_DEST')) {
171
+        if (!_TEST_EMAIL_DEST) {
172
+            return false;
173
+        } else {
174
+            $texte = "Dest : $destinataire\r\n" . $texte;
175
+            $destinataire = _TEST_EMAIL_DEST;
176
+        }
177
+    }
178
+
179
+    return @mail($destinataire, $sujet, $texte, $headers);
180 180
 }
181 181
 
182 182
 /**
@@ -190,58 +190,58 @@  discard block
 block discarded – undo
190 190
  * @return array
191 191
  */
192 192
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
193
-	$charset = $GLOBALS['meta']['charset'];
194
-
195
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
196
-	if (strpos($headers, 'Content-Type: ') === false) {
197
-		$type =
198
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
199
-			"Content-Transfer-Encoding: 8bit\n";
200
-	} else {
201
-		$type = '';
202
-	}
203
-
204
-	// calculer un identifiant unique
205
-	// Marie Toto <[email protected]> => @toto.com
206
-	if (preg_match('/@[^\s>]+/', $from, $domain)) {
207
-		$domain = $domain[0];
208
-	}
209
-	else {
210
-		$domain = '@unknown-' . md5($from) . '.org';
211
-	}
212
-	$uniq = rand() . '_' . md5($to . $texte) . $domain;
213
-
214
-	// Si multi-part, s'en servir comme borne ...
215
-	if ($parts) {
216
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
217
-		foreach ($parts as $part) {
218
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
219
-			$e = join("\n", $part[0]);
220
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
221
-		}
222
-		$texte .= "\n\n--$uniq--\n";
223
-		// Si boundary n'est pas entre guillemets,
224
-		// elle est comprise mais le charset est ignoree !
225
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
226
-	}
227
-
228
-	// .. et s'en servir pour plaire a SpamAssassin
229
-
230
-	$mid = 'Message-Id: <' . $uniq . '>';
231
-
232
-	// indispensable pour les sites qui collent d'office From: serveur-http
233
-	// sauf si deja mis par l'envoyeur
234
-	$rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
235
-
236
-	// Nettoyer les en-tetes envoyees
237
-	// Ajouter le \n final
238
-	if (strlen($headers = trim($headers))) {
239
-		$headers .= "\n";
240
-	}
241
-
242
-	// Et mentionner l'indeboulonable nomenclature ratee
243
-
244
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
245
-
246
-	return [$headers, $texte];
193
+    $charset = $GLOBALS['meta']['charset'];
194
+
195
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
196
+    if (strpos($headers, 'Content-Type: ') === false) {
197
+        $type =
198
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
199
+            "Content-Transfer-Encoding: 8bit\n";
200
+    } else {
201
+        $type = '';
202
+    }
203
+
204
+    // calculer un identifiant unique
205
+    // Marie Toto <[email protected]> => @toto.com
206
+    if (preg_match('/@[^\s>]+/', $from, $domain)) {
207
+        $domain = $domain[0];
208
+    }
209
+    else {
210
+        $domain = '@unknown-' . md5($from) . '.org';
211
+    }
212
+    $uniq = rand() . '_' . md5($to . $texte) . $domain;
213
+
214
+    // Si multi-part, s'en servir comme borne ...
215
+    if ($parts) {
216
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
217
+        foreach ($parts as $part) {
218
+            $n = strlen($part[1]) . ($part[0] ? "\n" : '');
219
+            $e = join("\n", $part[0]);
220
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
221
+        }
222
+        $texte .= "\n\n--$uniq--\n";
223
+        // Si boundary n'est pas entre guillemets,
224
+        // elle est comprise mais le charset est ignoree !
225
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
226
+    }
227
+
228
+    // .. et s'en servir pour plaire a SpamAssassin
229
+
230
+    $mid = 'Message-Id: <' . $uniq . '>';
231
+
232
+    // indispensable pour les sites qui collent d'office From: serveur-http
233
+    // sauf si deja mis par l'envoyeur
234
+    $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
235
+
236
+    // Nettoyer les en-tetes envoyees
237
+    // Ajouter le \n final
238
+    if (strlen($headers = trim($headers))) {
239
+        $headers .= "\n";
240
+    }
241
+
242
+    // Et mentionner l'indeboulonable nomenclature ratee
243
+
244
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
245
+
246
+    return [$headers, $texte];
247 247
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136 136
 	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
137
+		$from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', $from))).')';
138 138
 	}
139 139
 
140 140
 	// nettoyer les &eacute; &#8217, &emdash; etc...
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		if (!_TEST_EMAIL_DEST) {
172 172
 			return false;
173 173
 		} else {
174
-			$texte = "Dest : $destinataire\r\n" . $texte;
174
+			$texte = "Dest : $destinataire\r\n".$texte;
175 175
 			$destinataire = _TEST_EMAIL_DEST;
176 176
 		}
177 177
 	}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	// Ajouter le Content-Type et consort s'il n'y est pas deja
196 196
 	if (strpos($headers, 'Content-Type: ') === false) {
197 197
 		$type =
198
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
198
+			"Content-Type: text/plain;charset=\"$charset\";\n".
199 199
 			"Content-Transfer-Encoding: 8bit\n";
200 200
 	} else {
201 201
 		$type = '';
@@ -207,17 +207,17 @@  discard block
 block discarded – undo
207 207
 		$domain = $domain[0];
208 208
 	}
209 209
 	else {
210
-		$domain = '@unknown-' . md5($from) . '.org';
210
+		$domain = '@unknown-'.md5($from).'.org';
211 211
 	}
212
-	$uniq = rand() . '_' . md5($to . $texte) . $domain;
212
+	$uniq = rand().'_'.md5($to.$texte).$domain;
213 213
 
214 214
 	// Si multi-part, s'en servir comme borne ...
215 215
 	if ($parts) {
216
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
216
+		$texte = "--$uniq\n$type\n".$texte."\n";
217 217
 		foreach ($parts as $part) {
218
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
218
+			$n = strlen($part[1]).($part[0] ? "\n" : '');
219 219
 			$e = join("\n", $part[0]);
220
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
220
+			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1];
221 221
 		}
222 222
 		$texte .= "\n\n--$uniq--\n";
223 223
 		// Si boundary n'est pas entre guillemets,
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
 	// .. et s'en servir pour plaire a SpamAssassin
229 229
 
230
-	$mid = 'Message-Id: <' . $uniq . '>';
230
+	$mid = 'Message-Id: <'.$uniq.'>';
231 231
 
232 232
 	// indispensable pour les sites qui collent d'office From: serveur-http
233 233
 	// sauf si deja mis par l'envoyeur
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -205,8 +205,7 @@
 block discarded – undo
205 205
 	// Marie Toto <[email protected]> => @toto.com
206 206
 	if (preg_match('/@[^\s>]+/', $from, $domain)) {
207 207
 		$domain = $domain[0];
208
-	}
209
-	else {
208
+	} else {
210 209
 		$domain = '@unknown-' . md5($from) . '.org';
211 210
 	}
212 211
 	$uniq = rand() . '_' . md5($to . $texte) . $domain;
Please login to merge, or discard this patch.
ecrire/inc/queue.php 2 patches
Indentation   +523 added lines, -523 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Queue
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 define('_JQ_SCHEDULED', 1);
@@ -50,103 +50,103 @@  discard block
 block discarded – undo
50 50
  *  id of job
51 51
  */
52 52
 function queue_add_job(
53
-	$function,
54
-	$description,
55
-	$arguments = [],
56
-	$file = '',
57
-	$no_duplicate = false,
58
-	$time = 0,
59
-	$priority = 0
53
+    $function,
54
+    $description,
55
+    $arguments = [],
56
+    $file = '',
57
+    $no_duplicate = false,
58
+    $time = 0,
59
+    $priority = 0
60 60
 ) {
61
-	include_spip('base/abstract_sql');
62
-
63
-	// cas pourri de ecrire/action/editer_site avec l'option reload=oui
64
-	if (defined('_GENIE_SYNDIC_NOW')) {
65
-		$arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
66
-	}
67
-
68
-	// serialiser les arguments
69
-	$arguments = serialize($arguments);
70
-	$md5args = md5($arguments);
71
-
72
-	// si pas de date programee, des que possible
73
-	$duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
74
-	if (!$time) {
75
-		$time = time();
76
-		$duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
77
-	}
78
-	$date = date('Y-m-d H:i:s', $time);
79
-
80
-	$set_job = [
81
-		'fonction' => $function,
82
-		'descriptif' => $description,
83
-		'args' => $arguments,
84
-		'md5args' => $md5args,
85
-		'inclure' => $file,
86
-		'priorite' => max(-10, min(10, intval($priority))),
87
-		'date' => $date,
88
-		'status' => _JQ_SCHEDULED,
89
-	];
90
-	// si option ne pas dupliquer, regarder si la fonction existe deja
91
-	// avec les memes args et file
92
-	if (
93
-		$no_duplicate
94
-		and
95
-		$id_job = sql_getfetsel(
96
-			'id_job',
97
-			'spip_jobs',
98
-			$duplicate_where =
99
-				$duplicate_where . 'fonction=' . sql_quote($function)
100
-				. (($no_duplicate === 'function_only') ? '' :
101
-			' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
102
-		)
103
-	) {
104
-		return $id_job;
105
-	}
106
-
107
-	$id_job = sql_insertq('spip_jobs', $set_job);
108
-	// en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
109
-	// avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
110
-	// doit s'effacer
111
-	if (
112
-		$no_duplicate
113
-		and
114
-		$id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
115
-	) {
116
-		sql_delete('spip_jobs', 'id_job=' . intval($id_job));
117
-
118
-		return $id_prev;
119
-	}
120
-
121
-	// verifier la non duplication qui peut etre problematique en cas de concurence
122
-	// il faut dans ce cas que seul le dernier ajoute se supprime !
123
-
124
-	// une option de debug pour verifier que les arguments en base sont bons
125
-	// ie cas d'un char non acceptables sur certains type de champs
126
-	// qui coupe la valeur
127
-	if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
-		$args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
129
-		if ($args !== $arguments) {
130
-			spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
131
-				$arguments,
132
-				true
133
-			), 'queue');
134
-		}
135
-	}
136
-
137
-	if ($id_job) {
138
-		queue_update_next_job_time($time);
139
-	}
140
-	// si la mise en file d'attente du job echoue,
141
-	// il ne faut pas perdre l'execution de la fonction
142
-	// on la lance immediatement, c'est un fallback
143
-	// sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
144
-	elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) {
145
-		$set_job['id_job'] = 0;
146
-		queue_start_job($set_job);
147
-	}
148
-
149
-	return $id_job;
61
+    include_spip('base/abstract_sql');
62
+
63
+    // cas pourri de ecrire/action/editer_site avec l'option reload=oui
64
+    if (defined('_GENIE_SYNDIC_NOW')) {
65
+        $arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
66
+    }
67
+
68
+    // serialiser les arguments
69
+    $arguments = serialize($arguments);
70
+    $md5args = md5($arguments);
71
+
72
+    // si pas de date programee, des que possible
73
+    $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
74
+    if (!$time) {
75
+        $time = time();
76
+        $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
77
+    }
78
+    $date = date('Y-m-d H:i:s', $time);
79
+
80
+    $set_job = [
81
+        'fonction' => $function,
82
+        'descriptif' => $description,
83
+        'args' => $arguments,
84
+        'md5args' => $md5args,
85
+        'inclure' => $file,
86
+        'priorite' => max(-10, min(10, intval($priority))),
87
+        'date' => $date,
88
+        'status' => _JQ_SCHEDULED,
89
+    ];
90
+    // si option ne pas dupliquer, regarder si la fonction existe deja
91
+    // avec les memes args et file
92
+    if (
93
+        $no_duplicate
94
+        and
95
+        $id_job = sql_getfetsel(
96
+            'id_job',
97
+            'spip_jobs',
98
+            $duplicate_where =
99
+                $duplicate_where . 'fonction=' . sql_quote($function)
100
+                . (($no_duplicate === 'function_only') ? '' :
101
+            ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
102
+        )
103
+    ) {
104
+        return $id_job;
105
+    }
106
+
107
+    $id_job = sql_insertq('spip_jobs', $set_job);
108
+    // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
109
+    // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
110
+    // doit s'effacer
111
+    if (
112
+        $no_duplicate
113
+        and
114
+        $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
115
+    ) {
116
+        sql_delete('spip_jobs', 'id_job=' . intval($id_job));
117
+
118
+        return $id_prev;
119
+    }
120
+
121
+    // verifier la non duplication qui peut etre problematique en cas de concurence
122
+    // il faut dans ce cas que seul le dernier ajoute se supprime !
123
+
124
+    // une option de debug pour verifier que les arguments en base sont bons
125
+    // ie cas d'un char non acceptables sur certains type de champs
126
+    // qui coupe la valeur
127
+    if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
+        $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
129
+        if ($args !== $arguments) {
130
+            spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
131
+                $arguments,
132
+                true
133
+            ), 'queue');
134
+        }
135
+    }
136
+
137
+    if ($id_job) {
138
+        queue_update_next_job_time($time);
139
+    }
140
+    // si la mise en file d'attente du job echoue,
141
+    // il ne faut pas perdre l'execution de la fonction
142
+    // on la lance immediatement, c'est un fallback
143
+    // sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
144
+    elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) {
145
+        $set_job['id_job'] = 0;
146
+        queue_start_job($set_job);
147
+    }
148
+
149
+    return $id_job;
150 150
 }
151 151
 
152 152
 /**
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
  * @return void
156 156
  */
157 157
 function queue_purger() {
158
-	include_spip('base/abstract_sql');
159
-	sql_delete('spip_jobs');
160
-	sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
161
-	include_spip('inc/genie');
162
-	genie_queue_watch_dist();
158
+    include_spip('base/abstract_sql');
159
+    sql_delete('spip_jobs');
160
+    sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
161
+    include_spip('inc/genie');
162
+    genie_queue_watch_dist();
163 163
 }
164 164
 
165 165
 /**
@@ -170,24 +170,24 @@  discard block
 block discarded – undo
170 170
  * @return bool
171 171
  */
172 172
 function queue_remove_job($id_job) {
173
-	include_spip('base/abstract_sql');
174
-
175
-	if (
176
-		$row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
-		and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
178
-	) {
179
-		queue_unlink_job($id_job);
180
-		// est-ce une tache cron qu'il faut relancer ?
181
-		if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
182
-			// relancer avec les nouveaux arguments de temps
183
-			include_spip('inc/genie');
184
-			// relancer avec la periode prevue
185
-			queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date']));
186
-		}
187
-		queue_update_next_job_time();
188
-	}
189
-
190
-	return $res;
173
+    include_spip('base/abstract_sql');
174
+
175
+    if (
176
+        $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
+        and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
178
+    ) {
179
+        queue_unlink_job($id_job);
180
+        // est-ce une tache cron qu'il faut relancer ?
181
+        if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
182
+            // relancer avec les nouveaux arguments de temps
183
+            include_spip('inc/genie');
184
+            // relancer avec la periode prevue
185
+            queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date']));
186
+        }
187
+        queue_update_next_job_time();
188
+    }
189
+
190
+    return $res;
191 191
 }
192 192
 
193 193
 /**
@@ -200,18 +200,18 @@  discard block
 block discarded – undo
200 200
  *  ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois
201 201
  */
202 202
 function queue_link_job($id_job, $objets) {
203
-	include_spip('base/abstract_sql');
204
-
205
-	if (is_array($objets) and count($objets)) {
206
-		if (is_array(reset($objets))) {
207
-			foreach ($objets as $k => $o) {
208
-				$objets[$k]['id_job'] = $id_job;
209
-			}
210
-			sql_insertq_multi('spip_jobs_liens', $objets);
211
-		} else {
212
-			sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets));
213
-		}
214
-	}
203
+    include_spip('base/abstract_sql');
204
+
205
+    if (is_array($objets) and count($objets)) {
206
+        if (is_array(reset($objets))) {
207
+            foreach ($objets as $k => $o) {
208
+                $objets[$k]['id_job'] = $id_job;
209
+            }
210
+            sql_insertq_multi('spip_jobs_liens', $objets);
211
+        } else {
212
+            sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets));
213
+        }
214
+    }
215 215
 }
216 216
 
217 217
 /**
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
  *  resultat du sql_delete
224 224
  */
225 225
 function queue_unlink_job($id_job) {
226
-	return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
226
+    return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
227 227
 }
228 228
 
229 229
 /**
@@ -236,84 +236,84 @@  discard block
 block discarded – undo
236 236
  */
237 237
 function queue_start_job($row) {
238 238
 
239
-	// deserialiser les arguments
240
-	$args = unserialize($row['args']);
241
-	if ($args === false) {
242
-		spip_log('arguments job errones ' . var_export($row, true), 'queue');
243
-		$args = [];
244
-	}
245
-
246
-	$fonction = $row['fonction'];
247
-	if (strlen($inclure = trim($row['inclure']))) {
248
-		if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction
249
-			$f = charger_fonction($fonction, rtrim($inclure, '/'), false);
250
-			if ($f) {
251
-				$fonction = $f;
252
-			}
253
-		} else {
254
-			include_spip($inclure);
255
-		}
256
-	}
257
-
258
-	if (!function_exists($fonction)) {
259
-		spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
260
-
261
-		return false;
262
-	}
263
-
264
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
265
-	switch (count($args)) {
266
-		case 0:
267
-			$res = $fonction();
268
-			break;
269
-		case 1:
270
-			$res = $fonction($args[0]);
271
-			break;
272
-		case 2:
273
-			$res = $fonction($args[0], $args[1]);
274
-			break;
275
-		case 3:
276
-			$res = $fonction($args[0], $args[1], $args[2]);
277
-			break;
278
-		case 4:
279
-			$res = $fonction($args[0], $args[1], $args[2], $args[3]);
280
-			break;
281
-		case 5:
282
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]);
283
-			break;
284
-		case 6:
285
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
286
-			break;
287
-		case 7:
288
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
289
-			break;
290
-		case 8:
291
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
292
-			break;
293
-		case 9:
294
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);
295
-			break;
296
-		case 10:
297
-			$res = $fonction(
298
-				$args[0],
299
-				$args[1],
300
-				$args[2],
301
-				$args[3],
302
-				$args[4],
303
-				$args[5],
304
-				$args[6],
305
-				$args[7],
306
-				$args[8],
307
-				$args[9]
308
-			);
309
-			break;
310
-		default:
311
-			# plus lent mais completement generique
312
-			$res = call_user_func_array($fonction, $args);
313
-	}
314
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
315
-
316
-	return $res;
239
+    // deserialiser les arguments
240
+    $args = unserialize($row['args']);
241
+    if ($args === false) {
242
+        spip_log('arguments job errones ' . var_export($row, true), 'queue');
243
+        $args = [];
244
+    }
245
+
246
+    $fonction = $row['fonction'];
247
+    if (strlen($inclure = trim($row['inclure']))) {
248
+        if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction
249
+            $f = charger_fonction($fonction, rtrim($inclure, '/'), false);
250
+            if ($f) {
251
+                $fonction = $f;
252
+            }
253
+        } else {
254
+            include_spip($inclure);
255
+        }
256
+    }
257
+
258
+    if (!function_exists($fonction)) {
259
+        spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
260
+
261
+        return false;
262
+    }
263
+
264
+    spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
265
+    switch (count($args)) {
266
+        case 0:
267
+            $res = $fonction();
268
+            break;
269
+        case 1:
270
+            $res = $fonction($args[0]);
271
+            break;
272
+        case 2:
273
+            $res = $fonction($args[0], $args[1]);
274
+            break;
275
+        case 3:
276
+            $res = $fonction($args[0], $args[1], $args[2]);
277
+            break;
278
+        case 4:
279
+            $res = $fonction($args[0], $args[1], $args[2], $args[3]);
280
+            break;
281
+        case 5:
282
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]);
283
+            break;
284
+        case 6:
285
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
286
+            break;
287
+        case 7:
288
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
289
+            break;
290
+        case 8:
291
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
292
+            break;
293
+        case 9:
294
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);
295
+            break;
296
+        case 10:
297
+            $res = $fonction(
298
+                $args[0],
299
+                $args[1],
300
+                $args[2],
301
+                $args[3],
302
+                $args[4],
303
+                $args[5],
304
+                $args[6],
305
+                $args[7],
306
+                $args[8],
307
+                $args[9]
308
+            );
309
+            break;
310
+        default:
311
+            # plus lent mais completement generique
312
+            $res = call_user_func_array($fonction, $args);
313
+    }
314
+    spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
315
+
316
+    return $res;
317 317
 }
318 318
 
319 319
 /**
@@ -340,89 +340,89 @@  discard block
 block discarded – undo
340 340
  *     - true : une planification a été faite.
341 341
  */
342 342
 function queue_schedule($force_jobs = null) {
343
-	$time = time();
344
-	if (defined('_DEBUG_BLOCK_QUEUE')) {
345
-		spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
346
-
347
-		return;
348
-	}
349
-
350
-	// rien a faire si le prochain job est encore dans le futur
351
-	if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
352
-		spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
353
-
354
-		return;
355
-	}
356
-
357
-	include_spip('base/abstract_sql');
358
-	// on ne peut rien faire si pas de connexion SQL
359
-	if (!spip_connect()) {
360
-		return false;
361
-	}
362
-
363
-	if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) {
364
-		$max_time = ini_get('max_execution_time') / 2;
365
-		// valeur conservatrice si on a pas reussi a lire le max_execution_time
366
-		if (!$max_time) {
367
-			$max_time = 5;
368
-		}
369
-		define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps.
370
-	}
371
-	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
372
-
373
-	spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
374
-
375
-	if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
376
-		define('_JQ_MAX_JOBS_EXECUTE', 200);
377
-	}
378
-	$nbj = 0;
379
-	// attraper les jobs
380
-	// dont la date est passee (echus en attente),
381
-	// par ordre :
382
-	//	- de priorite
383
-	//	- de date
384
-	// lorsqu'un job cron n'a pas fini, sa priorite est descendue
385
-	// pour qu'il ne bloque pas les autres jobs en attente
386
-	if (is_array($force_jobs) and count($force_jobs)) {
387
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
388
-	} else {
389
-		$now = date('Y-m-d H:i:s', $time);
390
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
391
-	}
392
-
393
-	register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
394
-	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
395
-	do {
396
-		if ($row = array_shift($res)) {
397
-			$nbj++;
398
-			// il faut un verrou, a base de sql_delete
399
-			if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
400
-				#spip_log("JQ schedule job ".$nbj." OK",'jq');
401
-				// on reinsert dans la base aussitot avec un status=_JQ_PENDING
402
-				$row['status'] = _JQ_PENDING;
403
-				$row['date'] = date('Y-m-d H:i:s', $time);
404
-				sql_insertq('spip_jobs', $row);
405
-
406
-				// on a la main sur le job :
407
-				// l'executer
408
-				$result = queue_start_job($row);
409
-
410
-				$time = time();
411
-				queue_close_job($row, $time, $result);
412
-			}
413
-		}
414
-		spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
415
-	} while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
416
-	spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
417
-
418
-	if ($row = array_shift($res)) {
419
-		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
420
-		spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
421
-	} else {
422
-		queue_update_next_job_time();
423
-	}
424
-
425
-	return true;
343
+    $time = time();
344
+    if (defined('_DEBUG_BLOCK_QUEUE')) {
345
+        spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
346
+
347
+        return;
348
+    }
349
+
350
+    // rien a faire si le prochain job est encore dans le futur
351
+    if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
352
+        spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
353
+
354
+        return;
355
+    }
356
+
357
+    include_spip('base/abstract_sql');
358
+    // on ne peut rien faire si pas de connexion SQL
359
+    if (!spip_connect()) {
360
+        return false;
361
+    }
362
+
363
+    if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) {
364
+        $max_time = ini_get('max_execution_time') / 2;
365
+        // valeur conservatrice si on a pas reussi a lire le max_execution_time
366
+        if (!$max_time) {
367
+            $max_time = 5;
368
+        }
369
+        define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps.
370
+    }
371
+    $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
372
+
373
+    spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
374
+
375
+    if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
376
+        define('_JQ_MAX_JOBS_EXECUTE', 200);
377
+    }
378
+    $nbj = 0;
379
+    // attraper les jobs
380
+    // dont la date est passee (echus en attente),
381
+    // par ordre :
382
+    //	- de priorite
383
+    //	- de date
384
+    // lorsqu'un job cron n'a pas fini, sa priorite est descendue
385
+    // pour qu'il ne bloque pas les autres jobs en attente
386
+    if (is_array($force_jobs) and count($force_jobs)) {
387
+        $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
388
+    } else {
389
+        $now = date('Y-m-d H:i:s', $time);
390
+        $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
391
+    }
392
+
393
+    register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
394
+    $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
395
+    do {
396
+        if ($row = array_shift($res)) {
397
+            $nbj++;
398
+            // il faut un verrou, a base de sql_delete
399
+            if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
400
+                #spip_log("JQ schedule job ".$nbj." OK",'jq');
401
+                // on reinsert dans la base aussitot avec un status=_JQ_PENDING
402
+                $row['status'] = _JQ_PENDING;
403
+                $row['date'] = date('Y-m-d H:i:s', $time);
404
+                sql_insertq('spip_jobs', $row);
405
+
406
+                // on a la main sur le job :
407
+                // l'executer
408
+                $result = queue_start_job($row);
409
+
410
+                $time = time();
411
+                queue_close_job($row, $time, $result);
412
+            }
413
+        }
414
+        spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
415
+    } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
416
+    spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
417
+
418
+    if ($row = array_shift($res)) {
419
+        queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
420
+        spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
421
+    } else {
422
+        queue_update_next_job_time();
423
+    }
424
+
425
+    return true;
426 426
 }
427 427
 
428 428
 /**
@@ -440,21 +440,21 @@  discard block
 block discarded – undo
440 440
  * @param int $result
441 441
  */
442 442
 function queue_close_job(&$row, $time, $result = 0) {
443
-	// est-ce une tache cron qu'il faut relancer ?
444
-	if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
445
-		// relancer avec les nouveaux arguments de temps
446
-		include_spip('inc/genie');
447
-		if ($result < 0) { // relancer tout de suite, mais en baissant la priorite
448
-		queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1);
449
-		} else // relancer avec la periode prevue
450
-		{
451
-			queue_genie_replan_job($row['fonction'], $periode, $time);
452
-		}
453
-	}
454
-	// purger ses liens eventuels avec des objets
455
-	sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
456
-	// supprimer le job fini
457
-	sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
443
+    // est-ce une tache cron qu'il faut relancer ?
444
+    if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
445
+        // relancer avec les nouveaux arguments de temps
446
+        include_spip('inc/genie');
447
+        if ($result < 0) { // relancer tout de suite, mais en baissant la priorite
448
+        queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1);
449
+        } else // relancer avec la periode prevue
450
+        {
451
+            queue_genie_replan_job($row['fonction'], $periode, $time);
452
+        }
453
+    }
454
+    // purger ses liens eventuels avec des objets
455
+    sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
456
+    // supprimer le job fini
457
+    sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
458 458
 }
459 459
 
460 460
 /**
@@ -464,10 +464,10 @@  discard block
 block discarded – undo
464 464
  * @uses queue_update_next_job_time()
465 465
  */
466 466
 function queue_error_handler() {
467
-	// se remettre dans le bon dossier, car Apache le change parfois (toujours?)
468
-	chdir(_ROOT_CWD);
467
+    // se remettre dans le bon dossier, car Apache le change parfois (toujours?)
468
+    chdir(_ROOT_CWD);
469 469
 
470
-	queue_update_next_job_time();
470
+    queue_update_next_job_time();
471 471
 }
472 472
 
473 473
 
@@ -484,18 +484,18 @@  discard block
 block discarded – undo
484 484
  *     Périodicité de la tâche en secondes, si tâche périodique, sinon false.
485 485
  */
486 486
 function queue_is_cron_job($function, $inclure) {
487
-	static $taches = null;
488
-	if (strncmp($inclure, 'genie/', 6) == 0) {
489
-		if (is_null($taches)) {
490
-			include_spip('inc/genie');
491
-			$taches = taches_generales();
492
-		}
493
-		if (isset($taches[$function])) {
494
-			return $taches[$function];
495
-		}
496
-	}
497
-
498
-	return false;
487
+    static $taches = null;
488
+    if (strncmp($inclure, 'genie/', 6) == 0) {
489
+        if (is_null($taches)) {
490
+            include_spip('inc/genie');
491
+            $taches = taches_generales();
492
+        }
493
+        if (isset($taches[$function])) {
494
+            return $taches[$function];
495
+        }
496
+    }
497
+
498
+    return false;
499 499
 }
500 500
 
501 501
 /**
@@ -509,62 +509,62 @@  discard block
 block discarded – undo
509 509
  *  temps de la tache ajoutee ou 0 pour ASAP
510 510
  */
511 511
 function queue_update_next_job_time($next_time = null) {
512
-	static $nb_jobs_scheduled = null;
513
-	static $deja_la = false;
514
-	// prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
515
-	static $next = null;
516
-	// queue_close_job peut etre reentrant ici
517
-	if ($deja_la) {
518
-		return;
519
-	}
520
-	$deja_la = true;
521
-
522
-	include_spip('base/abstract_sql');
523
-	$time = time();
524
-
525
-	// traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
526
-	// pour cause de timeout ou autre erreur fatale
527
-	$res = sql_allfetsel(
528
-		'*',
529
-		'spip_jobs',
530
-		'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
531
-	);
532
-	if (is_array($res)) {
533
-		foreach ($res as $row) {
534
-			queue_close_job($row, $time);
535
-			spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
536
-		}
537
-	}
538
-
539
-	// chercher la date du prochain job si pas connu
540
-	if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
541
-		$date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
542
-		$next = strtotime($date);
543
-	}
544
-	if (!is_null($next_time)) {
545
-		if (is_null($next) or $next > $next_time) {
546
-			$next = $next_time;
547
-		}
548
-	}
549
-
550
-	if ($next) {
551
-		if (is_null($nb_jobs_scheduled)) {
552
-			$nb_jobs_scheduled = sql_countsel(
553
-				'spip_jobs',
554
-				'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
555
-			);
556
-		} elseif ($next <= $time) {
557
-			$nb_jobs_scheduled++;
558
-		}
559
-		// si trop de jobs en attente, on force la purge en fin de hit
560
-		// pour assurer le coup
561
-		if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) {
562
-			define('_DIRECT_CRON_FORCE', true);
563
-		}
564
-	}
565
-
566
-	queue_set_next_job_time($next);
567
-	$deja_la = false;
512
+    static $nb_jobs_scheduled = null;
513
+    static $deja_la = false;
514
+    // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
515
+    static $next = null;
516
+    // queue_close_job peut etre reentrant ici
517
+    if ($deja_la) {
518
+        return;
519
+    }
520
+    $deja_la = true;
521
+
522
+    include_spip('base/abstract_sql');
523
+    $time = time();
524
+
525
+    // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
526
+    // pour cause de timeout ou autre erreur fatale
527
+    $res = sql_allfetsel(
528
+        '*',
529
+        'spip_jobs',
530
+        'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
531
+    );
532
+    if (is_array($res)) {
533
+        foreach ($res as $row) {
534
+            queue_close_job($row, $time);
535
+            spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
536
+        }
537
+    }
538
+
539
+    // chercher la date du prochain job si pas connu
540
+    if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
541
+        $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
542
+        $next = strtotime($date);
543
+    }
544
+    if (!is_null($next_time)) {
545
+        if (is_null($next) or $next > $next_time) {
546
+            $next = $next_time;
547
+        }
548
+    }
549
+
550
+    if ($next) {
551
+        if (is_null($nb_jobs_scheduled)) {
552
+            $nb_jobs_scheduled = sql_countsel(
553
+                'spip_jobs',
554
+                'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
555
+            );
556
+        } elseif ($next <= $time) {
557
+            $nb_jobs_scheduled++;
558
+        }
559
+        // si trop de jobs en attente, on force la purge en fin de hit
560
+        // pour assurer le coup
561
+        if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) {
562
+            define('_DIRECT_CRON_FORCE', true);
563
+        }
564
+    }
565
+
566
+    queue_set_next_job_time($next);
567
+    $deja_la = false;
568 568
 }
569 569
 
570 570
 
@@ -575,26 +575,26 @@  discard block
 block discarded – undo
575 575
  */
576 576
 function queue_set_next_job_time($next) {
577 577
 
578
-	// utiliser le temps courant reel plutot que temps de la requete ici
579
-	$time = time();
580
-
581
-	// toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
582
-	// et ne mettre a jour que si il y a un interet a le faire
583
-	// permet ausis d'initialiser le nom de fichier a coup sur
584
-	$curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true));
585
-	if (
586
-		($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle
587
-		or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle
588
-	) {
589
-		if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
590
-			cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
591
-		} else {
592
-			ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
593
-		}
594
-		queue_sleep_time_to_next_job($next);
595
-	}
596
-
597
-	return queue_sleep_time_to_next_job();
578
+    // utiliser le temps courant reel plutot que temps de la requete ici
579
+    $time = time();
580
+
581
+    // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
582
+    // et ne mettre a jour que si il y a un interet a le faire
583
+    // permet ausis d'initialiser le nom de fichier a coup sur
584
+    $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true));
585
+    if (
586
+        ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle
587
+        or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle
588
+    ) {
589
+        if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
590
+            cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
591
+        } else {
592
+            ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
593
+        }
594
+        queue_sleep_time_to_next_job($next);
595
+    }
596
+
597
+    return queue_sleep_time_to_next_job();
598 598
 }
599 599
 
600 600
 /**
@@ -611,60 +611,60 @@  discard block
 block discarded – undo
611 611
  * @return string
612 612
  */
613 613
 function queue_affichage_cron() {
614
-	$texte = '';
615
-
616
-	$time_to_next = queue_sleep_time_to_next_job();
617
-	// rien a faire si le prochain job est encore dans le futur
618
-	if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) {
619
-		return $texte;
620
-	}
621
-
622
-	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
623
-	if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
624
-		return $texte;
625
-	}
626
-
627
-	@touch($lock);
628
-
629
-	// il y a des taches en attentes
630
-	// si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
631
-	// on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
632
-	$urgent = false;
633
-	if ($time_to_next < -300) {
634
-		$urgent = true;
635
-	}
636
-
637
-	$url_cron = generer_url_action('cron', '', false, true);
638
-
639
-	if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) {
640
-		if (queue_lancer_url_http_async($url_cron) and !$urgent) {
641
-			return $texte;
642
-		}
643
-	}
644
-
645
-	// si deja force, on retourne sans rien
646
-	if (defined('_DIRECT_CRON_FORCE')) {
647
-		return $texte;
648
-	}
649
-
650
-	// si c'est un bot
651
-	// inutile de faire un appel par image background,
652
-	// on force un appel direct en fin de hit
653
-	if ((defined('_IS_BOT') and _IS_BOT)) {
654
-		define('_DIRECT_CRON_FORCE', true);
655
-
656
-		return $texte;
657
-	}
658
-
659
-	if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) {
660
-		// en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS
661
-		$url_cron = generer_url_action('cron');
662
-		$texte = '<!-- SPIP-CRON -->'
663
-		  . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>"
664
-		  . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>";
665
-	}
666
-
667
-	return $texte;
614
+    $texte = '';
615
+
616
+    $time_to_next = queue_sleep_time_to_next_job();
617
+    // rien a faire si le prochain job est encore dans le futur
618
+    if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) {
619
+        return $texte;
620
+    }
621
+
622
+    // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
623
+    if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
624
+        return $texte;
625
+    }
626
+
627
+    @touch($lock);
628
+
629
+    // il y a des taches en attentes
630
+    // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
631
+    // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
632
+    $urgent = false;
633
+    if ($time_to_next < -300) {
634
+        $urgent = true;
635
+    }
636
+
637
+    $url_cron = generer_url_action('cron', '', false, true);
638
+
639
+    if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) {
640
+        if (queue_lancer_url_http_async($url_cron) and !$urgent) {
641
+            return $texte;
642
+        }
643
+    }
644
+
645
+    // si deja force, on retourne sans rien
646
+    if (defined('_DIRECT_CRON_FORCE')) {
647
+        return $texte;
648
+    }
649
+
650
+    // si c'est un bot
651
+    // inutile de faire un appel par image background,
652
+    // on force un appel direct en fin de hit
653
+    if ((defined('_IS_BOT') and _IS_BOT)) {
654
+        define('_DIRECT_CRON_FORCE', true);
655
+
656
+        return $texte;
657
+    }
658
+
659
+    if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) {
660
+        // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS
661
+        $url_cron = generer_url_action('cron');
662
+        $texte = '<!-- SPIP-CRON -->'
663
+            . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>"
664
+            . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>";
665
+    }
666
+
667
+    return $texte;
668 668
 }
669 669
 
670 670
 /**
@@ -673,73 +673,73 @@  discard block
 block discarded – undo
673 673
  * @return bool : true si l'url a pu être appelée en asynchrone, false sinon
674 674
  */
675 675
 function queue_lancer_url_http_async($url_cron) {
676
-	// methode la plus rapide :
677
-	// Si fsockopen est possible, on lance le cron via un socket en asynchrone
678
-	// si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
679
-	// car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
680
-	// mais on renvoie false direct
681
-	if (function_exists('fsockopen')) {
682
-		$parts = parse_url($url_cron);
683
-
684
-		switch ($parts['scheme']) {
685
-			case 'https':
686
-				$scheme = 'ssl://';
687
-				$port = 443;
688
-				break;
689
-			case 'http':
690
-			default:
691
-				$scheme = '';
692
-				$port = 80;
693
-		}
694
-		$fp = @fsockopen(
695
-			$scheme . $parts['host'],
696
-			isset($parts['port']) ? $parts['port'] : $port,
697
-			$errno,
698
-			$errstr,
699
-			1
700
-		);
701
-
702
-		if ($fp) {
703
-			$host_sent = $parts['host'];
704
-			if (isset($parts['port']) and $parts['port'] !== $port) {
705
-				$host_sent .= ':' . $parts['port'];
706
-			}
707
-			$timeout = 200; // ms
708
-			stream_set_timeout($fp, 0, $timeout * 1000);
709
-			$query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
710
-			$out = 'GET ' . $query . " HTTP/1.1\r\n";
711
-			$out .= 'Host: ' . $host_sent . "\r\n";
712
-			$out .= "Connection: Close\r\n\r\n";
713
-			fwrite($fp, $out);
714
-			spip_timer('read');
715
-			$t = 0;
716
-			// on lit la reponse si possible pour fermer proprement la connexion
717
-			// avec un timeout total de 200ms pour ne pas se bloquer
718
-			while (!feof($fp) and $t < $timeout) {
719
-				@fgets($fp, 1024);
720
-				$t += spip_timer('read', true);
721
-				spip_timer('read');
722
-			}
723
-			fclose($fp);
724
-			return true;
725
-		}
726
-	}
727
-	// si fsockopen n'est pas dispo on essaye cURL :
728
-	// lancer le cron par un cURL asynchrone si cURL est present
729
-	elseif (function_exists('curl_init')) {
730
-		//setting the curl parameters.
731
-		$ch = curl_init($url_cron);
732
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
733
-		// cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
734
-		curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
735
-		// valeur mini pour que la requete soit lancee
736
-		curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
737
-		// lancer
738
-		curl_exec($ch);
739
-		// fermer
740
-		curl_close($ch);
741
-		return true;
742
-	}
743
-
744
-	return false;
676
+    // methode la plus rapide :
677
+    // Si fsockopen est possible, on lance le cron via un socket en asynchrone
678
+    // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
679
+    // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
680
+    // mais on renvoie false direct
681
+    if (function_exists('fsockopen')) {
682
+        $parts = parse_url($url_cron);
683
+
684
+        switch ($parts['scheme']) {
685
+            case 'https':
686
+                $scheme = 'ssl://';
687
+                $port = 443;
688
+                break;
689
+            case 'http':
690
+            default:
691
+                $scheme = '';
692
+                $port = 80;
693
+        }
694
+        $fp = @fsockopen(
695
+            $scheme . $parts['host'],
696
+            isset($parts['port']) ? $parts['port'] : $port,
697
+            $errno,
698
+            $errstr,
699
+            1
700
+        );
701
+
702
+        if ($fp) {
703
+            $host_sent = $parts['host'];
704
+            if (isset($parts['port']) and $parts['port'] !== $port) {
705
+                $host_sent .= ':' . $parts['port'];
706
+            }
707
+            $timeout = 200; // ms
708
+            stream_set_timeout($fp, 0, $timeout * 1000);
709
+            $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
710
+            $out = 'GET ' . $query . " HTTP/1.1\r\n";
711
+            $out .= 'Host: ' . $host_sent . "\r\n";
712
+            $out .= "Connection: Close\r\n\r\n";
713
+            fwrite($fp, $out);
714
+            spip_timer('read');
715
+            $t = 0;
716
+            // on lit la reponse si possible pour fermer proprement la connexion
717
+            // avec un timeout total de 200ms pour ne pas se bloquer
718
+            while (!feof($fp) and $t < $timeout) {
719
+                @fgets($fp, 1024);
720
+                $t += spip_timer('read', true);
721
+                spip_timer('read');
722
+            }
723
+            fclose($fp);
724
+            return true;
725
+        }
726
+    }
727
+    // si fsockopen n'est pas dispo on essaye cURL :
728
+    // lancer le cron par un cURL asynchrone si cURL est present
729
+    elseif (function_exists('curl_init')) {
730
+        //setting the curl parameters.
731
+        $ch = curl_init($url_cron);
732
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
733
+        // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
734
+        curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
735
+        // valeur mini pour que la requete soit lancee
736
+        curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
737
+        // lancer
738
+        curl_exec($ch);
739
+        // fermer
740
+        curl_close($ch);
741
+        return true;
742
+    }
743
+
744
+    return false;
745 745
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -38 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	$md5args = md5($arguments);
71 71
 
72 72
 	// si pas de date programee, des que possible
73
-	$duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
73
+	$duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND ';
74 74
 	if (!$time) {
75 75
 		$time = time();
76 76
 		$duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
@@ -96,9 +96,8 @@  discard block
 block discarded – undo
96 96
 			'id_job',
97 97
 			'spip_jobs',
98 98
 			$duplicate_where =
99
-				$duplicate_where . 'fonction=' . sql_quote($function)
100
-				. (($no_duplicate === 'function_only') ? '' :
101
-			' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
99
+				$duplicate_where.'fonction='.sql_quote($function)
100
+				. (($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file))
102 101
 		)
103 102
 	) {
104 103
 		return $id_job;
@@ -111,9 +110,9 @@  discard block
 block discarded – undo
111 110
 	if (
112 111
 		$no_duplicate
113 112
 		and
114
-		$id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
113
+		$id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<'.intval($id_job)." AND $duplicate_where")
115 114
 	) {
116
-		sql_delete('spip_jobs', 'id_job=' . intval($id_job));
115
+		sql_delete('spip_jobs', 'id_job='.intval($id_job));
117 116
 
118 117
 		return $id_prev;
119 118
 	}
@@ -125,9 +124,9 @@  discard block
 block discarded – undo
125 124
 	// ie cas d'un char non acceptables sur certains type de champs
126 125
 	// qui coupe la valeur
127 126
 	if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
-		$args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
127
+		$args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job));
129 128
 		if ($args !== $arguments) {
130
-			spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
129
+			spip_log('arguments job errones / longueur '.strlen($args).' vs '.strlen($arguments).' / valeur : '.var_export(
131 130
 				$arguments,
132 131
 				true
133 132
 			), 'queue');
@@ -157,7 +156,7 @@  discard block
 block discarded – undo
157 156
 function queue_purger() {
158 157
 	include_spip('base/abstract_sql');
159 158
 	sql_delete('spip_jobs');
160
-	sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
159
+	sql_delete('spip_jobs_liens', 'id_job NOT IN ('.sql_get_select('id_job', 'spip_jobs').')');
161 160
 	include_spip('inc/genie');
162 161
 	genie_queue_watch_dist();
163 162
 }
@@ -173,8 +172,8 @@  discard block
 block discarded – undo
173 172
 	include_spip('base/abstract_sql');
174 173
 
175 174
 	if (
176
-		$row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
-		and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
175
+		$row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job))
176
+		and $res = sql_delete('spip_jobs', 'id_job='.intval($id_job))
178 177
 	) {
179 178
 		queue_unlink_job($id_job);
180 179
 		// est-ce une tache cron qu'il faut relancer ?
@@ -223,7 +222,7 @@  discard block
 block discarded – undo
223 222
  *  resultat du sql_delete
224 223
  */
225 224
 function queue_unlink_job($id_job) {
226
-	return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
225
+	return sql_delete('spip_jobs_liens', 'id_job='.intval($id_job));
227 226
 }
228 227
 
229 228
 /**
@@ -239,7 +238,7 @@  discard block
 block discarded – undo
239 238
 	// deserialiser les arguments
240 239
 	$args = unserialize($row['args']);
241 240
 	if ($args === false) {
242
-		spip_log('arguments job errones ' . var_export($row, true), 'queue');
241
+		spip_log('arguments job errones '.var_export($row, true), 'queue');
243 242
 		$args = [];
244 243
 	}
245 244
 
@@ -256,12 +255,12 @@  discard block
 block discarded – undo
256 255
 	}
257 256
 
258 257
 	if (!function_exists($fonction)) {
259
-		spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
258
+		spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue');
260 259
 
261 260
 		return false;
262 261
 	}
263 262
 
264
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
263
+	spip_log('queue ['.$row['id_job']."]: $fonction() start", 'queue');
265 264
 	switch (count($args)) {
266 265
 		case 0:
267 266
 			$res = $fonction();
@@ -311,7 +310,7 @@  discard block
 block discarded – undo
311 310
 			# plus lent mais completement generique
312 311
 			$res = call_user_func_array($fonction, $args);
313 312
 	}
314
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
313
+	spip_log('queue ['.$row['id_job']."]: $fonction() end", 'queue');
315 314
 
316 315
 	return $res;
317 316
 }
@@ -342,14 +341,14 @@  discard block
 block discarded – undo
342 341
 function queue_schedule($force_jobs = null) {
343 342
 	$time = time();
344 343
 	if (defined('_DEBUG_BLOCK_QUEUE')) {
345
-		spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
344
+		spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq'._LOG_DEBUG);
346 345
 
347 346
 		return;
348 347
 	}
349 348
 
350 349
 	// rien a faire si le prochain job est encore dans le futur
351 350
 	if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
352
-		spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
351
+		spip_log('queue_sleep_time_to_next_job', 'jq'._LOG_DEBUG);
353 352
 
354 353
 		return;
355 354
 	}
@@ -370,7 +369,7 @@  discard block
 block discarded – undo
370 369
 	}
371 370
 	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
372 371
 
373
-	spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
372
+	spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG);
374 373
 
375 374
 	if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
376 375
 		define('_JQ_MAX_JOBS_EXECUTE', 200);
@@ -384,19 +383,19 @@  discard block
 block discarded – undo
384 383
 	// lorsqu'un job cron n'a pas fini, sa priorite est descendue
385 384
 	// pour qu'il ne bloque pas les autres jobs en attente
386 385
 	if (is_array($force_jobs) and count($force_jobs)) {
387
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
386
+		$cond = 'status='.intval(_JQ_SCHEDULED).' AND '.sql_in('id_job', $force_jobs);
388 387
 	} else {
389 388
 		$now = date('Y-m-d H:i:s', $time);
390
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
389
+		$cond = 'status='.intval(_JQ_SCHEDULED).' AND date<='.sql_quote($now);
391 390
 	}
392 391
 
393 392
 	register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
394
-	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
393
+	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1));
395 394
 	do {
396 395
 		if ($row = array_shift($res)) {
397 396
 			$nbj++;
398 397
 			// il faut un verrou, a base de sql_delete
399
-			if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
398
+			if (sql_delete('spip_jobs', 'id_job='.intval($row['id_job']).' AND status='.intval(_JQ_SCHEDULED))) {
400 399
 				#spip_log("JQ schedule job ".$nbj." OK",'jq');
401 400
 				// on reinsert dans la base aussitot avec un status=_JQ_PENDING
402 401
 				$row['status'] = _JQ_PENDING;
@@ -411,13 +410,13 @@  discard block
 block discarded – undo
411 410
 				queue_close_job($row, $time, $result);
412 411
 			}
413 412
 		}
414
-		spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
413
+		spip_log('JQ schedule job end time '.$time, 'jq'._LOG_DEBUG);
415 414
 	} while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
416
-	spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
415
+	spip_log('JQ schedule end time '.time(), 'jq'._LOG_DEBUG);
417 416
 
418 417
 	if ($row = array_shift($res)) {
419 418
 		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
420
-		spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
419
+		spip_log('JQ encore !', 'jq'._LOG_DEBUG);
421 420
 	} else {
422 421
 		queue_update_next_job_time();
423 422
 	}
@@ -452,9 +451,9 @@  discard block
 block discarded – undo
452 451
 		}
453 452
 	}
454 453
 	// purger ses liens eventuels avec des objets
455
-	sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
454
+	sql_delete('spip_jobs_liens', 'id_job='.intval($row['id_job']));
456 455
 	// supprimer le job fini
457
-	sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
456
+	sql_delete('spip_jobs', 'id_job='.intval($row['id_job']));
458 457
 }
459 458
 
460 459
 /**
@@ -527,18 +526,18 @@  discard block
 block discarded – undo
527 526
 	$res = sql_allfetsel(
528 527
 		'*',
529 528
 		'spip_jobs',
530
-		'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
529
+		'status='.intval(_JQ_PENDING).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time - 180))
531 530
 	);
532 531
 	if (is_array($res)) {
533 532
 		foreach ($res as $row) {
534 533
 			queue_close_job($row, $time);
535
-			spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
534
+			spip_log('queue_close_job car _JQ_PENDING depuis +180s : '.print_r($row, 1), 'job_mort'._LOG_ERREUR);
536 535
 		}
537 536
 	}
538 537
 
539 538
 	// chercher la date du prochain job si pas connu
540 539
 	if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
541
-		$date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
540
+		$date = sql_getfetsel('date', 'spip_jobs', 'status='.intval(_JQ_SCHEDULED), '', 'date', '0,1');
542 541
 		$next = strtotime($date);
543 542
 	}
544 543
 	if (!is_null($next_time)) {
@@ -551,7 +550,7 @@  discard block
 block discarded – undo
551 550
 		if (is_null($nb_jobs_scheduled)) {
552 551
 			$nb_jobs_scheduled = sql_countsel(
553 552
 				'spip_jobs',
554
-				'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
553
+				'status='.intval(_JQ_SCHEDULED).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time))
555 554
 			);
556 555
 		} elseif ($next <= $time) {
557 556
 			$nb_jobs_scheduled++;
@@ -620,7 +619,7 @@  discard block
 block discarded – undo
620 619
 	}
621 620
 
622 621
 	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
623
-	if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
622
+	if (file_exists($lock = _DIR_TMP.'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
624 623
 		return $texte;
625 624
 	}
626 625
 
@@ -692,7 +691,7 @@  discard block
 block discarded – undo
692 691
 				$port = 80;
693 692
 		}
694 693
 		$fp = @fsockopen(
695
-			$scheme . $parts['host'],
694
+			$scheme.$parts['host'],
696 695
 			isset($parts['port']) ? $parts['port'] : $port,
697 696
 			$errno,
698 697
 			$errstr,
@@ -702,13 +701,13 @@  discard block
 block discarded – undo
702 701
 		if ($fp) {
703 702
 			$host_sent = $parts['host'];
704 703
 			if (isset($parts['port']) and $parts['port'] !== $port) {
705
-				$host_sent .= ':' . $parts['port'];
704
+				$host_sent .= ':'.$parts['port'];
706 705
 			}
707 706
 			$timeout = 200; // ms
708 707
 			stream_set_timeout($fp, 0, $timeout * 1000);
709
-			$query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
710
-			$out = 'GET ' . $query . " HTTP/1.1\r\n";
711
-			$out .= 'Host: ' . $host_sent . "\r\n";
708
+			$query = $parts['path'].($parts['query'] ? '?'.$parts['query'] : '');
709
+			$out = 'GET '.$query." HTTP/1.1\r\n";
710
+			$out .= 'Host: '.$host_sent."\r\n";
712 711
 			$out .= "Connection: Close\r\n\r\n";
713 712
 			fwrite($fp, $out);
714 713
 			spip_timer('read');
Please login to merge, or discard this patch.
ecrire/inc/texte.php 2 patches
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/texte_mini');
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @return array Tablea ('','')
35 35
  */
36 36
 function definir_raccourcis_alineas() {
37
-	return ['', ''];
37
+    return ['', ''];
38 38
 }
39 39
 
40 40
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
  * @return string
48 48
  */
49 49
 function traiter_tableau($bloc) {
50
-	return $bloc;
50
+    return $bloc;
51 51
 }
52 52
 
53 53
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
  * @return string
62 62
  */
63 63
 function traiter_listes($texte) {
64
-	return $texte;
64
+    return $texte;
65 65
 }
66 66
 
67 67
 /**
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function traiter_raccourcis($letexte) {
79 79
 
80
-	// Appeler les fonctions de pre_traitement
81
-	$letexte = pipeline('pre_propre', $letexte);
80
+    // Appeler les fonctions de pre_traitement
81
+    $letexte = pipeline('pre_propre', $letexte);
82 82
 
83
-	// APPELER ICI UN PIPELINE traiter_raccourcis ?
84
-	// $letexte = pipeline('traiter_raccourcis', $letexte);
83
+    // APPELER ICI UN PIPELINE traiter_raccourcis ?
84
+    // $letexte = pipeline('traiter_raccourcis', $letexte);
85 85
 
86
-	// Appeler les fonctions de post-traitement
87
-	$letexte = pipeline('post_propre', $letexte);
86
+    // Appeler les fonctions de post-traitement
87
+    $letexte = pipeline('post_propre', $letexte);
88 88
 
89
-	return $letexte;
89
+    return $letexte;
90 90
 }
91 91
 
92 92
 /*************************************************************************************************************************
@@ -102,22 +102,22 @@  discard block
 block discarded – undo
102 102
  * @return string
103 103
  */
104 104
 function echappe_js($t, $class = ' class = "echappe-js"') {
105
-	foreach (['script', 'iframe'] as $tag) {
106
-		if (
107
-			stripos($t, "<$tag") !== false
108
-			and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
109
-		) {
110
-			foreach ($r as $regs) {
111
-				$t = str_replace(
112
-					$regs[0],
113
-					"<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
114
-					$t
115
-				);
116
-			}
117
-		}
118
-	}
119
-
120
-	return $t;
105
+    foreach (['script', 'iframe'] as $tag) {
106
+        if (
107
+            stripos($t, "<$tag") !== false
108
+            and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
109
+        ) {
110
+            foreach ($r as $regs) {
111
+                $t = str_replace(
112
+                    $regs[0],
113
+                    "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
114
+                    $t
115
+                );
116
+            }
117
+        }
118
+    }
119
+
120
+    return $t;
121 121
 }
122 122
 
123 123
 
@@ -146,55 +146,55 @@  discard block
 block discarded – undo
146 146
  *     Code protégé
147 147
  **/
148 148
 function interdire_scripts($arg, $mode_filtre = null) {
149
-	// on memorise le resultat sur les arguments non triviaux
150
-	static $dejavu = [];
151
-
152
-	// Attention, si ce n'est pas une chaine, laisser intact
153
-	if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
154
-		return $arg;
155
-	}
156
-
157
-	if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) {
158
-		$mode_filtre = $GLOBALS['filtrer_javascript'];
159
-	}
160
-
161
-	if (isset($dejavu[$mode_filtre][$arg])) {
162
-		return $dejavu[$mode_filtre][$arg];
163
-	}
164
-
165
-	// echapper les tags asp/php
166
-	$t = str_replace('<' . '%', '&lt;%', $arg);
167
-
168
-	// echapper le php
169
-	$t = str_replace('<' . '?', '&lt;?', $t);
170
-
171
-	// echapper le < script language=php >
172
-	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
173
-
174
-	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
175
-	switch ($mode_filtre) {
176
-		case 0:
177
-			if (!_DIR_RESTREINT) {
178
-				$t = echappe_js($t);
179
-			}
180
-			break;
181
-		case -1:
182
-			$t = echappe_js($t);
183
-			break;
184
-	}
185
-
186
-	// pas de <base href /> svp !
187
-	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
188
-
189
-	// Reinserer les echappements des modeles
190
-	if (defined('_PROTEGE_JS_MODELES')) {
191
-		$t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
192
-	}
193
-	if (defined('_PROTEGE_PHP_MODELES')) {
194
-		$t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
195
-	}
196
-
197
-	return $dejavu[$mode_filtre][$arg] = $t;
149
+    // on memorise le resultat sur les arguments non triviaux
150
+    static $dejavu = [];
151
+
152
+    // Attention, si ce n'est pas une chaine, laisser intact
153
+    if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
154
+        return $arg;
155
+    }
156
+
157
+    if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) {
158
+        $mode_filtre = $GLOBALS['filtrer_javascript'];
159
+    }
160
+
161
+    if (isset($dejavu[$mode_filtre][$arg])) {
162
+        return $dejavu[$mode_filtre][$arg];
163
+    }
164
+
165
+    // echapper les tags asp/php
166
+    $t = str_replace('<' . '%', '&lt;%', $arg);
167
+
168
+    // echapper le php
169
+    $t = str_replace('<' . '?', '&lt;?', $t);
170
+
171
+    // echapper le < script language=php >
172
+    $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
173
+
174
+    // Pour le js, trois modes : parano (-1), prive (0), ok (1)
175
+    switch ($mode_filtre) {
176
+        case 0:
177
+            if (!_DIR_RESTREINT) {
178
+                $t = echappe_js($t);
179
+            }
180
+            break;
181
+        case -1:
182
+            $t = echappe_js($t);
183
+            break;
184
+    }
185
+
186
+    // pas de <base href /> svp !
187
+    $t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
188
+
189
+    // Reinserer les echappements des modeles
190
+    if (defined('_PROTEGE_JS_MODELES')) {
191
+        $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
192
+    }
193
+    if (defined('_PROTEGE_PHP_MODELES')) {
194
+        $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
195
+    }
196
+
197
+    return $dejavu[$mode_filtre][$arg] = $t;
198 198
 }
199 199
 
200 200
 
@@ -223,66 +223,66 @@  discard block
 block discarded – undo
223 223
  *     Texte transformé
224 224
  **/
225 225
 function typo($letexte, $echapper = true, $connect = null, $env = []) {
226
-	// Plus vite !
227
-	if (!$letexte) {
228
-		return $letexte;
229
-	}
230
-
231
-	// les appels directs a cette fonction depuis le php de l'espace
232
-	// prive etant historiquement ecrit sans argment $connect
233
-	// on utilise la presence de celui-ci pour distinguer les cas
234
-	// ou il faut passer interdire_script explicitement
235
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
236
-	// ne seront pas perturbes
237
-	$interdire_script = false;
238
-	if (is_null($connect)) {
239
-		$connect = '';
240
-		$interdire_script = true;
241
-		$env['espace_prive'] = test_espace_prive();
242
-	}
243
-
244
-	// Echapper les codes <html> etc
245
-	if ($echapper) {
246
-		$letexte = echappe_html($letexte, 'TYPO');
247
-	}
248
-
249
-	//
250
-	// Installer les modeles, notamment images et documents ;
251
-	//
252
-	// NOTE : propre() ne passe pas par ici mais directement par corriger_typo
253
-	// cf. inc/lien
254
-
255
-	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
256
-	if ($letexte != $mem) {
257
-		$echapper = true;
258
-	}
259
-	unset($mem);
260
-
261
-	$letexte = corriger_typo($letexte);
262
-	$letexte = echapper_faux_tags($letexte);
263
-
264
-	// reintegrer les echappements
265
-	if ($echapper) {
266
-		$letexte = echappe_retour($letexte, 'TYPO');
267
-	}
268
-
269
-	// Dans les appels directs hors squelette, securiser ici aussi
270
-	if ($interdire_script) {
271
-		$letexte = interdire_scripts($letexte);
272
-	}
273
-
274
-	// Dans l'espace prive on se mefie de tout contenu dangereux
275
-	// https://core.spip.net/issues/3371
276
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
277
-	// https://core.spip.net/issues/4166
278
-	if (
279
-		$GLOBALS['filtrer_javascript'] == -1
280
-		or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
281
-	) {
282
-		$letexte = echapper_html_suspect($letexte);
283
-	}
284
-
285
-	return $letexte;
226
+    // Plus vite !
227
+    if (!$letexte) {
228
+        return $letexte;
229
+    }
230
+
231
+    // les appels directs a cette fonction depuis le php de l'espace
232
+    // prive etant historiquement ecrit sans argment $connect
233
+    // on utilise la presence de celui-ci pour distinguer les cas
234
+    // ou il faut passer interdire_script explicitement
235
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
236
+    // ne seront pas perturbes
237
+    $interdire_script = false;
238
+    if (is_null($connect)) {
239
+        $connect = '';
240
+        $interdire_script = true;
241
+        $env['espace_prive'] = test_espace_prive();
242
+    }
243
+
244
+    // Echapper les codes <html> etc
245
+    if ($echapper) {
246
+        $letexte = echappe_html($letexte, 'TYPO');
247
+    }
248
+
249
+    //
250
+    // Installer les modeles, notamment images et documents ;
251
+    //
252
+    // NOTE : propre() ne passe pas par ici mais directement par corriger_typo
253
+    // cf. inc/lien
254
+
255
+    $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
256
+    if ($letexte != $mem) {
257
+        $echapper = true;
258
+    }
259
+    unset($mem);
260
+
261
+    $letexte = corriger_typo($letexte);
262
+    $letexte = echapper_faux_tags($letexte);
263
+
264
+    // reintegrer les echappements
265
+    if ($echapper) {
266
+        $letexte = echappe_retour($letexte, 'TYPO');
267
+    }
268
+
269
+    // Dans les appels directs hors squelette, securiser ici aussi
270
+    if ($interdire_script) {
271
+        $letexte = interdire_scripts($letexte);
272
+    }
273
+
274
+    // Dans l'espace prive on se mefie de tout contenu dangereux
275
+    // https://core.spip.net/issues/3371
276
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
277
+    // https://core.spip.net/issues/4166
278
+    if (
279
+        $GLOBALS['filtrer_javascript'] == -1
280
+        or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
281
+    ) {
282
+        $letexte = echapper_html_suspect($letexte);
283
+    }
284
+
285
+    return $letexte;
286 286
 }
287 287
 
288 288
 // Correcteur typographique
@@ -307,57 +307,57 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function corriger_typo($letexte, $lang = '') {
309 309
 
310
-	// Plus vite !
311
-	if (!$letexte) {
312
-		return $letexte;
313
-	}
314
-
315
-	$letexte = pipeline('pre_typo', $letexte);
316
-
317
-	// Caracteres de controle "illegaux"
318
-	$letexte = corriger_caracteres($letexte);
319
-
320
-	// Proteger les caracteres typographiques a l'interieur des tags html
321
-	if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
322
-		foreach ($regs as $reg) {
323
-			$insert = $reg[0];
324
-			// hack: on transforme les caracteres a proteger en les remplacant
325
-			// par des caracteres "illegaux". (cf corriger_caracteres())
326
-			$insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
327
-			$letexte = str_replace($reg[0], $insert, $letexte);
328
-		}
329
-	}
330
-
331
-	// trouver les blocs idiomes et les traiter à part
332
-	$letexte = extraire_idiome($ei = $letexte, $lang, true);
333
-	$ei = ($ei !== $letexte);
334
-
335
-	// trouver les blocs multi et les traiter a part
336
-	$letexte = extraire_multi($em = $letexte, $lang, true);
337
-	$em = ($em !== $letexte);
338
-
339
-	// Charger & appliquer les fonctions de typographie
340
-	$typographie = charger_fonction(lang_typo($lang), 'typographie');
341
-	$letexte = $typographie($letexte);
342
-
343
-	// Les citations en une autre langue, s'il y a lieu
344
-	if ($em) {
345
-		$letexte = echappe_retour($letexte, 'multi');
346
-	}
347
-	if ($ei) {
348
-		$letexte = echappe_retour($letexte, 'idiome');
349
-	}
350
-
351
-	// Retablir les caracteres proteges
352
-	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
353
-
354
-	// pipeline
355
-	$letexte = pipeline('post_typo', $letexte);
356
-
357
-	# un message pour abs_url - on est passe en mode texte
358
-	$GLOBALS['mode_abs_url'] = 'texte';
359
-
360
-	return $letexte;
310
+    // Plus vite !
311
+    if (!$letexte) {
312
+        return $letexte;
313
+    }
314
+
315
+    $letexte = pipeline('pre_typo', $letexte);
316
+
317
+    // Caracteres de controle "illegaux"
318
+    $letexte = corriger_caracteres($letexte);
319
+
320
+    // Proteger les caracteres typographiques a l'interieur des tags html
321
+    if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
322
+        foreach ($regs as $reg) {
323
+            $insert = $reg[0];
324
+            // hack: on transforme les caracteres a proteger en les remplacant
325
+            // par des caracteres "illegaux". (cf corriger_caracteres())
326
+            $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
327
+            $letexte = str_replace($reg[0], $insert, $letexte);
328
+        }
329
+    }
330
+
331
+    // trouver les blocs idiomes et les traiter à part
332
+    $letexte = extraire_idiome($ei = $letexte, $lang, true);
333
+    $ei = ($ei !== $letexte);
334
+
335
+    // trouver les blocs multi et les traiter a part
336
+    $letexte = extraire_multi($em = $letexte, $lang, true);
337
+    $em = ($em !== $letexte);
338
+
339
+    // Charger & appliquer les fonctions de typographie
340
+    $typographie = charger_fonction(lang_typo($lang), 'typographie');
341
+    $letexte = $typographie($letexte);
342
+
343
+    // Les citations en une autre langue, s'il y a lieu
344
+    if ($em) {
345
+        $letexte = echappe_retour($letexte, 'multi');
346
+    }
347
+    if ($ei) {
348
+        $letexte = echappe_retour($letexte, 'idiome');
349
+    }
350
+
351
+    // Retablir les caracteres proteges
352
+    $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
353
+
354
+    // pipeline
355
+    $letexte = pipeline('post_typo', $letexte);
356
+
357
+    # un message pour abs_url - on est passe en mode texte
358
+    $GLOBALS['mode_abs_url'] = 'texte';
359
+
360
+    return $letexte;
361 361
 }
362 362
 
363 363
 
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
  * @return string
374 374
  */
375 375
 function paragrapher($letexte, $forcer = true) {
376
-	return $letexte;
376
+    return $letexte;
377 377
 }
378 378
 
379 379
 /**
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
  * @return string Texte
386 386
  **/
387 387
 function traiter_retours_chariots($letexte) {
388
-	$letexte = preg_replace(",\r\n?,S", "\n", $letexte);
389
-	$letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte);
390
-	$letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte);
388
+    $letexte = preg_replace(",\r\n?,S", "\n", $letexte);
389
+    $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte);
390
+    $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte);
391 391
 
392
-	return $letexte;
392
+    return $letexte;
393 393
 }
394 394
 
395 395
 
@@ -415,39 +415,39 @@  discard block
 block discarded – undo
415 415
  *     Texte transformé
416 416
  **/
417 417
 function propre($t, $connect = null, $env = []) {
418
-	// les appels directs a cette fonction depuis le php de l'espace
419
-	// prive etant historiquement ecrits sans argment $connect
420
-	// on utilise la presence de celui-ci pour distinguer les cas
421
-	// ou il faut passer interdire_script explicitement
422
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
423
-	// ne seront pas perturbes
424
-	$interdire_script = false;
425
-	if (is_null($connect)) {
426
-		$connect = '';
427
-		$interdire_script = true;
428
-	}
429
-
430
-	if (!$t) {
431
-		return strval($t);
432
-	}
433
-
434
-	// Dans l'espace prive on se mefie de tout contenu dangereux
435
-	// avant echappement des balises <html>
436
-	// https://core.spip.net/issues/3371
437
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
438
-	// https://core.spip.net/issues/4166
439
-	if (
440
-		$interdire_script
441
-		or $GLOBALS['filtrer_javascript'] == -1
442
-		or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
443
-		or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)
444
-	) {
445
-		$t = echapper_html_suspect($t, false);
446
-	}
447
-	$t = echappe_html($t);
448
-	$t = expanser_liens($t, $connect, $env);
449
-	$t = traiter_raccourcis($t);
450
-	$t = echappe_retour_modeles($t, $interdire_script);
451
-
452
-	return $t;
418
+    // les appels directs a cette fonction depuis le php de l'espace
419
+    // prive etant historiquement ecrits sans argment $connect
420
+    // on utilise la presence de celui-ci pour distinguer les cas
421
+    // ou il faut passer interdire_script explicitement
422
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
423
+    // ne seront pas perturbes
424
+    $interdire_script = false;
425
+    if (is_null($connect)) {
426
+        $connect = '';
427
+        $interdire_script = true;
428
+    }
429
+
430
+    if (!$t) {
431
+        return strval($t);
432
+    }
433
+
434
+    // Dans l'espace prive on se mefie de tout contenu dangereux
435
+    // avant echappement des balises <html>
436
+    // https://core.spip.net/issues/3371
437
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
438
+    // https://core.spip.net/issues/4166
439
+    if (
440
+        $interdire_script
441
+        or $GLOBALS['filtrer_javascript'] == -1
442
+        or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
443
+        or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)
444
+    ) {
445
+        $t = echapper_html_suspect($t, false);
446
+    }
447
+    $t = echappe_html($t);
448
+    $t = expanser_liens($t, $connect, $env);
449
+    $t = traiter_raccourcis($t);
450
+    $t = echappe_retour_modeles($t, $interdire_script);
451
+
452
+    return $t;
453 453
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 	foreach (['script', 'iframe'] as $tag) {
106 106
 		if (
107 107
 			stripos($t, "<$tag") !== false
108
-			and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
108
+			and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER)
109 109
 		) {
110 110
 			foreach ($r as $regs) {
111 111
 				$t = str_replace(
112 112
 					$regs[0],
113
-					"<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
113
+					"<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>',
114 114
 					$t
115 115
 				);
116 116
 			}
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 	}
164 164
 
165 165
 	// echapper les tags asp/php
166
-	$t = str_replace('<' . '%', '&lt;%', $arg);
166
+	$t = str_replace('<'.'%', '&lt;%', $arg);
167 167
 
168 168
 	// echapper le php
169
-	$t = str_replace('<' . '?', '&lt;?', $t);
169
+	$t = str_replace('<'.'?', '&lt;?', $t);
170 170
 
171 171
 	// echapper le < script language=php >
172 172
 	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
@@ -188,10 +188,10 @@  discard block
 block discarded – undo
188 188
 
189 189
 	// Reinserer les echappements des modeles
190 190
 	if (defined('_PROTEGE_JS_MODELES')) {
191
-		$t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
191
+		$t = echappe_retour($t, 'javascript'._PROTEGE_JS_MODELES);
192 192
 	}
193 193
 	if (defined('_PROTEGE_PHP_MODELES')) {
194
-		$t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
194
+		$t = echappe_retour($t, 'php'._PROTEGE_PHP_MODELES);
195 195
 	}
196 196
 
197 197
 	return $dejavu[$mode_filtre][$arg] = $t;
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 define('_TYPO_PROTEGER', "!':;?~%-");
290 290
 define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8");
291 291
 
292
-define('_TYPO_BALISE', ',</?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS');
292
+define('_TYPO_BALISE', ',</?[a-z!][^<>]*['.preg_quote(_TYPO_PROTEGER).'][^<>]*>,imsS');
293 293
 
294 294
 /**
295 295
  * Corrige la typographie
Please login to merge, or discard this patch.
ecrire/inc/xml.php 2 patches
Indentation   +157 added lines, -157 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 = [];
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 = [];
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,153 +83,153 @@  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 = [];
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 = [];
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(
140
-						'{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is',
141
-						$morceau,
142
-						$matches,
143
-						PREG_SET_ORDER
144
-					)) > $nclose)
145
-				) {
146
-					$nclose++;
147
-					$d = $p + $ncclos;
148
-					$p = strpos($txt, "</$closing_tag>", $d);
149
-				}
150
-			}
151
-			if ($p === false) {
152
-				if ($strict) {
153
-					$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(
140
+                        '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is',
141
+                        $morceau,
142
+                        $matches,
143
+                        PREG_SET_ORDER
144
+                    )) > $nclose)
145
+                ) {
146
+                    $nclose++;
147
+                    $d = $p + $ncclos;
148
+                    $p = strpos($txt, "</$closing_tag>", $d);
149
+                }
150
+            }
151
+            if ($p === false) {
152
+                if ($strict) {
153
+                    $out[$tag][] = "erreur : tag fermant $tag manquant::$txt";
154 154
 
155
-					return $out;
156
-				} else {
157
-					return importer_charset($texte, $charset);
158
-				}//$texte // un tag qui constitue du texte a reporter dans $before
159
-			}
160
-			$content = substr($txt, 0, $p);
161
-			$txt = substr($txt, $p + $ncclos);
162
-			if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile
163
-			$out[$tag][] = importer_charset($content, $charset);
164
-			}//$content;
165
-			else {
166
-				$out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
167
-			}
168
-		}
169
-		$chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
170
-	}
171
-	if (count($out) && (strlen(trim($txt)) == 0)) {
172
-		return $out;
173
-	} else {
174
-		return importer_charset($texte, $charset);
175
-	}//$texte;
155
+                    return $out;
156
+                } else {
157
+                    return importer_charset($texte, $charset);
158
+                }//$texte // un tag qui constitue du texte a reporter dans $before
159
+            }
160
+            $content = substr($txt, 0, $p);
161
+            $txt = substr($txt, $p + $ncclos);
162
+            if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile
163
+            $out[$tag][] = importer_charset($content, $charset);
164
+            }//$content;
165
+            else {
166
+                $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
167
+            }
168
+        }
169
+        $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
170
+    }
171
+    if (count($out) && (strlen(trim($txt)) == 0)) {
172
+        return $out;
173
+    } else {
174
+        return importer_charset($texte, $charset);
175
+    }//$texte;
176 176
 }
177 177
 
178 178
 // https://code.spip.net/@spip_xml_aplatit
179 179
 function spip_xml_aplatit($arbre, $separateur = ' ') {
180
-	$s = '';
181
-	if (is_array($arbre)) {
182
-		foreach ($arbre as $tag => $feuille) {
183
-			if (is_array($feuille)) {
184
-				if ($tag !== intval($tag)) {
185
-					$f = spip_xml_aplatit($feuille, $separateur);
186
-					if (strlen($f)) {
187
-						$tagf = explode(' ', $tag);
188
-						$tagf = $tagf[0];
189
-						$s .= "<$tag>$f</$tagf>";
190
-					} else {
191
-						$s .= "<$tag />";
192
-					}
193
-				} else {
194
-					$s .= spip_xml_aplatit($feuille);
195
-				}
196
-				$s .= $separateur;
197
-			} else {
198
-				$s .= "$feuille$separateur";
199
-			}
200
-		}
201
-	}
180
+    $s = '';
181
+    if (is_array($arbre)) {
182
+        foreach ($arbre as $tag => $feuille) {
183
+            if (is_array($feuille)) {
184
+                if ($tag !== intval($tag)) {
185
+                    $f = spip_xml_aplatit($feuille, $separateur);
186
+                    if (strlen($f)) {
187
+                        $tagf = explode(' ', $tag);
188
+                        $tagf = $tagf[0];
189
+                        $s .= "<$tag>$f</$tagf>";
190
+                    } else {
191
+                        $s .= "<$tag />";
192
+                    }
193
+                } else {
194
+                    $s .= spip_xml_aplatit($feuille);
195
+                }
196
+                $s .= $separateur;
197
+            } else {
198
+                $s .= "$feuille$separateur";
199
+            }
200
+        }
201
+    }
202 202
 
203
-	return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
203
+    return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
204 204
 }
205 205
 
206 206
 // https://code.spip.net/@spip_xml_tagname
207 207
 function spip_xml_tagname($tag) {
208
-	if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
209
-		return $reg[1];
210
-	}
208
+    if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
209
+        return $reg[1];
210
+    }
211 211
 
212
-	return '';
212
+    return '';
213 213
 }
214 214
 
215 215
 // https://code.spip.net/@spip_xml_decompose_tag
216 216
 function spip_xml_decompose_tag($tag) {
217
-	$tagname = spip_xml_tagname($tag);
218
-	$liste = [];
219
-	$tag = ltrim(strpbrk($tag, " \n\t"));
220
-	$p = strpos($tag, '=');
221
-	while ($p !== false) {
222
-		$attr = trim(substr($tag, 0, $p));
223
-		$tag = ltrim(substr($tag, $p + 1));
224
-		$quote = $tag[0];
225
-		$p = strpos($tag, $quote, 1);
226
-		$cont = substr($tag, 1, $p - 1);
227
-		$liste[$attr] = $cont;
228
-		$tag = substr($tag, $p + 1);
229
-		$p = strpos($tag, '=');
230
-	}
217
+    $tagname = spip_xml_tagname($tag);
218
+    $liste = [];
219
+    $tag = ltrim(strpbrk($tag, " \n\t"));
220
+    $p = strpos($tag, '=');
221
+    while ($p !== false) {
222
+        $attr = trim(substr($tag, 0, $p));
223
+        $tag = ltrim(substr($tag, $p + 1));
224
+        $quote = $tag[0];
225
+        $p = strpos($tag, $quote, 1);
226
+        $cont = substr($tag, 1, $p - 1);
227
+        $liste[$attr] = $cont;
228
+        $tag = substr($tag, $p + 1);
229
+        $p = strpos($tag, '=');
230
+    }
231 231
 
232
-	return [$tagname, $liste];
232
+    return [$tagname, $liste];
233 233
 }
234 234
 
235 235
 /**
@@ -252,21 +252,21 @@  discard block
 block discarded – undo
252 252
  *     false si aucun élément ne valide l'expression régulière, true sinon.
253 253
  **/
254 254
 function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) {
255
-	if ($init) {
256
-		$matches = [];
257
-	}
258
-	if (is_array($arbre) && count($arbre)) {
259
-		foreach (array_keys($arbre) as $tag) {
260
-			if (preg_match($regexp, $tag)) {
261
-				$matches[$tag] = &$arbre[$tag];
262
-			}
263
-			if (is_array($arbre[$tag])) {
264
-				foreach (array_keys($arbre[$tag]) as $occurences) {
265
-					spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
266
-				}
267
-			}
268
-		}
269
-	}
255
+    if ($init) {
256
+        $matches = [];
257
+    }
258
+    if (is_array($arbre) && count($arbre)) {
259
+        foreach (array_keys($arbre) as $tag) {
260
+            if (preg_match($regexp, $tag)) {
261
+                $matches[$tag] = &$arbre[$tag];
262
+            }
263
+            if (is_array($arbre[$tag])) {
264
+                foreach (array_keys($arbre[$tag]) as $occurences) {
265
+                    spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
266
+                }
267
+            }
268
+        }
269
+    }
270 270
 
271
-	return (count($matches));
271
+    return (count($matches));
272 272
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@
 block discarded – undo
137 137
 					$p !== false
138 138
 					and ($morceau = substr($txt, $d, $p - $d))
139 139
 					and (($nopen += preg_match_all(
140
-						'{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is',
140
+						'{<'.preg_quote($closing_tag).'(\s*>|\s[^>]*[^/>]>)}is',
141 141
 						$morceau,
142 142
 						$matches,
143 143
 						PREG_SET_ORDER
Please login to merge, or discard this patch.
ecrire/inc/editer.php 3 patches
Indentation   +494 added lines, -494 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('base/abstract_sql');
23 23
 
@@ -59,56 +59,56 @@  discard block
 block discarded – undo
59 59
  *     Retour des traitements.
60 60
  **/
61 61
 function formulaires_editer_objet_traiter(
62
-	$type,
63
-	$id = 'new',
64
-	$id_parent = 0,
65
-	$lier_trad = 0,
66
-	$retour = '',
67
-	$config_fonc = 'articles_edit_config',
68
-	$row = [],
69
-	$hidden = ''
62
+    $type,
63
+    $id = 'new',
64
+    $id_parent = 0,
65
+    $lier_trad = 0,
66
+    $retour = '',
67
+    $config_fonc = 'articles_edit_config',
68
+    $row = [],
69
+    $hidden = ''
70 70
 ) {
71 71
 
72
-	$res = [];
73
-	// eviter la redirection forcee par l'action...
74
-	set_request('redirect');
75
-	if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
-		list($id, $err) = $action_editer($id);
77
-	} else {
78
-		$action_editer = charger_fonction('editer_objet', 'action');
79
-		list($id, $err) = $action_editer($id, $type);
80
-	}
81
-	$id_table_objet = id_table_objet($type);
82
-	$res[$id_table_objet] = $id;
83
-	if ($err or !$id) {
84
-		$res['message_erreur'] = ($err ? $err : _T('erreur'));
85
-	} else {
86
-		// Un lien de trad a prendre en compte
87
-		if ($lier_trad) {
88
-			// referencer la traduction
89
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
-			$referencer_traduction($type, $id, $lier_trad);
91
-			// actions de recopie de champs / liens sur le nouvel objet créé
92
-			$completer_traduction = charger_fonction('completer_traduction', 'inc');
93
-			$err = $completer_traduction($type, $id, $lier_trad);
94
-			if ($err) {
95
-				$res['message_erreur'] = $err;
96
-				return $res;
97
-			}
98
-		}
99
-
100
-		$res['message_ok'] = _T('info_modification_enregistree');
101
-		if ($retour) {
102
-			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
-				$res['editable'] = true;
105
-			} else {
106
-				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
-			}
108
-		}
109
-	}
110
-
111
-	return $res;
72
+    $res = [];
73
+    // eviter la redirection forcee par l'action...
74
+    set_request('redirect');
75
+    if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
+        list($id, $err) = $action_editer($id);
77
+    } else {
78
+        $action_editer = charger_fonction('editer_objet', 'action');
79
+        list($id, $err) = $action_editer($id, $type);
80
+    }
81
+    $id_table_objet = id_table_objet($type);
82
+    $res[$id_table_objet] = $id;
83
+    if ($err or !$id) {
84
+        $res['message_erreur'] = ($err ? $err : _T('erreur'));
85
+    } else {
86
+        // Un lien de trad a prendre en compte
87
+        if ($lier_trad) {
88
+            // referencer la traduction
89
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
+            $referencer_traduction($type, $id, $lier_trad);
91
+            // actions de recopie de champs / liens sur le nouvel objet créé
92
+            $completer_traduction = charger_fonction('completer_traduction', 'inc');
93
+            $err = $completer_traduction($type, $id, $lier_trad);
94
+            if ($err) {
95
+                $res['message_erreur'] = $err;
96
+                return $res;
97
+            }
98
+        }
99
+
100
+        $res['message_ok'] = _T('info_modification_enregistree');
101
+        if ($retour) {
102
+            if (strncmp($retour, 'javascript:', 11) == 0) {
103
+                $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
+                $res['editable'] = true;
105
+            } else {
106
+                $res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
+            }
108
+        }
109
+    }
110
+
111
+    return $res;
112 112
 }
113 113
 
114 114
 /**
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
  *     Tableau des erreurs
133 133
  **/
134 134
 function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) {
135
-	$erreurs = [];
136
-	if (intval($id)) {
137
-		$conflits = controler_contenu($type, $id);
138
-		if ($conflits and count($conflits)) {
139
-			foreach ($conflits as $champ => $conflit) {
140
-				if (!isset($erreurs[$champ])) {
141
-					$erreurs[$champ] = '';
142
-				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
-			}
145
-		}
146
-	}
147
-	foreach ($oblis as $obli) {
148
-		$value = _request($obli);
149
-		if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
-			if (!isset($erreurs[$obli])) {
151
-				$erreurs[$obli] = '';
152
-			}
153
-			$erreurs[$obli] .= _T('info_obligatoire');
154
-		}
155
-	}
156
-
157
-	return $erreurs;
135
+    $erreurs = [];
136
+    if (intval($id)) {
137
+        $conflits = controler_contenu($type, $id);
138
+        if ($conflits and count($conflits)) {
139
+            foreach ($conflits as $champ => $conflit) {
140
+                if (!isset($erreurs[$champ])) {
141
+                    $erreurs[$champ] = '';
142
+                }
143
+                $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
+            }
145
+        }
146
+    }
147
+    foreach ($oblis as $obli) {
148
+        $value = _request($obli);
149
+        if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
+            if (!isset($erreurs[$obli])) {
151
+                $erreurs[$obli] = '';
152
+            }
153
+            $erreurs[$obli] .= _T('info_obligatoire');
154
+        }
155
+    }
156
+
157
+    return $erreurs;
158 158
 }
159 159
 
160 160
 /**
@@ -198,151 +198,151 @@  discard block
 block discarded – undo
198 198
  *     Environnement du formulaire.
199 199
  **/
200 200
 function formulaires_editer_objet_charger(
201
-	$type,
202
-	$id = 'new',
203
-	$id_parent = 0,
204
-	$lier_trad = 0,
205
-	$retour = '',
206
-	$config_fonc = 'articles_edit_config',
207
-	$row = [],
208
-	$hidden = ''
201
+    $type,
202
+    $id = 'new',
203
+    $id_parent = 0,
204
+    $lier_trad = 0,
205
+    $retour = '',
206
+    $config_fonc = 'articles_edit_config',
207
+    $row = [],
208
+    $hidden = ''
209 209
 ) {
210 210
 
211
-	$table_objet = table_objet($type);
212
-	$table_objet_sql = table_objet_sql($type);
213
-	$id_table_objet = id_table_objet($type);
214
-
215
-	// on accepte pas une fonction de config inconnue si elle vient d'un modele
216
-	if (
217
-		$config_fonc
218
-		and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
219
-		and $config_fonc !== $table_objet . '_edit_config'
220
-	) {
221
-		if (
222
-			$args = test_formulaire_inclus_par_modele()
223
-			and in_array($config_fonc, $args)
224
-		) {
225
-			$config_fonc = '';
226
-		}
227
-	}
228
-
229
-	$new = !is_numeric($id);
230
-	$lang_default = '';
231
-	// Appel direct dans un squelette
232
-	if (!$row) {
233
-		if (!$new or $lier_trad) {
234
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
235
-				$row = $select($id, $id_parent, $lier_trad);
236
-				// si on a une fonction precharger, elle pu faire un reglage de langue
237
-				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
238
-			} else {
239
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
240
-			}
241
-			if (!$new) {
242
-				$md5 = controles_md5($row);
243
-			}
244
-		}
245
-		if (!$row) {
246
-			$row = [];
247
-			$trouver_table = charger_fonction('trouver_table', 'base');
248
-			if ($desc = $trouver_table($table_objet)) {
249
-				foreach ($desc['field'] as $k => $v) {
250
-					$row[$k] = '';
251
-				}
252
-			}
253
-		}
254
-	}
255
-
256
-	// Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
257
-	// (et donc: pas de lien de traduction)
258
-	$id = ($new or $lier_trad)
259
-		? 'oui'
260
-		: $row[$id_table_objet];
261
-	$row[$id_table_objet] = $id;
262
-
263
-	$contexte = $row;
264
-	if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
265
-		if (!isset($contexte['id_parent'])) {
266
-			unset($contexte['id_rubrique']);
267
-		}
268
-		$contexte['id_parent'] = $id_parent;
269
-	} elseif (!isset($contexte['id_parent'])) {
270
-		// id_rubrique dans id_parent si possible
271
-		if (isset($contexte['id_rubrique'])) {
272
-			$contexte['id_parent'] = $contexte['id_rubrique'];
273
-			unset($contexte['id_rubrique']);
274
-		} else {
275
-			$contexte['id_parent'] = '';
276
-		}
277
-		if (
278
-			!$contexte['id_parent']
279
-			and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
280
-		) {
281
-			$contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
282
-		}
283
-	}
284
-
285
-	$config = [];
286
-	if ($config_fonc) {
287
-		$contexte['config'] = $config = $config_fonc($contexte);
288
-		if (!$lang_default) {
289
-			$lang_default = $config['langue'] ?? session_get('lang') ;
290
-		}
291
-	}
292
-	$config = $config + [
293
-		'lignes' => 0,
294
-		'langue' => '',
295
-	];
296
-
297
-	$att_text = " class='textarea' "
298
-		. " rows='"
299
-		. ($config['lignes'] + 15)
300
-		. "' cols='40'";
301
-	if (isset($contexte['texte'])) {
302
-		list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
303
-	}
304
-
305
-	// on veut conserver la langue de l'interface ;
306
-	// on passe cette donnee sous un autre nom, au cas ou le squelette
307
-	// voudrait l'exploiter
308
-	if (isset($contexte['lang'])) {
309
-		$contexte['langue'] = $contexte['lang'];
310
-		unset($contexte['lang']);
311
-	}
312
-
313
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
314
-		(!$lier_trad ? '' :
315
-			("\n<input type='hidden' name='lier_trad' value='" .
316
-				$lier_trad .
317
-				"' />" .
318
-				"\n<input type='hidden' name='changer_lang' value='" .
319
-				$lang_default .
320
-				"' />"))
321
-		. $hidden
322
-		. (isset($md5) ? $md5 : '');
323
-
324
-	// preciser que le formulaire doit passer dans un pipeline
325
-	$contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]];
326
-
327
-	// preciser que le formulaire doit etre securise auteur/action
328
-	// n'est plus utile lorsque l'action accepte l'id en argument direct
329
-	// on le garde pour compat
330
-	$contexte['_action'] = ["editer_$type", $id];
331
-
332
-	// et in fine placer l'autorisation
333
-	include_spip('inc/autoriser');
334
-	if (intval($id)) {
335
-		if (!autoriser('modifier', $type, intval($id))) {
336
-			$valeurs['editable'] = '';
337
-		}
338
-	}
339
-	else {
340
-		if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
341
-			$valeurs['editable'] = '';
342
-		}
343
-	}
344
-
345
-	return $contexte;
211
+    $table_objet = table_objet($type);
212
+    $table_objet_sql = table_objet_sql($type);
213
+    $id_table_objet = id_table_objet($type);
214
+
215
+    // on accepte pas une fonction de config inconnue si elle vient d'un modele
216
+    if (
217
+        $config_fonc
218
+        and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
219
+        and $config_fonc !== $table_objet . '_edit_config'
220
+    ) {
221
+        if (
222
+            $args = test_formulaire_inclus_par_modele()
223
+            and in_array($config_fonc, $args)
224
+        ) {
225
+            $config_fonc = '';
226
+        }
227
+    }
228
+
229
+    $new = !is_numeric($id);
230
+    $lang_default = '';
231
+    // Appel direct dans un squelette
232
+    if (!$row) {
233
+        if (!$new or $lier_trad) {
234
+            if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
235
+                $row = $select($id, $id_parent, $lier_trad);
236
+                // si on a une fonction precharger, elle pu faire un reglage de langue
237
+                $lang_default = (!empty($row['lang']) ? $row['lang'] : null);
238
+            } else {
239
+                $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
240
+            }
241
+            if (!$new) {
242
+                $md5 = controles_md5($row);
243
+            }
244
+        }
245
+        if (!$row) {
246
+            $row = [];
247
+            $trouver_table = charger_fonction('trouver_table', 'base');
248
+            if ($desc = $trouver_table($table_objet)) {
249
+                foreach ($desc['field'] as $k => $v) {
250
+                    $row[$k] = '';
251
+                }
252
+            }
253
+        }
254
+    }
255
+
256
+    // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
257
+    // (et donc: pas de lien de traduction)
258
+    $id = ($new or $lier_trad)
259
+        ? 'oui'
260
+        : $row[$id_table_objet];
261
+    $row[$id_table_objet] = $id;
262
+
263
+    $contexte = $row;
264
+    if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
265
+        if (!isset($contexte['id_parent'])) {
266
+            unset($contexte['id_rubrique']);
267
+        }
268
+        $contexte['id_parent'] = $id_parent;
269
+    } elseif (!isset($contexte['id_parent'])) {
270
+        // id_rubrique dans id_parent si possible
271
+        if (isset($contexte['id_rubrique'])) {
272
+            $contexte['id_parent'] = $contexte['id_rubrique'];
273
+            unset($contexte['id_rubrique']);
274
+        } else {
275
+            $contexte['id_parent'] = '';
276
+        }
277
+        if (
278
+            !$contexte['id_parent']
279
+            and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
280
+        ) {
281
+            $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
282
+        }
283
+    }
284
+
285
+    $config = [];
286
+    if ($config_fonc) {
287
+        $contexte['config'] = $config = $config_fonc($contexte);
288
+        if (!$lang_default) {
289
+            $lang_default = $config['langue'] ?? session_get('lang') ;
290
+        }
291
+    }
292
+    $config = $config + [
293
+        'lignes' => 0,
294
+        'langue' => '',
295
+    ];
296
+
297
+    $att_text = " class='textarea' "
298
+        . " rows='"
299
+        . ($config['lignes'] + 15)
300
+        . "' cols='40'";
301
+    if (isset($contexte['texte'])) {
302
+        list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
303
+    }
304
+
305
+    // on veut conserver la langue de l'interface ;
306
+    // on passe cette donnee sous un autre nom, au cas ou le squelette
307
+    // voudrait l'exploiter
308
+    if (isset($contexte['lang'])) {
309
+        $contexte['langue'] = $contexte['lang'];
310
+        unset($contexte['lang']);
311
+    }
312
+
313
+    $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
314
+        (!$lier_trad ? '' :
315
+            ("\n<input type='hidden' name='lier_trad' value='" .
316
+                $lier_trad .
317
+                "' />" .
318
+                "\n<input type='hidden' name='changer_lang' value='" .
319
+                $lang_default .
320
+                "' />"))
321
+        . $hidden
322
+        . (isset($md5) ? $md5 : '');
323
+
324
+    // preciser que le formulaire doit passer dans un pipeline
325
+    $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]];
326
+
327
+    // preciser que le formulaire doit etre securise auteur/action
328
+    // n'est plus utile lorsque l'action accepte l'id en argument direct
329
+    // on le garde pour compat
330
+    $contexte['_action'] = ["editer_$type", $id];
331
+
332
+    // et in fine placer l'autorisation
333
+    include_spip('inc/autoriser');
334
+    if (intval($id)) {
335
+        if (!autoriser('modifier', $type, intval($id))) {
336
+            $valeurs['editable'] = '';
337
+        }
338
+    }
339
+    else {
340
+        if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
341
+            $valeurs['editable'] = '';
342
+        }
343
+    }
344
+
345
+    return $contexte;
346 346
 }
347 347
 
348 348
 /**
@@ -353,29 +353,29 @@  discard block
 block discarded – undo
353 353
  * @return array
354 354
  */
355 355
 function coupe_trop_long($texte) {
356
-	$aider = charger_fonction('aider', 'inc');
357
-	if (strlen($texte) > 28 * 1024) {
358
-		$texte = str_replace("\r\n", "\n", $texte);
359
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
360
-		if ($pos > 0 and $pos < 32 * 1024) {
361
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
362
-			$suite = substr($texte, $pos + 2);
363
-		} else {
364
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
365
-			if (!($pos > 0 and $pos < 32 * 1024)) {
366
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
367
-				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
368
-			} else {
369
-				$decalage = 1;
370
-			}
371
-			$debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
372
-			$suite = substr($texte, $pos + $decalage);
373
-		}
374
-
375
-		return ([$debut, $suite]);
376
-	} else {
377
-		return ([$texte, '']);
378
-	}
356
+    $aider = charger_fonction('aider', 'inc');
357
+    if (strlen($texte) > 28 * 1024) {
358
+        $texte = str_replace("\r\n", "\n", $texte);
359
+        $pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
360
+        if ($pos > 0 and $pos < 32 * 1024) {
361
+            $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
362
+            $suite = substr($texte, $pos + 2);
363
+        } else {
364
+            $pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
365
+            if (!($pos > 0 and $pos < 32 * 1024)) {
366
+                $pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
367
+                $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
368
+            } else {
369
+                $decalage = 1;
370
+            }
371
+            $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
372
+            $suite = substr($texte, $pos + $decalage);
373
+        }
374
+
375
+        return ([$debut, $suite]);
376
+    } else {
377
+        return ([$texte, '']);
378
+    }
379 379
 }
380 380
 
381 381
 /**
@@ -386,25 +386,25 @@  discard block
 block discarded – undo
386 386
  * @return array
387 387
  */
388 388
 function editer_texte_recolle($texte, $att_text) {
389
-	if (
390
-		(strlen($texte) < 29 * 1024)
391
-		or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
392
-	) {
393
-		return [$texte, ''];
394
-	}
395
-
396
-	include_spip('inc/barre');
397
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
398
-	$nombre = 0;
399
-
400
-	while (strlen($texte) > 29 * 1024) {
401
-		$nombre++;
402
-		list($texte1, $texte) = coupe_trop_long($texte);
403
-		$textes_supplement .= '<br />' .
404
-			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
405
-	}
406
-
407
-	return [$texte, $textes_supplement];
389
+    if (
390
+        (strlen($texte) < 29 * 1024)
391
+        or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
392
+    ) {
393
+        return [$texte, ''];
394
+    }
395
+
396
+    include_spip('inc/barre');
397
+    $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
398
+    $nombre = 0;
399
+
400
+    while (strlen($texte) > 29 * 1024) {
401
+        $nombre++;
402
+        list($texte1, $texte) = coupe_trop_long($texte);
403
+        $textes_supplement .= '<br />' .
404
+            "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
405
+    }
406
+
407
+    return [$texte, $textes_supplement];
408 408
 }
409 409
 
410 410
 /**
@@ -415,17 +415,17 @@  discard block
 block discarded – undo
415 415
  * @param int $longueur
416 416
  */
417 417
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
418
-	if (!_request($champ_titre)) {
419
-		$titrer_contenu = charger_fonction('titrer_contenu', 'inc');
420
-		if (!is_null($longueur)) {
421
-			$t = $titrer_contenu($champs_contenu, null, $longueur);
422
-		} else {
423
-			$t = $titrer_contenu($champs_contenu);
424
-		}
425
-		if ($t) {
426
-			set_request($champ_titre, $t);
427
-		}
428
-	}
418
+    if (!_request($champ_titre)) {
419
+        $titrer_contenu = charger_fonction('titrer_contenu', 'inc');
420
+        if (!is_null($longueur)) {
421
+            $t = $titrer_contenu($champs_contenu, null, $longueur);
422
+        } else {
423
+            $t = $titrer_contenu($champs_contenu);
424
+        }
425
+        if ($t) {
426
+            set_request($champ_titre, $t);
427
+        }
428
+    }
429 429
 }
430 430
 
431 431
 /**
@@ -445,20 +445,20 @@  discard block
 block discarded – undo
445 445
  * @return string
446 446
  */
447 447
 function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) {
448
-	// trouver un champ texte non vide
449
-	$t = '';
450
-	foreach ($champs_contenu as $champ) {
451
-		if ($t = _request($champ, $c)) {
452
-			break;
453
-		}
454
-	}
455
-
456
-	if ($t) {
457
-		include_spip('inc/texte_mini');
458
-		$t = couper($t, $longueur, '...');
459
-	}
460
-
461
-	return $t;
448
+    // trouver un champ texte non vide
449
+    $t = '';
450
+    foreach ($champs_contenu as $champ) {
451
+        if ($t = _request($champ, $c)) {
452
+            break;
453
+        }
454
+    }
455
+
456
+    if ($t) {
457
+        include_spip('inc/texte_mini');
458
+        $t = couper($t, $longueur, '...');
459
+    }
460
+
461
+    return $t;
462 462
 }
463 463
 
464 464
 /**
@@ -481,30 +481,30 @@  discard block
 block discarded – undo
481 481
  *      - array sinon couples ('$prefixe$colonne => md5)
482 482
  **/
483 483
 function controles_md5($data, $prefixe = 'ctr_', $format = 'html') {
484
-	if (!is_array($data)) {
485
-		return false;
486
-	}
487
-
488
-	$ctr = [];
489
-	foreach ($data as $key => $val) {
490
-		$m = md5($val);
491
-		$k = $prefixe . $key;
492
-
493
-		switch ($format) {
494
-			case 'html':
495
-				$ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
496
-				break;
497
-			default:
498
-				$ctr[$k] = $m;
499
-				break;
500
-		}
501
-	}
502
-
503
-	if ($format == 'html') {
504
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
505
-	} else {
506
-		return $ctr;
507
-	}
484
+    if (!is_array($data)) {
485
+        return false;
486
+    }
487
+
488
+    $ctr = [];
489
+    foreach ($data as $key => $val) {
490
+        $m = md5($val);
491
+        $k = $prefixe . $key;
492
+
493
+        switch ($format) {
494
+            case 'html':
495
+                $ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
496
+                break;
497
+            default:
498
+                $ctr[$k] = $m;
499
+                break;
500
+        }
501
+    }
502
+
503
+    if ($format == 'html') {
504
+        return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
505
+    } else {
506
+        return $ctr;
507
+    }
508 508
 }
509 509
 
510 510
 /**
@@ -543,79 +543,79 @@  discard block
 block discarded – undo
543 543
  *     - post : le contenu posté
544 544
  **/
545 545
 function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') {
546
-	include_spip('inc/filtres');
547
-
548
-	$table_objet = table_objet($type);
549
-	$spip_table_objet = table_objet_sql($type);
550
-	$trouver_table = charger_fonction('trouver_table', 'base');
551
-	$desc = $trouver_table($table_objet, $serveur);
552
-
553
-	// Appels incomplets (sans $c)
554
-	if (!is_array($c)) {
555
-		foreach ($desc['field'] as $champ => $ignore) {
556
-			if (_request($champ)) {
557
-				$c[$champ] = _request($champ);
558
-			}
559
-		}
560
-	}
561
-
562
-	// Securite : certaines variables ne sont jamais acceptees ici
563
-	// car elles ne relevent pas de autoriser(article, modifier) ;
564
-	// il faut passer par instituer_XX()
565
-	// TODO: faut-il passer ces variables interdites
566
-	// dans un fichier de description separe ?
567
-	unset($c['statut']);
568
-	unset($c['id_parent']);
569
-	unset($c['id_rubrique']);
570
-	unset($c['id_secteur']);
571
-
572
-	// Gerer les champs non vides
573
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
574
-		foreach ($options['nonvide'] as $champ => $sinon) {
575
-			if ($c[$champ] === '') {
576
-				$c[$champ] = $sinon;
577
-			}
578
-		}
579
-	}
580
-
581
-	// N'accepter que les champs qui existent
582
-	// [TODO] ici aussi on peut valider les contenus en fonction du type
583
-	$champs = [];
584
-	foreach ($desc['field'] as $champ => $ignore) {
585
-		if (isset($c[$champ])) {
586
-			$champs[$champ] = $c[$champ];
587
-		}
588
-	}
589
-
590
-	// Nettoyer les valeurs
591
-	$champs = array_map('corriger_caracteres', $champs);
592
-
593
-	// Envoyer aux plugins
594
-	$champs = pipeline(
595
-		'pre_edition',
596
-		[
597
-			'args' => [
598
-				'table' => $spip_table_objet, // compatibilite
599
-				'table_objet' => $table_objet,
600
-				'spip_table_objet' => $spip_table_objet,
601
-				'type' => $type,
602
-				'id_objet' => $id,
603
-				'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
604
-				'action' => 'controler',
605
-				'serveur' => $serveur,
606
-			],
607
-			'data' => $champs
608
-		]
609
-	);
610
-
611
-	if (!$champs) {
612
-		return false;
613
-	}
614
-
615
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
616
-	$conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
617
-
618
-	return $conflits;
546
+    include_spip('inc/filtres');
547
+
548
+    $table_objet = table_objet($type);
549
+    $spip_table_objet = table_objet_sql($type);
550
+    $trouver_table = charger_fonction('trouver_table', 'base');
551
+    $desc = $trouver_table($table_objet, $serveur);
552
+
553
+    // Appels incomplets (sans $c)
554
+    if (!is_array($c)) {
555
+        foreach ($desc['field'] as $champ => $ignore) {
556
+            if (_request($champ)) {
557
+                $c[$champ] = _request($champ);
558
+            }
559
+        }
560
+    }
561
+
562
+    // Securite : certaines variables ne sont jamais acceptees ici
563
+    // car elles ne relevent pas de autoriser(article, modifier) ;
564
+    // il faut passer par instituer_XX()
565
+    // TODO: faut-il passer ces variables interdites
566
+    // dans un fichier de description separe ?
567
+    unset($c['statut']);
568
+    unset($c['id_parent']);
569
+    unset($c['id_rubrique']);
570
+    unset($c['id_secteur']);
571
+
572
+    // Gerer les champs non vides
573
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
574
+        foreach ($options['nonvide'] as $champ => $sinon) {
575
+            if ($c[$champ] === '') {
576
+                $c[$champ] = $sinon;
577
+            }
578
+        }
579
+    }
580
+
581
+    // N'accepter que les champs qui existent
582
+    // [TODO] ici aussi on peut valider les contenus en fonction du type
583
+    $champs = [];
584
+    foreach ($desc['field'] as $champ => $ignore) {
585
+        if (isset($c[$champ])) {
586
+            $champs[$champ] = $c[$champ];
587
+        }
588
+    }
589
+
590
+    // Nettoyer les valeurs
591
+    $champs = array_map('corriger_caracteres', $champs);
592
+
593
+    // Envoyer aux plugins
594
+    $champs = pipeline(
595
+        'pre_edition',
596
+        [
597
+            'args' => [
598
+                'table' => $spip_table_objet, // compatibilite
599
+                'table_objet' => $table_objet,
600
+                'spip_table_objet' => $spip_table_objet,
601
+                'type' => $type,
602
+                'id_objet' => $id,
603
+                'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
604
+                'action' => 'controler',
605
+                'serveur' => $serveur,
606
+            ],
607
+            'data' => $champs
608
+        ]
609
+    );
610
+
611
+    if (!$champs) {
612
+        return false;
613
+    }
614
+
615
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
616
+    $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
617
+
618
+    return $conflits;
619 619
 }
620 620
 
621 621
 
@@ -645,64 +645,64 @@  discard block
 block discarded – undo
645 645
  *     - post : le contenu posté
646 646
  **/
647 647
 function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') {
648
-	$spip_table_objet = table_objet_sql($type);
649
-	$id_table_objet = id_table_objet($type);
650
-
651
-	// Controle des MD5 envoyes
652
-	// On elimine les donnees non modifiees par le formulaire (mais
653
-	// potentiellement modifiees entre temps par un autre utilisateur)
654
-	foreach ($champs as $key => $val) {
655
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
656
-			if (is_scalar($val) and $m == md5($val)) {
657
-				unset($champs[$key]);
658
-			}
659
-		}
660
-	}
661
-	if (!$champs) {
662
-		return;
663
-	}
664
-
665
-	// On veut savoir si notre modif va avoir un impact
666
-	// par rapport aux donnees contenues dans la base
667
-	// (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
668
-	$s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
669
-	$intact = true;
670
-	foreach ($champs as $ch => $val) {
671
-		$intact &= ($s[$ch] == $val);
672
-	}
673
-	if ($intact) {
674
-		return;
675
-	}
676
-
677
-	// Detection de conflits :
678
-	// On verifie si notre modif ne provient pas d'un formulaire
679
-	// genere a partir de donnees modifiees dans l'intervalle ; ici
680
-	// on compare a ce qui est dans la base, et on bloque en cas
681
-	// de conflit.
682
-	$ctrh = $ctrq = $conflits = [];
683
-	foreach (array_keys($champs) as $key) {
684
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
685
-			$ctrh[$key] = $m;
686
-			$ctrq[] = $key;
687
-		}
688
-	}
689
-	if ($ctrq) {
690
-		$ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
691
-		foreach ($ctrh as $key => $m) {
692
-			if (
693
-				$m != md5($ctrq[$key])
694
-				and $champs[$key] !== $ctrq[$key]
695
-			) {
696
-				$conflits[$key] = [
697
-					'base' => $ctrq[$key],
698
-					'post' => $champs[$key]
699
-				];
700
-				unset($champs[$key]); # stocker quand meme les modifs ?
701
-			}
702
-		}
703
-	}
704
-
705
-	return $conflits;
648
+    $spip_table_objet = table_objet_sql($type);
649
+    $id_table_objet = id_table_objet($type);
650
+
651
+    // Controle des MD5 envoyes
652
+    // On elimine les donnees non modifiees par le formulaire (mais
653
+    // potentiellement modifiees entre temps par un autre utilisateur)
654
+    foreach ($champs as $key => $val) {
655
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
656
+            if (is_scalar($val) and $m == md5($val)) {
657
+                unset($champs[$key]);
658
+            }
659
+        }
660
+    }
661
+    if (!$champs) {
662
+        return;
663
+    }
664
+
665
+    // On veut savoir si notre modif va avoir un impact
666
+    // par rapport aux donnees contenues dans la base
667
+    // (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
668
+    $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
669
+    $intact = true;
670
+    foreach ($champs as $ch => $val) {
671
+        $intact &= ($s[$ch] == $val);
672
+    }
673
+    if ($intact) {
674
+        return;
675
+    }
676
+
677
+    // Detection de conflits :
678
+    // On verifie si notre modif ne provient pas d'un formulaire
679
+    // genere a partir de donnees modifiees dans l'intervalle ; ici
680
+    // on compare a ce qui est dans la base, et on bloque en cas
681
+    // de conflit.
682
+    $ctrh = $ctrq = $conflits = [];
683
+    foreach (array_keys($champs) as $key) {
684
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
685
+            $ctrh[$key] = $m;
686
+            $ctrq[] = $key;
687
+        }
688
+    }
689
+    if ($ctrq) {
690
+        $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
691
+        foreach ($ctrh as $key => $m) {
692
+            if (
693
+                $m != md5($ctrq[$key])
694
+                and $champs[$key] !== $ctrq[$key]
695
+            ) {
696
+                $conflits[$key] = [
697
+                    'base' => $ctrq[$key],
698
+                    'post' => $champs[$key]
699
+                ];
700
+                unset($champs[$key]); # stocker quand meme les modifs ?
701
+            }
702
+        }
703
+    }
704
+
705
+    return $conflits;
706 706
 }
707 707
 
708 708
 /**
@@ -714,11 +714,11 @@  discard block
 block discarded – undo
714 714
  * @return string
715 715
  */
716 716
 function display_conflit_champ($x) {
717
-	if (strstr($x, "\n") or strlen($x) > 80) {
718
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
719
-	} else {
720
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
721
-	}
717
+    if (strstr($x, "\n") or strlen($x) > 80) {
718
+        return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
719
+    } else {
720
+        return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
721
+    }
722 722
 }
723 723
 
724 724
 /**
@@ -736,57 +736,57 @@  discard block
 block discarded – undo
736 736
  * @return string
737 737
  */
738 738
 function signaler_conflits_edition($conflits, $redirect = '') {
739
-	include_spip('inc/minipres');
740
-	include_spip('inc/revisions');
741
-	include_spip('afficher_diff/champ');
742
-	include_spip('inc/suivi_versions');
743
-	include_spip('inc/diff');
744
-	$diffs = [];
745
-	foreach ($conflits as $champ => $a) {
746
-		// probleme de stockage ou conflit d'edition ?
747
-		$base = isset($a['save']) ? $a['save'] : $a['base'];
748
-
749
-		$diff = new Diff(new DiffTexte());
750
-		$n = preparer_diff($a['post']);
751
-		$o = preparer_diff($base);
752
-		$d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
753
-
754
-		$titre = isset($a['save']) ? _L(
755
-			'Echec lors de l\'enregistrement du champ @champ@',
756
-			['champ' => $champ]
757
-		) : $champ;
758
-
759
-		$diffs[] = "<h2>$titre</h2>\n"
760
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
761
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
762
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
763
-			. display_conflit_champ($a['post'])
764
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
765
-			. display_conflit_champ($base);
766
-	}
767
-
768
-	if ($redirect) {
769
-		$id = uniqid(rand());
770
-		$redirect = "<form action='$redirect' method='get'
739
+    include_spip('inc/minipres');
740
+    include_spip('inc/revisions');
741
+    include_spip('afficher_diff/champ');
742
+    include_spip('inc/suivi_versions');
743
+    include_spip('inc/diff');
744
+    $diffs = [];
745
+    foreach ($conflits as $champ => $a) {
746
+        // probleme de stockage ou conflit d'edition ?
747
+        $base = isset($a['save']) ? $a['save'] : $a['base'];
748
+
749
+        $diff = new Diff(new DiffTexte());
750
+        $n = preparer_diff($a['post']);
751
+        $o = preparer_diff($base);
752
+        $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
753
+
754
+        $titre = isset($a['save']) ? _L(
755
+            'Echec lors de l\'enregistrement du champ @champ@',
756
+            ['champ' => $champ]
757
+        ) : $champ;
758
+
759
+        $diffs[] = "<h2>$titre</h2>\n"
760
+            . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
761
+            . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
762
+            . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
763
+            . display_conflit_champ($a['post'])
764
+            . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
765
+            . display_conflit_champ($base);
766
+    }
767
+
768
+    if ($redirect) {
769
+        $id = uniqid(rand());
770
+        $redirect = "<form action='$redirect' method='get'
771 771
 			id='$id'
772 772
 			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
773
-			. form_hidden($redirect)
774
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
773
+            . form_hidden($redirect)
774
+            . "<input type='submit' value='" . _T('icone_retour') . "' />
775 775
 		</form>\n";
776 776
 
777
-		// pour les documents, on est probablement en ajax : il faut ajaxer
778
-		if (_AJAX) {
779
-			$redirect .= '<script type="text/javascript">'
780
-				. 'setTimeout(function(){$("#' . $id . '")
777
+        // pour les documents, on est probablement en ajax : il faut ajaxer
778
+        if (_AJAX) {
779
+            $redirect .= '<script type="text/javascript">'
780
+                . 'setTimeout(function(){$("#' . $id . '")
781 781
 			.ajaxForm({target:$("#' . $id . '").parent()});
782 782
 			}, 200);'
783
-				. "</script>\n";
784
-		}
785
-	}
783
+                . "</script>\n";
784
+        }
785
+    }
786 786
 
787
-	echo minipres(
788
-		_T('titre_conflit_edition'),
789
-		'<style>
787
+    echo minipres(
788
+        _T('titre_conflit_edition'),
789
+        '<style>
790 790
 .diff-para-deplace { background: #e8e8ff; }
791 791
 .diff-para-ajoute { background: #d0ffc0; color: #000; }
792 792
 .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; }
@@ -797,12 +797,12 @@  discard block
 block discarded – undo
797 797
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
798 798
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
799 799
 </style>'
800
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
801
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
802
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
803
-		. join("\n", $diffs)
804
-		. "</div>\n"
805
-
806
-		. $redirect
807
-	);
800
+        . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
801
+        . '<p>' . _T('texte_conflit_edition_correction') . '</p>'
802
+        . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
803
+        . join("\n", $diffs)
804
+        . "</div>\n"
805
+
806
+        . $redirect
807
+    );
808 808
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -36 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		$res['message_ok'] = _T('info_modification_enregistree');
101 101
 		if ($retour) {
102 102
 			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
+				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>';
104 104
 				$res['editable'] = true;
105 105
 			} else {
106 106
 				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				if (!isset($erreurs[$champ])) {
141 141
 					$erreurs[$champ] = '';
142 142
 				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
143
+				$erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>';
144 144
 			}
145 145
 		}
146 146
 	}
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	if (
217 217
 		$config_fonc
218 218
 		and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
219
-		and $config_fonc !== $table_objet . '_edit_config'
219
+		and $config_fonc !== $table_objet.'_edit_config'
220 220
 	) {
221 221
 		if (
222 222
 			$args = test_formulaire_inclus_par_modele()
@@ -231,12 +231,12 @@  discard block
 block discarded – undo
231 231
 	// Appel direct dans un squelette
232 232
 	if (!$row) {
233 233
 		if (!$new or $lier_trad) {
234
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
234
+			if ($select = charger_fonction('precharger_'.$type, 'inc', true)) {
235 235
 				$row = $select($id, $id_parent, $lier_trad);
236 236
 				// si on a une fonction precharger, elle pu faire un reglage de langue
237 237
 				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
238 238
 			} else {
239
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
239
+				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.intval($id));
240 240
 			}
241 241
 			if (!$new) {
242 242
 				$md5 = controles_md5($row);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	if ($config_fonc) {
287 287
 		$contexte['config'] = $config = $config_fonc($contexte);
288 288
 		if (!$lang_default) {
289
-			$lang_default = $config['langue'] ?? session_get('lang') ;
289
+			$lang_default = $config['langue'] ?? session_get('lang');
290 290
 		}
291 291
 	}
292 292
 	$config = $config + [
@@ -310,13 +310,12 @@  discard block
 block discarded – undo
310 310
 		unset($contexte['lang']);
311 311
 	}
312 312
 
313
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
314
-		(!$lier_trad ? '' :
315
-			("\n<input type='hidden' name='lier_trad' value='" .
316
-				$lier_trad .
317
-				"' />" .
318
-				"\n<input type='hidden' name='changer_lang' value='" .
319
-				$lang_default .
313
+	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n".
314
+		(!$lier_trad ? '' : ("\n<input type='hidden' name='lier_trad' value='".
315
+				$lier_trad.
316
+				"' />".
317
+				"\n<input type='hidden' name='changer_lang' value='".
318
+				$lang_default.
320 319
 				"' />"))
321 320
 		. $hidden
322 321
 		. (isset($md5) ? $md5 : '');
@@ -356,14 +355,14 @@  discard block
 block discarded – undo
356 355
 	$aider = charger_fonction('aider', 'inc');
357 356
 	if (strlen($texte) > 28 * 1024) {
358 357
 		$texte = str_replace("\r\n", "\n", $texte);
359
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
358
+		$pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko
360 359
 		if ($pos > 0 and $pos < 32 * 1024) {
361
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
360
+			$debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n";
362 361
 			$suite = substr($texte, $pos + 2);
363 362
 		} else {
364
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
363
+			$pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace
365 364
 			if (!($pos > 0 and $pos < 32 * 1024)) {
366
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
365
+				$pos = 28 * 1024; // au pire (pas d'espace trouv'e)
367 366
 				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
368 367
 			} else {
369 368
 				$decalage = 1;
@@ -394,13 +393,13 @@  discard block
 block discarded – undo
394 393
 	}
395 394
 
396 395
 	include_spip('inc/barre');
397
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
396
+	$textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n";
398 397
 	$nombre = 0;
399 398
 
400 399
 	while (strlen($texte) > 29 * 1024) {
401 400
 		$nombre++;
402 401
 		list($texte1, $texte) = coupe_trop_long($texte);
403
-		$textes_supplement .= '<br />' .
402
+		$textes_supplement .= '<br />'.
404 403
 			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
405 404
 	}
406 405
 
@@ -488,7 +487,7 @@  discard block
 block discarded – undo
488 487
 	$ctr = [];
489 488
 	foreach ($data as $key => $val) {
490 489
 		$m = md5($val);
491
-		$k = $prefixe . $key;
490
+		$k = $prefixe.$key;
492 491
 
493 492
 		switch ($format) {
494 493
 			case 'html':
@@ -501,7 +500,7 @@  discard block
 block discarded – undo
501 500
 	}
502 501
 
503 502
 	if ($format == 'html') {
504
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
503
+		return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n";
505 504
 	} else {
506 505
 		return $ctr;
507 506
 	}
@@ -652,7 +651,7 @@  discard block
 block discarded – undo
652 651
 	// On elimine les donnees non modifiees par le formulaire (mais
653 652
 	// potentiellement modifiees entre temps par un autre utilisateur)
654 653
 	foreach ($champs as $key => $val) {
655
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
654
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
656 655
 			if (is_scalar($val) and $m == md5($val)) {
657 656
 				unset($champs[$key]);
658 657
 			}
@@ -681,7 +680,7 @@  discard block
 block discarded – undo
681 680
 	// de conflit.
682 681
 	$ctrh = $ctrq = $conflits = [];
683 682
 	foreach (array_keys($champs) as $key) {
684
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
683
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
685 684
 			$ctrh[$key] = $m;
686 685
 			$ctrq[] = $key;
687 686
 		}
@@ -715,9 +714,9 @@  discard block
 block discarded – undo
715 714
  */
716 715
 function display_conflit_champ($x) {
717 716
 	if (strstr($x, "\n") or strlen($x) > 80) {
718
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
717
+		return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n";
719 718
 	} else {
720
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
719
+		return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n";
721 720
 	}
722 721
 }
723 722
 
@@ -757,11 +756,11 @@  discard block
 block discarded – undo
757 756
 		) : $champ;
758 757
 
759 758
 		$diffs[] = "<h2>$titre</h2>\n"
760
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
761
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
762
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
759
+			. '<h3>'._T('info_conflit_edition_differences')."</h3>\n"
760
+			. "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n"
761
+			. '<h4>'._T('info_conflit_edition_votre_version').'</h4>'
763 762
 			. display_conflit_champ($a['post'])
764
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
763
+			. '<h4>'._T('info_conflit_edition_version_enregistree').'</h4>'
765 764
 			. display_conflit_champ($base);
766 765
 	}
767 766
 
@@ -769,16 +768,16 @@  discard block
 block discarded – undo
769 768
 		$id = uniqid(rand());
770 769
 		$redirect = "<form action='$redirect' method='get'
771 770
 			id='$id'
772
-			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
771
+			style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n"
773 772
 			. form_hidden($redirect)
774
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
773
+			. "<input type='submit' value='"._T('icone_retour')."' />
775 774
 		</form>\n";
776 775
 
777 776
 		// pour les documents, on est probablement en ajax : il faut ajaxer
778 777
 		if (_AJAX) {
779 778
 			$redirect .= '<script type="text/javascript">'
780
-				. 'setTimeout(function(){$("#' . $id . '")
781
-			.ajaxForm({target:$("#' . $id . '").parent()});
779
+				. 'setTimeout(function(){$("#'.$id.'")
780
+			.ajaxForm({target:$("#' . $id.'").parent()});
782 781
 			}, 200);'
783 782
 				. "</script>\n";
784 783
 		}
@@ -797,9 +796,9 @@  discard block
 block discarded – undo
797 796
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
798 797
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
799 798
 </style>'
800
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
801
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
802
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
799
+		. '<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>'
800
+		. '<p>'._T('texte_conflit_edition_correction').'</p>'
801
+		. "<div style='text-align:".$GLOBALS['spip_lang_left'].";'>"
803 802
 		. join("\n", $diffs)
804 803
 		. "</div>\n"
805 804
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -335,8 +335,7 @@
 block discarded – undo
335 335
 		if (!autoriser('modifier', $type, intval($id))) {
336 336
 			$valeurs['editable'] = '';
337 337
 		}
338
-	}
339
-	else {
338
+	} else {
340 339
 		if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
341 340
 			$valeurs['editable'] = '';
342 341
 		}
Please login to merge, or discard this patch.