Completed
Push — master ( 342b7b...105b81 )
by cam
01:15
created
ecrire/inc/filtres_images_lib_mini.php 3 patches
Braces   +4 added lines, -9 removed lines patch added patch discarded remove patch
@@ -524,8 +524,7 @@  discard block
 block discarded – undo
524 524
 			process_image_svg_identite($ret);
525 525
 			$ret['creer'] = false;
526 526
 		}
527
-	}
528
-	else {
527
+	} else {
529 528
 		if (!function_exists($ret['fonction_imagecreatefrom'])) {
530 529
 			return false;
531 530
 		}
@@ -628,8 +627,7 @@  discard block
 block discarded – undo
628 627
 
629 628
 	if (isset($info['mime'])) {
630 629
 		$mime = $info['mime'];
631
-	}
632
-	else {
630
+	} else {
633 631
 		$mime = image_type_to_mime_type($info[2]);
634 632
 	}
635 633
 
@@ -1408,9 +1406,7 @@  discard block
 block discarded – undo
1408 1406
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1409 1407
 		$vignette = $destination . '.' . $format;
1410 1408
 		@copy($image, $vignette);
1411
-	}
1412
-
1413
-	elseif ($valeurs['format_source'] === 'svg') {
1409
+	} elseif ($valeurs['format_source'] === 'svg') {
1414 1410
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1415 1411
 			$format_sortie = 'svg';
1416 1412
 			$vignette = $destination . '.' . $format_sortie;
@@ -1846,8 +1842,7 @@  discard block
 block discarded – undo
1846 1842
 		$date = test_espace_prive() ? ('?' . $date) : '';
1847 1843
 
1848 1844
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1849
-	}
1850
-	else {
1845
+	} else {
1851 1846
 		# BMP, tiff ... les redacteurs osent tout!
1852 1847
 		return $img;
1853 1848
 	}
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
 	$blue = dechex($blue);
44 44
 
45 45
 	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
46
+		$red = '0'.$red;
47 47
 	}
48 48
 	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
49
+		$green = '0'.$green;
50 50
 	}
51 51
 	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
52
+		$blue = '0'.$blue;
53 53
 	}
54 54
 
55 55
 	return "$red$green$blue";
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	$couleur = couleur_html_to_hex($couleur);
68 68
 	$couleur = ltrim($couleur, '#');
69 69
 	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
70
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
71 71
 	}
72 72
 	$retour = [];
73 73
 	$retour['red'] = hexdec(substr($couleur, 0, 2));
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 	$var_G = ($G / 255);
126 126
 	$var_B = ($B / 255);
127 127
 
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
128
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
129
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
130
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
131 131
 
132 132
 	$L = ($var_Max + $var_Min) / 2;
133 133
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
  */
190 190
 function _couleur_hsl_to_rgb($H, $S, $L) {
191 191
 	// helper
192
-	$hue_2_rgb = function ($v1, $v2, $vH) {
192
+	$hue_2_rgb = function($v1, $v2, $vH) {
193 193
 		if ($vH < 0) {
194 194
 			$vH += 1;
195 195
 		}
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
 		$img = "<img src='$source' />";
322 322
 	} elseif (
323 323
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
324
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
324
+		and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])
325 325
 		and in_array($extension, _image_extensions_acceptees_en_entree())
326 326
 	) {
327 327
 		# gerer img src="data:....base64"
328
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
328
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
329 329
 		if (!file_exists($local)) {
330 330
 			ecrire_fichier($local, base64_decode($regs[2]));
331 331
 		}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	// les protocoles web prennent au moins 3 lettres
343 343
 	if (tester_url_absolue($source)) {
344 344
 		include_spip('inc/distant');
345
-		$fichier = _DIR_RACINE . copie_locale($source);
345
+		$fichier = _DIR_RACINE.copie_locale($source);
346 346
 		if (!$fichier) {
347 347
 			return '';
348 348
 		}
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
 			// on garde la terminaison initiale car image simplement copiee
441 441
 			// et on postfixe son nom avec un md5 du path
442 442
 			$terminaison_dest = $terminaison;
443
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
443
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
444 444
 		} else {
445
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
445
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
446 446
 		}
447 447
 		$cache = sous_repertoire(_DIR_VAR, $cache);
448 448
 		$cache = sous_repertoire($cache, $effet);
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		$fichier_dest = substr($fichier_dest, 2);
454 454
 	}
455 455
 
456
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
456
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
457 457
 
458 458
 	$GLOBALS['images_calculees'][] = $fichier_dest;
459 459
 
@@ -491,15 +491,15 @@  discard block
 block discarded – undo
491 491
 
492 492
 	if ($creer) {
493 493
 		spip_log(
494
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
-			'images' . _LOG_DEBUG
494
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
495
+			'images'._LOG_DEBUG
496 496
 		);
497 497
 	}
498 498
 
499 499
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
500
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
501 501
 	$ret['fichier'] = $fichier;
502
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
503 503
 	$ret['fichier_dest'] = $fichier_dest;
504 504
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
505 505
 	$ret['format_dest'] = $terminaison_dest;
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 
650 650
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
651 651
 	if ($_terminaison and $_terminaison !== $terminaison) {
652
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
652
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
653 653
 		$terminaison = $_terminaison;
654 654
 	}
655 655
 	return $terminaison;
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 	if (!function_exists('imagepng')) {
807 807
 		return false;
808 808
 	}
809
-	$tmp = $fichier . '.tmp';
809
+	$tmp = $fichier.'.tmp';
810 810
 	$ret = imagepng($img, $tmp);
811 811
 	if (file_exists($tmp)) {
812 812
 		$taille_test = getimagesize($tmp);
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 	if (!function_exists('imagegif')) {
842 842
 		return false;
843 843
 	}
844
-	$tmp = $fichier . '.tmp';
844
+	$tmp = $fichier.'.tmp';
845 845
 	$ret = imagegif($img, $tmp);
846 846
 	if (file_exists($tmp)) {
847 847
 		$taille_test = getimagesize($tmp);
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
 	if (!function_exists('imagejpeg')) {
882 882
 		return false;
883 883
 	}
884
-	$tmp = $fichier . '.tmp';
884
+	$tmp = $fichier.'.tmp';
885 885
 
886 886
 	// Enable interlancing
887 887
 	imageinterlace($img, true);
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 	if (!function_exists('imagewebp')) {
943 943
 		return false;
944 944
 	}
945
-	$tmp = $fichier . '.tmp';
945
+	$tmp = $fichier.'.tmp';
946 946
 	$ret = imagewebp($img, $tmp, $qualite);
947 947
 	if (file_exists($tmp)) {
948 948
 		$taille_test = getimagesize($tmp);
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
  */
977 977
 function _image_imagesvg($img, $fichier) {
978 978
 
979
-	$tmp = $fichier . '.tmp';
979
+	$tmp = $fichier.'.tmp';
980 980
 	if (strpos($img, '<') === false) {
981 981
 		$img = supprimer_timestamp($img);
982 982
 		if (!file_exists($img)) {
@@ -1033,13 +1033,13 @@  discard block
 block discarded – undo
1033 1033
  */
1034 1034
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1035 1035
 	if (is_null($fonction)) {
1036
-		$fonction = '_image_image' . $valeurs['format_dest'];
1036
+		$fonction = '_image_image'.$valeurs['format_dest'];
1037 1037
 	}
1038 1038
 	$ret = false;
1039 1039
 	#un flag pour reperer les images gravees
1040 1040
 	$lock = (
1041 1041
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1042
-		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1042
+		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'))
1043 1043
 	);
1044 1044
 	if (
1045 1045
 		function_exists($fonction)
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 			// dans tous les cas mettre a jour la taille de l'image finale
1052 1052
 			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1053 1053
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1054
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1054
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1055 1055
 		}
1056 1056
 	}
1057 1057
 
@@ -1226,7 +1226,7 @@  discard block
 block discarded – undo
1226 1226
 
1227 1227
 	// attributs deprecies. Transformer en CSS
1228 1228
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1229
-		$style = "margin:{$espace}px;" . $style;
1229
+		$style = "margin:{$espace}px;".$style;
1230 1230
 		$tag = inserer_attribut($tag, 'hspace', '');
1231 1231
 	}
1232 1232
 
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 	$image = $valeurs['fichier'];
1354 1354
 	$format = $valeurs['format_source'];
1355 1355
 	$destdir = dirname($valeurs['fichier_dest']);
1356
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1356
+	$destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1357 1357
 
1358 1358
 	$format_sortie = $valeurs['format_dest'];
1359 1359
 
@@ -1385,14 +1385,14 @@  discard block
 block discarded – undo
1385 1385
 
1386 1386
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1387 1387
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1388
-		$vignette = $destination . '.' . $format;
1388
+		$vignette = $destination.'.'.$format;
1389 1389
 		@copy($image, $vignette);
1390 1390
 	}
1391 1391
 
1392 1392
 	elseif ($valeurs['format_source'] === 'svg') {
1393 1393
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1394 1394
 			$format_sortie = 'svg';
1395
-			$vignette = $destination . '.' . $format_sortie;
1395
+			$vignette = $destination.'.'.$format_sortie;
1396 1396
 			$valeurs['fichier_dest'] = $vignette;
1397 1397
 			_image_gd_output($svg, $valeurs);
1398 1398
 		}
@@ -1404,9 +1404,9 @@  discard block
 block discarded – undo
1404 1404
 			define('_CONVERT_COMMAND', 'convert');
1405 1405
 		} // Securite : mes_options.php peut preciser le chemin absolu
1406 1406
 		if (!defined('_RESIZE_COMMAND')) {
1407
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1407
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1408 1408
 		}
1409
-		$vignette = $destination . '.' . $format_sortie;
1409
+		$vignette = $destination.'.'.$format_sortie;
1410 1410
 		$commande = str_replace(
1411 1411
 			['%x', '%y', '%src', '%dest'],
1412 1412
 			[
@@ -1422,7 +1422,7 @@  discard block
 block discarded – undo
1422 1422
 		if (!@file_exists($vignette)) {
1423 1423
 			spip_log("echec convert sur $vignette");
1424 1424
 
1425
-			return;  // echec commande
1425
+			return; // echec commande
1426 1426
 		}
1427 1427
 	}
1428 1428
 
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
 		if (!$output) {
1440 1440
 			return;
1441 1441
 		}
1442
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1442
+		$vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie;
1443 1443
 
1444 1444
 		$imagick = new Imagick();
1445 1445
 		$imagick->readImage(realpath($image));
@@ -1448,7 +1448,7 @@  discard block
 block discarded – undo
1448 1448
 			$destHeight,
1449 1449
 			Imagick::FILTER_LANCZOS,
1450 1450
 			1
1451
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1451
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1452 1452
 		$imagick->writeImage($vignette);
1453 1453
 
1454 1454
 		if (!@file_exists($vignette)) {
@@ -1457,7 +1457,7 @@  discard block
 block discarded – undo
1457 1457
 			return;
1458 1458
 		}
1459 1459
 		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1460
-		$vignette = $destination . '.' . $format_sortie;
1460
+		$vignette = $destination.'.'.$format_sortie;
1461 1461
 	}
1462 1462
 
1463 1463
 	// netpbm
@@ -1468,11 +1468,11 @@  discard block
 block discarded – undo
1468 1468
 		if (_PNMSCALE_COMMAND == '') {
1469 1469
 			return;
1470 1470
 		}
1471
-		$vignette = $destination . '.' . $format_sortie;
1471
+		$vignette = $destination.'.'.$format_sortie;
1472 1472
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1473 1473
 		if ($format == 'jpg') {
1474 1474
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1475
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1475
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1476 1476
 			if (!($s = @filesize($vignette))) {
1477 1477
 				spip_unlink($vignette);
1478 1478
 			}
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
 		} else {
1485 1485
 			if ($format == 'gif') {
1486 1486
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1487
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1487
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1488 1488
 				if (!($s = @filesize($vignette))) {
1489 1489
 					spip_unlink($vignette);
1490 1490
 				}
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
 			} else {
1497 1497
 				if ($format == 'png') {
1498 1498
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1499
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1499
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1500 1500
 					if (!($s = @filesize($vignette))) {
1501 1501
 						spip_unlink($vignette);
1502 1502
 					}
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
 			return;
1519 1519
 		}
1520 1520
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1521
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1521
+			spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1522 1522
 
1523 1523
 			return;
1524 1524
 		}
@@ -1828,7 +1828,7 @@  discard block
 block discarded – undo
1828 1828
 		// de l'image, de facon a tromper le cache du navigateur
1829 1829
 		// quand on fait supprimer/reuploader un logo
1830 1830
 		// (pas de filemtime si SAFE MODE)
1831
-		$date = test_espace_prive() ? ('?' . $date) : '';
1831
+		$date = test_espace_prive() ? ('?'.$date) : '';
1832 1832
 
1833 1833
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1834 1834
 	}
@@ -1874,7 +1874,7 @@  discard block
 block discarded – undo
1874 1874
 	public static function LittleEndian2String($number, $minbytes = 1) {
1875 1875
 		$intstring = '';
1876 1876
 		while ($number > 0) {
1877
-			$intstring = $intstring . chr($number & 255);
1877
+			$intstring = $intstring.chr($number & 255);
1878 1878
 			$number >>= 8;
1879 1879
 		}
1880 1880
 
@@ -1906,9 +1906,9 @@  discard block
 block discarded – undo
1906 1906
 					$b = $argb['blue'];
1907 1907
 
1908 1908
 					if ($bpp[$key] == 32) {
1909
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1909
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1910 1910
 					} elseif ($bpp[$key] == 24) {
1911
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1911
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1912 1912
 					}
1913 1913
 
1914 1914
 					if ($a < 128) {
@@ -1935,48 +1935,48 @@  discard block
 block discarded – undo
1935 1935
 
1936 1936
 			// BITMAPINFOHEADER - 40 bytes
1937 1937
 			$BitmapInfoHeader[$key] = '';
1938
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1939
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1938
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1939
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1940 1940
 			// The biHeight member specifies the combined
1941 1941
 			// height of the XOR and AND masks.
1942 1942
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1943
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1944
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1945
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1946
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1947
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1948
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1949
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1950
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1943
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1944
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1945
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1946
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1947
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1948
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1949
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1950
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1951 1951
 		}
1952 1952
 
1953 1953
 
1954
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1955
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1956
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1954
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1955
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1956
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1957 1957
 
1958 1958
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1959 1959
 		foreach ($gd_image_array as $key => $gd_image) {
1960 1960
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1961 1961
 
1962
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1963
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1964
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1965
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1962
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1963
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1964
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1965
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1966 1966
 
1967
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1968
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1967
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1968
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1969 1969
 
1970 1970
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1971 1971
 			$icondata .= phpthumb_functions::LittleEndian2String(
1972 1972
 				$dwBytesInRes,
1973 1973
 				4
1974
-			);     // dwBytesInRes;	// How many bytes in this resource?
1974
+			); // dwBytesInRes;	// How many bytes in this resource?
1975 1975
 
1976 1976
 			$icondata .= phpthumb_functions::LittleEndian2String(
1977 1977
 				$dwImageOffset,
1978 1978
 				4
1979
-			);    // dwImageOffset;   // Where in the file is this image?
1979
+			); // dwImageOffset;   // Where in the file is this image?
1980 1980
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1981 1981
 			$dwImageOffset += strlen($icXOR[$key]);
1982 1982
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
Indentation   +1324 added lines, -1324 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres'); // par precaution
24 24
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -38,21 +38,21 @@  discard block
 block discarded – undo
38 38
  *     Le code de la couleur en hexadécimal.
39 39
  */
40 40
 function _couleur_dec_to_hex($red, $green, $blue) {
41
-	$red = dechex($red);
42
-	$green = dechex($green);
43
-	$blue = dechex($blue);
44
-
45
-	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
47
-	}
48
-	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
50
-	}
51
-	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
53
-	}
54
-
55
-	return "$red$green$blue";
41
+    $red = dechex($red);
42
+    $green = dechex($green);
43
+    $blue = dechex($blue);
44
+
45
+    if (strlen($red) == 1) {
46
+        $red = '0' . $red;
47
+    }
48
+    if (strlen($green) == 1) {
49
+        $green = '0' . $green;
50
+    }
51
+    if (strlen($blue) == 1) {
52
+        $blue = '0' . $blue;
53
+    }
54
+
55
+    return "$red$green$blue";
56 56
 }
57 57
 
58 58
 /**
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
  *     Un tableau des 3 éléments : rouge, vert, bleu.
65 65
  */
66 66
 function _couleur_hex_to_dec($couleur) {
67
-	$couleur ??= '';
68
-	$couleur = couleur_html_to_hex($couleur);
69
-	$couleur = ltrim($couleur, '#');
70
-	if (strlen($couleur) === 3) {
71
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
-	}
73
-	$retour = [];
74
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
75
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
76
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
77
-
78
-	return $retour;
67
+    $couleur ??= '';
68
+    $couleur = couleur_html_to_hex($couleur);
69
+    $couleur = ltrim($couleur, '#');
70
+    if (strlen($couleur) === 3) {
71
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
+    }
73
+    $retour = [];
74
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
75
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
76
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
77
+
78
+    return $retour;
79 79
 }
80 80
 
81 81
 
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
  *     Le code de la couleur en hexadécimal.
93 93
  */
94 94
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
95
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
96
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
95
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
96
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
97 97
 }
98 98
 
99 99
 /**
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
106 106
  */
107 107
 function _couleur_hex_to_hsl($couleur) {
108
-	$rgb = _couleur_hex_to_dec($couleur);
109
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
108
+    $rgb = _couleur_hex_to_dec($couleur);
109
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
110 110
 }
111 111
 
112 112
 /**
@@ -121,59 +121,59 @@  discard block
 block discarded – undo
121 121
  * @return array
122 122
  */
123 123
 function _couleur_rgb_to_hsl($R, $G, $B) {
124
-	$H = null;
125
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
126
-	$var_G = ($G / 255);
127
-	$var_B = ($B / 255);
128
-
129
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
130
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
131
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
132
-
133
-	$L = ($var_Max + $var_Min) / 2;
134
-
135
-	if ($del_Max == 0) {
136
-		//This is a gray, no chroma...
137
-		$H = 0; //HSL results = 0 ÷ 1
138
-		$S = 0;
139
-	} else {
140
-		// Chromatic data...
141
-		if ($L < 0.5) {
142
-			$S = $del_Max / ($var_Max + $var_Min);
143
-		} else {
144
-			$S = $del_Max / (2 - $var_Max - $var_Min);
145
-		}
146
-
147
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
148
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
149
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
150
-
151
-		if ($var_R == $var_Max) {
152
-			$H = $del_B - $del_G;
153
-		} else {
154
-			if ($var_G == $var_Max) {
155
-				$H = (1 / 3) + $del_R - $del_B;
156
-			} else {
157
-				if ($var_B == $var_Max) {
158
-					$H = (2 / 3) + $del_G - $del_R;
159
-				}
160
-			}
161
-		}
162
-
163
-		if ($H < 0) {
164
-			$H += 1;
165
-		}
166
-		if ($H > 1) {
167
-			$H -= 1;
168
-		}
169
-	}
170
-
171
-	$ret = [];
172
-	$ret['h'] = $H;
173
-	$ret['s'] = $S;
174
-	$ret['l'] = $L;
175
-
176
-	return $ret;
124
+    $H = null;
125
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
126
+    $var_G = ($G / 255);
127
+    $var_B = ($B / 255);
128
+
129
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
130
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
131
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
132
+
133
+    $L = ($var_Max + $var_Min) / 2;
134
+
135
+    if ($del_Max == 0) {
136
+        //This is a gray, no chroma...
137
+        $H = 0; //HSL results = 0 ÷ 1
138
+        $S = 0;
139
+    } else {
140
+        // Chromatic data...
141
+        if ($L < 0.5) {
142
+            $S = $del_Max / ($var_Max + $var_Min);
143
+        } else {
144
+            $S = $del_Max / (2 - $var_Max - $var_Min);
145
+        }
146
+
147
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
148
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
149
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
150
+
151
+        if ($var_R == $var_Max) {
152
+            $H = $del_B - $del_G;
153
+        } else {
154
+            if ($var_G == $var_Max) {
155
+                $H = (1 / 3) + $del_R - $del_B;
156
+            } else {
157
+                if ($var_B == $var_Max) {
158
+                    $H = (2 / 3) + $del_G - $del_R;
159
+                }
160
+            }
161
+        }
162
+
163
+        if ($H < 0) {
164
+            $H += 1;
165
+        }
166
+        if ($H > 1) {
167
+            $H -= 1;
168
+        }
169
+    }
170
+
171
+    $ret = [];
172
+    $ret['h'] = $H;
173
+    $ret['s'] = $S;
174
+    $ret['l'] = $L;
175
+
176
+    return $ret;
177 177
 }
178 178
 
179 179
 
@@ -189,52 +189,52 @@  discard block
 block discarded – undo
189 189
  * @return array
190 190
  */
191 191
 function _couleur_hsl_to_rgb($H, $S, $L) {
192
-	// helper
193
-	$hue_2_rgb = function ($v1, $v2, $vH) {
194
-		if ($vH < 0) {
195
-			$vH += 1;
196
-		}
197
-		if ($vH > 1) {
198
-			$vH -= 1;
199
-		}
200
-		if ((6 * $vH) < 1) {
201
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
202
-		}
203
-		if ((2 * $vH) < 1) {
204
-			return ($v2);
205
-		}
206
-		if ((3 * $vH) < 2) {
207
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
208
-		}
209
-
210
-		return ($v1);
211
-	};
212
-
213
-	if ($S == 0) {
214
-		// HSV values = 0 -> 1
215
-		$R = $L * 255;
216
-		$G = $L * 255;
217
-		$B = $L * 255;
218
-	} else {
219
-		if ($L < 0.5) {
220
-			$var_2 = $L * (1 + $S);
221
-		} else {
222
-			$var_2 = ($L + $S) - ($S * $L);
223
-		}
224
-
225
-		$var_1 = 2 * $L - $var_2;
226
-
227
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
228
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
229
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
230
-	}
231
-
232
-	$ret = [];
233
-	$ret['r'] = floor($R);
234
-	$ret['g'] = floor($G);
235
-	$ret['b'] = floor($B);
236
-
237
-	return $ret;
192
+    // helper
193
+    $hue_2_rgb = function ($v1, $v2, $vH) {
194
+        if ($vH < 0) {
195
+            $vH += 1;
196
+        }
197
+        if ($vH > 1) {
198
+            $vH -= 1;
199
+        }
200
+        if ((6 * $vH) < 1) {
201
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
202
+        }
203
+        if ((2 * $vH) < 1) {
204
+            return ($v2);
205
+        }
206
+        if ((3 * $vH) < 2) {
207
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
208
+        }
209
+
210
+        return ($v1);
211
+    };
212
+
213
+    if ($S == 0) {
214
+        // HSV values = 0 -> 1
215
+        $R = $L * 255;
216
+        $G = $L * 255;
217
+        $B = $L * 255;
218
+    } else {
219
+        if ($L < 0.5) {
220
+            $var_2 = $L * (1 + $S);
221
+        } else {
222
+            $var_2 = ($L + $S) - ($S * $L);
223
+        }
224
+
225
+        $var_1 = 2 * $L - $var_2;
226
+
227
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
228
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
229
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
230
+    }
231
+
232
+    $ret = [];
233
+    $ret['r'] = floor($R);
234
+    $ret['g'] = floor($G);
235
+    $ret['b'] = floor($B);
236
+
237
+    return $ret;
238 238
 }
239 239
 
240 240
 /**
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
  *     true si il faut supprimer le fichier temporaire ; false sinon.
253 253
  */
254 254
 function statut_effacer_images_temporaires($stat) {
255
-	static $statut = false; // par defaut on grave toute les images
256
-	if ($stat === 'get') {
257
-		return $statut;
258
-	}
259
-	$statut = $stat ? true : false;
255
+    static $statut = false; // par defaut on grave toute les images
256
+    if ($stat === 'get') {
257
+        return $statut;
258
+    }
259
+    $statut = $stat ? true : false;
260 260
 }
261 261
 
262 262
 
@@ -309,243 +309,243 @@  discard block
 block discarded – undo
309 309
  *     - array : tableau décrivant de l'image
310 310
  */
311 311
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
312
-	$ret = [];
313
-	$f = null;
314
-	static $images_recalcul = [];
315
-	if (strlen($img) == 0) {
316
-		return false;
317
-	}
318
-
319
-	$source = trim(extraire_attribut($img, 'src') ?? '');
320
-	if (strlen($source) < 1) {
321
-		$source = $img;
322
-		$img = "<img src='$source' />";
323
-	} elseif (
324
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
325
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
326
-		and in_array($extension, _image_extensions_acceptees_en_entree())
327
-	) {
328
-		# gerer img src="data:....base64"
329
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
330
-		if (!file_exists($local)) {
331
-			ecrire_fichier($local, base64_decode($regs[2]));
332
-		}
333
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
334
-			$sanitizer($local);
335
-		}
336
-		$source = $local;
337
-		$img = inserer_attribut($img, 'src', $source);
338
-		# eviter les mauvaises surprises lors de conversions de format
339
-		$img = inserer_attribut($img, 'width', '');
340
-		$img = inserer_attribut($img, 'height', '');
341
-	}
342
-
343
-	// les protocoles web prennent au moins 3 lettres
344
-	if (tester_url_absolue($source)) {
345
-		include_spip('inc/distant');
346
-		$fichier = _DIR_RACINE . copie_locale($source);
347
-		if (!$fichier) {
348
-			return '';
349
-		}
350
-		if (
351
-			$extension = _image_trouver_extension($fichier)
352
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
353
-		) {
354
-			$sanitizer($fichier);
355
-		}
356
-	} else {
357
-		// enlever le timestamp eventuel
358
-		if (strpos($source, '?') !== false) {
359
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
360
-		}
361
-		if (
362
-			strpos($source, '?') !== false
363
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
364
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
365
-		) {
366
-			$source = $f;
367
-		}
368
-		$fichier = $source;
369
-	}
370
-
371
-	$terminaison_dest = '';
372
-	if ($terminaison = _image_trouver_extension($fichier)) {
373
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
374
-	}
375
-
376
-	if (
377
-		$forcer_format !== false
378
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
379
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
380
-	) {
381
-		$terminaison_dest = $forcer_format;
382
-	}
383
-
384
-	if (!$terminaison_dest) {
385
-		return false;
386
-	}
387
-
388
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
389
-	$fichier_dest = $nom_fichier;
390
-	if (
391
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
392
-		or @file_exists($f = $fichier)
393
-	) {
394
-		// on passe la balise img a taille image qui exraira les attributs si possible
395
-		// au lieu de faire un acces disque sur le fichier
396
-		[$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
397
-		$date_src = @filemtime($f);
398
-	} elseif (
399
-		@file_exists($f = "$fichier.src")
400
-		and lire_fichier($f, $valeurs)
401
-		and $valeurs = unserialize($valeurs)
402
-		and isset($valeurs['hauteur_dest'])
403
-		and isset($valeurs['largeur_dest'])
404
-	) {
405
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
406
-		$ret['largeur'] = $valeurs['largeur_dest'];
407
-		$date_src = $valeurs['date'];
408
-	} // pas de fichier source par la
409
-	else {
410
-		return false;
411
-	}
412
-
413
-	// pas de taille mesurable
414
-	if (!($ret['hauteur'] or $ret['largeur'])) {
415
-		return false;
416
-	}
417
-
418
-	// les images calculees dependent du chemin du fichier source
419
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
420
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
421
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
422
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
423
-	// alors que ca concerne peu de site au final
424
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
425
-	$identifiant = $fichier;
426
-
427
-	// cas general :
428
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
429
-	// cas particulier de reduire :
430
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
431
-	$cache = 'cache-gd2';
432
-	if (substr($effet, 0, 7) == 'reduire') {
433
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
434
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
435
-		$ret['largeur_dest'] = $destWidth;
436
-		$ret['hauteur_dest'] = $destHeight;
437
-		$effet = "L{$destWidth}xH$destHeight";
438
-		$cache = 'cache-vignettes';
439
-		$fichier_dest = basename($fichier_dest);
440
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
441
-			// on garde la terminaison initiale car image simplement copiee
442
-			// et on postfixe son nom avec un md5 du path
443
-			$terminaison_dest = $terminaison;
444
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
445
-		} else {
446
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
447
-		}
448
-		$cache = sous_repertoire(_DIR_VAR, $cache);
449
-		$cache = sous_repertoire($cache, $effet);
450
-	} else {
451
-		$fichier_dest = md5("$identifiant-$effet");
452
-		$cache = sous_repertoire(_DIR_VAR, $cache);
453
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
454
-		$fichier_dest = substr($fichier_dest, 2);
455
-	}
456
-
457
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
458
-
459
-	$GLOBALS['images_calculees'][] = $fichier_dest;
460
-
461
-	$creer = true;
462
-	// si recalcul des images demande, recalculer chaque image une fois
463
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
464
-		$images_recalcul[$fichier_dest] = true;
465
-	} else {
466
-		if (@file_exists($f = $fichier_dest)) {
467
-			if (filemtime($f) >= $date_src) {
468
-				$creer = false;
469
-			}
470
-		} else {
471
-			if (
472
-				@file_exists($f = "$fichier_dest.src")
473
-				and lire_fichier($f, $valeurs)
474
-				and $valeurs = unserialize($valeurs)
475
-				and $valeurs['date'] >= $date_src
476
-			) {
477
-				$creer = false;
478
-			}
479
-		}
480
-	}
481
-	if ($creer) {
482
-		if (!@file_exists($fichier)) {
483
-			if (!@file_exists("$fichier.src")) {
484
-				spip_log("Image absente : $fichier");
485
-
486
-				return false;
487
-			}
488
-			# on reconstruit l'image source absente a partir de la chaine des .src
489
-			reconstruire_image_intermediaire($fichier);
490
-		}
491
-	}
492
-
493
-	if ($creer) {
494
-		spip_log(
495
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
496
-			'images' . _LOG_DEBUG
497
-		);
498
-	}
499
-
500
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
501
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
502
-	$ret['fichier'] = $fichier;
503
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
504
-	$ret['fichier_dest'] = $fichier_dest;
505
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
506
-	$ret['format_dest'] = $terminaison_dest;
507
-	$ret['date_src'] = $date_src;
508
-	$ret['creer'] = $creer;
509
-	$ret['class'] = extraire_attribut($img, 'class');
510
-	$ret['alt'] = extraire_attribut($img, 'alt');
511
-	$ret['style'] = extraire_attribut($img, 'style');
512
-	$ret['tag'] = $img;
513
-	if ($fonction_creation) {
514
-		$ret['reconstruction'] = $fonction_creation;
515
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
516
-		# cas de image_reduire qui finalement ne reduit pas l'image source
517
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
518
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
519
-	}
520
-
521
-	$ret = pipeline('image_preparer_filtre', [
522
-			'args' => [
523
-				'img' => $img,
524
-				'effet' => $effet,
525
-				'forcer_format' => $forcer_format,
526
-				'fonction_creation' => $fonction_creation,
527
-				'find_in_path' => $find_in_path,
528
-			],
529
-			'data' => $ret
530
-		]);
531
-
532
-	// une globale pour le debug en cas de crash memoire
533
-	$GLOBALS['derniere_image_calculee'] = $ret;
534
-
535
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
536
-	if ($term_fonction === 'svg') {
537
-		if ($creer and !$support_svg) {
538
-			process_image_svg_identite($ret);
539
-			$ret['creer'] = false;
540
-		}
541
-	}
542
-	else {
543
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
544
-			return false;
545
-		}
546
-	}
547
-
548
-	return $ret;
312
+    $ret = [];
313
+    $f = null;
314
+    static $images_recalcul = [];
315
+    if (strlen($img) == 0) {
316
+        return false;
317
+    }
318
+
319
+    $source = trim(extraire_attribut($img, 'src') ?? '');
320
+    if (strlen($source) < 1) {
321
+        $source = $img;
322
+        $img = "<img src='$source' />";
323
+    } elseif (
324
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
325
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
326
+        and in_array($extension, _image_extensions_acceptees_en_entree())
327
+    ) {
328
+        # gerer img src="data:....base64"
329
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
330
+        if (!file_exists($local)) {
331
+            ecrire_fichier($local, base64_decode($regs[2]));
332
+        }
333
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
334
+            $sanitizer($local);
335
+        }
336
+        $source = $local;
337
+        $img = inserer_attribut($img, 'src', $source);
338
+        # eviter les mauvaises surprises lors de conversions de format
339
+        $img = inserer_attribut($img, 'width', '');
340
+        $img = inserer_attribut($img, 'height', '');
341
+    }
342
+
343
+    // les protocoles web prennent au moins 3 lettres
344
+    if (tester_url_absolue($source)) {
345
+        include_spip('inc/distant');
346
+        $fichier = _DIR_RACINE . copie_locale($source);
347
+        if (!$fichier) {
348
+            return '';
349
+        }
350
+        if (
351
+            $extension = _image_trouver_extension($fichier)
352
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
353
+        ) {
354
+            $sanitizer($fichier);
355
+        }
356
+    } else {
357
+        // enlever le timestamp eventuel
358
+        if (strpos($source, '?') !== false) {
359
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
360
+        }
361
+        if (
362
+            strpos($source, '?') !== false
363
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
364
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
365
+        ) {
366
+            $source = $f;
367
+        }
368
+        $fichier = $source;
369
+    }
370
+
371
+    $terminaison_dest = '';
372
+    if ($terminaison = _image_trouver_extension($fichier)) {
373
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
374
+    }
375
+
376
+    if (
377
+        $forcer_format !== false
378
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
379
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
380
+    ) {
381
+        $terminaison_dest = $forcer_format;
382
+    }
383
+
384
+    if (!$terminaison_dest) {
385
+        return false;
386
+    }
387
+
388
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
389
+    $fichier_dest = $nom_fichier;
390
+    if (
391
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
392
+        or @file_exists($f = $fichier)
393
+    ) {
394
+        // on passe la balise img a taille image qui exraira les attributs si possible
395
+        // au lieu de faire un acces disque sur le fichier
396
+        [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
397
+        $date_src = @filemtime($f);
398
+    } elseif (
399
+        @file_exists($f = "$fichier.src")
400
+        and lire_fichier($f, $valeurs)
401
+        and $valeurs = unserialize($valeurs)
402
+        and isset($valeurs['hauteur_dest'])
403
+        and isset($valeurs['largeur_dest'])
404
+    ) {
405
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
406
+        $ret['largeur'] = $valeurs['largeur_dest'];
407
+        $date_src = $valeurs['date'];
408
+    } // pas de fichier source par la
409
+    else {
410
+        return false;
411
+    }
412
+
413
+    // pas de taille mesurable
414
+    if (!($ret['hauteur'] or $ret['largeur'])) {
415
+        return false;
416
+    }
417
+
418
+    // les images calculees dependent du chemin du fichier source
419
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
420
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
421
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
422
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
423
+    // alors que ca concerne peu de site au final
424
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
425
+    $identifiant = $fichier;
426
+
427
+    // cas general :
428
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
429
+    // cas particulier de reduire :
430
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
431
+    $cache = 'cache-gd2';
432
+    if (substr($effet, 0, 7) == 'reduire') {
433
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
434
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
435
+        $ret['largeur_dest'] = $destWidth;
436
+        $ret['hauteur_dest'] = $destHeight;
437
+        $effet = "L{$destWidth}xH$destHeight";
438
+        $cache = 'cache-vignettes';
439
+        $fichier_dest = basename($fichier_dest);
440
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
441
+            // on garde la terminaison initiale car image simplement copiee
442
+            // et on postfixe son nom avec un md5 du path
443
+            $terminaison_dest = $terminaison;
444
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
445
+        } else {
446
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
447
+        }
448
+        $cache = sous_repertoire(_DIR_VAR, $cache);
449
+        $cache = sous_repertoire($cache, $effet);
450
+    } else {
451
+        $fichier_dest = md5("$identifiant-$effet");
452
+        $cache = sous_repertoire(_DIR_VAR, $cache);
453
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
454
+        $fichier_dest = substr($fichier_dest, 2);
455
+    }
456
+
457
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
458
+
459
+    $GLOBALS['images_calculees'][] = $fichier_dest;
460
+
461
+    $creer = true;
462
+    // si recalcul des images demande, recalculer chaque image une fois
463
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
464
+        $images_recalcul[$fichier_dest] = true;
465
+    } else {
466
+        if (@file_exists($f = $fichier_dest)) {
467
+            if (filemtime($f) >= $date_src) {
468
+                $creer = false;
469
+            }
470
+        } else {
471
+            if (
472
+                @file_exists($f = "$fichier_dest.src")
473
+                and lire_fichier($f, $valeurs)
474
+                and $valeurs = unserialize($valeurs)
475
+                and $valeurs['date'] >= $date_src
476
+            ) {
477
+                $creer = false;
478
+            }
479
+        }
480
+    }
481
+    if ($creer) {
482
+        if (!@file_exists($fichier)) {
483
+            if (!@file_exists("$fichier.src")) {
484
+                spip_log("Image absente : $fichier");
485
+
486
+                return false;
487
+            }
488
+            # on reconstruit l'image source absente a partir de la chaine des .src
489
+            reconstruire_image_intermediaire($fichier);
490
+        }
491
+    }
492
+
493
+    if ($creer) {
494
+        spip_log(
495
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
496
+            'images' . _LOG_DEBUG
497
+        );
498
+    }
499
+
500
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
501
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
502
+    $ret['fichier'] = $fichier;
503
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
504
+    $ret['fichier_dest'] = $fichier_dest;
505
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
506
+    $ret['format_dest'] = $terminaison_dest;
507
+    $ret['date_src'] = $date_src;
508
+    $ret['creer'] = $creer;
509
+    $ret['class'] = extraire_attribut($img, 'class');
510
+    $ret['alt'] = extraire_attribut($img, 'alt');
511
+    $ret['style'] = extraire_attribut($img, 'style');
512
+    $ret['tag'] = $img;
513
+    if ($fonction_creation) {
514
+        $ret['reconstruction'] = $fonction_creation;
515
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
516
+        # cas de image_reduire qui finalement ne reduit pas l'image source
517
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
518
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
519
+    }
520
+
521
+    $ret = pipeline('image_preparer_filtre', [
522
+            'args' => [
523
+                'img' => $img,
524
+                'effet' => $effet,
525
+                'forcer_format' => $forcer_format,
526
+                'fonction_creation' => $fonction_creation,
527
+                'find_in_path' => $find_in_path,
528
+            ],
529
+            'data' => $ret
530
+        ]);
531
+
532
+    // une globale pour le debug en cas de crash memoire
533
+    $GLOBALS['derniere_image_calculee'] = $ret;
534
+
535
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
536
+    if ($term_fonction === 'svg') {
537
+        if ($creer and !$support_svg) {
538
+            process_image_svg_identite($ret);
539
+            $ret['creer'] = false;
540
+        }
541
+    }
542
+    else {
543
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
544
+            return false;
545
+        }
546
+    }
547
+
548
+    return $ret;
549 549
 }
550 550
 
551 551
 
@@ -554,54 +554,54 @@  discard block
 block discarded – undo
554 554
  * @return array
555 555
  */
556 556
 function _image_extensions_acceptees_en_entree() {
557
-	static $extensions = null;
558
-	if (empty($extensions)) {
559
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
560
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
561
-			// action=tester renseigne gd_formats et detecte le support de webp
562
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
563
-			$extensions = array_map('trim', $extensions);
564
-			$extensions = array_filter($extensions);
565
-			if (in_array('jpg', $extensions)) {
566
-				$extensions[] = 'jpeg';
567
-			}
568
-			$extensions = array_unique($extensions);
569
-		}
570
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
571
-	}
572
-
573
-	return $extensions;
557
+    static $extensions = null;
558
+    if (empty($extensions)) {
559
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
560
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
561
+            // action=tester renseigne gd_formats et detecte le support de webp
562
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
563
+            $extensions = array_map('trim', $extensions);
564
+            $extensions = array_filter($extensions);
565
+            if (in_array('jpg', $extensions)) {
566
+                $extensions[] = 'jpeg';
567
+            }
568
+            $extensions = array_unique($extensions);
569
+        }
570
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
571
+    }
572
+
573
+    return $extensions;
574 574
 }
575 575
 
576 576
 /**
577 577
  * @return array|string[]|null
578 578
  */
579 579
 function _image_extensions_acceptees_en_sortie() {
580
-	static $extensions = null;
581
-	if (empty($extensions)) {
582
-		$extensions = _image_extensions_acceptees_en_entree();
583
-		$extensions = array_diff($extensions, ['jpeg']);
584
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
585
-			$extensions = array_diff($extensions, ['gif']);
586
-		}
587
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
588
-			$extensions = array_diff($extensions, ['webp']);
589
-		}
590
-	}
591
-
592
-	return $extensions;
580
+    static $extensions = null;
581
+    if (empty($extensions)) {
582
+        $extensions = _image_extensions_acceptees_en_entree();
583
+        $extensions = array_diff($extensions, ['jpeg']);
584
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
585
+            $extensions = array_diff($extensions, ['gif']);
586
+        }
587
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
588
+            $extensions = array_diff($extensions, ['webp']);
589
+        }
590
+    }
591
+
592
+    return $extensions;
593 593
 }
594 594
 
595 595
 function _image_extension_normalisee($extension) {
596
-	$extension = strtolower($extension);
597
-	if ($extension === 'jpeg') {
598
-		$extension = 'jpg';
599
-	}
600
-	return $extension;
596
+    $extension = strtolower($extension);
597
+    if ($extension === 'jpeg') {
598
+        $extension = 'jpg';
599
+    }
600
+    return $extension;
601 601
 }
602 602
 
603 603
 function _image_extensions_conservent_transparence() {
604
-	return ['png', 'webp'];
604
+    return ['png', 'webp'];
605 605
 }
606 606
 
607 607
 
@@ -611,12 +611,12 @@  discard block
 block discarded – undo
611 611
  * @return string
612 612
  */
613 613
 function _image_trouver_extension($path) {
614
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
615
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
616
-		$terminaison = strtolower($regs[1]);
617
-		return $terminaison;
618
-	}
619
-	return '';
614
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
615
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
616
+        $terminaison = strtolower($regs[1]);
617
+        return $terminaison;
618
+    }
619
+    return '';
620 620
 }
621 621
 
622 622
 /**
@@ -627,33 +627,33 @@  discard block
 block discarded – undo
627 627
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
628 628
  */
629 629
 function _image_trouver_extension_pertinente($path) {
630
-	$path = supprimer_timestamp($path);
631
-	$terminaison = _image_trouver_extension($path);
632
-	if ($terminaison == 'jpg') {
633
-		$terminaison = 'jpeg';
634
-	}
635
-
636
-	if (!file_exists($path)) {
637
-		return $terminaison;
638
-	}
639
-
640
-	if (!$info = @spip_getimagesize($path)) {
641
-		return $terminaison;
642
-	}
643
-
644
-	if (isset($info['mime'])) {
645
-		$mime = $info['mime'];
646
-	}
647
-	else {
648
-		$mime = image_type_to_mime_type($info[2]);
649
-	}
650
-
651
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
652
-	if ($_terminaison and $_terminaison !== $terminaison) {
653
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
654
-		$terminaison = $_terminaison;
655
-	}
656
-	return $terminaison;
630
+    $path = supprimer_timestamp($path);
631
+    $terminaison = _image_trouver_extension($path);
632
+    if ($terminaison == 'jpg') {
633
+        $terminaison = 'jpeg';
634
+    }
635
+
636
+    if (!file_exists($path)) {
637
+        return $terminaison;
638
+    }
639
+
640
+    if (!$info = @spip_getimagesize($path)) {
641
+        return $terminaison;
642
+    }
643
+
644
+    if (isset($info['mime'])) {
645
+        $mime = $info['mime'];
646
+    }
647
+    else {
648
+        $mime = image_type_to_mime_type($info[2]);
649
+    }
650
+
651
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
652
+    if ($_terminaison and $_terminaison !== $terminaison) {
653
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
654
+        $terminaison = $_terminaison;
655
+    }
656
+    return $terminaison;
657 657
 }
658 658
 
659 659
 /**
@@ -661,36 +661,36 @@  discard block
 block discarded – undo
661 661
  * @return string
662 662
  */
663 663
 function _image_trouver_extension_depuis_mime($mime) {
664
-	switch (strtolower($mime)) {
665
-		case 'image/png':
666
-		case 'image/x-png':
667
-			$terminaison = 'png';
668
-			break;
669
-
670
-		case 'image/jpg':
671
-		case 'image/jpeg':
672
-		case 'image/pjpeg':
673
-			$terminaison = 'jpeg';
674
-			break;
675
-
676
-		case 'image/gif':
677
-			$terminaison = 'gif';
678
-			break;
679
-
680
-		case 'image/webp':
681
-		case 'image/x-webp':
682
-			$terminaison = 'webp';
683
-			break;
684
-
685
-		case 'image/svg+xml':
686
-			$terminaison = 'svg';
687
-			break;
688
-
689
-		default:
690
-			$terminaison = '';
691
-	}
692
-
693
-	return $terminaison;
664
+    switch (strtolower($mime)) {
665
+        case 'image/png':
666
+        case 'image/x-png':
667
+            $terminaison = 'png';
668
+            break;
669
+
670
+        case 'image/jpg':
671
+        case 'image/jpeg':
672
+        case 'image/pjpeg':
673
+            $terminaison = 'jpeg';
674
+            break;
675
+
676
+        case 'image/gif':
677
+            $terminaison = 'gif';
678
+            break;
679
+
680
+        case 'image/webp':
681
+        case 'image/x-webp':
682
+            $terminaison = 'webp';
683
+            break;
684
+
685
+        case 'image/svg+xml':
686
+            $terminaison = 'svg';
687
+            break;
688
+
689
+        default:
690
+            $terminaison = '';
691
+    }
692
+
693
+    return $terminaison;
694 694
 }
695 695
 
696 696
 
@@ -710,18 +710,18 @@  discard block
 block discarded – undo
710 710
  *     Une ressource de type Image GD.
711 711
  */
712 712
 function _imagecreatefrom_func(string $func, string $filename) {
713
-	if (!function_exists($func)) {
714
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
715
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
716
-		return null;
717
-	}
718
-	$img = @$func($filename);
719
-	if (!$img) {
720
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
721
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
722
-		$img = imagecreate(10, 10);
723
-	}
724
-	return $img;
713
+    if (!function_exists($func)) {
714
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
715
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
716
+        return null;
717
+    }
718
+    $img = @$func($filename);
719
+    if (!$img) {
720
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
721
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
722
+        $img = imagecreate(10, 10);
723
+    }
724
+    return $img;
725 725
 }
726 726
 
727 727
 /**
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
  *     Une ressource de type Image GD.
738 738
  */
739 739
 function _imagecreatefromjpeg($filename) {
740
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
740
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
741 741
 }
742 742
 
743 743
 /**
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
  *     Une ressource de type Image GD.
754 754
  */
755 755
 function _imagecreatefrompng($filename) {
756
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
756
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
757 757
 }
758 758
 
759 759
 /**
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
  *     Une ressource de type Image GD.
770 770
  */
771 771
 function _imagecreatefromgif($filename) {
772
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
772
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
773 773
 }
774 774
 
775 775
 
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
  *     Une ressource de type Image GD.
787 787
  */
788 788
 function _imagecreatefromwebp($filename) {
789
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
789
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
790 790
 }
791 791
 
792 792
 /**
@@ -804,24 +804,24 @@  discard block
 block discarded – undo
804 804
  *     - true si une image est bien retournée.
805 805
  */
806 806
 function _image_imagepng($img, $fichier) {
807
-	if (!function_exists('imagepng')) {
808
-		return false;
809
-	}
810
-	$tmp = $fichier . '.tmp';
811
-	$ret = imagepng($img, $tmp);
812
-	if (file_exists($tmp)) {
813
-		$taille_test = getimagesize($tmp);
814
-		if ($taille_test[0] < 1) {
815
-			return false;
816
-		}
817
-
818
-		spip_unlink($fichier); // le fichier peut deja exister
819
-		@rename($tmp, $fichier);
820
-
821
-		return $ret;
822
-	}
823
-
824
-	return false;
807
+    if (!function_exists('imagepng')) {
808
+        return false;
809
+    }
810
+    $tmp = $fichier . '.tmp';
811
+    $ret = imagepng($img, $tmp);
812
+    if (file_exists($tmp)) {
813
+        $taille_test = getimagesize($tmp);
814
+        if ($taille_test[0] < 1) {
815
+            return false;
816
+        }
817
+
818
+        spip_unlink($fichier); // le fichier peut deja exister
819
+        @rename($tmp, $fichier);
820
+
821
+        return $ret;
822
+    }
823
+
824
+    return false;
825 825
 }
826 826
 
827 827
 /**
@@ -839,24 +839,24 @@  discard block
 block discarded – undo
839 839
  *     - true si une image est bien retournée.
840 840
  */
841 841
 function _image_imagegif($img, $fichier) {
842
-	if (!function_exists('imagegif')) {
843
-		return false;
844
-	}
845
-	$tmp = $fichier . '.tmp';
846
-	$ret = imagegif($img, $tmp);
847
-	if (file_exists($tmp)) {
848
-		$taille_test = getimagesize($tmp);
849
-		if ($taille_test[0] < 1) {
850
-			return false;
851
-		}
852
-
853
-		spip_unlink($fichier); // le fichier peut deja exister
854
-		@rename($tmp, $fichier);
855
-
856
-		return $ret;
857
-	}
858
-
859
-	return false;
842
+    if (!function_exists('imagegif')) {
843
+        return false;
844
+    }
845
+    $tmp = $fichier . '.tmp';
846
+    $ret = imagegif($img, $tmp);
847
+    if (file_exists($tmp)) {
848
+        $taille_test = getimagesize($tmp);
849
+        if ($taille_test[0] < 1) {
850
+            return false;
851
+        }
852
+
853
+        spip_unlink($fichier); // le fichier peut deja exister
854
+        @rename($tmp, $fichier);
855
+
856
+        return $ret;
857
+    }
858
+
859
+    return false;
860 860
 }
861 861
 
862 862
 /**
@@ -879,29 +879,29 @@  discard block
 block discarded – undo
879 879
  *     - true si une image est bien retournée.
880 880
  */
881 881
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
882
-	if (!function_exists('imagejpeg')) {
883
-		return false;
884
-	}
885
-	$tmp = $fichier . '.tmp';
882
+    if (!function_exists('imagejpeg')) {
883
+        return false;
884
+    }
885
+    $tmp = $fichier . '.tmp';
886 886
 
887
-	// Enable interlancing
888
-	imageinterlace($img, true);
887
+    // Enable interlancing
888
+    imageinterlace($img, true);
889 889
 
890
-	$ret = imagejpeg($img, $tmp, $qualite);
890
+    $ret = imagejpeg($img, $tmp, $qualite);
891 891
 
892
-	if (file_exists($tmp)) {
893
-		$taille_test = getimagesize($tmp);
894
-		if ($taille_test[0] < 1) {
895
-			return false;
896
-		}
892
+    if (file_exists($tmp)) {
893
+        $taille_test = getimagesize($tmp);
894
+        if ($taille_test[0] < 1) {
895
+            return false;
896
+        }
897 897
 
898
-		spip_unlink($fichier); // le fichier peut deja exister
899
-		@rename($tmp, $fichier);
898
+        spip_unlink($fichier); // le fichier peut deja exister
899
+        @rename($tmp, $fichier);
900 900
 
901
-		return $ret;
902
-	}
901
+        return $ret;
902
+    }
903 903
 
904
-	return false;
904
+    return false;
905 905
 }
906 906
 
907 907
 /**
@@ -919,9 +919,9 @@  discard block
 block discarded – undo
919 919
  *     true si le fichier a bien été créé ; false sinon.
920 920
  */
921 921
 function _image_imageico($img, $fichier) {
922
-	$gd_image_array = [$img];
922
+    $gd_image_array = [$img];
923 923
 
924
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
924
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
925 925
 }
926 926
 
927 927
 
@@ -940,24 +940,24 @@  discard block
 block discarded – undo
940 940
  *     - true si une image est bien retournée.
941 941
  */
942 942
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
943
-	if (!function_exists('imagewebp')) {
944
-		return false;
945
-	}
946
-	$tmp = $fichier . '.tmp';
947
-	$ret = imagewebp($img, $tmp, $qualite);
948
-	if (file_exists($tmp)) {
949
-		$taille_test = getimagesize($tmp);
950
-		if ($taille_test[0] < 1) {
951
-			return false;
952
-		}
953
-
954
-		spip_unlink($fichier); // le fichier peut deja exister
955
-		@rename($tmp, $fichier);
956
-
957
-		return $ret;
958
-	}
959
-
960
-	return false;
943
+    if (!function_exists('imagewebp')) {
944
+        return false;
945
+    }
946
+    $tmp = $fichier . '.tmp';
947
+    $ret = imagewebp($img, $tmp, $qualite);
948
+    if (file_exists($tmp)) {
949
+        $taille_test = getimagesize($tmp);
950
+        if ($taille_test[0] < 1) {
951
+            return false;
952
+        }
953
+
954
+        spip_unlink($fichier); // le fichier peut deja exister
955
+        @rename($tmp, $fichier);
956
+
957
+        return $ret;
958
+    }
959
+
960
+    return false;
961 961
 }
962 962
 
963 963
 /**
@@ -977,35 +977,35 @@  discard block
 block discarded – undo
977 977
  */
978 978
 function _image_imagesvg($img, $fichier) {
979 979
 
980
-	$tmp = $fichier . '.tmp';
981
-	if (strpos($img, '<') === false) {
982
-		$img = supprimer_timestamp($img);
983
-		if (!file_exists($img)) {
984
-			return false;
985
-		}
986
-		@copy($img, $tmp);
987
-		if (filesize($tmp) == filesize($img)) {
988
-			spip_unlink($fichier); // le fichier peut deja exister
989
-			@rename($tmp, $fichier);
990
-			return true;
991
-		}
992
-		return false;
993
-	}
994
-
995
-	file_put_contents($tmp, $img);
996
-	if (file_exists($tmp)) {
997
-		$taille_test = spip_getimagesize($tmp);
998
-		if ($taille_test[0] < 1) {
999
-			return false;
1000
-		}
1001
-
1002
-		spip_unlink($fichier); // le fichier peut deja exister
1003
-		@rename($tmp, $fichier);
1004
-
1005
-		return true;
1006
-	}
1007
-
1008
-	return false;
980
+    $tmp = $fichier . '.tmp';
981
+    if (strpos($img, '<') === false) {
982
+        $img = supprimer_timestamp($img);
983
+        if (!file_exists($img)) {
984
+            return false;
985
+        }
986
+        @copy($img, $tmp);
987
+        if (filesize($tmp) == filesize($img)) {
988
+            spip_unlink($fichier); // le fichier peut deja exister
989
+            @rename($tmp, $fichier);
990
+            return true;
991
+        }
992
+        return false;
993
+    }
994
+
995
+    file_put_contents($tmp, $img);
996
+    if (file_exists($tmp)) {
997
+        $taille_test = spip_getimagesize($tmp);
998
+        if ($taille_test[0] < 1) {
999
+            return false;
1000
+        }
1001
+
1002
+        spip_unlink($fichier); // le fichier peut deja exister
1003
+        @rename($tmp, $fichier);
1004
+
1005
+        return true;
1006
+    }
1007
+
1008
+    return false;
1009 1009
 }
1010 1010
 
1011 1011
 
@@ -1033,30 +1033,30 @@  discard block
 block discarded – undo
1033 1033
  *     - false sinon.
1034 1034
  */
1035 1035
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1036
-	if (is_null($fonction)) {
1037
-		$fonction = '_image_image' . $valeurs['format_dest'];
1038
-	}
1039
-	$ret = false;
1040
-	#un flag pour reperer les images gravees
1041
-	$lock = (
1042
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1043
-		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1044
-	);
1045
-	if (
1046
-		function_exists($fonction)
1047
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1048
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1049
-		&& !$lock
1050
-	) {
1051
-		if (@file_exists($valeurs['fichier_dest'])) {
1052
-			// dans tous les cas mettre a jour la taille de l'image finale
1053
-			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1054
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1055
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1056
-		}
1057
-	}
1058
-
1059
-	return $ret;
1036
+    if (is_null($fonction)) {
1037
+        $fonction = '_image_image' . $valeurs['format_dest'];
1038
+    }
1039
+    $ret = false;
1040
+    #un flag pour reperer les images gravees
1041
+    $lock = (
1042
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1043
+        or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1044
+    );
1045
+    if (
1046
+        function_exists($fonction)
1047
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1048
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1049
+        && !$lock
1050
+    ) {
1051
+        if (@file_exists($valeurs['fichier_dest'])) {
1052
+            // dans tous les cas mettre a jour la taille de l'image finale
1053
+            [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1054
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1055
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1056
+        }
1057
+    }
1058
+
1059
+    return $ret;
1060 1060
 }
1061 1061
 
1062 1062
 /**
@@ -1069,27 +1069,27 @@  discard block
 block discarded – undo
1069 1069
  *     Chemin vers le fichier manquant
1070 1070
  **/
1071 1071
 function reconstruire_image_intermediaire($fichier_manquant) {
1072
-	$reconstruire = [];
1073
-	$fichier = $fichier_manquant;
1074
-	while (
1075
-		strpos($fichier, '://') === false
1076
-		and !@file_exists($fichier)
1077
-		and lire_fichier($src = "$fichier.src", $source)
1078
-		and $valeurs = unserialize($source)
1079
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1080
-	) {
1081
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1082
-		$reconstruire[] = $valeurs['reconstruction'];
1083
-	}
1084
-	while (count($reconstruire)) {
1085
-		$r = array_pop($reconstruire);
1086
-		$fonction = $r[0];
1087
-		$args = $r[1];
1088
-		$fonction(...$args);
1089
-	}
1090
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1091
-	// mais l'on peut nettoyer les miettes de sa creation
1092
-	ramasse_miettes($fichier_manquant);
1072
+    $reconstruire = [];
1073
+    $fichier = $fichier_manquant;
1074
+    while (
1075
+        strpos($fichier, '://') === false
1076
+        and !@file_exists($fichier)
1077
+        and lire_fichier($src = "$fichier.src", $source)
1078
+        and $valeurs = unserialize($source)
1079
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1080
+    ) {
1081
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1082
+        $reconstruire[] = $valeurs['reconstruction'];
1083
+    }
1084
+    while (count($reconstruire)) {
1085
+        $r = array_pop($reconstruire);
1086
+        $fonction = $r[0];
1087
+        $args = $r[1];
1088
+        $fonction(...$args);
1089
+    }
1090
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1091
+    // mais l'on peut nettoyer les miettes de sa creation
1092
+    ramasse_miettes($fichier_manquant);
1093 1093
 }
1094 1094
 
1095 1095
 /**
@@ -1109,28 +1109,28 @@  discard block
 block discarded – undo
1109 1109
  *     Chemin du fichier d'image calculé
1110 1110
  **/
1111 1111
 function ramasse_miettes($fichier) {
1112
-	if (
1113
-		strpos($fichier, '://') !== false
1114
-		or !lire_fichier($src = "$fichier.src", $source)
1115
-		or !$valeurs = unserialize($source)
1116
-	) {
1117
-		return;
1118
-	}
1119
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1120
-	while (
1121
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1122
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1123
-		and (lire_fichier(
1124
-			$src = "$fichier.src",
1125
-			$source
1126
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1127
-		and ($valeurs = unserialize($source))  # et valide
1128
-	) {
1129
-		# on efface le fichier
1130
-		spip_unlink($fichier);
1131
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1132
-		#spip_unlink($src);
1133
-	}
1112
+    if (
1113
+        strpos($fichier, '://') !== false
1114
+        or !lire_fichier($src = "$fichier.src", $source)
1115
+        or !$valeurs = unserialize($source)
1116
+    ) {
1117
+        return;
1118
+    }
1119
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1120
+    while (
1121
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1122
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1123
+        and (lire_fichier(
1124
+            $src = "$fichier.src",
1125
+            $source
1126
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1127
+        and ($valeurs = unserialize($source))  # et valide
1128
+    ) {
1129
+        # on efface le fichier
1130
+        spip_unlink($fichier);
1131
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1132
+        #spip_unlink($src);
1133
+    }
1134 1134
 }
1135 1135
 
1136 1136
 
@@ -1155,31 +1155,31 @@  discard block
 block discarded – undo
1155 1155
  *     Code HTML de l'image
1156 1156
  **/
1157 1157
 function image_graver($img) {
1158
-	// appeler le filtre post_image_filtrer qui permet de faire
1159
-	// des traitements auto a la fin d'une serie de filtres
1160
-	$img = pipeline('post_image_filtrer', $img);
1161
-
1162
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1163
-	if (($p = strpos($fichier, '?')) !== false) {
1164
-		$fichier = substr($fichier, 0, $p);
1165
-	}
1166
-	if (strlen($fichier) < 1) {
1167
-		$fichier = $img;
1168
-	}
1169
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1170
-	# et qu'il ne s'agit pas d'une URL
1171
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1172
-		reconstruire_image_intermediaire($fichier);
1173
-	}
1174
-	ramasse_miettes($fichier);
1175
-
1176
-	// ajouter le timestamp si besoin
1177
-	if (strpos($fichier_ori, '?') === false) {
1178
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1179
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1180
-	}
1181
-
1182
-	return $img;
1158
+    // appeler le filtre post_image_filtrer qui permet de faire
1159
+    // des traitements auto a la fin d'une serie de filtres
1160
+    $img = pipeline('post_image_filtrer', $img);
1161
+
1162
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1163
+    if (($p = strpos($fichier, '?')) !== false) {
1164
+        $fichier = substr($fichier, 0, $p);
1165
+    }
1166
+    if (strlen($fichier) < 1) {
1167
+        $fichier = $img;
1168
+    }
1169
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1170
+    # et qu'il ne s'agit pas d'une URL
1171
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1172
+        reconstruire_image_intermediaire($fichier);
1173
+    }
1174
+    ramasse_miettes($fichier);
1175
+
1176
+    // ajouter le timestamp si besoin
1177
+    if (strpos($fichier_ori, '?') === false) {
1178
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1179
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1180
+    }
1181
+
1182
+    return $img;
1183 1183
 }
1184 1184
 
1185 1185
 /**
@@ -1206,34 +1206,34 @@  discard block
 block discarded – undo
1206 1206
  *     Code html modifié de la balise.
1207 1207
  **/
1208 1208
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1209
-	if ($style === false) {
1210
-		$style = extraire_attribut($tag, 'style');
1211
-	}
1212
-
1213
-	// enlever le width et height du style
1214
-	if ($style) {
1215
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1216
-	}
1217
-	if ($style and $style[0] === ';') {
1218
-		$style = substr($style, 1);
1219
-	}
1220
-
1221
-	// mettre des attributs de width et height sur les images,
1222
-	// ca accelere le rendu du navigateur
1223
-	// ca permet aux navigateurs de reserver la bonne taille
1224
-	// quand on a desactive l'affichage des images.
1225
-	$tag = inserer_attribut($tag, 'width', round($width));
1226
-	$tag = inserer_attribut($tag, 'height', round($height));
1227
-
1228
-	// attributs deprecies. Transformer en CSS
1229
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1230
-		$style = "margin:{$espace}px;" . $style;
1231
-		$tag = inserer_attribut($tag, 'hspace', '');
1232
-	}
1233
-
1234
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1235
-
1236
-	return $tag;
1209
+    if ($style === false) {
1210
+        $style = extraire_attribut($tag, 'style');
1211
+    }
1212
+
1213
+    // enlever le width et height du style
1214
+    if ($style) {
1215
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1216
+    }
1217
+    if ($style and $style[0] === ';') {
1218
+        $style = substr($style, 1);
1219
+    }
1220
+
1221
+    // mettre des attributs de width et height sur les images,
1222
+    // ca accelere le rendu du navigateur
1223
+    // ca permet aux navigateurs de reserver la bonne taille
1224
+    // quand on a desactive l'affichage des images.
1225
+    $tag = inserer_attribut($tag, 'width', round($width));
1226
+    $tag = inserer_attribut($tag, 'height', round($height));
1227
+
1228
+    // attributs deprecies. Transformer en CSS
1229
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1230
+        $style = "margin:{$espace}px;" . $style;
1231
+        $tag = inserer_attribut($tag, 'hspace', '');
1232
+    }
1233
+
1234
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1235
+
1236
+    return $tag;
1237 1237
 }
1238 1238
 
1239 1239
 
@@ -1259,72 +1259,72 @@  discard block
 block discarded – undo
1259 1259
  *     Retourne le code HTML de l'image
1260 1260
  **/
1261 1261
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1262
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1263
-
1264
-	// fermer les tags img pas bien fermes;
1265
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1266
-
1267
-	// le style
1268
-	$style = $valeurs['style'];
1269
-	if (isset($surcharge['style'])) {
1270
-		$style = $surcharge['style'];
1271
-		unset($surcharge['style']);
1272
-	}
1273
-
1274
-	// traiter specifiquement la largeur et la hauteur
1275
-	$width = $valeurs['largeur'];
1276
-	if (isset($surcharge['width'])) {
1277
-		$width = $surcharge['width'];
1278
-		unset($surcharge['width']);
1279
-	}
1280
-	$height = $valeurs['hauteur'];
1281
-	if (isset($surcharge['height'])) {
1282
-		$height = $surcharge['height'];
1283
-		unset($surcharge['height']);
1284
-	}
1285
-
1286
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1287
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1288
-	// on remplace toute les ref a src dans le tag
1289
-	$src = extraire_attribut($tag, 'src');
1290
-	if (isset($surcharge['src'])) {
1291
-		$tag = str_replace($src, $surcharge['src'], $tag);
1292
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1293
-		// pas garanti comme methode, mais mieux que rien
1294
-		if (strpos($src, '&') !== false) {
1295
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1296
-		}
1297
-		$src = $surcharge['src'];
1298
-		unset($surcharge['src']);
1299
-	}
1300
-
1301
-	$class = $valeurs['class'];
1302
-	if (isset($surcharge['class'])) {
1303
-		$class = $surcharge['class'];
1304
-		unset($surcharge['class']);
1305
-	}
1306
-	if (is_scalar($class) && strlen($class)) {
1307
-		$tag = inserer_attribut($tag, 'class', $class);
1308
-	}
1309
-
1310
-	if (count($surcharge)) {
1311
-		foreach ($surcharge as $attribut => $valeur) {
1312
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1313
-		}
1314
-	}
1315
-
1316
-	$tag = pipeline(
1317
-		'image_ecrire_tag_finir',
1318
-		[
1319
-			'args' => [
1320
-				'valeurs' => $valeurs,
1321
-				'surcharge' => $surcharge,
1322
-			],
1323
-			'data' => $tag
1324
-		]
1325
-	);
1326
-
1327
-	return $tag;
1262
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1263
+
1264
+    // fermer les tags img pas bien fermes;
1265
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1266
+
1267
+    // le style
1268
+    $style = $valeurs['style'];
1269
+    if (isset($surcharge['style'])) {
1270
+        $style = $surcharge['style'];
1271
+        unset($surcharge['style']);
1272
+    }
1273
+
1274
+    // traiter specifiquement la largeur et la hauteur
1275
+    $width = $valeurs['largeur'];
1276
+    if (isset($surcharge['width'])) {
1277
+        $width = $surcharge['width'];
1278
+        unset($surcharge['width']);
1279
+    }
1280
+    $height = $valeurs['hauteur'];
1281
+    if (isset($surcharge['height'])) {
1282
+        $height = $surcharge['height'];
1283
+        unset($surcharge['height']);
1284
+    }
1285
+
1286
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1287
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1288
+    // on remplace toute les ref a src dans le tag
1289
+    $src = extraire_attribut($tag, 'src');
1290
+    if (isset($surcharge['src'])) {
1291
+        $tag = str_replace($src, $surcharge['src'], $tag);
1292
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1293
+        // pas garanti comme methode, mais mieux que rien
1294
+        if (strpos($src, '&') !== false) {
1295
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1296
+        }
1297
+        $src = $surcharge['src'];
1298
+        unset($surcharge['src']);
1299
+    }
1300
+
1301
+    $class = $valeurs['class'];
1302
+    if (isset($surcharge['class'])) {
1303
+        $class = $surcharge['class'];
1304
+        unset($surcharge['class']);
1305
+    }
1306
+    if (is_scalar($class) && strlen($class)) {
1307
+        $tag = inserer_attribut($tag, 'class', $class);
1308
+    }
1309
+
1310
+    if (count($surcharge)) {
1311
+        foreach ($surcharge as $attribut => $valeur) {
1312
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1313
+        }
1314
+    }
1315
+
1316
+    $tag = pipeline(
1317
+        'image_ecrire_tag_finir',
1318
+        [
1319
+            'args' => [
1320
+                'valeurs' => $valeurs,
1321
+                'surcharge' => $surcharge,
1322
+            ],
1323
+            'data' => $tag
1324
+        ]
1325
+    );
1326
+
1327
+    return $tag;
1328 1328
 }
1329 1329
 
1330 1330
 /**
@@ -1347,267 +1347,267 @@  discard block
 block discarded – undo
1347 1347
  *     Description de l'image, sinon null.
1348 1348
  **/
1349 1349
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1350
-	$srcHeight = null;
1351
-	$retour = [];
1352
-	// ordre de preference des formats graphiques pour creer les vignettes
1353
-	// le premier format disponible, selon la methode demandee, est utilise
1354
-	$image = $valeurs['fichier'];
1355
-	$format = $valeurs['format_source'];
1356
-	$destdir = dirname($valeurs['fichier_dest']);
1357
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1358
-
1359
-	$format_sortie = $valeurs['format_dest'];
1360
-
1361
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1362
-		$process = $GLOBALS['meta']['image_process'];
1363
-	}
1364
-
1365
-	// si le doc n'est pas une image dans un format accetpable, refuser
1366
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1367
-		return;
1368
-	}
1369
-	$destination = "$destdir/$destfile";
1370
-
1371
-	// calculer la taille
1372
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1373
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1374
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1375
-		}
1376
-	} elseif ($process == 'convert' or $process == 'imagick') {
1377
-		$destWidth = $maxWidth;
1378
-		$destHeight = $maxHeight;
1379
-	} else {
1380
-		spip_log("echec $process sur $image");
1381
-
1382
-		return;
1383
-	}
1384
-
1385
-	$vignette = '';
1386
-
1387
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1388
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1389
-		$vignette = $destination . '.' . $format;
1390
-		@copy($image, $vignette);
1391
-	}
1392
-
1393
-	elseif ($valeurs['format_source'] === 'svg') {
1394
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1395
-			$format_sortie = 'svg';
1396
-			$vignette = $destination . '.' . $format_sortie;
1397
-			$valeurs['fichier_dest'] = $vignette;
1398
-			_image_gd_output($svg, $valeurs);
1399
-		}
1400
-	}
1401
-
1402
-	// imagemagick en ligne de commande
1403
-	elseif ($process == 'convert') {
1404
-		if (!defined('_CONVERT_COMMAND')) {
1405
-			define('_CONVERT_COMMAND', 'convert');
1406
-		} // Securite : mes_options.php peut preciser le chemin absolu
1407
-		if (!defined('_RESIZE_COMMAND')) {
1408
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1409
-		}
1410
-		$vignette = $destination . '.' . $format_sortie;
1411
-		$commande = str_replace(
1412
-			['%x', '%y', '%src', '%dest'],
1413
-			[
1414
-				$destWidth,
1415
-				$destHeight,
1416
-				escapeshellcmd($image),
1417
-				escapeshellcmd($vignette)
1418
-			],
1419
-			_RESIZE_COMMAND
1420
-		);
1421
-		spip_log($commande);
1422
-		exec($commande);
1423
-		if (!@file_exists($vignette)) {
1424
-			spip_log("echec convert sur $vignette");
1425
-
1426
-			return;  // echec commande
1427
-		}
1428
-	}
1429
-
1430
-	// php5 imagemagick
1431
-	elseif ($process == 'imagick') {
1432
-		if (!class_exists(\Imagick::class)) {
1433
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1434
-
1435
-			return;
1436
-		}
1437
-
1438
-		// chemin compatible Windows
1439
-		$output = realpath(dirname($destination));
1440
-		if (!$output) {
1441
-			return;
1442
-		}
1443
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1444
-
1445
-		$imagick = new Imagick();
1446
-		$imagick->readImage(realpath($image));
1447
-		$imagick->resizeImage(
1448
-			$destWidth,
1449
-			$destHeight,
1450
-			Imagick::FILTER_LANCZOS,
1451
-			1
1452
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1453
-		$imagick->writeImage($vignette);
1454
-
1455
-		if (!@file_exists($vignette)) {
1456
-			spip_log("echec imagick sur $vignette");
1457
-
1458
-			return;
1459
-		}
1460
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1461
-		$vignette = $destination . '.' . $format_sortie;
1462
-	}
1463
-
1464
-	// netpbm
1465
-	elseif ($process == 'netpbm') {
1466
-		if (!defined('_PNMSCALE_COMMAND')) {
1467
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1468
-		} // Securite : mes_options.php peut preciser le chemin absolu
1469
-		if (_PNMSCALE_COMMAND == '') {
1470
-			return;
1471
-		}
1472
-		$vignette = $destination . '.' . $format_sortie;
1473
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1474
-		if ($format == 'jpg') {
1475
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1476
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1477
-			if (!($s = @filesize($vignette))) {
1478
-				spip_unlink($vignette);
1479
-			}
1480
-			if (!@file_exists($vignette)) {
1481
-				spip_log("echec netpbm-jpg sur $vignette");
1482
-
1483
-				return;
1484
-			}
1485
-		} else {
1486
-			if ($format == 'gif') {
1487
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1488
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1489
-				if (!($s = @filesize($vignette))) {
1490
-					spip_unlink($vignette);
1491
-				}
1492
-				if (!@file_exists($vignette)) {
1493
-					spip_log("echec netpbm-gif sur $vignette");
1494
-
1495
-					return;
1496
-				}
1497
-			} else {
1498
-				if ($format == 'png') {
1499
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1500
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1501
-					if (!($s = @filesize($vignette))) {
1502
-						spip_unlink($vignette);
1503
-					}
1504
-					if (!@file_exists($vignette)) {
1505
-						spip_log("echec netpbm-png sur $vignette");
1506
-
1507
-						return;
1508
-					}
1509
-				}
1510
-			}
1511
-		}
1512
-	}
1513
-
1514
-	// gd ou gd2
1515
-	elseif ($process == 'gd1' or $process == 'gd2') {
1516
-		if (!function_exists('gd_info')) {
1517
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1518
-
1519
-			return;
1520
-		}
1521
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1522
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1523
-
1524
-			return;
1525
-		}
1526
-		$destFormat = $format_sortie;
1527
-		if (!$destFormat) {
1528
-			spip_log("pas de format pour $image");
1529
-
1530
-			return;
1531
-		}
1532
-
1533
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1534
-		if (!function_exists($fonction_imagecreatefrom)) {
1535
-			return;
1536
-		}
1537
-		$srcImage = @$fonction_imagecreatefrom($image);
1538
-		if (!$srcImage) {
1539
-			spip_log('echec gd1/gd2');
1540
-
1541
-			return;
1542
-		}
1543
-
1544
-		// Initialisation de l'image destination
1545
-		$destImage = null;
1546
-		if ($process == 'gd2' and $destFormat != 'gif') {
1547
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1548
-		}
1549
-		if (!$destImage) {
1550
-			$destImage = ImageCreate($destWidth, $destHeight);
1551
-		}
1552
-
1553
-		// Recopie de l'image d'origine avec adaptation de la taille
1554
-		$ok = false;
1555
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1556
-			if ($format == 'gif') {
1557
-				// Si un GIF est transparent,
1558
-				// fabriquer un PNG transparent
1559
-				$transp = imagecolortransparent($srcImage);
1560
-				if ($transp > 0) {
1561
-					$destFormat = 'png';
1562
-				}
1563
-			}
1564
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1565
-				// Conserver la transparence
1566
-				if (function_exists('imageAntiAlias')) {
1567
-					imageAntiAlias($destImage, true);
1568
-				}
1569
-				@imagealphablending($destImage, false);
1570
-				@imagesavealpha($destImage, true);
1571
-			}
1572
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1573
-		}
1574
-		if (!$ok) {
1575
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1576
-		}
1577
-
1578
-		// Sauvegarde de l'image destination
1579
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1580
-		$valeurs['format_dest'] = $format = $destFormat;
1581
-		_image_gd_output($destImage, $valeurs);
1582
-
1583
-		if ($srcImage) {
1584
-			ImageDestroy($srcImage);
1585
-		}
1586
-		ImageDestroy($destImage);
1587
-	}
1588
-
1589
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1590
-		$size = [$destWidth, $destHeight];
1591
-	}
1592
-
1593
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1594
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1595
-	if ($size[0] < 1) {
1596
-		$size[0] = $destWidth;
1597
-	}
1598
-	if ($size[1] < 1) {
1599
-		$size[1] = $destHeight;
1600
-	}
1601
-
1602
-	$retour['width'] = $largeur = $size[0];
1603
-	$retour['height'] = $hauteur = $size[1];
1604
-
1605
-	$retour['fichier'] = $vignette;
1606
-	$retour['format'] = $format;
1607
-	$retour['date'] = @filemtime($vignette);
1608
-
1609
-	// renvoyer l'image
1610
-	return $retour;
1350
+    $srcHeight = null;
1351
+    $retour = [];
1352
+    // ordre de preference des formats graphiques pour creer les vignettes
1353
+    // le premier format disponible, selon la methode demandee, est utilise
1354
+    $image = $valeurs['fichier'];
1355
+    $format = $valeurs['format_source'];
1356
+    $destdir = dirname($valeurs['fichier_dest']);
1357
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1358
+
1359
+    $format_sortie = $valeurs['format_dest'];
1360
+
1361
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1362
+        $process = $GLOBALS['meta']['image_process'];
1363
+    }
1364
+
1365
+    // si le doc n'est pas une image dans un format accetpable, refuser
1366
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1367
+        return;
1368
+    }
1369
+    $destination = "$destdir/$destfile";
1370
+
1371
+    // calculer la taille
1372
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1373
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1374
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1375
+        }
1376
+    } elseif ($process == 'convert' or $process == 'imagick') {
1377
+        $destWidth = $maxWidth;
1378
+        $destHeight = $maxHeight;
1379
+    } else {
1380
+        spip_log("echec $process sur $image");
1381
+
1382
+        return;
1383
+    }
1384
+
1385
+    $vignette = '';
1386
+
1387
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1388
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1389
+        $vignette = $destination . '.' . $format;
1390
+        @copy($image, $vignette);
1391
+    }
1392
+
1393
+    elseif ($valeurs['format_source'] === 'svg') {
1394
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1395
+            $format_sortie = 'svg';
1396
+            $vignette = $destination . '.' . $format_sortie;
1397
+            $valeurs['fichier_dest'] = $vignette;
1398
+            _image_gd_output($svg, $valeurs);
1399
+        }
1400
+    }
1401
+
1402
+    // imagemagick en ligne de commande
1403
+    elseif ($process == 'convert') {
1404
+        if (!defined('_CONVERT_COMMAND')) {
1405
+            define('_CONVERT_COMMAND', 'convert');
1406
+        } // Securite : mes_options.php peut preciser le chemin absolu
1407
+        if (!defined('_RESIZE_COMMAND')) {
1408
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1409
+        }
1410
+        $vignette = $destination . '.' . $format_sortie;
1411
+        $commande = str_replace(
1412
+            ['%x', '%y', '%src', '%dest'],
1413
+            [
1414
+                $destWidth,
1415
+                $destHeight,
1416
+                escapeshellcmd($image),
1417
+                escapeshellcmd($vignette)
1418
+            ],
1419
+            _RESIZE_COMMAND
1420
+        );
1421
+        spip_log($commande);
1422
+        exec($commande);
1423
+        if (!@file_exists($vignette)) {
1424
+            spip_log("echec convert sur $vignette");
1425
+
1426
+            return;  // echec commande
1427
+        }
1428
+    }
1429
+
1430
+    // php5 imagemagick
1431
+    elseif ($process == 'imagick') {
1432
+        if (!class_exists(\Imagick::class)) {
1433
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1434
+
1435
+            return;
1436
+        }
1437
+
1438
+        // chemin compatible Windows
1439
+        $output = realpath(dirname($destination));
1440
+        if (!$output) {
1441
+            return;
1442
+        }
1443
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1444
+
1445
+        $imagick = new Imagick();
1446
+        $imagick->readImage(realpath($image));
1447
+        $imagick->resizeImage(
1448
+            $destWidth,
1449
+            $destHeight,
1450
+            Imagick::FILTER_LANCZOS,
1451
+            1
1452
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1453
+        $imagick->writeImage($vignette);
1454
+
1455
+        if (!@file_exists($vignette)) {
1456
+            spip_log("echec imagick sur $vignette");
1457
+
1458
+            return;
1459
+        }
1460
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1461
+        $vignette = $destination . '.' . $format_sortie;
1462
+    }
1463
+
1464
+    // netpbm
1465
+    elseif ($process == 'netpbm') {
1466
+        if (!defined('_PNMSCALE_COMMAND')) {
1467
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1468
+        } // Securite : mes_options.php peut preciser le chemin absolu
1469
+        if (_PNMSCALE_COMMAND == '') {
1470
+            return;
1471
+        }
1472
+        $vignette = $destination . '.' . $format_sortie;
1473
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1474
+        if ($format == 'jpg') {
1475
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1476
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1477
+            if (!($s = @filesize($vignette))) {
1478
+                spip_unlink($vignette);
1479
+            }
1480
+            if (!@file_exists($vignette)) {
1481
+                spip_log("echec netpbm-jpg sur $vignette");
1482
+
1483
+                return;
1484
+            }
1485
+        } else {
1486
+            if ($format == 'gif') {
1487
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1488
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1489
+                if (!($s = @filesize($vignette))) {
1490
+                    spip_unlink($vignette);
1491
+                }
1492
+                if (!@file_exists($vignette)) {
1493
+                    spip_log("echec netpbm-gif sur $vignette");
1494
+
1495
+                    return;
1496
+                }
1497
+            } else {
1498
+                if ($format == 'png') {
1499
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1500
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1501
+                    if (!($s = @filesize($vignette))) {
1502
+                        spip_unlink($vignette);
1503
+                    }
1504
+                    if (!@file_exists($vignette)) {
1505
+                        spip_log("echec netpbm-png sur $vignette");
1506
+
1507
+                        return;
1508
+                    }
1509
+                }
1510
+            }
1511
+        }
1512
+    }
1513
+
1514
+    // gd ou gd2
1515
+    elseif ($process == 'gd1' or $process == 'gd2') {
1516
+        if (!function_exists('gd_info')) {
1517
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1518
+
1519
+            return;
1520
+        }
1521
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1522
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1523
+
1524
+            return;
1525
+        }
1526
+        $destFormat = $format_sortie;
1527
+        if (!$destFormat) {
1528
+            spip_log("pas de format pour $image");
1529
+
1530
+            return;
1531
+        }
1532
+
1533
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1534
+        if (!function_exists($fonction_imagecreatefrom)) {
1535
+            return;
1536
+        }
1537
+        $srcImage = @$fonction_imagecreatefrom($image);
1538
+        if (!$srcImage) {
1539
+            spip_log('echec gd1/gd2');
1540
+
1541
+            return;
1542
+        }
1543
+
1544
+        // Initialisation de l'image destination
1545
+        $destImage = null;
1546
+        if ($process == 'gd2' and $destFormat != 'gif') {
1547
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1548
+        }
1549
+        if (!$destImage) {
1550
+            $destImage = ImageCreate($destWidth, $destHeight);
1551
+        }
1552
+
1553
+        // Recopie de l'image d'origine avec adaptation de la taille
1554
+        $ok = false;
1555
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1556
+            if ($format == 'gif') {
1557
+                // Si un GIF est transparent,
1558
+                // fabriquer un PNG transparent
1559
+                $transp = imagecolortransparent($srcImage);
1560
+                if ($transp > 0) {
1561
+                    $destFormat = 'png';
1562
+                }
1563
+            }
1564
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1565
+                // Conserver la transparence
1566
+                if (function_exists('imageAntiAlias')) {
1567
+                    imageAntiAlias($destImage, true);
1568
+                }
1569
+                @imagealphablending($destImage, false);
1570
+                @imagesavealpha($destImage, true);
1571
+            }
1572
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1573
+        }
1574
+        if (!$ok) {
1575
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1576
+        }
1577
+
1578
+        // Sauvegarde de l'image destination
1579
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1580
+        $valeurs['format_dest'] = $format = $destFormat;
1581
+        _image_gd_output($destImage, $valeurs);
1582
+
1583
+        if ($srcImage) {
1584
+            ImageDestroy($srcImage);
1585
+        }
1586
+        ImageDestroy($destImage);
1587
+    }
1588
+
1589
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1590
+        $size = [$destWidth, $destHeight];
1591
+    }
1592
+
1593
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1594
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1595
+    if ($size[0] < 1) {
1596
+        $size[0] = $destWidth;
1597
+    }
1598
+    if ($size[1] < 1) {
1599
+        $size[1] = $destHeight;
1600
+    }
1601
+
1602
+    $retour['width'] = $largeur = $size[0];
1603
+    $retour['height'] = $hauteur = $size[1];
1604
+
1605
+    $retour['fichier'] = $vignette;
1606
+    $retour['format'] = $format;
1607
+    $retour['date'] = @filemtime($vignette);
1608
+
1609
+    // renvoyer l'image
1610
+    return $retour;
1611 1611
 }
1612 1612
 
1613 1613
 /**
@@ -1627,25 +1627,25 @@  discard block
 block discarded – undo
1627 1627
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1628 1628
  **/
1629 1629
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1630
-	$ratioWidth = $srcWidth / $maxWidth;
1631
-	$ratioHeight = $srcHeight / $maxHeight;
1632
-
1633
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1634
-		$destWidth = $srcWidth;
1635
-		$destHeight = $srcHeight;
1636
-	} elseif ($ratioWidth < $ratioHeight) {
1637
-		$destWidth = $srcWidth / $ratioHeight;
1638
-		$destHeight = $maxHeight;
1639
-	} else {
1640
-		$destWidth = $maxWidth;
1641
-		$destHeight = $srcHeight / $ratioWidth;
1642
-	}
1643
-
1644
-	return [
1645
-		intval(round($destWidth)),
1646
-		intval(round($destHeight)),
1647
-		max($ratioWidth, $ratioHeight)
1648
-	];
1630
+    $ratioWidth = $srcWidth / $maxWidth;
1631
+    $ratioHeight = $srcHeight / $maxHeight;
1632
+
1633
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1634
+        $destWidth = $srcWidth;
1635
+        $destHeight = $srcHeight;
1636
+    } elseif ($ratioWidth < $ratioHeight) {
1637
+        $destWidth = $srcWidth / $ratioHeight;
1638
+        $destHeight = $maxHeight;
1639
+    } else {
1640
+        $destWidth = $maxWidth;
1641
+        $destHeight = $srcHeight / $ratioWidth;
1642
+    }
1643
+
1644
+    return [
1645
+        intval(round($destWidth)),
1646
+        intval(round($destHeight)),
1647
+        max($ratioWidth, $ratioHeight)
1648
+    ];
1649 1649
 }
1650 1650
 
1651 1651
 /**
@@ -1665,25 +1665,25 @@  discard block
 block discarded – undo
1665 1665
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1666 1666
  **/
1667 1667
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1668
-	$ratioWidth = $srcWidth / $maxWidth;
1669
-	$ratioHeight = $srcHeight / $maxHeight;
1670
-
1671
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1672
-		$destWidth = $srcWidth;
1673
-		$destHeight = $srcHeight;
1674
-	} elseif ($ratioWidth > $ratioHeight) {
1675
-		$destWidth = $srcWidth / $ratioHeight;
1676
-		$destHeight = $maxHeight;
1677
-	} else {
1678
-		$destWidth = $maxWidth;
1679
-		$destHeight = $srcHeight / $ratioWidth;
1680
-	}
1681
-
1682
-	return [
1683
-		intval(round($destWidth)),
1684
-		intval(round($destHeight)),
1685
-		min($ratioWidth, $ratioHeight)
1686
-	];
1668
+    $ratioWidth = $srcWidth / $maxWidth;
1669
+    $ratioHeight = $srcHeight / $maxHeight;
1670
+
1671
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1672
+        $destWidth = $srcWidth;
1673
+        $destHeight = $srcHeight;
1674
+    } elseif ($ratioWidth > $ratioHeight) {
1675
+        $destWidth = $srcWidth / $ratioHeight;
1676
+        $destHeight = $maxHeight;
1677
+    } else {
1678
+        $destWidth = $maxWidth;
1679
+        $destHeight = $srcHeight / $ratioWidth;
1680
+    }
1681
+
1682
+    return [
1683
+        intval(round($destWidth)),
1684
+        intval(round($destHeight)),
1685
+        min($ratioWidth, $ratioHeight)
1686
+    ];
1687 1687
 }
1688 1688
 
1689 1689
 
@@ -1696,12 +1696,12 @@  discard block
 block discarded – undo
1696 1696
  * @return string
1697 1697
  */
1698 1698
 function process_image_svg_identite($image) {
1699
-	if ($image['creer']) {
1700
-		$source = $image['fichier'];
1701
-		_image_gd_output($source, $image);
1702
-	}
1699
+    if ($image['creer']) {
1700
+        $source = $image['fichier'];
1701
+        _image_gd_output($source, $image);
1702
+    }
1703 1703
 
1704
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1704
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1705 1705
 }
1706 1706
 
1707 1707
 
@@ -1734,109 +1734,109 @@  discard block
 block discarded – undo
1734 1734
  *     Code HTML de la balise img produite
1735 1735
  **/
1736 1736
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1737
-	$image = false;
1738
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1739
-		$process = $GLOBALS['meta']['image_process'];
1740
-	}
1741
-	# determiner le format de sortie
1742
-	$format_sortie = false; // le choix par defaut sera bon
1743
-	if ($process == 'netpbm') {
1744
-		$format_sortie = 'jpg';
1745
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1746
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1747
-		// on verifie que l'extension choisie est bonne (en principe oui)
1748
-		$gd_formats = formats_image_acceptables(true);
1749
-		if (
1750
-			is_array($image)
1751
-			and (!in_array($image['format_dest'], $gd_formats)
1752
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1753
-			)
1754
-		) {
1755
-			if ($image['format_source'] == 'jpg') {
1756
-				$formats_sortie = ['jpg', 'png', 'gif'];
1757
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1758
-			{
1759
-				$formats_sortie = ['png', 'jpg', 'gif'];
1760
-			}
1761
-			// Choisir le format destination
1762
-			// - on sauve de preference en JPEG (meilleure compression)
1763
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1764
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1765
-			# pas *ecrire*
1766
-			$format_sortie = '';
1767
-			foreach ($formats_sortie as $fmt) {
1768
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1769
-					$format_sortie = $fmt;
1770
-					break;
1771
-				}
1772
-			}
1773
-			$image = false;
1774
-		}
1775
-	}
1776
-
1777
-	if (!is_array($image)) {
1778
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1779
-	}
1780
-
1781
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1782
-		spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1783
-		// on peut resizer en mode html si on dispose des elements
1784
-		[$srcw, $srch] = taille_image($img);
1785
-		if ($srcw and $srch) {
1786
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1787
-
1788
-			return _image_tag_changer_taille($img, $w, $h);
1789
-		}
1790
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1791
-		// sous la forme style='max-width: NNpx;'
1792
-		return inserer_attribut(
1793
-			$img,
1794
-			'style',
1795
-			"max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1796
-		);
1797
-	}
1798
-
1799
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1800
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1801
-		if ($image['creer']) {
1802
-			@copy($image['fichier'], $image['fichier_dest']);
1803
-		}
1804
-
1805
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1806
-	}
1807
-
1808
-	if ($image['creer'] == false && !$force) {
1809
-		return _image_ecrire_tag(
1810
-			$image,
1811
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1812
-		);
1813
-	}
1814
-
1815
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1816
-		$destWidth = $image['largeur_dest'];
1817
-		$destHeight = $image['hauteur_dest'];
1818
-		$logo = $image['fichier'];
1819
-		$date = $image['date_src'];
1820
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1821
-
1822
-		if ($preview && $preview['fichier']) {
1823
-			$logo = $preview['fichier'];
1824
-			$destWidth = $preview['width'];
1825
-			$destHeight = $preview['height'];
1826
-			$date = $preview['date'];
1827
-		}
1828
-		// dans l'espace prive mettre un timestamp sur l'adresse
1829
-		// de l'image, de facon a tromper le cache du navigateur
1830
-		// quand on fait supprimer/reuploader un logo
1831
-		// (pas de filemtime si SAFE MODE)
1832
-		$date = test_espace_prive() ? ('?' . $date) : '';
1833
-
1834
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1835
-	}
1836
-	else {
1837
-		# BMP, tiff ... les redacteurs osent tout!
1838
-		return $img;
1839
-	}
1737
+    $image = false;
1738
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1739
+        $process = $GLOBALS['meta']['image_process'];
1740
+    }
1741
+    # determiner le format de sortie
1742
+    $format_sortie = false; // le choix par defaut sera bon
1743
+    if ($process == 'netpbm') {
1744
+        $format_sortie = 'jpg';
1745
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1746
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1747
+        // on verifie que l'extension choisie est bonne (en principe oui)
1748
+        $gd_formats = formats_image_acceptables(true);
1749
+        if (
1750
+            is_array($image)
1751
+            and (!in_array($image['format_dest'], $gd_formats)
1752
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1753
+            )
1754
+        ) {
1755
+            if ($image['format_source'] == 'jpg') {
1756
+                $formats_sortie = ['jpg', 'png', 'gif'];
1757
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1758
+            {
1759
+                $formats_sortie = ['png', 'jpg', 'gif'];
1760
+            }
1761
+            // Choisir le format destination
1762
+            // - on sauve de preference en JPEG (meilleure compression)
1763
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1764
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1765
+            # pas *ecrire*
1766
+            $format_sortie = '';
1767
+            foreach ($formats_sortie as $fmt) {
1768
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1769
+                    $format_sortie = $fmt;
1770
+                    break;
1771
+                }
1772
+            }
1773
+            $image = false;
1774
+        }
1775
+    }
1776
+
1777
+    if (!is_array($image)) {
1778
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1779
+    }
1780
+
1781
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1782
+        spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1783
+        // on peut resizer en mode html si on dispose des elements
1784
+        [$srcw, $srch] = taille_image($img);
1785
+        if ($srcw and $srch) {
1786
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1787
+
1788
+            return _image_tag_changer_taille($img, $w, $h);
1789
+        }
1790
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1791
+        // sous la forme style='max-width: NNpx;'
1792
+        return inserer_attribut(
1793
+            $img,
1794
+            'style',
1795
+            "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1796
+        );
1797
+    }
1798
+
1799
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1800
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1801
+        if ($image['creer']) {
1802
+            @copy($image['fichier'], $image['fichier_dest']);
1803
+        }
1804
+
1805
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1806
+    }
1807
+
1808
+    if ($image['creer'] == false && !$force) {
1809
+        return _image_ecrire_tag(
1810
+            $image,
1811
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1812
+        );
1813
+    }
1814
+
1815
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1816
+        $destWidth = $image['largeur_dest'];
1817
+        $destHeight = $image['hauteur_dest'];
1818
+        $logo = $image['fichier'];
1819
+        $date = $image['date_src'];
1820
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1821
+
1822
+        if ($preview && $preview['fichier']) {
1823
+            $logo = $preview['fichier'];
1824
+            $destWidth = $preview['width'];
1825
+            $destHeight = $preview['height'];
1826
+            $date = $preview['date'];
1827
+        }
1828
+        // dans l'espace prive mettre un timestamp sur l'adresse
1829
+        // de l'image, de facon a tromper le cache du navigateur
1830
+        // quand on fait supprimer/reuploader un logo
1831
+        // (pas de filemtime si SAFE MODE)
1832
+        $date = test_espace_prive() ? ('?' . $date) : '';
1833
+
1834
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1835
+    }
1836
+    else {
1837
+        # BMP, tiff ... les redacteurs osent tout!
1838
+        return $img;
1839
+    }
1840 1840
 }
1841 1841
 
1842 1842
 /**
@@ -1850,145 +1850,145 @@  discard block
 block discarded – undo
1850 1850
  * Class phpthumb_functions
1851 1851
  */
1852 1852
 class phpthumb_functions {
1853
-	/**
1854
-	 * Retourne la couleur d'un pixel dans une image
1855
-	 *
1856
-	 * @param resource|GdImage $img
1857
-	 * @param int $x
1858
-	 * @param int $y
1859
-	 * @return array|bool
1860
-	 */
1861
-	public static function GetPixelColor(&$img, $x, $y) {
1862
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1863
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1864
-		}
1865
-		return false;
1866
-	}
1867
-
1868
-	/**
1869
-	 * Retourne un nombre dans une représentation en Little Endian
1870
-	 *
1871
-	 * @param int $number
1872
-	 * @param int $minbytes
1873
-	 * @return string
1874
-	 */
1875
-	public static function LittleEndian2String($number, $minbytes = 1) {
1876
-		$intstring = '';
1877
-		while ($number > 0) {
1878
-			$intstring = $intstring . chr($number & 255);
1879
-			$number >>= 8;
1880
-		}
1881
-
1882
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1883
-	}
1884
-
1885
-	/**
1886
-	 * Transforme une ressource GD en image au format ICO
1887
-	 *
1888
-	 * @param array $gd_image_array
1889
-	 *     Tableau de ressources d'images GD
1890
-	 * @return string
1891
-	 *     Image au format ICO
1892
-	 */
1893
-	public static function GD2ICOstring(&$gd_image_array) {
1894
-		foreach ($gd_image_array as $key => $gd_image) {
1895
-			$ImageWidths[$key] = ImageSX($gd_image);
1896
-			$ImageHeights[$key] = ImageSY($gd_image);
1897
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1898
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1899
-
1900
-			$icXOR[$key] = '';
1901
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1902
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1903
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1904
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1905
-					$r = $argb['red'];
1906
-					$g = $argb['green'];
1907
-					$b = $argb['blue'];
1908
-
1909
-					if ($bpp[$key] == 32) {
1910
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1911
-					} elseif ($bpp[$key] == 24) {
1912
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1913
-					}
1914
-
1915
-					if ($a < 128) {
1916
-						@$icANDmask[$key][$y] .= '1';
1917
-					} else {
1918
-						@$icANDmask[$key][$y] .= '0';
1919
-					}
1920
-				}
1921
-				// mask bits are 32-bit aligned per scanline
1922
-				while (strlen($icANDmask[$key][$y]) % 32) {
1923
-					$icANDmask[$key][$y] .= '0';
1924
-				}
1925
-			}
1926
-			$icAND[$key] = '';
1927
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1928
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1929
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1930
-				}
1931
-			}
1932
-		}
1933
-
1934
-		foreach ($gd_image_array as $key => $gd_image) {
1935
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1936
-
1937
-			// BITMAPINFOHEADER - 40 bytes
1938
-			$BitmapInfoHeader[$key] = '';
1939
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1940
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1941
-			// The biHeight member specifies the combined
1942
-			// height of the XOR and AND masks.
1943
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1944
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1945
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1946
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1947
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1948
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1949
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1950
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1951
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1952
-		}
1953
-
1954
-
1955
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1956
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1957
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1958
-
1959
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1960
-		foreach ($gd_image_array as $key => $gd_image) {
1961
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1962
-
1963
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1964
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1965
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1966
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1967
-
1968
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1969
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1970
-
1971
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1972
-			$icondata .= phpthumb_functions::LittleEndian2String(
1973
-				$dwBytesInRes,
1974
-				4
1975
-			);     // dwBytesInRes;	// How many bytes in this resource?
1976
-
1977
-			$icondata .= phpthumb_functions::LittleEndian2String(
1978
-				$dwImageOffset,
1979
-				4
1980
-			);    // dwImageOffset;   // Where in the file is this image?
1981
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1982
-			$dwImageOffset += strlen($icXOR[$key]);
1983
-			$dwImageOffset += strlen($icAND[$key]);
1984
-		}
1985
-
1986
-		foreach ($gd_image_array as $key => $gd_image) {
1987
-			$icondata .= $BitmapInfoHeader[$key];
1988
-			$icondata .= $icXOR[$key];
1989
-			$icondata .= $icAND[$key];
1990
-		}
1991
-
1992
-		return $icondata;
1993
-	}
1853
+    /**
1854
+     * Retourne la couleur d'un pixel dans une image
1855
+     *
1856
+     * @param resource|GdImage $img
1857
+     * @param int $x
1858
+     * @param int $y
1859
+     * @return array|bool
1860
+     */
1861
+    public static function GetPixelColor(&$img, $x, $y) {
1862
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1863
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1864
+        }
1865
+        return false;
1866
+    }
1867
+
1868
+    /**
1869
+     * Retourne un nombre dans une représentation en Little Endian
1870
+     *
1871
+     * @param int $number
1872
+     * @param int $minbytes
1873
+     * @return string
1874
+     */
1875
+    public static function LittleEndian2String($number, $minbytes = 1) {
1876
+        $intstring = '';
1877
+        while ($number > 0) {
1878
+            $intstring = $intstring . chr($number & 255);
1879
+            $number >>= 8;
1880
+        }
1881
+
1882
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1883
+    }
1884
+
1885
+    /**
1886
+     * Transforme une ressource GD en image au format ICO
1887
+     *
1888
+     * @param array $gd_image_array
1889
+     *     Tableau de ressources d'images GD
1890
+     * @return string
1891
+     *     Image au format ICO
1892
+     */
1893
+    public static function GD2ICOstring(&$gd_image_array) {
1894
+        foreach ($gd_image_array as $key => $gd_image) {
1895
+            $ImageWidths[$key] = ImageSX($gd_image);
1896
+            $ImageHeights[$key] = ImageSY($gd_image);
1897
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1898
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1899
+
1900
+            $icXOR[$key] = '';
1901
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1902
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1903
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1904
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1905
+                    $r = $argb['red'];
1906
+                    $g = $argb['green'];
1907
+                    $b = $argb['blue'];
1908
+
1909
+                    if ($bpp[$key] == 32) {
1910
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1911
+                    } elseif ($bpp[$key] == 24) {
1912
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1913
+                    }
1914
+
1915
+                    if ($a < 128) {
1916
+                        @$icANDmask[$key][$y] .= '1';
1917
+                    } else {
1918
+                        @$icANDmask[$key][$y] .= '0';
1919
+                    }
1920
+                }
1921
+                // mask bits are 32-bit aligned per scanline
1922
+                while (strlen($icANDmask[$key][$y]) % 32) {
1923
+                    $icANDmask[$key][$y] .= '0';
1924
+                }
1925
+            }
1926
+            $icAND[$key] = '';
1927
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1928
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1929
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1930
+                }
1931
+            }
1932
+        }
1933
+
1934
+        foreach ($gd_image_array as $key => $gd_image) {
1935
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1936
+
1937
+            // BITMAPINFOHEADER - 40 bytes
1938
+            $BitmapInfoHeader[$key] = '';
1939
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1940
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1941
+            // The biHeight member specifies the combined
1942
+            // height of the XOR and AND masks.
1943
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1944
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1945
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1946
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1947
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1948
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1949
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1950
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1951
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1952
+        }
1953
+
1954
+
1955
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1956
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1957
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1958
+
1959
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1960
+        foreach ($gd_image_array as $key => $gd_image) {
1961
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1962
+
1963
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1964
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1965
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1966
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1967
+
1968
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1969
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1970
+
1971
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1972
+            $icondata .= phpthumb_functions::LittleEndian2String(
1973
+                $dwBytesInRes,
1974
+                4
1975
+            );     // dwBytesInRes;	// How many bytes in this resource?
1976
+
1977
+            $icondata .= phpthumb_functions::LittleEndian2String(
1978
+                $dwImageOffset,
1979
+                4
1980
+            );    // dwImageOffset;   // Where in the file is this image?
1981
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1982
+            $dwImageOffset += strlen($icXOR[$key]);
1983
+            $dwImageOffset += strlen($icAND[$key]);
1984
+        }
1985
+
1986
+        foreach ($gd_image_array as $key => $gd_image) {
1987
+            $icondata .= $BitmapInfoHeader[$key];
1988
+            $icondata .= $icXOR[$key];
1989
+            $icondata .= $icAND[$key];
1990
+        }
1991
+
1992
+        return $icondata;
1993
+    }
1994 1994
 }
Please login to merge, or discard this patch.
ecrire/inc/minipres.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -193,11 +193,9 @@
 block discarded – undo
193 193
 
194 194
 		if ($statut and test_espace_prive()) {
195 195
 			$corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil'));
196
-		}
197
-		elseif (!empty($_COOKIE['spip_admin'])) {
196
+		} elseif (!empty($_COOKIE['spip_admin'])) {
198 197
 			$corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login'));
199
-		}
200
-		else {
198
+		} else {
201 199
 			$corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202 200
 		}
203 201
 		$corps = "<div class='boutons'>$corps</div>";
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			lire_fichier($file, $c);
75 75
 			$css .= $c;
76 76
 		}
77
-		$css = "<style type='text/css'>" . $css . '</style>';
77
+		$css = "<style type='text/css'>".$css.'</style>';
78 78
 	} else {
79 79
 		foreach ($files as $name) {
80 80
 			$file = direction_css(find_in_theme($name));
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
 		define('_DOCTYPE_ECRIRE', '');
88 88
 	}
89 89
 
90
-	return _DOCTYPE_ECRIRE .
91
-	html_lang_attributes() .
92
-	"<head>\n" .
93
-	'<title>' .
94
-	textebrut($titre) .
95
-	"</title>\n" .
96
-	"<meta name='viewport' content='width=device-width' />\n" .
97
-	$css .
90
+	return _DOCTYPE_ECRIRE.
91
+	html_lang_attributes().
92
+	"<head>\n".
93
+	'<title>'.
94
+	textebrut($titre).
95
+	"</title>\n".
96
+	"<meta name='viewport' content='width=device-width' />\n".
97
+	$css.
98 98
 	'</head>
99
-<body' . $onLoad . " class='minipres'>
99
+<body' . $onLoad." class='minipres'>
100 100
 	<div id='minipres'>
101 101
 	<h1>" .
102
-	$titre .
102
+	$titre.
103 103
 	"</h1>
104 104
 	<div>\n";
105 105
 }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
 		$titre = ($titre == 'install')
184 184
 			? _T('avis_espace_interdit')
185
-			: $titre . '&nbsp;: ' . _T('info_acces_interdit');
185
+			: $titre.'&nbsp;: '._T('info_acces_interdit');
186 186
 
187 187
 		$statut = $GLOBALS['visiteur_session']['statut'] ?? '';
188 188
 		$nom = $GLOBALS['visiteur_session']['nom'] ?? '';
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 			$corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202 202
 		}
203 203
 		$corps = "<div class='boutons'>$corps</div>";
204
-		spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']);
204
+		spip_log($nom." $titre ".$_SERVER['REQUEST_URI']);
205 205
 	}
206 206
 
207 207
 	if (!_AJAX) {
@@ -219,6 +219,6 @@  discard block
 block discarded – undo
219 219
 		foreach ($_POST as $v => $c) {
220 220
 			$url = parametre_url($url, $v, $c, '&');
221 221
 		}
222
-		ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
222
+		ajax_retour('<div>'.$titre.redirige_formulaire($url).'</div>', false);
223 223
 	}
224 224
 }
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Minipres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/headers');
@@ -46,61 +46,61 @@  discard block
 block discarded – undo
46 46
  */
47 47
 function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) {
48 48
 
49
-	utiliser_langue_visiteur();
50
-
51
-	http_no_cache();
52
-
53
-	if ($titre == 'AUTO') {
54
-		$titre = _T('info_installation_systeme_publication');
55
-	}
56
-
57
-	# le charset est en utf-8, pour recuperer le nom comme il faut
58
-	# lors de l'installation
59
-	if (!headers_sent()) {
60
-		header('Content-Type: text/html; charset=utf-8');
61
-	}
62
-
63
-	$css = '';
64
-	$files = ['reset.css', 'clear.css', 'minipres.css'];
65
-	if ($all_inline) {
66
-		// inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande)
67
-		foreach ($files as $name) {
68
-			$file = direction_css(find_in_theme($name));
69
-			if (function_exists('minifier')) {
70
-				$file = minifier($file);
71
-			} else {
72
-				$file = url_absolue_css($file); // precaution
73
-			}
74
-			lire_fichier($file, $c);
75
-			$css .= $c;
76
-		}
77
-		$css = "<style type='text/css'>" . $css . '</style>';
78
-	} else {
79
-		foreach ($files as $name) {
80
-			$file = direction_css(find_in_theme($name));
81
-			$css .= "<link rel='stylesheet' href='$file' type='text/css' />\n";
82
-		}
83
-	}
84
-
85
-	// au cas ou minipres() est appele avant spip_initialisation_suite()
86
-	if (!defined('_DOCTYPE_ECRIRE')) {
87
-		define('_DOCTYPE_ECRIRE', '');
88
-	}
89
-
90
-	return _DOCTYPE_ECRIRE .
91
-	html_lang_attributes() .
92
-	"<head>\n" .
93
-	'<title>' .
94
-	textebrut($titre) .
95
-	"</title>\n" .
96
-	"<meta name='viewport' content='width=device-width' />\n" .
97
-	$css .
98
-	'</head>
49
+    utiliser_langue_visiteur();
50
+
51
+    http_no_cache();
52
+
53
+    if ($titre == 'AUTO') {
54
+        $titre = _T('info_installation_systeme_publication');
55
+    }
56
+
57
+    # le charset est en utf-8, pour recuperer le nom comme il faut
58
+    # lors de l'installation
59
+    if (!headers_sent()) {
60
+        header('Content-Type: text/html; charset=utf-8');
61
+    }
62
+
63
+    $css = '';
64
+    $files = ['reset.css', 'clear.css', 'minipres.css'];
65
+    if ($all_inline) {
66
+        // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande)
67
+        foreach ($files as $name) {
68
+            $file = direction_css(find_in_theme($name));
69
+            if (function_exists('minifier')) {
70
+                $file = minifier($file);
71
+            } else {
72
+                $file = url_absolue_css($file); // precaution
73
+            }
74
+            lire_fichier($file, $c);
75
+            $css .= $c;
76
+        }
77
+        $css = "<style type='text/css'>" . $css . '</style>';
78
+    } else {
79
+        foreach ($files as $name) {
80
+            $file = direction_css(find_in_theme($name));
81
+            $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n";
82
+        }
83
+    }
84
+
85
+    // au cas ou minipres() est appele avant spip_initialisation_suite()
86
+    if (!defined('_DOCTYPE_ECRIRE')) {
87
+        define('_DOCTYPE_ECRIRE', '');
88
+    }
89
+
90
+    return _DOCTYPE_ECRIRE .
91
+    html_lang_attributes() .
92
+    "<head>\n" .
93
+    '<title>' .
94
+    textebrut($titre) .
95
+    "</title>\n" .
96
+    "<meta name='viewport' content='width=device-width' />\n" .
97
+    $css .
98
+    '</head>
99 99
 <body' . $onLoad . " class='minipres'>
100 100
 	<div id='minipres'>
101 101
 	<h1>" .
102
-	$titre .
103
-	"</h1>
102
+    $titre .
103
+    "</h1>
104 104
 	<div>\n";
105 105
 }
106 106
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
  * @return string Code HTML
111 111
  */
112 112
 function install_fin_html() {
113
-	return "\n\t</div>\n\t</div>\n</body>\n</html>";
113
+    return "\n\t</div>\n\t</div>\n</body>\n</html>";
114 114
 }
115 115
 
116 116
 
@@ -148,88 +148,88 @@  discard block
 block discarded – undo
148 148
  */
149 149
 function minipres($titre = '', $corps = '', $options = []) {
150 150
 
151
-	// compat signature old
152
-	// minipres($titre='', $corps="", $onload='', $all_inline = false)
153
-	$args = func_get_args();
154
-	if (isset($args[2]) and is_string($args[2])) {
155
-		$options = ['onload' => $args[2]];
156
-	}
157
-	if (isset($args[3])) {
158
-		$options['all_inline'] = $args[3];
159
-	}
160
-
161
-	$options = array_merge([
162
-		'onload' => '',
163
-		'all_inline' => false,
164
-	], $options);
165
-
166
-	if (!defined('_AJAX')) {
167
-		define('_AJAX', false);
168
-	} // par securite
169
-	if (!$titre) {
170
-		if (!isset($options['status'])) {
171
-			$options['status'] = 403;
172
-		}
173
-		if (
174
-			!$titre = _request('action')
175
-			and !$titre = _request('exec')
176
-			and !$titre = _request('page')
177
-		) {
178
-			$titre = '?';
179
-		}
180
-
181
-		$titre = spip_htmlspecialchars($titre);
182
-
183
-		$titre = ($titre == 'install')
184
-			? _T('avis_espace_interdit')
185
-			: $titre . '&nbsp;: ' . _T('info_acces_interdit');
186
-
187
-		$statut = $GLOBALS['visiteur_session']['statut'] ?? '';
188
-		$nom = $GLOBALS['visiteur_session']['nom'] ?? '';
189
-
190
-		if ($statut != '0minirezo') {
191
-			$titre = _T('info_acces_interdit');
192
-		}
193
-
194
-		if ($statut and test_espace_prive()) {
195
-			$corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil'));
196
-		}
197
-		elseif (!empty($_COOKIE['spip_admin'])) {
198
-			$corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login'));
199
-		}
200
-		else {
201
-			$corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202
-		}
203
-		$corps = "<div class='boutons'>$corps</div>";
204
-		spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']);
205
-	}
206
-
207
-	if (!_AJAX) {
208
-		if (isset($options['status'])) {
209
-			http_response_code($options['status']);
210
-		}
211
-
212
-		$html = install_debut_html($titre, $options['onload'], $options['all_inline'])
213
-				. $corps
214
-				. install_fin_html();
215
-
216
-		if (
217
-			$GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2)
218
-			and empty($options['all_inline'])
219
-		) {
220
-			define('_SET_HTML_BASE', true);
221
-			include_spip('public/assembler');
222
-			$GLOBALS['html'] = true;
223
-			page_base_href($html);
224
-		}
225
-		return $html;
226
-	} else {
227
-		include_spip('inc/headers');
228
-		include_spip('inc/actions');
229
-		$url = self('&', true);
230
-		foreach ($_POST as $v => $c) {
231
-			$url = parametre_url($url, $v, $c, '&');
232
-		}
233
-		ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
234
-	}
151
+    // compat signature old
152
+    // minipres($titre='', $corps="", $onload='', $all_inline = false)
153
+    $args = func_get_args();
154
+    if (isset($args[2]) and is_string($args[2])) {
155
+        $options = ['onload' => $args[2]];
156
+    }
157
+    if (isset($args[3])) {
158
+        $options['all_inline'] = $args[3];
159
+    }
160
+
161
+    $options = array_merge([
162
+        'onload' => '',
163
+        'all_inline' => false,
164
+    ], $options);
165
+
166
+    if (!defined('_AJAX')) {
167
+        define('_AJAX', false);
168
+    } // par securite
169
+    if (!$titre) {
170
+        if (!isset($options['status'])) {
171
+            $options['status'] = 403;
172
+        }
173
+        if (
174
+            !$titre = _request('action')
175
+            and !$titre = _request('exec')
176
+            and !$titre = _request('page')
177
+        ) {
178
+            $titre = '?';
179
+        }
180
+
181
+        $titre = spip_htmlspecialchars($titre);
182
+
183
+        $titre = ($titre == 'install')
184
+            ? _T('avis_espace_interdit')
185
+            : $titre . '&nbsp;: ' . _T('info_acces_interdit');
186
+
187
+        $statut = $GLOBALS['visiteur_session']['statut'] ?? '';
188
+        $nom = $GLOBALS['visiteur_session']['nom'] ?? '';
189
+
190
+        if ($statut != '0minirezo') {
191
+            $titre = _T('info_acces_interdit');
192
+        }
193
+
194
+        if ($statut and test_espace_prive()) {
195
+            $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil'));
196
+        }
197
+        elseif (!empty($_COOKIE['spip_admin'])) {
198
+            $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login'));
199
+        }
200
+        else {
201
+            $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202
+        }
203
+        $corps = "<div class='boutons'>$corps</div>";
204
+        spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']);
205
+    }
206
+
207
+    if (!_AJAX) {
208
+        if (isset($options['status'])) {
209
+            http_response_code($options['status']);
210
+        }
211
+
212
+        $html = install_debut_html($titre, $options['onload'], $options['all_inline'])
213
+                . $corps
214
+                . install_fin_html();
215
+
216
+        if (
217
+            $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2)
218
+            and empty($options['all_inline'])
219
+        ) {
220
+            define('_SET_HTML_BASE', true);
221
+            include_spip('public/assembler');
222
+            $GLOBALS['html'] = true;
223
+            page_base_href($html);
224
+        }
225
+        return $html;
226
+    } else {
227
+        include_spip('inc/headers');
228
+        include_spip('inc/actions');
229
+        $url = self('&', true);
230
+        foreach ($_POST as $v => $c) {
231
+            $url = parametre_url($url, $v, $c, '&');
232
+        }
233
+        ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
234
+    }
235 235
 }
Please login to merge, or discard this patch.
ecrire/inc/boutons.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 			&& autoriser('onglet', "_$id")
103 103
 		) {
104 104
 			$onglets[$id] = new Bouton(
105
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
106
-				$infos['titre'],  // titre
105
+				isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone
106
+				$infos['titre'], // titre
107 107
 				(isset($infos['action']) and $infos['action'])
108 108
 					? generer_url_ecrire(
109 109
 						$infos['action'],
@@ -142,5 +142,5 @@  discard block
 block discarded – undo
142 142
 		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
143 143
 	}
144 144
 
145
-	return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
145
+	return !$res ? '' : (debut_onglet($class).$res.fin_onglet());
146 146
 }
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 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
 /**
@@ -35,35 +35,35 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function definir_barre_onglets($script) {
37 37
 
38
-	$onglets = [];
39
-	$liste_onglets = [];
38
+    $onglets = [];
39
+    $liste_onglets = [];
40 40
 
41
-	// ajouter les onglets issus des plugin via paquet.xml
42
-	if (function_exists('onglets_plugins')) {
43
-		$liste_onglets = onglets_plugins();
44
-	}
41
+    // ajouter les onglets issus des plugin via paquet.xml
42
+    if (function_exists('onglets_plugins')) {
43
+        $liste_onglets = onglets_plugins();
44
+    }
45 45
 
46 46
 
47
-	foreach ($liste_onglets as $id => $infos) {
48
-		if (
49
-			($parent = $infos['parent'])
50
-			&& $parent == $script
51
-			&& autoriser('onglet', "_$id")
52
-		) {
53
-			$onglets[$id] = new Bouton(
54
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
55
-				$infos['titre'],  // titre
56
-				(isset($infos['action']) and $infos['action'])
57
-					? generer_url_ecrire(
58
-						$infos['action'],
59
-						(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
60
-					)
61
-					: null
62
-			);
63
-		}
64
-	}
47
+    foreach ($liste_onglets as $id => $infos) {
48
+        if (
49
+            ($parent = $infos['parent'])
50
+            && $parent == $script
51
+            && autoriser('onglet', "_$id")
52
+        ) {
53
+            $onglets[$id] = new Bouton(
54
+                isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
55
+                $infos['titre'],  // titre
56
+                (isset($infos['action']) and $infos['action'])
57
+                    ? generer_url_ecrire(
58
+                        $infos['action'],
59
+                        (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
60
+                    )
61
+                    : null
62
+            );
63
+        }
64
+    }
65 65
 
66
-	return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
66
+    return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
67 67
 }
68 68
 
69 69
 /**
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
  * @return string
82 82
  */
83 83
 function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') {
84
-	include_spip('inc/presentation');
84
+    include_spip('inc/presentation');
85 85
 
86
-	$res = '';
86
+    $res = '';
87 87
 
88
-	foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
89
-		$url = $onglet->url ?: generer_url_ecrire($exec);
90
-		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
91
-	}
88
+    foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
89
+        $url = $onglet->url ?: generer_url_ecrire($exec);
90
+        $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
91
+    }
92 92
 
93
-	return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
93
+    return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
94 94
 }
Please login to merge, or discard this patch.
ecrire/inc/recherche_to_array.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$_id_table = reset($_id_table);
68 68
 	}
69 69
 
70
-	$requete['SELECT'][] = 't.' . $_id_table;
70
+	$requete['SELECT'][] = 't.'.$_id_table;
71 71
 	$a = [];
72 72
 	// Recherche fulltext
73 73
 	foreach ($champs as $champ => $poids) {
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
 				$champ = "t.$champ";
79 79
 			}
80 80
 			$requete['SELECT'][] = $champ;
81
-			$a[] = $champ . ' ' . $methode . ' ' . $q;
81
+			$a[] = $champ.' '.$methode.' '.$q;
82 82
 		}
83 83
 	}
84 84
 	if ($a) {
85 85
 		$requete['WHERE'][] = join(' OR ', $a);
86 86
 	}
87
-	$requete['FROM'][] = table_objet_sql($table) . ' AS t';
87
+	$requete['FROM'][] = table_objet_sql($table).' AS t';
88 88
 
89 89
 	$results = [];
90 90
 
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 					);
253 253
 				} // cas table de liaison generique spip_xxx_yyy
254 254
 				elseif (
255
-					$t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)
256
-					or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)
255
+					$t = $trouver_table($table_arrivee.'_'.$table_depart, $serveur)
256
+					or $t = $trouver_table($table_depart.'_'.$table_arrivee, $serveur)
257 257
 				) {
258 258
 					$s = sql_select(
259 259
 						"$cle_depart,$cle_arrivee",
@@ -292,12 +292,12 @@  discard block
 block discarded – undo
292 292
 				}
293 293
 				if (isset($joint['champs']) and $joint['champs']) {
294 294
 					foreach ($joint['champs'] as $c => $val) {
295
-						$results[$id]['champs'][$table_liee . '.' . $c] = $val;
295
+						$results[$id]['champs'][$table_liee.'.'.$c] = $val;
296 296
 					}
297 297
 				}
298 298
 				if (isset($joint['matches']) and $joint['matches']) {
299 299
 					foreach ($joint['matches'] as $c => $val) {
300
-						$results[$id]['matches'][$table_liee . '.' . $c] = $val;
300
+						$results[$id]['matches'][$table_liee.'.'.$c] = $val;
301 301
 					}
302 302
 				}
303 303
 			}
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -11,298 +11,298 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 
18 18
 // methodes sql
19 19
 function inc_recherche_to_array_dist($recherche, $options = []) {
20 20
 
21
-	// options par defaut
22
-	$options = array_merge(
23
-		[
24
-			'score' => true,
25
-			'champs' => false,
26
-			'toutvoir' => false,
27
-			'matches' => false,
28
-			'jointures' => false
29
-		],
30
-		$options
31
-	);
21
+    // options par defaut
22
+    $options = array_merge(
23
+        [
24
+            'score' => true,
25
+            'champs' => false,
26
+            'toutvoir' => false,
27
+            'matches' => false,
28
+            'jointures' => false
29
+        ],
30
+        $options
31
+    );
32 32
 
33
-	include_spip('inc/rechercher');
34
-	include_spip('inc/autoriser');
33
+    include_spip('inc/rechercher');
34
+    include_spip('inc/autoriser');
35 35
 
36
-	$requete = [
37
-		'SELECT' => [],
38
-		'FROM' => [],
39
-		'WHERE' => [],
40
-		'GROUPBY' => [],
41
-		'ORDERBY' => [],
42
-		'LIMIT' => '',
43
-		'HAVING' => []
44
-	];
36
+    $requete = [
37
+        'SELECT' => [],
38
+        'FROM' => [],
39
+        'WHERE' => [],
40
+        'GROUPBY' => [],
41
+        'ORDERBY' => [],
42
+        'LIMIT' => '',
43
+        'HAVING' => []
44
+    ];
45 45
 
46
-	$table = sinon($options['table'], 'article');
47
-	if ($options['champs']) {
48
-		$champs = $options['champs'];
49
-	} else {
50
-		$l = liste_des_champs();
51
-		$champs = $l['article'];
52
-	}
53
-	$serveur = $options['serveur'];
46
+    $table = sinon($options['table'], 'article');
47
+    if ($options['champs']) {
48
+        $champs = $options['champs'];
49
+    } else {
50
+        $l = liste_des_champs();
51
+        $champs = $l['article'];
52
+    }
53
+    $serveur = $options['serveur'];
54 54
 
55
-	[$methode, $q, $preg] = expression_recherche($recherche, $options);
55
+    [$methode, $q, $preg] = expression_recherche($recherche, $options);
56 56
 
57
-	$jointures = $options['jointures']
58
-		? liste_des_jointures()
59
-		: [];
57
+    $jointures = $options['jointures']
58
+        ? liste_des_jointures()
59
+        : [];
60 60
 
61
-	$_id_table = id_table_objet($table);
61
+    $_id_table = id_table_objet($table);
62 62
 
63
-	// c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
64
-	// (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
65
-	if (strpos($_id_table, ',') !== false) {
66
-		$_id_table = explode(',', $_id_table);
67
-		$_id_table = reset($_id_table);
68
-	}
63
+    // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
64
+    // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
65
+    if (strpos($_id_table, ',') !== false) {
66
+        $_id_table = explode(',', $_id_table);
67
+        $_id_table = reset($_id_table);
68
+    }
69 69
 
70
-	$requete['SELECT'][] = 't.' . $_id_table;
71
-	$a = [];
72
-	// Recherche fulltext
73
-	foreach ($champs as $champ => $poids) {
74
-		if (is_array($champ)) {
75
-			spip_log('requetes imbriquees interdites');
76
-		} else {
77
-			if (strpos($champ, '.') === false) {
78
-				$champ = "t.$champ";
79
-			}
80
-			$requete['SELECT'][] = $champ;
81
-			$a[] = $champ . ' ' . $methode . ' ' . $q;
82
-		}
83
-	}
84
-	if ($a) {
85
-		$requete['WHERE'][] = join(' OR ', $a);
86
-	}
87
-	$requete['FROM'][] = table_objet_sql($table) . ' AS t';
70
+    $requete['SELECT'][] = 't.' . $_id_table;
71
+    $a = [];
72
+    // Recherche fulltext
73
+    foreach ($champs as $champ => $poids) {
74
+        if (is_array($champ)) {
75
+            spip_log('requetes imbriquees interdites');
76
+        } else {
77
+            if (strpos($champ, '.') === false) {
78
+                $champ = "t.$champ";
79
+            }
80
+            $requete['SELECT'][] = $champ;
81
+            $a[] = $champ . ' ' . $methode . ' ' . $q;
82
+        }
83
+    }
84
+    if ($a) {
85
+        $requete['WHERE'][] = join(' OR ', $a);
86
+    }
87
+    $requete['FROM'][] = table_objet_sql($table) . ' AS t';
88 88
 
89
-	$results = [];
89
+    $results = [];
90 90
 
91
-	$s = sql_select(
92
-		$requete['SELECT'],
93
-		$requete['FROM'],
94
-		$requete['WHERE'],
95
-		implode(' ', $requete['GROUPBY']),
96
-		$requete['ORDERBY'],
97
-		$requete['LIMIT'],
98
-		$requete['HAVING'],
99
-		$serveur
100
-	);
91
+    $s = sql_select(
92
+        $requete['SELECT'],
93
+        $requete['FROM'],
94
+        $requete['WHERE'],
95
+        implode(' ', $requete['GROUPBY']),
96
+        $requete['ORDERBY'],
97
+        $requete['LIMIT'],
98
+        $requete['HAVING'],
99
+        $serveur
100
+    );
101 101
 
102
-	while (
103
-		$t = sql_fetch($s, $serveur)
104
-		and (!isset($t['score']) or $t['score'] > 0)
105
-	) {
106
-		$id = intval($t[$_id_table]);
102
+    while (
103
+        $t = sql_fetch($s, $serveur)
104
+        and (!isset($t['score']) or $t['score'] > 0)
105
+    ) {
106
+        $id = intval($t[$_id_table]);
107 107
 
108
-		if (
109
-			$options['toutvoir']
110
-			or autoriser('voir', $table, $id)
111
-		) {
112
-			// indiquer les champs concernes
113
-			$champs_vus = [];
114
-			$score = 0;
115
-			$matches = [];
108
+        if (
109
+            $options['toutvoir']
110
+            or autoriser('voir', $table, $id)
111
+        ) {
112
+            // indiquer les champs concernes
113
+            $champs_vus = [];
114
+            $score = 0;
115
+            $matches = [];
116 116
 
117
-			$vu = false;
118
-			foreach ($champs as $champ => $poids) {
119
-				$champ = explode('.', $champ);
120
-				$champ = end($champ);
121
-				// translitteration_rapide uniquement si on est deja en utf-8
122
-				$value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
123
-				if (
124
-					$n =
125
-					($options['score'] || $options['matches'])
126
-						? preg_match_all($preg, $value, $regs, PREG_SET_ORDER)
127
-						: preg_match($preg, $value)
128
-				) {
129
-					$vu = true;
117
+            $vu = false;
118
+            foreach ($champs as $champ => $poids) {
119
+                $champ = explode('.', $champ);
120
+                $champ = end($champ);
121
+                // translitteration_rapide uniquement si on est deja en utf-8
122
+                $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
123
+                if (
124
+                    $n =
125
+                    ($options['score'] || $options['matches'])
126
+                        ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER)
127
+                        : preg_match($preg, $value)
128
+                ) {
129
+                    $vu = true;
130 130
 
131
-					if ($options['champs']) {
132
-						$champs_vus[$champ] = $t[$champ];
133
-					}
134
-					if ($options['score']) {
135
-						// compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
136
-						$score += $poids * strlen(implode('', array_column($regs, 0)));
137
-					}
131
+                    if ($options['champs']) {
132
+                        $champs_vus[$champ] = $t[$champ];
133
+                    }
134
+                    if ($options['score']) {
135
+                        // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
136
+                        $score += $poids * strlen(implode('', array_column($regs, 0)));
137
+                    }
138 138
 
139
-					if ($options['matches']) {
140
-						$matches[$champ] = $regs;
141
-					}
139
+                    if ($options['matches']) {
140
+                        $matches[$champ] = $regs;
141
+                    }
142 142
 
143
-					if (
144
-						!$options['champs']
145
-						and !$options['score']
146
-						and !$options['matches']
147
-					) {
148
-						break;
149
-					}
150
-				}
151
-			}
143
+                    if (
144
+                        !$options['champs']
145
+                        and !$options['score']
146
+                        and !$options['matches']
147
+                    ) {
148
+                        break;
149
+                    }
150
+                }
151
+            }
152 152
 
153
-			if ($vu) {
154
-				if (!isset($results)) {
155
-					$results = [];
156
-				}
157
-				$results[$id] = [];
158
-				if ($champs_vus) {
159
-					$results[$id]['champs'] = $champs_vus;
160
-				}
161
-				if ($score) {
162
-					$results[$id]['score'] = $score;
163
-				}
164
-				if ($matches) {
165
-					$results[$id]['matches'] = $matches;
166
-				}
167
-			}
168
-		}
169
-	}
153
+            if ($vu) {
154
+                if (!isset($results)) {
155
+                    $results = [];
156
+                }
157
+                $results[$id] = [];
158
+                if ($champs_vus) {
159
+                    $results[$id]['champs'] = $champs_vus;
160
+                }
161
+                if ($score) {
162
+                    $results[$id]['score'] = $score;
163
+                }
164
+                if ($matches) {
165
+                    $results[$id]['matches'] = $matches;
166
+                }
167
+            }
168
+        }
169
+    }
170 170
 
171 171
 
172
-	// Gerer les donnees associees
173
-	// ici on est un peu naze : pas capables de reconstruire une jointure complexe
174
-	// on ne sait passer que par table de laison en 1 coup
175
-	if (
176
-		isset($jointures[$table])
177
-		and $joints = recherche_en_base(
178
-			$recherche,
179
-			$jointures[$table],
180
-			array_merge($options, ['jointures' => false])
181
-		)
182
-	) {
183
-		include_spip('action/editer_liens');
184
-		$trouver_table = charger_fonction('trouver_table', 'base');
185
-		$cle_depart = id_table_objet($table);
186
-		$table_depart = table_objet($table, $serveur);
187
-		$desc_depart = $trouver_table($table_depart, $serveur);
188
-		$depart_associable = objet_associable($table);
189
-		foreach ($joints as $table_liee => $ids_trouves) {
190
-			// on peut definir une fonction de recherche jointe pour regler les cas particuliers
191
-			if (
192
-				!(
193
-				$rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)
194
-				or $rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)
195
-				or $rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)
196
-				)
197
-			) {
198
-				$cle_arrivee = id_table_objet($table_liee);
199
-				$table_arrivee = table_objet($table_liee, $serveur);
200
-				$desc_arrivee = $trouver_table($table_arrivee, $serveur);
201
-				// cas simple : $cle_depart dans la table_liee
202
-				if (isset($desc_arrivee['field'][$cle_depart])) {
203
-					$s = sql_select(
204
-						"$cle_depart, $cle_arrivee",
205
-						$desc_arrivee['table_sql'],
206
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
207
-						'',
208
-						'',
209
-						'',
210
-						'',
211
-						$serveur
212
-					);
213
-				} // cas simple : $cle_arrivee dans la table
214
-				elseif (isset($desc_depart['field'][$cle_arrivee])) {
215
-					$s = sql_select(
216
-						"$cle_depart, $cle_arrivee",
217
-						$desc_depart['table_sql'],
218
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
219
-						'',
220
-						'',
221
-						'',
222
-						'',
223
-						$serveur
224
-					);
225
-				}
226
-				// sinon cherchons une table de liaison
227
-				// cas recherche principale article, objet lie document : passer par spip_documents_liens
228
-				elseif ($l = objet_associable($table_liee)) {
229
-					[$primary, $table_liens] = $l;
230
-					$s = sql_select(
231
-						"id_objet as $cle_depart, $primary as $cle_arrivee",
232
-						$table_liens,
233
-						["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
234
-						'',
235
-						'',
236
-						'',
237
-						'',
238
-						$serveur
239
-					);
240
-				} // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
241
-				elseif ($l = $depart_associable) {
242
-					[$primary, $table_liens] = $l;
243
-					$s = sql_select(
244
-						"$primary as $cle_depart, id_objet as $cle_arrivee",
245
-						$table_liens,
246
-						["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
247
-						'',
248
-						'',
249
-						'',
250
-						'',
251
-						$serveur
252
-					);
253
-				} // cas table de liaison generique spip_xxx_yyy
254
-				elseif (
255
-					$t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)
256
-					or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)
257
-				) {
258
-					$s = sql_select(
259
-						"$cle_depart,$cle_arrivee",
260
-						$t['table_sql'],
261
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
262
-						'',
263
-						'',
264
-						'',
265
-						'',
266
-						$serveur
267
-					);
268
-				}
269
-			} else {
270
-				[$cle_depart, $cle_arrivee, $s] = $rechercher_joints(
271
-					$table,
272
-					$table_liee,
273
-					array_keys($ids_trouves),
274
-					$serveur
275
-				);
276
-			}
172
+    // Gerer les donnees associees
173
+    // ici on est un peu naze : pas capables de reconstruire une jointure complexe
174
+    // on ne sait passer que par table de laison en 1 coup
175
+    if (
176
+        isset($jointures[$table])
177
+        and $joints = recherche_en_base(
178
+            $recherche,
179
+            $jointures[$table],
180
+            array_merge($options, ['jointures' => false])
181
+        )
182
+    ) {
183
+        include_spip('action/editer_liens');
184
+        $trouver_table = charger_fonction('trouver_table', 'base');
185
+        $cle_depart = id_table_objet($table);
186
+        $table_depart = table_objet($table, $serveur);
187
+        $desc_depart = $trouver_table($table_depart, $serveur);
188
+        $depart_associable = objet_associable($table);
189
+        foreach ($joints as $table_liee => $ids_trouves) {
190
+            // on peut definir une fonction de recherche jointe pour regler les cas particuliers
191
+            if (
192
+                !(
193
+                $rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)
194
+                or $rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)
195
+                or $rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)
196
+                )
197
+            ) {
198
+                $cle_arrivee = id_table_objet($table_liee);
199
+                $table_arrivee = table_objet($table_liee, $serveur);
200
+                $desc_arrivee = $trouver_table($table_arrivee, $serveur);
201
+                // cas simple : $cle_depart dans la table_liee
202
+                if (isset($desc_arrivee['field'][$cle_depart])) {
203
+                    $s = sql_select(
204
+                        "$cle_depart, $cle_arrivee",
205
+                        $desc_arrivee['table_sql'],
206
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
207
+                        '',
208
+                        '',
209
+                        '',
210
+                        '',
211
+                        $serveur
212
+                    );
213
+                } // cas simple : $cle_arrivee dans la table
214
+                elseif (isset($desc_depart['field'][$cle_arrivee])) {
215
+                    $s = sql_select(
216
+                        "$cle_depart, $cle_arrivee",
217
+                        $desc_depart['table_sql'],
218
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
219
+                        '',
220
+                        '',
221
+                        '',
222
+                        '',
223
+                        $serveur
224
+                    );
225
+                }
226
+                // sinon cherchons une table de liaison
227
+                // cas recherche principale article, objet lie document : passer par spip_documents_liens
228
+                elseif ($l = objet_associable($table_liee)) {
229
+                    [$primary, $table_liens] = $l;
230
+                    $s = sql_select(
231
+                        "id_objet as $cle_depart, $primary as $cle_arrivee",
232
+                        $table_liens,
233
+                        ["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
234
+                        '',
235
+                        '',
236
+                        '',
237
+                        '',
238
+                        $serveur
239
+                    );
240
+                } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
241
+                elseif ($l = $depart_associable) {
242
+                    [$primary, $table_liens] = $l;
243
+                    $s = sql_select(
244
+                        "$primary as $cle_depart, id_objet as $cle_arrivee",
245
+                        $table_liens,
246
+                        ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
247
+                        '',
248
+                        '',
249
+                        '',
250
+                        '',
251
+                        $serveur
252
+                    );
253
+                } // cas table de liaison generique spip_xxx_yyy
254
+                elseif (
255
+                    $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)
256
+                    or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)
257
+                ) {
258
+                    $s = sql_select(
259
+                        "$cle_depart,$cle_arrivee",
260
+                        $t['table_sql'],
261
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
262
+                        '',
263
+                        '',
264
+                        '',
265
+                        '',
266
+                        $serveur
267
+                    );
268
+                }
269
+            } else {
270
+                [$cle_depart, $cle_arrivee, $s] = $rechercher_joints(
271
+                    $table,
272
+                    $table_liee,
273
+                    array_keys($ids_trouves),
274
+                    $serveur
275
+                );
276
+            }
277 277
 
278
-			while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
279
-				$id = $t[$cle_depart];
280
-				$joint = $ids_trouves[$t[$cle_arrivee]];
281
-				if (!isset($results)) {
282
-					$results = [];
283
-				}
284
-				if (!isset($results[$id])) {
285
-					$results[$id] = [];
286
-				}
287
-				if (isset($joint['score']) and $joint['score']) {
288
-					if (!isset($results[$id]['score'])) {
289
-						$results[$id]['score'] = 0;
290
-					}
291
-					$results[$id]['score'] += $joint['score'];
292
-				}
293
-				if (isset($joint['champs']) and $joint['champs']) {
294
-					foreach ($joint['champs'] as $c => $val) {
295
-						$results[$id]['champs'][$table_liee . '.' . $c] = $val;
296
-					}
297
-				}
298
-				if (isset($joint['matches']) and $joint['matches']) {
299
-					foreach ($joint['matches'] as $c => $val) {
300
-						$results[$id]['matches'][$table_liee . '.' . $c] = $val;
301
-					}
302
-				}
303
-			}
304
-		}
305
-	}
278
+            while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
279
+                $id = $t[$cle_depart];
280
+                $joint = $ids_trouves[$t[$cle_arrivee]];
281
+                if (!isset($results)) {
282
+                    $results = [];
283
+                }
284
+                if (!isset($results[$id])) {
285
+                    $results[$id] = [];
286
+                }
287
+                if (isset($joint['score']) and $joint['score']) {
288
+                    if (!isset($results[$id]['score'])) {
289
+                        $results[$id]['score'] = 0;
290
+                    }
291
+                    $results[$id]['score'] += $joint['score'];
292
+                }
293
+                if (isset($joint['champs']) and $joint['champs']) {
294
+                    foreach ($joint['champs'] as $c => $val) {
295
+                        $results[$id]['champs'][$table_liee . '.' . $c] = $val;
296
+                    }
297
+                }
298
+                if (isset($joint['matches']) and $joint['matches']) {
299
+                    foreach ($joint['matches'] as $c => $val) {
300
+                        $results[$id]['matches'][$table_liee . '.' . $c] = $val;
301
+                    }
302
+                }
303
+            }
304
+        }
305
+    }
306 306
 
307
-	return $results;
307
+    return $results;
308 308
 }
Please login to merge, or discard this patch.
ecrire/inc/icone_renommer.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -11,71 +11,71 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/boutons');
18 18
 include_spip('base/objets');
19 19
 
20 20
 function inc_icone_renommer_dist($fond, $fonction) {
21
-	$size = 24;
22
-	if (
23
-		preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match)
24
-		and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1]))
25
-	) {
26
-		if (isset($match[1]) and $match[1]) {
27
-			$size = $match[1];
28
-		}
29
-		$type = substr($fond, 0, -strlen($match[0]));
30
-		if (!isset($match[2]) or !$match[2]) {
31
-			$fond .= '.png';
32
-		}
33
-	} else {
34
-		$type = $fond;
35
-		$fond .= '.png';
36
-	}
21
+    $size = 24;
22
+    if (
23
+        preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match)
24
+        and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1]))
25
+    ) {
26
+        if (isset($match[1]) and $match[1]) {
27
+            $size = $match[1];
28
+        }
29
+        $type = substr($fond, 0, -strlen($match[0]));
30
+        if (!isset($match[2]) or !$match[2]) {
31
+            $fond .= '.png';
32
+        }
33
+    } else {
34
+        $type = $fond;
35
+        $fond .= '.png';
36
+    }
37 37
 
38
-	$rtl = false;
39
-	if (preg_match(',[-_]rtl$,i', $type, $match)) {
40
-		$rtl = true;
41
-		$type = substr($type, 0, -strlen($match[0]));
42
-	}
38
+    $rtl = false;
39
+    if (preg_match(',[-_]rtl$,i', $type, $match)) {
40
+        $rtl = true;
41
+        $type = substr($type, 0, -strlen($match[0]));
42
+    }
43 43
 
44
-	// objet_type garde invariant tout ce qui ne commence par par id_, spip_
45
-	// et ne finit pas par un s, sauf si c'est une exception declaree
46
-	$type = objet_type($type, false);
44
+    // objet_type garde invariant tout ce qui ne commence par par id_, spip_
45
+    // et ne finit pas par un s, sauf si c'est une exception declaree
46
+    $type = objet_type($type, false);
47 47
 
48
-	$dir = 'images/';
49
-	$f = "$type-$size.png";
50
-	if ($icone = find_in_theme($dir . $f)) {
51
-		$dir = dirname($icone);
52
-		$fond = $icone;
48
+    $dir = 'images/';
49
+    $f = "$type-$size.png";
50
+    if ($icone = find_in_theme($dir . $f)) {
51
+        $dir = dirname($icone);
52
+        $fond = $icone;
53 53
 
54
-		if (
55
-			$rtl
56
-			and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone))
57
-			and file_exists($fr)
58
-		) {
59
-			$fond = $fr;
60
-		}
54
+        if (
55
+            $rtl
56
+            and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone))
57
+            and file_exists($fr)
58
+        ) {
59
+            $fond = $fr;
60
+        }
61 61
 
62
-		$action = $fonction;
63
-		if ($action == 'supprimer.gif') {
64
-			$action = 'del';
65
-		} elseif ($action == 'creer.gif') {
66
-			$action = 'new';
67
-		} elseif ($action == 'edit.gif') {
68
-			$action = 'edit';
69
-		}
62
+        $action = $fonction;
63
+        if ($action == 'supprimer.gif') {
64
+            $action = 'del';
65
+        } elseif ($action == 'creer.gif') {
66
+            $action = 'new';
67
+        } elseif ($action == 'edit.gif') {
68
+            $action = 'edit';
69
+        }
70 70
 
71
-		$fonction = '';
72
-		if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
73
-			$fonction = $action;
74
-		}
71
+        $fonction = '';
72
+        if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
73
+            $fonction = $action;
74
+        }
75 75
 
76
-		// c'est bon !
77
-		return [$fond, $fonction];
78
-	}
76
+        // c'est bon !
77
+        return [$fond, $fonction];
78
+    }
79 79
 
80
-	return [$fond, $fonction];
80
+    return [$fond, $fonction];
81 81
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
 
48 48
 	$dir = 'images/';
49 49
 	$f = "$type-$size.png";
50
-	if ($icone = find_in_theme($dir . $f)) {
50
+	if ($icone = find_in_theme($dir.$f)) {
51 51
 		$dir = dirname($icone);
52 52
 		$fond = $icone;
53 53
 
54 54
 		if (
55 55
 			$rtl
56
-			and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone))
56
+			and $fr = $dir.'/'.str_replace("$type-", "$type-rtl-", basename($icone))
57 57
 			and file_exists($fr)
58 58
 		) {
59 59
 			$fond = $fr;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		}
70 70
 
71 71
 		$fonction = '';
72
-		if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
72
+		if (in_array($action, ['add', 'del', 'new', 'edit', 'config'])) {
73 73
 			$fonction = $action;
74 74
 		}
75 75
 
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83 83
 	if (!isset($cache[$serveur][$table][$recherche])) {
84 84
 		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
-		$hash = substr(md5($recherche . $table), 0, 16);
86
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
+		$hash = substr(md5($recherche.$table), 0, 16);
86
+		$where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')";
87 87
 		$row = sql_fetsel(
88 88
 			'recherche',
89 89
 			'spip_resultats AS resultats',
90
-			$where . " AND $where_resultat_recent",
90
+			$where." AND $where_resultat_recent",
91 91
 			'',
92 92
 			'',
93 93
 			'0,1'
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		}
197 197
 
198 198
 		foreach ($listes_ids as $p => $ids) {
199
-			$select .= "+$p*(" .
199
+			$select .= "+$p*(".
200 200
 				sql_in("$table.$primary", $ids, '', $serveur)
201 201
 				. ') ';
202 202
 		}
Please login to merge, or discard this patch.
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  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/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,129 +49,129 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = [],
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = [],
57
+    $primary = ''
58 58
 ) {
59
-	$where = null;
60
-	$rows = null;
61
-	static $cache = [];
62
-	$delai_fraicheur = min(
63
-		\_DELAI_CACHE_resultats,
64
-		time() - ($GLOBALS['meta']['derniere_modif'] ?? 0)
65
-	);
66
-
67
-	// si recherche n'est pas dans le contexte, on va prendre en globals
68
-	// ca permet de faire des inclure simple.
69
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
70
-		$recherche = $GLOBALS['recherche'];
71
-	}
72
-
73
-	// traiter le cas {recherche?}
74
-	if ($cond and !strlen($recherche)) {
75
-		return [
76
-			'0 as points' /* as points */, /* where */
77
-			''
78
-		];
79
-	}
80
-
81
-
82
-	$rechercher = false;
83
-
84
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
85
-	if (!isset($cache[$serveur][$table][$recherche])) {
86
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
87
-		$hash = substr(md5($recherche . $table), 0, 16);
88
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
89
-		$row = sql_fetsel(
90
-			'recherche',
91
-			'spip_resultats AS resultats',
92
-			$where . " AND $where_resultat_recent",
93
-			'',
94
-			'',
95
-			'0,1'
96
-		);
97
-		if (
98
-			!$row
99
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
100
-		) {
101
-			$rechercher = true;
102
-		}
103
-	}
104
-
105
-	// si on n'a pas encore traite les donnees dans une boucle precedente
106
-	if ($rechercher) {
107
-		//$tables = liste_des_champs();
108
-		$x = objet_type($table);
109
-		$points = recherche_en_base(
110
-			$recherche,
111
-			$x,
112
-			[
113
-				'score' => true,
114
-				'toutvoir' => true,
115
-				'jointures' => true
116
-			],
117
-			$serveur
118
-		);
119
-		// pas de résultat, pas de point
120
-		$points = $points[$x] ?? [];
121
-
122
-		// permettre aux plugins de modifier le resultat
123
-		$points = pipeline('prepare_recherche', [
124
-			'args' => [
125
-				'type' => $x,
126
-				'recherche' => $recherche,
127
-				'serveur' => $serveur,
128
-				'modificateurs' => $modificateurs
129
-			],
130
-			'data' => $points
131
-		]);
132
-
133
-		// supprimer les anciens resultats de cette recherche
134
-		// et les resultats trop vieux avec une marge
135
-		// pas de AS resultats dans un delete (mysql)
136
-		$whered = str_replace(
137
-			['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
138
-			['recherche', 'table_objet', 'serveur'],
139
-			$where
140
-		);
141
-
142
-		sql_delete(
143
-			'spip_resultats',
144
-			"NOT($where_resultat_recent) OR ($whered)"
145
-		);
146
-
147
-		// inserer les resultats dans la table de cache des resultats
148
-		if (is_countable($points) ? count($points) : 0) {
149
-			$tab_couples = [];
150
-			foreach ($points as $id => $p) {
151
-				$tab_couples[] = [
152
-					'recherche' => $hash,
153
-					'id' => $id,
154
-					'points' => $p['score'],
155
-					'table_objet' => $table,
156
-					'serveur' => $hash_serv,
157
-				];
158
-			}
159
-			sql_insertq_multi('spip_resultats', $tab_couples, []);
160
-		}
161
-	}
162
-
163
-	if (!isset($cache[$serveur][$table][$recherche])) {
164
-		if (!$serveur) {
165
-			$cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
166
-		} else {
167
-			if (sql_countsel('spip_resultats as resultats', $where)) {
168
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
169
-			}
170
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
171
-		}
172
-	}
173
-
174
-	return $cache[$serveur][$table][$recherche];
59
+    $where = null;
60
+    $rows = null;
61
+    static $cache = [];
62
+    $delai_fraicheur = min(
63
+        \_DELAI_CACHE_resultats,
64
+        time() - ($GLOBALS['meta']['derniere_modif'] ?? 0)
65
+    );
66
+
67
+    // si recherche n'est pas dans le contexte, on va prendre en globals
68
+    // ca permet de faire des inclure simple.
69
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
70
+        $recherche = $GLOBALS['recherche'];
71
+    }
72
+
73
+    // traiter le cas {recherche?}
74
+    if ($cond and !strlen($recherche)) {
75
+        return [
76
+            '0 as points' /* as points */, /* where */
77
+            ''
78
+        ];
79
+    }
80
+
81
+
82
+    $rechercher = false;
83
+
84
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
85
+    if (!isset($cache[$serveur][$table][$recherche])) {
86
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
87
+        $hash = substr(md5($recherche . $table), 0, 16);
88
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
89
+        $row = sql_fetsel(
90
+            'recherche',
91
+            'spip_resultats AS resultats',
92
+            $where . " AND $where_resultat_recent",
93
+            '',
94
+            '',
95
+            '0,1'
96
+        );
97
+        if (
98
+            !$row
99
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
100
+        ) {
101
+            $rechercher = true;
102
+        }
103
+    }
104
+
105
+    // si on n'a pas encore traite les donnees dans une boucle precedente
106
+    if ($rechercher) {
107
+        //$tables = liste_des_champs();
108
+        $x = objet_type($table);
109
+        $points = recherche_en_base(
110
+            $recherche,
111
+            $x,
112
+            [
113
+                'score' => true,
114
+                'toutvoir' => true,
115
+                'jointures' => true
116
+            ],
117
+            $serveur
118
+        );
119
+        // pas de résultat, pas de point
120
+        $points = $points[$x] ?? [];
121
+
122
+        // permettre aux plugins de modifier le resultat
123
+        $points = pipeline('prepare_recherche', [
124
+            'args' => [
125
+                'type' => $x,
126
+                'recherche' => $recherche,
127
+                'serveur' => $serveur,
128
+                'modificateurs' => $modificateurs
129
+            ],
130
+            'data' => $points
131
+        ]);
132
+
133
+        // supprimer les anciens resultats de cette recherche
134
+        // et les resultats trop vieux avec une marge
135
+        // pas de AS resultats dans un delete (mysql)
136
+        $whered = str_replace(
137
+            ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
138
+            ['recherche', 'table_objet', 'serveur'],
139
+            $where
140
+        );
141
+
142
+        sql_delete(
143
+            'spip_resultats',
144
+            "NOT($where_resultat_recent) OR ($whered)"
145
+        );
146
+
147
+        // inserer les resultats dans la table de cache des resultats
148
+        if (is_countable($points) ? count($points) : 0) {
149
+            $tab_couples = [];
150
+            foreach ($points as $id => $p) {
151
+                $tab_couples[] = [
152
+                    'recherche' => $hash,
153
+                    'id' => $id,
154
+                    'points' => $p['score'],
155
+                    'table_objet' => $table,
156
+                    'serveur' => $hash_serv,
157
+                ];
158
+            }
159
+            sql_insertq_multi('spip_resultats', $tab_couples, []);
160
+        }
161
+    }
162
+
163
+    if (!isset($cache[$serveur][$table][$recherche])) {
164
+        if (!$serveur) {
165
+            $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
166
+        } else {
167
+            if (sql_countsel('spip_resultats as resultats', $where)) {
168
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
169
+            }
170
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
171
+        }
172
+    }
173
+
174
+    return $cache[$serveur][$table][$recherche];
175 175
 }
176 176
 
177 177
 
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
  * @return array
188 188
  */
189 189
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
190
-	# calculer le {id_article IN()} et le {... as points}
191
-	if (!count($rows)) {
192
-		return ["''", '0=1'];
193
-	} else {
194
-		$listes_ids = [];
195
-		$select = '0';
196
-		foreach ($rows as $r) {
197
-			$listes_ids[$r['points']][] = $r['id'];
198
-		}
199
-
200
-		foreach ($listes_ids as $p => $ids) {
201
-			$select .= "+$p*(" .
202
-				sql_in("$table.$primary", $ids, '', $serveur)
203
-				. ') ';
204
-		}
205
-
206
-		return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
207
-	}
190
+    # calculer le {id_article IN()} et le {... as points}
191
+    if (!count($rows)) {
192
+        return ["''", '0=1'];
193
+    } else {
194
+        $listes_ids = [];
195
+        $select = '0';
196
+        foreach ($rows as $r) {
197
+            $listes_ids[$r['points']][] = $r['id'];
198
+        }
199
+
200
+        foreach ($listes_ids as $p => $ids) {
201
+            $select .= "+$p*(" .
202
+                sql_in("$table.$primary", $ids, '', $serveur)
203
+                . ') ';
204
+        }
205
+
206
+        return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
207
+    }
208 208
 }
Please login to merge, or discard this patch.
ecrire/inc/exporter_csv.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -173,8 +173,7 @@
 block discarded – undo
173 173
 	// sinon on ecrit directement sur stdout
174 174
 	if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175 175
 		$fichier = 'php://output';
176
-	}
177
-	else {
176
+	} else {
178 177
 	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179 178
 	}
180 179
 
Please login to merge, or discard this patch.
Indentation   +114 added lines, -114 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/charsets');
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function exporter_csv_champ($champ) {
35
-	#$champ = str_replace("\r", "\n", $champ);
36
-	#$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
-	#$champ = str_replace("\n", ", ", $champ);
38
-	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
-	$champ = str_replace('"', '""', $champ);
35
+    #$champ = str_replace("\r", "\n", $champ);
36
+    #$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
+    #$champ = str_replace("\n", ", ", $champ);
38
+    $champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
+    $champ = str_replace('"', '""', $champ);
40 40
 
41
-	return '"' . $champ . '"';
41
+    return '"' . $champ . '"';
42 42
 }
43 43
 
44 44
 /**
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
  * @return string
56 56
  */
57 57
 function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, ?callable $callback = null) {
58
-	if ($callback) {
59
-		$ligne = $callback($nb, $ligne, $delim, $importer_charset);
60
-	}
61
-	$output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
-	if ($importer_charset) {
63
-		$output = str_replace('’', '\'', $output);
64
-		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
-	}
66
-	return $output;
58
+    if ($callback) {
59
+        $ligne = $callback($nb, $ligne, $delim, $importer_charset);
60
+    }
61
+    $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
+    if ($importer_charset) {
63
+        $output = str_replace('’', '\'', $output);
64
+        $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
+    }
66
+    return $output;
67 67
 }
68 68
 
69 69
 /**
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
  * @return string
76 76
  */
77 77
 function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) {
78
-	return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
78
+    return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
79 79
 }
80 80
 
81 81
 /**
@@ -101,101 +101,101 @@  discard block
 block discarded – undo
101 101
  */
102 102
 function inc_exporter_csv_dist($titre, $resource, $options = []) {
103 103
 
104
-	// support ancienne syntaxe
105
-	// inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
-	if (is_string($options)) {
107
-		$args = func_get_args();
108
-		$options = [];
109
-		foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
-			if (!empty($args[$k])) {
111
-				$options[$option] = $args[$k];
112
-			}
113
-		}
114
-	}
115
-
116
-	$default_options = [
117
-		'delim' => ', ',
118
-		'entetes' => null,
119
-		'envoyer' => true,
120
-		'charset' => null,
121
-		'callback' => null,
122
-	];
123
-	$options = array_merge($default_options, $options);
124
-
125
-	$filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
-
127
-	if ($options['delim'] == 'TAB') {
128
-		$options['delim'] = "\t";
129
-	}
130
-	if (!in_array($options['delim'], [',', ';', "\t"])) {
131
-		$options['delim'] = ',';
132
-	}
133
-
134
-	$charset = $GLOBALS['meta']['charset'];
135
-	$importer_charset = null;
136
-	if ($options['delim'] == ',') {
137
-		$extension = 'csv';
138
-	} else {
139
-		$extension = 'xls';
140
-		# Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
-		$charset = 'iso-8859-1';
142
-	}
143
-	// mais si une option charset est explicite, elle a la priorite
144
-	if (!empty($options['charset'])) {
145
-		$charset = $options['charset'];
146
-	}
147
-
148
-	$importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
-
150
-	$filename = "$filename.$extension";
151
-
152
-	$output = '';
153
-	$nb = 0;
154
-	if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
-		$output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
-	}
157
-	// les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
-	$nb++;
159
-
160
-	if ($options['envoyer']) {
161
-		$disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
-		header("Content-Type: text/comma-separated-values; charset=$charset");
163
-		header("Content-Disposition: $disposition; filename=$filename");
164
-
165
-		// Vider tous les tampons
166
-		$level = @ob_get_level();
167
-		while ($level--) {
168
-			@ob_end_flush();
169
-		}
170
-	}
171
-
172
-	// si envoyer=='attachment' on passe par un fichier temporaire
173
-	// sinon on ecrit directement sur stdout
174
-	if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
-		$fichier = 'php://output';
176
-	}
177
-	else {
178
-	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
-	}
180
-
181
-	$fp = fopen($fichier, 'w');
182
-	$length = fwrite($fp, $output);
183
-
184
-	while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
-		$output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
-		$length += fwrite($fp, $output);
187
-		$nb++;
188
-	}
189
-	fclose($fp);
190
-
191
-	if ($options['envoyer']) {
192
-		if ($options['envoyer'] === 'attachment') {
193
-			header("Content-Length: $length");
194
-			readfile($fichier);
195
-		}
196
-		// si on a envoye inline, c'est deja tout bon
197
-		exit;
198
-	}
199
-
200
-	return $fichier;
104
+    // support ancienne syntaxe
105
+    // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
+    if (is_string($options)) {
107
+        $args = func_get_args();
108
+        $options = [];
109
+        foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
+            if (!empty($args[$k])) {
111
+                $options[$option] = $args[$k];
112
+            }
113
+        }
114
+    }
115
+
116
+    $default_options = [
117
+        'delim' => ', ',
118
+        'entetes' => null,
119
+        'envoyer' => true,
120
+        'charset' => null,
121
+        'callback' => null,
122
+    ];
123
+    $options = array_merge($default_options, $options);
124
+
125
+    $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
+
127
+    if ($options['delim'] == 'TAB') {
128
+        $options['delim'] = "\t";
129
+    }
130
+    if (!in_array($options['delim'], [',', ';', "\t"])) {
131
+        $options['delim'] = ',';
132
+    }
133
+
134
+    $charset = $GLOBALS['meta']['charset'];
135
+    $importer_charset = null;
136
+    if ($options['delim'] == ',') {
137
+        $extension = 'csv';
138
+    } else {
139
+        $extension = 'xls';
140
+        # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
+        $charset = 'iso-8859-1';
142
+    }
143
+    // mais si une option charset est explicite, elle a la priorite
144
+    if (!empty($options['charset'])) {
145
+        $charset = $options['charset'];
146
+    }
147
+
148
+    $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
+
150
+    $filename = "$filename.$extension";
151
+
152
+    $output = '';
153
+    $nb = 0;
154
+    if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
+        $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
+    }
157
+    // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
+    $nb++;
159
+
160
+    if ($options['envoyer']) {
161
+        $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
+        header("Content-Type: text/comma-separated-values; charset=$charset");
163
+        header("Content-Disposition: $disposition; filename=$filename");
164
+
165
+        // Vider tous les tampons
166
+        $level = @ob_get_level();
167
+        while ($level--) {
168
+            @ob_end_flush();
169
+        }
170
+    }
171
+
172
+    // si envoyer=='attachment' on passe par un fichier temporaire
173
+    // sinon on ecrit directement sur stdout
174
+    if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
+        $fichier = 'php://output';
176
+    }
177
+    else {
178
+    $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
+    }
180
+
181
+    $fp = fopen($fichier, 'w');
182
+    $length = fwrite($fp, $output);
183
+
184
+    while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
+        $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
+        $length += fwrite($fp, $output);
187
+        $nb++;
188
+    }
189
+    fclose($fp);
190
+
191
+    if ($options['envoyer']) {
192
+        if ($options['envoyer'] === 'attachment') {
193
+            header("Content-Length: $length");
194
+            readfile($fichier);
195
+        }
196
+        // si on a envoye inline, c'est deja tout bon
197
+        exit;
198
+    }
199
+
200
+    return $fichier;
201 201
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
39 39
 	$champ = str_replace('"', '""', $champ);
40 40
 
41
-	return '"' . $champ . '"';
41
+	return '"'.$champ.'"';
42 42
 }
43 43
 
44 44
 /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	if ($callback) {
59 59
 		$ligne = $callback($nb, $ligne, $delim, $importer_charset);
60 60
 	}
61
-	$output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
61
+	$output = join($delim, array_map('exporter_csv_champ', $ligne))."\r\n";
62 62
 	if ($importer_charset) {
63 63
 		$output = str_replace('’', '\'', $output);
64 64
 		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 		$fichier = 'php://output';
176 176
 	}
177 177
 	else {
178
-	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
178
+	$fichier = sous_repertoire(_DIR_CACHE, 'export').$filename;
179 179
 	}
180 180
 
181 181
 	$fp = fopen($fichier, 'w');
Please login to merge, or discard this patch.
ecrire/inc/lister_objets.php 2 patches
Indentation   +21 added lines, -21 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
 
@@ -40,29 +40,29 @@  discard block
 block discarded – undo
40 40
  *     Code HTML de la liste
41 41
  */
42 42
 function inc_lister_objets_dist($vue, $contexte = [], $force = false) {
43
-	$res = ''; // debug
44
-	if (!is_array($contexte)) {
45
-		return _L('$contexte doit etre un tableau dans inc/lister_objets');
46
-	}
43
+    $res = ''; // debug
44
+    if (!is_array($contexte)) {
45
+        return _L('$contexte doit etre un tableau dans inc/lister_objets');
46
+    }
47 47
 
48
-	$fond = "prive/objets/liste/$vue";
49
-	if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
50
-		// traiter les cas particuliers
51
-		include_spip('base/connect_sql');
52
-		$vue = table_objet($vue);
53
-		$fond = "prive/objets/liste/$vue";
54
-		if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
55
-			return _L("vue $vue introuvable pour lister les objets");
56
-		}
57
-	}
48
+    $fond = "prive/objets/liste/$vue";
49
+    if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
50
+        // traiter les cas particuliers
51
+        include_spip('base/connect_sql');
52
+        $vue = table_objet($vue);
53
+        $fond = "prive/objets/liste/$vue";
54
+        if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
55
+            return _L("vue $vue introuvable pour lister les objets");
56
+        }
57
+    }
58 58
 
59 59
 
60
-	$contexte['sinon'] = ($force ? $contexte['titre'] : '');
60
+    $contexte['sinon'] = ($force ? $contexte['titre'] : '');
61 61
 
62
-	$res = recuperer_fond($fond, $contexte, ['ajax' => true]);
63
-	if (_request('var_liste')) {
64
-		echo var_export($contexte, true);
65
-	}
62
+    $res = recuperer_fond($fond, $contexte, ['ajax' => true]);
63
+    if (_request('var_liste')) {
64
+        echo var_export($contexte, true);
65
+    }
66 66
 
67
-	return $res;
67
+    return $res;
68 68
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,12 +46,12 @@
 block discarded – undo
46 46
 	}
47 47
 
48 48
 	$fond = "prive/objets/liste/$vue";
49
-	if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
49
+	if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) {
50 50
 		// traiter les cas particuliers
51 51
 		include_spip('base/connect_sql');
52 52
 		$vue = table_objet($vue);
53 53
 		$fond = "prive/objets/liste/$vue";
54
-		if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
54
+		if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) {
55 55
 			return _L("vue $vue introuvable pour lister les objets");
56 56
 		}
57 57
 	}
Please login to merge, or discard this patch.
ecrire/inc/pipelines_ecrire.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
 		$titre = '<title>['
95 95
 			. $nom_site_spip
96
-			. '] ' . $match
96
+			. '] '.$match
97 97
 			. '</title>';
98 98
 
99 99
 		$texte = substr_replace($texte, $titre, $p + 6, 0);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$flux['data']['texte'] = pipeline(
156 156
 				'affiche_droite',
157 157
 				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
-			) . liste_objets_bloques(
158
+			).liste_objets_bloques(
159 159
 				$exec,
160 160
 				$flux['args']['contexte']
161 161
 			);
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 				$flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191 191
 					'prive/objets/editer/traductions',
192 192
 					['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
-				) . '<!--affiche_milieu-->', $flux['data']['texte']);
193
+				).'<!--affiche_milieu-->', $flux['data']['texte']);
194 194
 				$flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195 195
 					'args' => [
196 196
 						'contexte' => $flux['args']['contexte'],
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		$full_marqueur = "$ouvrir$marqueur$fermer";
259 259
 
260 260
 		// Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
-		if ($marqueur_pos  === false) {
261
+		if ($marqueur_pos === false) {
262 262
 			$texte = preg_replace(
263 263
 				",$inserer_avant,",
264 264
 				"$full_marqueur\\0",
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 		}
306 306
 	}
307 307
 	if ($res) {
308
-		$flux['data'] = $res . $flux['data'];
308
+		$flux['data'] = $res.$flux['data'];
309 309
 	}
310 310
 
311 311
 	return $flux;
Please login to merge, or discard this patch.
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Pipelines
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -35,36 +35,36 @@  discard block
 block discarded – undo
35 35
  * @return string          Contenu complété des scripts javascripts, dont jQuery
36 36
  **/
37 37
 function f_jQuery_prive($texte) {
38
-	$x = '';
39
-	$jquery_plugins = pipeline(
40
-		'jquery_plugins',
41
-		[
42
-			'prive/javascript/jquery.js',
43
-			'prive/javascript/jquery.form.js',
44
-			'prive/javascript/jquery.autosave.js',
45
-			'prive/javascript/jquery.placeholder-label.js',
46
-			'prive/javascript/ajaxCallback.js',
47
-			'prive/javascript/js.cookie.js',
48
-			'prive/javascript/spip_barre.js',
49
-		]
50
-	);
51
-	foreach (array_unique($jquery_plugins) as $script) {
52
-		if ($script = find_in_path(supprimer_timestamp($script))) {
53
-			$script = timestamp($script);
54
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
55
-		}
56
-	}
57
-	// inserer avant le premier script externe ou a la fin
58
-	if (
59
-		preg_match(',<script[^><]*src=,', $texte, $match)
60
-		and $p = strpos($texte, (string) $match[0])
61
-	) {
62
-		$texte = substr_replace($texte, $x, $p, 0);
63
-	} else {
64
-		$texte .= $x;
65
-	}
38
+    $x = '';
39
+    $jquery_plugins = pipeline(
40
+        'jquery_plugins',
41
+        [
42
+            'prive/javascript/jquery.js',
43
+            'prive/javascript/jquery.form.js',
44
+            'prive/javascript/jquery.autosave.js',
45
+            'prive/javascript/jquery.placeholder-label.js',
46
+            'prive/javascript/ajaxCallback.js',
47
+            'prive/javascript/js.cookie.js',
48
+            'prive/javascript/spip_barre.js',
49
+        ]
50
+    );
51
+    foreach (array_unique($jquery_plugins) as $script) {
52
+        if ($script = find_in_path(supprimer_timestamp($script))) {
53
+            $script = timestamp($script);
54
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
55
+        }
56
+    }
57
+    // inserer avant le premier script externe ou a la fin
58
+    if (
59
+        preg_match(',<script[^><]*src=,', $texte, $match)
60
+        and $p = strpos($texte, (string) $match[0])
61
+    ) {
62
+        $texte = substr_replace($texte, $x, $p, 0);
63
+    } else {
64
+        $texte .= $x;
65
+    }
66 66
 
67
-	return $texte;
67
+    return $texte;
68 68
 }
69 69
 
70 70
 
@@ -77,42 +77,42 @@  discard block
 block discarded – undo
77 77
  * @return string
78 78
  */
79 79
 function affichage_final_prive_title_auto($texte) {
80
-	if (
81
-		strpos($texte, '<title>') === false
82
-		and
83
-		(preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
84
-			or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
85
-		and $match = textebrut(trim($match[1]))
86
-		and ($p = strpos($texte, '<head>')) !== false
87
-	) {
88
-		if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
89
-			$nom_site_spip = _T('info_mon_site_spip');
90
-		}
80
+    if (
81
+        strpos($texte, '<title>') === false
82
+        and
83
+        (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
84
+            or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
85
+        and $match = textebrut(trim($match[1]))
86
+        and ($p = strpos($texte, '<head>')) !== false
87
+    ) {
88
+        if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
89
+            $nom_site_spip = _T('info_mon_site_spip');
90
+        }
91 91
 
92
-		$titre = '<title>['
93
-			. $nom_site_spip
94
-			. '] ' . $match
95
-			. '</title>';
92
+        $titre = '<title>['
93
+            . $nom_site_spip
94
+            . '] ' . $match
95
+            . '</title>';
96 96
 
97
-		$texte = substr_replace($texte, $titre, $p + 6, 0);
98
-	}
97
+        $texte = substr_replace($texte, $titre, $p + 6, 0);
98
+    }
99 99
 
100
-	return $texte;
100
+    return $texte;
101 101
 }
102 102
 
103 103
 
104 104
 // Fonction standard pour le pipeline 'boite_infos'
105 105
 function f_boite_infos($flux) {
106
-	$args = $flux['args'];
107
-	$type = $args['type'];
108
-	unset($args['row']);
109
-	if (!trouver_fond($type, 'prive/objets/infos/')) {
110
-		$type = 'objet';
111
-	}
112
-	$args['espace_prive'] = 1;
113
-	$flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
106
+    $args = $flux['args'];
107
+    $type = $args['type'];
108
+    unset($args['row']);
109
+    if (!trouver_fond($type, 'prive/objets/infos/')) {
110
+        $type = 'objet';
111
+    }
112
+    $args['espace_prive'] = 1;
113
+    $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
114 114
 
115
-	return $flux;
115
+    return $flux;
116 116
 }
117 117
 
118 118
 
@@ -131,97 +131,97 @@  discard block
 block discarded – undo
131 131
  * @return array Données du pipeline
132 132
  */
133 133
 function f_afficher_blocs_ecrire($flux) {
134
-	static $o = [];
135
-	if (is_string($fond = $flux['args']['fond'])) {
136
-		$exec = $flux['args']['contexte']['exec'] ?? _request('exec');
137
-		if (!isset($o[$exec])) {
138
-			$o[$exec] = trouver_objet_exec($exec);
139
-		}
140
-		// cas particulier
141
-		if ($exec == 'infos_perso') {
142
-			$flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
143
-		}
144
-		$typepage = ($flux['args']['contexte']['type-page'] ?? $exec);
145
-		if ($fond == "prive/squelettes/navigation/$typepage") {
146
-			$flux['data']['texte'] = pipeline(
147
-				'affiche_gauche',
148
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
149
-			);
150
-		} elseif ($fond == "prive/squelettes/extra/$typepage") {
151
-			include_spip('inc/presentation_mini');
152
-			$flux['data']['texte'] = pipeline(
153
-				'affiche_droite',
154
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
155
-			) . liste_objets_bloques(
156
-				$exec,
157
-				$flux['args']['contexte']
158
-			);
159
-		} elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
160
-			// id non defini sur les formulaire de nouveaux objets
161
-			$id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
162
-			$flux['data']['texte'] = pipeline(
163
-				'affiche_hierarchie',
164
-				['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
165
-			);
166
-		} elseif ($fond == "prive/squelettes/contenu/$typepage") {
167
-			// Préparation du marqueur affiche_milieu
168
-			// Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
169
-			$est_page_objet = !empty($o[$exec]['type']);
170
-			$est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
171
-			$encapsuler_milieu = ($est_page_objet and !$est_en_edition);
172
-			$flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
173
-				$flux['data']['texte'],
174
-				'<!--affiche_milieu-->',
175
-				'<div id=["\']wysiwyg',
176
-				$encapsuler_milieu ? '<div class="affiche_milieu">' : '',
177
-				$encapsuler_milieu ? '</div>' : ''
178
-			);
179
-			if (
180
-				$o[$exec]
181
-				and $objet = $o[$exec]['type']
182
-				and $o[$exec]['edition'] == false
183
-				and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
184
-				and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
185
-			) {
186
-				// inserer le formulaire de traduction
187
-				$flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
188
-					'prive/objets/editer/traductions',
189
-					['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
190
-				) . '<!--affiche_milieu-->', $flux['data']['texte']);
191
-				$flux['data']['texte'] = pipeline('afficher_fiche_objet', [
192
-					'args' => [
193
-						'contexte' => $flux['args']['contexte'],
194
-						'type' => $objet,
195
-						'id' => $id
196
-					],
197
-					'data' => $flux['data']['texte']
198
-				]);
199
-			}
200
-			$flux['data']['texte'] = pipeline(
201
-				'affiche_milieu',
202
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
203
-			);
204
-		} elseif ($fond == 'prive/squelettes/inclure/pied') {
205
-			$flux['data']['texte'] = pipeline(
206
-				'affiche_pied',
207
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
208
-			);
209
-		} elseif (
210
-			strncmp($fond, 'prive/objets/contenu/', 21) == 0
211
-			and $objet = basename($fond)
212
-			and $objet == substr($fond, 21)
213
-			and isset($o[$objet])
214
-			and $o[$objet]
215
-		) {
216
-			$id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
217
-			$flux['data']['texte'] = pipeline('afficher_contenu_objet', [
218
-				'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
219
-				'data' => $flux['data']['texte']
220
-			]);
221
-		}
222
-	}
134
+    static $o = [];
135
+    if (is_string($fond = $flux['args']['fond'])) {
136
+        $exec = $flux['args']['contexte']['exec'] ?? _request('exec');
137
+        if (!isset($o[$exec])) {
138
+            $o[$exec] = trouver_objet_exec($exec);
139
+        }
140
+        // cas particulier
141
+        if ($exec == 'infos_perso') {
142
+            $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
143
+        }
144
+        $typepage = ($flux['args']['contexte']['type-page'] ?? $exec);
145
+        if ($fond == "prive/squelettes/navigation/$typepage") {
146
+            $flux['data']['texte'] = pipeline(
147
+                'affiche_gauche',
148
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
149
+            );
150
+        } elseif ($fond == "prive/squelettes/extra/$typepage") {
151
+            include_spip('inc/presentation_mini');
152
+            $flux['data']['texte'] = pipeline(
153
+                'affiche_droite',
154
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
155
+            ) . liste_objets_bloques(
156
+                $exec,
157
+                $flux['args']['contexte']
158
+            );
159
+        } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
160
+            // id non defini sur les formulaire de nouveaux objets
161
+            $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
162
+            $flux['data']['texte'] = pipeline(
163
+                'affiche_hierarchie',
164
+                ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
165
+            );
166
+        } elseif ($fond == "prive/squelettes/contenu/$typepage") {
167
+            // Préparation du marqueur affiche_milieu
168
+            // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
169
+            $est_page_objet = !empty($o[$exec]['type']);
170
+            $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
171
+            $encapsuler_milieu = ($est_page_objet and !$est_en_edition);
172
+            $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
173
+                $flux['data']['texte'],
174
+                '<!--affiche_milieu-->',
175
+                '<div id=["\']wysiwyg',
176
+                $encapsuler_milieu ? '<div class="affiche_milieu">' : '',
177
+                $encapsuler_milieu ? '</div>' : ''
178
+            );
179
+            if (
180
+                $o[$exec]
181
+                and $objet = $o[$exec]['type']
182
+                and $o[$exec]['edition'] == false
183
+                and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
184
+                and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
185
+            ) {
186
+                // inserer le formulaire de traduction
187
+                $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
188
+                    'prive/objets/editer/traductions',
189
+                    ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
190
+                ) . '<!--affiche_milieu-->', $flux['data']['texte']);
191
+                $flux['data']['texte'] = pipeline('afficher_fiche_objet', [
192
+                    'args' => [
193
+                        'contexte' => $flux['args']['contexte'],
194
+                        'type' => $objet,
195
+                        'id' => $id
196
+                    ],
197
+                    'data' => $flux['data']['texte']
198
+                ]);
199
+            }
200
+            $flux['data']['texte'] = pipeline(
201
+                'affiche_milieu',
202
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
203
+            );
204
+        } elseif ($fond == 'prive/squelettes/inclure/pied') {
205
+            $flux['data']['texte'] = pipeline(
206
+                'affiche_pied',
207
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
208
+            );
209
+        } elseif (
210
+            strncmp($fond, 'prive/objets/contenu/', 21) == 0
211
+            and $objet = basename($fond)
212
+            and $objet == substr($fond, 21)
213
+            and isset($o[$objet])
214
+            and $o[$objet]
215
+        ) {
216
+            $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
217
+            $flux['data']['texte'] = pipeline('afficher_contenu_objet', [
218
+                'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
219
+                'data' => $flux['data']['texte']
220
+            ]);
221
+        }
222
+    }
223 223
 
224
-	return $flux;
224
+    return $flux;
225 225
 }
226 226
 
227 227
 /**
@@ -249,36 +249,36 @@  discard block
 block discarded – undo
249 249
  */
250 250
 function afficher_blocs_ecrire_preparer_marqueur(?string $texte, string $marqueur, string $inserer_avant, string $ouvrir = '', string $fermer = ''): ?string {
251 251
 
252
-	if ($texte) {
253
-		$encapsuler = (($ouvrir and $fermer) ? true : false);
254
-		$marqueur_pos = strpos($texte, $marqueur);
255
-		$full_marqueur = "$ouvrir$marqueur$fermer";
252
+    if ($texte) {
253
+        $encapsuler = (($ouvrir and $fermer) ? true : false);
254
+        $marqueur_pos = strpos($texte, $marqueur);
255
+        $full_marqueur = "$ouvrir$marqueur$fermer";
256 256
 
257
-		// Le marqueur est absent : on l'ajoute avant l'élément indiqué
258
-		if ($marqueur_pos  === false) {
259
-			$texte = preg_replace(
260
-				",$inserer_avant,",
261
-				"$full_marqueur\\0",
262
-				$texte
263
-			);
264
-		// Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
265
-		// Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
266
-		// Il ne faut donc aucun espace blanc en trop.
267
-		} elseif (
268
-			$marqueur_pos !== false
269
-			and $encapsuler
270
-			and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
271
-		) {
272
-			$texte = substr_replace(
273
-				$texte,
274
-				$full_marqueur,
275
-				$marqueur_pos,
276
-				strlen($marqueur)
277
-			);
278
-		}
279
-	}
257
+        // Le marqueur est absent : on l'ajoute avant l'élément indiqué
258
+        if ($marqueur_pos  === false) {
259
+            $texte = preg_replace(
260
+                ",$inserer_avant,",
261
+                "$full_marqueur\\0",
262
+                $texte
263
+            );
264
+        // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
265
+        // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
266
+        // Il ne faut donc aucun espace blanc en trop.
267
+        } elseif (
268
+            $marqueur_pos !== false
269
+            and $encapsuler
270
+            and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
271
+        ) {
272
+            $texte = substr_replace(
273
+                $texte,
274
+                $full_marqueur,
275
+                $marqueur_pos,
276
+                strlen($marqueur)
277
+            );
278
+        }
279
+    }
280 280
 
281
-	return $texte;
281
+    return $texte;
282 282
 }
283 283
 
284 284
 /**
@@ -289,23 +289,23 @@  discard block
 block discarded – undo
289 289
  * @return string
290 290
  */
291 291
 function f_queue_affiche_milieu($flux) {
292
-	$args = $flux['args'];
293
-	$res = '';
294
-	foreach ($args as $key => $arg) {
295
-		if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
296
-			$objet = preg_replace(',^id_,', '', $key);
297
-			$res .= recuperer_fond(
298
-				'modeles/object_jobs_list',
299
-				['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
300
-				['ajax' => true]
301
-			);
302
-		}
303
-	}
304
-	if ($res) {
305
-		$flux['data'] = $res . $flux['data'];
306
-	}
292
+    $args = $flux['args'];
293
+    $res = '';
294
+    foreach ($args as $key => $arg) {
295
+        if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
296
+            $objet = preg_replace(',^id_,', '', $key);
297
+            $res .= recuperer_fond(
298
+                'modeles/object_jobs_list',
299
+                ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
300
+                ['ajax' => true]
301
+            );
302
+        }
303
+    }
304
+    if ($res) {
305
+        $flux['data'] = $res . $flux['data'];
306
+    }
307 307
 
308
-	return $flux;
308
+    return $flux;
309 309
 }
310 310
 
311 311
 /**
@@ -319,39 +319,39 @@  discard block
 block discarded – undo
319 319
  * @return array|bool
320 320
  */
321 321
 function trouver_objet_exec(?string $exec) {
322
-	static $objet_exec = [];
323
-	if (!$exec) {
324
-		return false;
325
-	}
326
-	// cas particulier
327
-	if ($exec === 'infos_perso') {
328
-		$exec = 'auteur';
329
-		set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
330
-	}
331
-	if (!isset($objet_exec[$exec])) {
332
-		$objet_exec[$exec] = false;
333
-		$infos = lister_tables_objets_sql();
334
-		foreach ($infos as $t => $info) {
335
-			if ($exec === $info['url_edit'] and $info['editable']) {
336
-				return $objet_exec[$exec] = [
337
-					'edition' => $exec == $info['url_voir'] ? '' : true,
338
-					'table_objet_sql' => $t,
339
-					'table' => $info['table_objet'],
340
-					'type' => $info['type'],
341
-					'id_table_objet' => id_table_objet($info['type'])
342
-				];
343
-			}
344
-			if ($exec === $info['url_voir']) {
345
-				return $objet_exec[$exec] = [
346
-					'edition' => false,
347
-					'table_objet_sql' => $t,
348
-					'table' => $info['table_objet'],
349
-					'type' => $info['type'],
350
-					'id_table_objet' => id_table_objet($info['type'])
351
-				];
352
-			}
353
-		}
354
-	}
322
+    static $objet_exec = [];
323
+    if (!$exec) {
324
+        return false;
325
+    }
326
+    // cas particulier
327
+    if ($exec === 'infos_perso') {
328
+        $exec = 'auteur';
329
+        set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
330
+    }
331
+    if (!isset($objet_exec[$exec])) {
332
+        $objet_exec[$exec] = false;
333
+        $infos = lister_tables_objets_sql();
334
+        foreach ($infos as $t => $info) {
335
+            if ($exec === $info['url_edit'] and $info['editable']) {
336
+                return $objet_exec[$exec] = [
337
+                    'edition' => $exec == $info['url_voir'] ? '' : true,
338
+                    'table_objet_sql' => $t,
339
+                    'table' => $info['table_objet'],
340
+                    'type' => $info['type'],
341
+                    'id_table_objet' => id_table_objet($info['type'])
342
+                ];
343
+            }
344
+            if ($exec === $info['url_voir']) {
345
+                return $objet_exec[$exec] = [
346
+                    'edition' => false,
347
+                    'table_objet_sql' => $t,
348
+                    'table' => $info['table_objet'],
349
+                    'type' => $info['type'],
350
+                    'id_table_objet' => id_table_objet($info['type'])
351
+                ];
352
+            }
353
+        }
354
+    }
355 355
 
356
-	return $objet_exec[$exec];
356
+    return $objet_exec[$exec];
357 357
 }
Please login to merge, or discard this patch.