Completed
Push — master ( a07606...4c3c71 )
by cam
02:01
created
ecrire/inc/filtres_images_lib_mini.php 3 patches
Spacing   +66 added lines, -66 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));
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	$var_G = ($G / 255);
125 125
 	$var_B = ($B / 255);
126 126
 
127
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
128
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
129
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
127
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
128
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
129
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
130 130
 
131 131
 	$L = ($var_Max + $var_Min) / 2;
132 132
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
  */
189 189
 function _couleur_hsl_to_rgb($H, $S, $L) {
190 190
 	// helper
191
-	$hue_2_rgb = function ($v1, $v2, $vH) {
191
+	$hue_2_rgb = function($v1, $v2, $vH) {
192 192
 		if ($vH < 0) {
193 193
 			$vH += 1;
194 194
 		}
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
 	} # gerer img src="data:....base64"
319 319
 	elseif (
320 320
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
321
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
321
+		and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])
322 322
 		and in_array($extension, _image_extensions_acceptees_en_entree())
323 323
 	) {
324
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
324
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
325 325
 		if (!file_exists($local)) {
326 326
 			ecrire_fichier($local, base64_decode($regs[2]));
327 327
 		}
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 	// les protocoles web prennent au moins 3 lettres
336 336
 	if (tester_url_absolue($source)) {
337 337
 		include_spip('inc/distant');
338
-		$fichier = _DIR_RACINE . copie_locale($source);
338
+		$fichier = _DIR_RACINE.copie_locale($source);
339 339
 		if (!$fichier) {
340 340
 			return '';
341 341
 		}
@@ -427,9 +427,9 @@  discard block
 block discarded – undo
427 427
 			// on garde la terminaison initiale car image simplement copiee
428 428
 			// et on postfixe son nom avec un md5 du path
429 429
 			$terminaison_dest = $terminaison;
430
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
430
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
431 431
 		} else {
432
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
432
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
433 433
 		}
434 434
 		$cache = sous_repertoire(_DIR_VAR, $cache);
435 435
 		$cache = sous_repertoire($cache, $effet);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 		$fichier_dest = substr($fichier_dest, 2);
441 441
 	}
442 442
 
443
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
443
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
444 444
 
445 445
 	$GLOBALS['images_calculees'][] = $fichier_dest;
446 446
 
@@ -478,15 +478,15 @@  discard block
 block discarded – undo
478 478
 
479 479
 	if ($creer) {
480 480
 		spip_log(
481
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
482
-			'images' . _LOG_DEBUG
481
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
482
+			'images'._LOG_DEBUG
483 483
 		);
484 484
 	}
485 485
 
486 486
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
487
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
487
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
488 488
 	$ret['fichier'] = $fichier;
489
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
489
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
490 490
 	$ret['fichier_dest'] = $fichier_dest;
491 491
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
492 492
 	$ret['format_dest'] = $terminaison_dest;
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 
636 636
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
637 637
 	if ($_terminaison and $_terminaison !== $terminaison) {
638
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
638
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
639 639
 		$terminaison = $_terminaison;
640 640
 	}
641 641
 	return $terminaison;
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	if (!function_exists('imagepng')) {
793 793
 		return false;
794 794
 	}
795
-	$tmp = $fichier . '.tmp';
795
+	$tmp = $fichier.'.tmp';
796 796
 	$ret = imagepng($img, $tmp);
797 797
 	if (file_exists($tmp)) {
798 798
 		$taille_test = getimagesize($tmp);
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
 	if (!function_exists('imagegif')) {
828 828
 		return false;
829 829
 	}
830
-	$tmp = $fichier . '.tmp';
830
+	$tmp = $fichier.'.tmp';
831 831
 	$ret = imagegif($img, $tmp);
832 832
 	if (file_exists($tmp)) {
833 833
 		$taille_test = getimagesize($tmp);
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 	if (!function_exists('imagejpeg')) {
868 868
 		return false;
869 869
 	}
870
-	$tmp = $fichier . '.tmp';
870
+	$tmp = $fichier.'.tmp';
871 871
 
872 872
 	// Enable interlancing
873 873
 	imageinterlace($img, true);
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 	if (!function_exists('imagewebp')) {
929 929
 		return false;
930 930
 	}
931
-	$tmp = $fichier . '.tmp';
931
+	$tmp = $fichier.'.tmp';
932 932
 	$ret = imagewebp($img, $tmp, $qualite);
933 933
 	if (file_exists($tmp)) {
934 934
 		$taille_test = getimagesize($tmp);
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
  */
963 963
 function _image_imagesvg($img, $fichier) {
964 964
 
965
-	$tmp = $fichier . '.tmp';
965
+	$tmp = $fichier.'.tmp';
966 966
 	if (strpos($img, '<') === false) {
967 967
 		$img = supprimer_timestamp($img);
968 968
 		if (!file_exists($img)) {
@@ -1019,13 +1019,13 @@  discard block
 block discarded – undo
1019 1019
  */
1020 1020
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1021 1021
 	if (is_null($fonction)) {
1022
-		$fonction = '_image_image' . $valeurs['format_dest'];
1022
+		$fonction = '_image_image'.$valeurs['format_dest'];
1023 1023
 	}
1024 1024
 	$ret = false;
1025 1025
 	#un flag pour reperer les images gravees
1026 1026
 	$lock =
1027 1027
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1028
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1028
+	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'));
1029 1029
 	if (
1030 1030
 		function_exists($fonction)
1031 1031
 		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
 			// dans tous les cas mettre a jour la taille de l'image finale
1037 1037
 			list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1038 1038
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1039
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1039
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1040 1040
 		}
1041 1041
 	}
1042 1042
 
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
 
1250 1250
 	// attributs deprecies. Transformer en CSS
1251 1251
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1252
-		$style = "margin:${espace}px;" . $style;
1252
+		$style = "margin:${espace}px;".$style;
1253 1253
 		$tag = inserer_attribut($tag, 'hspace', '');
1254 1254
 	}
1255 1255
 
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 	$image = $valeurs['fichier'];
1375 1375
 	$format = $valeurs['format_source'];
1376 1376
 	$destdir = dirname($valeurs['fichier_dest']);
1377
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1377
+	$destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1378 1378
 
1379 1379
 	$format_sortie = $valeurs['format_dest'];
1380 1380
 
@@ -1406,14 +1406,14 @@  discard block
 block discarded – undo
1406 1406
 
1407 1407
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1408 1408
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1409
-		$vignette = $destination . '.' . $format;
1409
+		$vignette = $destination.'.'.$format;
1410 1410
 		@copy($image, $vignette);
1411 1411
 	}
1412 1412
 
1413 1413
 	elseif ($valeurs['format_source'] === 'svg') {
1414 1414
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1415 1415
 			$format_sortie = 'svg';
1416
-			$vignette = $destination . '.' . $format_sortie;
1416
+			$vignette = $destination.'.'.$format_sortie;
1417 1417
 			$valeurs['fichier_dest'] = $vignette;
1418 1418
 			_image_gd_output($svg, $valeurs);
1419 1419
 		}
@@ -1425,9 +1425,9 @@  discard block
 block discarded – undo
1425 1425
 			define('_CONVERT_COMMAND', 'convert');
1426 1426
 		} // Securite : mes_options.php peut preciser le chemin absolu
1427 1427
 		if (!defined('_RESIZE_COMMAND')) {
1428
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1428
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1429 1429
 		}
1430
-		$vignette = $destination . '.' . $format_sortie;
1430
+		$vignette = $destination.'.'.$format_sortie;
1431 1431
 		$commande = str_replace(
1432 1432
 			['%x', '%y', '%src', '%dest'],
1433 1433
 			[
@@ -1443,13 +1443,13 @@  discard block
 block discarded – undo
1443 1443
 		if (!@file_exists($vignette)) {
1444 1444
 			spip_log("echec convert sur $vignette");
1445 1445
 
1446
-			return;  // echec commande
1446
+			return; // echec commande
1447 1447
 		}
1448 1448
 	}
1449 1449
 
1450 1450
 	// php5 imagemagick
1451 1451
 	elseif ($process == 'imagick') {
1452
-		$vignette = "$destination." . $format_sortie;
1452
+		$vignette = "$destination.".$format_sortie;
1453 1453
 
1454 1454
 		if (!class_exists('Imagick')) {
1455 1455
 			spip_log('Classe Imagick absente !', _LOG_ERREUR);
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 			$destHeight,
1464 1464
 			Imagick::FILTER_LANCZOS,
1465 1465
 			1
1466
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1466
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1467 1467
 		$imagick->writeImage($vignette);
1468 1468
 
1469 1469
 		if (!@file_exists($vignette)) {
@@ -1481,11 +1481,11 @@  discard block
 block discarded – undo
1481 1481
 		if (_PNMSCALE_COMMAND == '') {
1482 1482
 			return;
1483 1483
 		}
1484
-		$vignette = $destination . '.' . $format_sortie;
1484
+		$vignette = $destination.'.'.$format_sortie;
1485 1485
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1486 1486
 		if ($format == 'jpg') {
1487 1487
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1488
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1488
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1489 1489
 			if (!($s = @filesize($vignette))) {
1490 1490
 				spip_unlink($vignette);
1491 1491
 			}
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
 		} else {
1498 1498
 			if ($format == 'gif') {
1499 1499
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1500
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1500
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1501 1501
 				if (!($s = @filesize($vignette))) {
1502 1502
 					spip_unlink($vignette);
1503 1503
 				}
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
 			} else {
1510 1510
 				if ($format == 'png') {
1511 1511
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1512
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1512
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1513 1513
 					if (!($s = @filesize($vignette))) {
1514 1514
 						spip_unlink($vignette);
1515 1515
 					}
@@ -1531,7 +1531,7 @@  discard block
 block discarded – undo
1531 1531
 			return;
1532 1532
 		}
1533 1533
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1534
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1534
+			spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1535 1535
 
1536 1536
 			return;
1537 1537
 		}
@@ -1843,7 +1843,7 @@  discard block
 block discarded – undo
1843 1843
 		// de l'image, de facon a tromper le cache du navigateur
1844 1844
 		// quand on fait supprimer/reuploader un logo
1845 1845
 		// (pas de filemtime si SAFE MODE)
1846
-		$date = test_espace_prive() ? ('?' . $date) : '';
1846
+		$date = test_espace_prive() ? ('?'.$date) : '';
1847 1847
 
1848 1848
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1849 1849
 	}
@@ -1890,7 +1890,7 @@  discard block
 block discarded – undo
1890 1890
 	public static function LittleEndian2String($number, $minbytes = 1) {
1891 1891
 		$intstring = '';
1892 1892
 		while ($number > 0) {
1893
-			$intstring = $intstring . chr($number & 255);
1893
+			$intstring = $intstring.chr($number & 255);
1894 1894
 			$number >>= 8;
1895 1895
 		}
1896 1896
 
@@ -1922,9 +1922,9 @@  discard block
 block discarded – undo
1922 1922
 					$b = $argb['blue'];
1923 1923
 
1924 1924
 					if ($bpp[$key] == 32) {
1925
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1925
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1926 1926
 					} elseif ($bpp[$key] == 24) {
1927
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1927
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1928 1928
 					}
1929 1929
 
1930 1930
 					if ($a < 128) {
@@ -1951,48 +1951,48 @@  discard block
 block discarded – undo
1951 1951
 
1952 1952
 			// BITMAPINFOHEADER - 40 bytes
1953 1953
 			$BitmapInfoHeader[$key] = '';
1954
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1955
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1954
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1955
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1956 1956
 			// The biHeight member specifies the combined
1957 1957
 			// height of the XOR and AND masks.
1958 1958
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1959
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1960
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1961
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1962
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1963
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1964
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1965
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1966
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1959
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1960
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1961
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1962
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1963
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1964
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1965
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1966
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1967 1967
 		}
1968 1968
 
1969 1969
 
1970
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1971
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1972
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1970
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1971
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1972
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1973 1973
 
1974 1974
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1975 1975
 		foreach ($gd_image_array as $key => $gd_image) {
1976 1976
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1977 1977
 
1978
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1979
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1980
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1981
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1978
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1979
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1980
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1981
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1982 1982
 
1983
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1984
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1983
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1984
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1985 1985
 
1986 1986
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1987 1987
 			$icondata .= phpthumb_functions::LittleEndian2String(
1988 1988
 				$dwBytesInRes,
1989 1989
 				4
1990
-			);     // dwBytesInRes;	// How many bytes in this resource?
1990
+			); // dwBytesInRes;	// How many bytes in this resource?
1991 1991
 
1992 1992
 			$icondata .= phpthumb_functions::LittleEndian2String(
1993 1993
 				$dwImageOffset,
1994 1994
 				4
1995
-			);    // dwImageOffset;   // Where in the file is this image?
1995
+			); // dwImageOffset;   // Where in the file is this image?
1996 1996
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1997 1997
 			$dwImageOffset += strlen($icXOR[$key]);
1998 1998
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
Braces   +4 added lines, -9 removed lines patch added patch discarded remove patch
@@ -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.
Indentation   +1344 added lines, -1344 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,17 +64,17 @@  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 = couleur_html_to_hex($couleur);
68
-	$couleur = ltrim($couleur, '#');
69
-	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
-	}
72
-	$retour = [];
73
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
74
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
75
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
67
+    $couleur = couleur_html_to_hex($couleur);
68
+    $couleur = ltrim($couleur, '#');
69
+    if (strlen($couleur) === 3) {
70
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+    }
72
+    $retour = [];
73
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
74
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
75
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
  *     Le code de la couleur en hexadécimal.
92 92
  */
93 93
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
94
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
94
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
96 96
 }
97 97
 
98 98
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
105 105
  */
106 106
 function _couleur_hex_to_hsl($couleur) {
107
-	$rgb = _couleur_hex_to_dec($couleur);
108
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
107
+    $rgb = _couleur_hex_to_dec($couleur);
108
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
109 109
 }
110 110
 
111 111
 /**
@@ -120,58 +120,58 @@  discard block
 block discarded – undo
120 120
  * @return array
121 121
  */
122 122
 function _couleur_rgb_to_hsl($R, $G, $B) {
123
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
124
-	$var_G = ($G / 255);
125
-	$var_B = ($B / 255);
126
-
127
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
128
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
129
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
130
-
131
-	$L = ($var_Max + $var_Min) / 2;
132
-
133
-	if ($del_Max == 0) {
134
-		//This is a gray, no chroma...
135
-		$H = 0; //HSL results = 0 ÷ 1
136
-		$S = 0;
137
-	} else {
138
-		// Chromatic data...
139
-		if ($L < 0.5) {
140
-			$S = $del_Max / ($var_Max + $var_Min);
141
-		} else {
142
-			$S = $del_Max / (2 - $var_Max - $var_Min);
143
-		}
144
-
145
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
146
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
147
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
148
-
149
-		if ($var_R == $var_Max) {
150
-			$H = $del_B - $del_G;
151
-		} else {
152
-			if ($var_G == $var_Max) {
153
-				$H = (1 / 3) + $del_R - $del_B;
154
-			} else {
155
-				if ($var_B == $var_Max) {
156
-					$H = (2 / 3) + $del_G - $del_R;
157
-				}
158
-			}
159
-		}
160
-
161
-		if ($H < 0) {
162
-			$H += 1;
163
-		}
164
-		if ($H > 1) {
165
-			$H -= 1;
166
-		}
167
-	}
168
-
169
-	$ret = [];
170
-	$ret['h'] = $H;
171
-	$ret['s'] = $S;
172
-	$ret['l'] = $L;
173
-
174
-	return $ret;
123
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
124
+    $var_G = ($G / 255);
125
+    $var_B = ($B / 255);
126
+
127
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
128
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
129
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
130
+
131
+    $L = ($var_Max + $var_Min) / 2;
132
+
133
+    if ($del_Max == 0) {
134
+        //This is a gray, no chroma...
135
+        $H = 0; //HSL results = 0 ÷ 1
136
+        $S = 0;
137
+    } else {
138
+        // Chromatic data...
139
+        if ($L < 0.5) {
140
+            $S = $del_Max / ($var_Max + $var_Min);
141
+        } else {
142
+            $S = $del_Max / (2 - $var_Max - $var_Min);
143
+        }
144
+
145
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
146
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
147
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
148
+
149
+        if ($var_R == $var_Max) {
150
+            $H = $del_B - $del_G;
151
+        } else {
152
+            if ($var_G == $var_Max) {
153
+                $H = (1 / 3) + $del_R - $del_B;
154
+            } else {
155
+                if ($var_B == $var_Max) {
156
+                    $H = (2 / 3) + $del_G - $del_R;
157
+                }
158
+            }
159
+        }
160
+
161
+        if ($H < 0) {
162
+            $H += 1;
163
+        }
164
+        if ($H > 1) {
165
+            $H -= 1;
166
+        }
167
+    }
168
+
169
+    $ret = [];
170
+    $ret['h'] = $H;
171
+    $ret['s'] = $S;
172
+    $ret['l'] = $L;
173
+
174
+    return $ret;
175 175
 }
176 176
 
177 177
 
@@ -187,52 +187,52 @@  discard block
 block discarded – undo
187 187
  * @return array
188 188
  */
189 189
 function _couleur_hsl_to_rgb($H, $S, $L) {
190
-	// helper
191
-	$hue_2_rgb = function ($v1, $v2, $vH) {
192
-		if ($vH < 0) {
193
-			$vH += 1;
194
-		}
195
-		if ($vH > 1) {
196
-			$vH -= 1;
197
-		}
198
-		if ((6 * $vH) < 1) {
199
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
200
-		}
201
-		if ((2 * $vH) < 1) {
202
-			return ($v2);
203
-		}
204
-		if ((3 * $vH) < 2) {
205
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
206
-		}
207
-
208
-		return ($v1);
209
-	};
210
-
211
-	if ($S == 0) {
212
-		// HSV values = 0 -> 1
213
-		$R = $L * 255;
214
-		$G = $L * 255;
215
-		$B = $L * 255;
216
-	} else {
217
-		if ($L < 0.5) {
218
-			$var_2 = $L * (1 + $S);
219
-		} else {
220
-			$var_2 = ($L + $S) - ($S * $L);
221
-		}
222
-
223
-		$var_1 = 2 * $L - $var_2;
224
-
225
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
226
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
227
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
228
-	}
229
-
230
-	$ret = [];
231
-	$ret['r'] = floor($R);
232
-	$ret['g'] = floor($G);
233
-	$ret['b'] = floor($B);
234
-
235
-	return $ret;
190
+    // helper
191
+    $hue_2_rgb = function ($v1, $v2, $vH) {
192
+        if ($vH < 0) {
193
+            $vH += 1;
194
+        }
195
+        if ($vH > 1) {
196
+            $vH -= 1;
197
+        }
198
+        if ((6 * $vH) < 1) {
199
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
200
+        }
201
+        if ((2 * $vH) < 1) {
202
+            return ($v2);
203
+        }
204
+        if ((3 * $vH) < 2) {
205
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
206
+        }
207
+
208
+        return ($v1);
209
+    };
210
+
211
+    if ($S == 0) {
212
+        // HSV values = 0 -> 1
213
+        $R = $L * 255;
214
+        $G = $L * 255;
215
+        $B = $L * 255;
216
+    } else {
217
+        if ($L < 0.5) {
218
+            $var_2 = $L * (1 + $S);
219
+        } else {
220
+            $var_2 = ($L + $S) - ($S * $L);
221
+        }
222
+
223
+        $var_1 = 2 * $L - $var_2;
224
+
225
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
226
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
227
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
228
+    }
229
+
230
+    $ret = [];
231
+    $ret['r'] = floor($R);
232
+    $ret['g'] = floor($G);
233
+    $ret['b'] = floor($B);
234
+
235
+    return $ret;
236 236
 }
237 237
 
238 238
 /**
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
  *     true si il faut supprimer le fichier temporaire ; false sinon.
250 250
  */
251 251
 function statut_effacer_images_temporaires($stat) {
252
-	static $statut = false; // par defaut on grave toute les images
253
-	if ($stat === 'get') {
254
-		return $statut;
255
-	}
256
-	$statut = $stat ? true : false;
252
+    static $statut = false; // par defaut on grave toute les images
253
+    if ($stat === 'get') {
254
+        return $statut;
255
+    }
256
+    $statut = $stat ? true : false;
257 257
 }
258 258
 
259 259
 
@@ -306,241 +306,241 @@  discard block
 block discarded – undo
306 306
  *     - array : tableau décrivant de l'image
307 307
  */
308 308
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
309
-	static $images_recalcul = [];
310
-	if (strlen($img) == 0) {
311
-		return false;
312
-	}
313
-
314
-	$source = trim(extraire_attribut($img, 'src'));
315
-	if (strlen($source) < 1) {
316
-		$source = $img;
317
-		$img = "<img src='$source' />";
318
-	} # gerer img src="data:....base64"
319
-	elseif (
320
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
321
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
322
-		and in_array($extension, _image_extensions_acceptees_en_entree())
323
-	) {
324
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
325
-		if (!file_exists($local)) {
326
-			ecrire_fichier($local, base64_decode($regs[2]));
327
-		}
328
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
329
-			$sanitizer($local);
330
-		}
331
-		$source = $local;
332
-		$img = inserer_attribut($img, 'src', $source);
333
-		# eviter les mauvaises surprises lors de conversions de format
334
-		$img = inserer_attribut($img, 'width', '');
335
-		$img = inserer_attribut($img, 'height', '');
336
-	}
337
-
338
-	// les protocoles web prennent au moins 3 lettres
339
-	if (tester_url_absolue($source)) {
340
-		include_spip('inc/distant');
341
-		$fichier = _DIR_RACINE . copie_locale($source);
342
-		if (!$fichier) {
343
-			return '';
344
-		}
345
-		if (
346
-			$extension = _image_trouver_extension($fichier)
347
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
348
-		) {
349
-			$sanitizer($fichier);
350
-		}
351
-	} else {
352
-		// enlever le timestamp eventuel
353
-		if (strpos($source, '?') !== false) {
354
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
355
-		}
356
-		if (
357
-			strpos($source, '?') !== false
358
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
359
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
360
-		) {
361
-			$source = $f;
362
-		}
363
-		$fichier = $source;
364
-	}
365
-
366
-	$terminaison_dest = '';
367
-	if ($terminaison = _image_trouver_extension($fichier)) {
368
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
369
-	}
370
-
371
-	if (
372
-		$forcer_format !== false
373
-		// 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
374
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
375
-	) {
376
-		$terminaison_dest = $forcer_format;
377
-	}
378
-
379
-	if (!$terminaison_dest) {
380
-		return false;
381
-	}
382
-
383
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
384
-	$fichier_dest = $nom_fichier;
385
-	if (
386
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
387
-		or @file_exists($f = $fichier)
388
-	) {
389
-		// on passe la balise img a taille image qui exraira les attributs si possible
390
-		// au lieu de faire un acces disque sur le fichier
391
-		list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img);
392
-		$date_src = @filemtime($f);
393
-	} elseif (
394
-		@file_exists($f = "$fichier.src")
395
-		and lire_fichier($f, $valeurs)
396
-		and $valeurs = unserialize($valeurs)
397
-		and isset($valeurs['hauteur_dest'])
398
-		and isset($valeurs['largeur_dest'])
399
-	) {
400
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
401
-		$ret['largeur'] = $valeurs['largeur_dest'];
402
-		$date_src = $valeurs['date'];
403
-	} // pas de fichier source par la
404
-	else {
405
-		return false;
406
-	}
407
-
408
-	// pas de taille mesurable
409
-	if (!($ret['hauteur'] or $ret['largeur'])) {
410
-		return false;
411
-	}
412
-
413
-	// les images calculees dependent du chemin du fichier source
414
-	// 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
415
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
416
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
417
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
418
-	// alors que ca concerne peu de site au final
419
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
420
-	$identifiant = $fichier;
421
-
422
-	// cas general :
423
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
424
-	// cas particulier de reduire :
425
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
426
-	$cache = 'cache-gd2';
427
-	if (substr($effet, 0, 7) == 'reduire') {
428
-		list(, $maxWidth, $maxHeight) = explode('-', $effet);
429
-		list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
430
-		$ret['largeur_dest'] = $destWidth;
431
-		$ret['hauteur_dest'] = $destHeight;
432
-		$effet = "L{$destWidth}xH$destHeight";
433
-		$cache = 'cache-vignettes';
434
-		$fichier_dest = basename($fichier_dest);
435
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
436
-			// on garde la terminaison initiale car image simplement copiee
437
-			// et on postfixe son nom avec un md5 du path
438
-			$terminaison_dest = $terminaison;
439
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
440
-		} else {
441
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
442
-		}
443
-		$cache = sous_repertoire(_DIR_VAR, $cache);
444
-		$cache = sous_repertoire($cache, $effet);
445
-	} else {
446
-		$fichier_dest = md5("$identifiant-$effet");
447
-		$cache = sous_repertoire(_DIR_VAR, $cache);
448
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
449
-		$fichier_dest = substr($fichier_dest, 2);
450
-	}
451
-
452
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
453
-
454
-	$GLOBALS['images_calculees'][] = $fichier_dest;
455
-
456
-	$creer = true;
457
-	// si recalcul des images demande, recalculer chaque image une fois
458
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
459
-		$images_recalcul[$fichier_dest] = true;
460
-	} else {
461
-		if (@file_exists($f = $fichier_dest)) {
462
-			if (filemtime($f) >= $date_src) {
463
-				$creer = false;
464
-			}
465
-		} else {
466
-			if (
467
-				@file_exists($f = "$fichier_dest.src")
468
-				and lire_fichier($f, $valeurs)
469
-				and $valeurs = unserialize($valeurs)
470
-				and $valeurs['date'] >= $date_src
471
-			) {
472
-				$creer = false;
473
-			}
474
-		}
475
-	}
476
-	if ($creer) {
477
-		if (!@file_exists($fichier)) {
478
-			if (!@file_exists("$fichier.src")) {
479
-				spip_log("Image absente : $fichier");
480
-
481
-				return false;
482
-			}
483
-			# on reconstruit l'image source absente a partir de la chaine des .src
484
-			reconstruire_image_intermediaire($fichier);
485
-		}
486
-	}
487
-
488
-	if ($creer) {
489
-		spip_log(
490
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
491
-			'images' . _LOG_DEBUG
492
-		);
493
-	}
494
-
495
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
496
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
497
-	$ret['fichier'] = $fichier;
498
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
499
-	$ret['fichier_dest'] = $fichier_dest;
500
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
501
-	$ret['format_dest'] = $terminaison_dest;
502
-	$ret['date_src'] = $date_src;
503
-	$ret['creer'] = $creer;
504
-	$ret['class'] = extraire_attribut($img, 'class');
505
-	$ret['alt'] = extraire_attribut($img, 'alt');
506
-	$ret['style'] = extraire_attribut($img, 'style');
507
-	$ret['tag'] = $img;
508
-	if ($fonction_creation) {
509
-		$ret['reconstruction'] = $fonction_creation;
510
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
511
-		# cas de image_reduire qui finalement ne reduit pas l'image source
512
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
513
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
514
-	}
515
-
516
-	$ret = pipeline('image_preparer_filtre', [
517
-			'args' => [
518
-				'img' => $img,
519
-				'effet' => $effet,
520
-				'forcer_format' => $forcer_format,
521
-				'fonction_creation' => $fonction_creation,
522
-				'find_in_path' => $find_in_path,
523
-			],
524
-			'data' => $ret
525
-		]);
526
-
527
-	// une globale pour le debug en cas de crash memoire
528
-	$GLOBALS['derniere_image_calculee'] = $ret;
529
-
530
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
531
-	if ($term_fonction === 'svg') {
532
-		if ($creer and !$support_svg) {
533
-			process_image_svg_identite($ret);
534
-			$ret['creer'] = false;
535
-		}
536
-	}
537
-	else {
538
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
539
-			return false;
540
-		}
541
-	}
542
-
543
-	return $ret;
309
+    static $images_recalcul = [];
310
+    if (strlen($img) == 0) {
311
+        return false;
312
+    }
313
+
314
+    $source = trim(extraire_attribut($img, 'src'));
315
+    if (strlen($source) < 1) {
316
+        $source = $img;
317
+        $img = "<img src='$source' />";
318
+    } # gerer img src="data:....base64"
319
+    elseif (
320
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
321
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
322
+        and in_array($extension, _image_extensions_acceptees_en_entree())
323
+    ) {
324
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
325
+        if (!file_exists($local)) {
326
+            ecrire_fichier($local, base64_decode($regs[2]));
327
+        }
328
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
329
+            $sanitizer($local);
330
+        }
331
+        $source = $local;
332
+        $img = inserer_attribut($img, 'src', $source);
333
+        # eviter les mauvaises surprises lors de conversions de format
334
+        $img = inserer_attribut($img, 'width', '');
335
+        $img = inserer_attribut($img, 'height', '');
336
+    }
337
+
338
+    // les protocoles web prennent au moins 3 lettres
339
+    if (tester_url_absolue($source)) {
340
+        include_spip('inc/distant');
341
+        $fichier = _DIR_RACINE . copie_locale($source);
342
+        if (!$fichier) {
343
+            return '';
344
+        }
345
+        if (
346
+            $extension = _image_trouver_extension($fichier)
347
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
348
+        ) {
349
+            $sanitizer($fichier);
350
+        }
351
+    } else {
352
+        // enlever le timestamp eventuel
353
+        if (strpos($source, '?') !== false) {
354
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
355
+        }
356
+        if (
357
+            strpos($source, '?') !== false
358
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
359
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
360
+        ) {
361
+            $source = $f;
362
+        }
363
+        $fichier = $source;
364
+    }
365
+
366
+    $terminaison_dest = '';
367
+    if ($terminaison = _image_trouver_extension($fichier)) {
368
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
369
+    }
370
+
371
+    if (
372
+        $forcer_format !== false
373
+        // 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
374
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
375
+    ) {
376
+        $terminaison_dest = $forcer_format;
377
+    }
378
+
379
+    if (!$terminaison_dest) {
380
+        return false;
381
+    }
382
+
383
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
384
+    $fichier_dest = $nom_fichier;
385
+    if (
386
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
387
+        or @file_exists($f = $fichier)
388
+    ) {
389
+        // on passe la balise img a taille image qui exraira les attributs si possible
390
+        // au lieu de faire un acces disque sur le fichier
391
+        list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img);
392
+        $date_src = @filemtime($f);
393
+    } elseif (
394
+        @file_exists($f = "$fichier.src")
395
+        and lire_fichier($f, $valeurs)
396
+        and $valeurs = unserialize($valeurs)
397
+        and isset($valeurs['hauteur_dest'])
398
+        and isset($valeurs['largeur_dest'])
399
+    ) {
400
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
401
+        $ret['largeur'] = $valeurs['largeur_dest'];
402
+        $date_src = $valeurs['date'];
403
+    } // pas de fichier source par la
404
+    else {
405
+        return false;
406
+    }
407
+
408
+    // pas de taille mesurable
409
+    if (!($ret['hauteur'] or $ret['largeur'])) {
410
+        return false;
411
+    }
412
+
413
+    // les images calculees dependent du chemin du fichier source
414
+    // 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
415
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
416
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
417
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
418
+    // alors que ca concerne peu de site au final
419
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
420
+    $identifiant = $fichier;
421
+
422
+    // cas general :
423
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
424
+    // cas particulier de reduire :
425
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
426
+    $cache = 'cache-gd2';
427
+    if (substr($effet, 0, 7) == 'reduire') {
428
+        list(, $maxWidth, $maxHeight) = explode('-', $effet);
429
+        list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
430
+        $ret['largeur_dest'] = $destWidth;
431
+        $ret['hauteur_dest'] = $destHeight;
432
+        $effet = "L{$destWidth}xH$destHeight";
433
+        $cache = 'cache-vignettes';
434
+        $fichier_dest = basename($fichier_dest);
435
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
436
+            // on garde la terminaison initiale car image simplement copiee
437
+            // et on postfixe son nom avec un md5 du path
438
+            $terminaison_dest = $terminaison;
439
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
440
+        } else {
441
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
442
+        }
443
+        $cache = sous_repertoire(_DIR_VAR, $cache);
444
+        $cache = sous_repertoire($cache, $effet);
445
+    } else {
446
+        $fichier_dest = md5("$identifiant-$effet");
447
+        $cache = sous_repertoire(_DIR_VAR, $cache);
448
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
449
+        $fichier_dest = substr($fichier_dest, 2);
450
+    }
451
+
452
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
453
+
454
+    $GLOBALS['images_calculees'][] = $fichier_dest;
455
+
456
+    $creer = true;
457
+    // si recalcul des images demande, recalculer chaque image une fois
458
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
459
+        $images_recalcul[$fichier_dest] = true;
460
+    } else {
461
+        if (@file_exists($f = $fichier_dest)) {
462
+            if (filemtime($f) >= $date_src) {
463
+                $creer = false;
464
+            }
465
+        } else {
466
+            if (
467
+                @file_exists($f = "$fichier_dest.src")
468
+                and lire_fichier($f, $valeurs)
469
+                and $valeurs = unserialize($valeurs)
470
+                and $valeurs['date'] >= $date_src
471
+            ) {
472
+                $creer = false;
473
+            }
474
+        }
475
+    }
476
+    if ($creer) {
477
+        if (!@file_exists($fichier)) {
478
+            if (!@file_exists("$fichier.src")) {
479
+                spip_log("Image absente : $fichier");
480
+
481
+                return false;
482
+            }
483
+            # on reconstruit l'image source absente a partir de la chaine des .src
484
+            reconstruire_image_intermediaire($fichier);
485
+        }
486
+    }
487
+
488
+    if ($creer) {
489
+        spip_log(
490
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
491
+            'images' . _LOG_DEBUG
492
+        );
493
+    }
494
+
495
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
496
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
497
+    $ret['fichier'] = $fichier;
498
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
499
+    $ret['fichier_dest'] = $fichier_dest;
500
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
501
+    $ret['format_dest'] = $terminaison_dest;
502
+    $ret['date_src'] = $date_src;
503
+    $ret['creer'] = $creer;
504
+    $ret['class'] = extraire_attribut($img, 'class');
505
+    $ret['alt'] = extraire_attribut($img, 'alt');
506
+    $ret['style'] = extraire_attribut($img, 'style');
507
+    $ret['tag'] = $img;
508
+    if ($fonction_creation) {
509
+        $ret['reconstruction'] = $fonction_creation;
510
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
511
+        # cas de image_reduire qui finalement ne reduit pas l'image source
512
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
513
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
514
+    }
515
+
516
+    $ret = pipeline('image_preparer_filtre', [
517
+            'args' => [
518
+                'img' => $img,
519
+                'effet' => $effet,
520
+                'forcer_format' => $forcer_format,
521
+                'fonction_creation' => $fonction_creation,
522
+                'find_in_path' => $find_in_path,
523
+            ],
524
+            'data' => $ret
525
+        ]);
526
+
527
+    // une globale pour le debug en cas de crash memoire
528
+    $GLOBALS['derniere_image_calculee'] = $ret;
529
+
530
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
531
+    if ($term_fonction === 'svg') {
532
+        if ($creer and !$support_svg) {
533
+            process_image_svg_identite($ret);
534
+            $ret['creer'] = false;
535
+        }
536
+    }
537
+    else {
538
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
539
+            return false;
540
+        }
541
+    }
542
+
543
+    return $ret;
544 544
 }
545 545
 
546 546
 
@@ -549,53 +549,53 @@  discard block
 block discarded – undo
549 549
  * @return array
550 550
  */
551 551
 function _image_extensions_acceptees_en_entree() {
552
-	static $extensions = null;
553
-	if (empty($extensions)) {
554
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
555
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
556
-			// action=tester renseigne gd_formats et detecte le support de webp
557
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
558
-			$extensions = array_map('trim', $extensions);
559
-			$extensions = array_filter($extensions);
560
-			$extensions = array_unique($extensions);
561
-			if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
562
-			}
563
-		}
564
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
565
-	}
566
-
567
-	return $extensions;
552
+    static $extensions = null;
553
+    if (empty($extensions)) {
554
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
555
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
556
+            // action=tester renseigne gd_formats et detecte le support de webp
557
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
558
+            $extensions = array_map('trim', $extensions);
559
+            $extensions = array_filter($extensions);
560
+            $extensions = array_unique($extensions);
561
+            if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
562
+            }
563
+        }
564
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
565
+    }
566
+
567
+    return $extensions;
568 568
 }
569 569
 
570 570
 /**
571 571
  * @return array|string[]|null
572 572
  */
573 573
 function _image_extensions_acceptees_en_sortie() {
574
-	static $extensions = null;
575
-	if (empty($extensions)) {
576
-		$extensions = _image_extensions_acceptees_en_entree();
577
-		$extensions = array_diff($extensions, ['jpeg']);
578
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
579
-			$extensions = array_diff($extensions, ['gif']);
580
-		}
581
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
582
-			$extensions = array_diff($extensions, ['webp']);
583
-		}
584
-	}
585
-
586
-	return $extensions;
574
+    static $extensions = null;
575
+    if (empty($extensions)) {
576
+        $extensions = _image_extensions_acceptees_en_entree();
577
+        $extensions = array_diff($extensions, ['jpeg']);
578
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
579
+            $extensions = array_diff($extensions, ['gif']);
580
+        }
581
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
582
+            $extensions = array_diff($extensions, ['webp']);
583
+        }
584
+    }
585
+
586
+    return $extensions;
587 587
 }
588 588
 
589 589
 function _image_extension_normalisee($extension) {
590
-	$extension = strtolower($extension);
591
-	if ($extension === 'jpeg') {
592
-		$extension = 'jpg';
593
-	}
594
-	return $extension;
590
+    $extension = strtolower($extension);
591
+    if ($extension === 'jpeg') {
592
+        $extension = 'jpg';
593
+    }
594
+    return $extension;
595 595
 }
596 596
 
597 597
 function _image_extensions_conservent_transparence() {
598
-	return ['png', 'webp'];
598
+    return ['png', 'webp'];
599 599
 }
600 600
 
601 601
 
@@ -605,12 +605,12 @@  discard block
 block discarded – undo
605 605
  * @return string
606 606
  */
607 607
 function _image_trouver_extension($path) {
608
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
609
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
610
-		$terminaison = strtolower($regs[1]);
611
-		return $terminaison;
612
-	}
613
-	return '';
608
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
609
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
610
+        $terminaison = strtolower($regs[1]);
611
+        return $terminaison;
612
+    }
613
+    return '';
614 614
 }
615 615
 
616 616
 /**
@@ -621,33 +621,33 @@  discard block
 block discarded – undo
621 621
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
622 622
  */
623 623
 function _image_trouver_extension_pertinente($path) {
624
-	$path = supprimer_timestamp($path);
625
-	$terminaison = _image_trouver_extension($path);
626
-	if ($terminaison == 'jpg') {
627
-		$terminaison = 'jpeg';
628
-	}
629
-
630
-	if (!file_exists($path)) {
631
-		return $terminaison;
632
-	}
633
-
634
-	if (!$info = @spip_getimagesize($path)) {
635
-		return $terminaison;
636
-	}
637
-
638
-	if (isset($info['mime'])) {
639
-		$mime = $info['mime'];
640
-	}
641
-	else {
642
-		$mime = image_type_to_mime_type($info[2]);
643
-	}
644
-
645
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
646
-	if ($_terminaison and $_terminaison !== $terminaison) {
647
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
648
-		$terminaison = $_terminaison;
649
-	}
650
-	return $terminaison;
624
+    $path = supprimer_timestamp($path);
625
+    $terminaison = _image_trouver_extension($path);
626
+    if ($terminaison == 'jpg') {
627
+        $terminaison = 'jpeg';
628
+    }
629
+
630
+    if (!file_exists($path)) {
631
+        return $terminaison;
632
+    }
633
+
634
+    if (!$info = @spip_getimagesize($path)) {
635
+        return $terminaison;
636
+    }
637
+
638
+    if (isset($info['mime'])) {
639
+        $mime = $info['mime'];
640
+    }
641
+    else {
642
+        $mime = image_type_to_mime_type($info[2]);
643
+    }
644
+
645
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
646
+    if ($_terminaison and $_terminaison !== $terminaison) {
647
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
648
+        $terminaison = $_terminaison;
649
+    }
650
+    return $terminaison;
651 651
 }
652 652
 
653 653
 /**
@@ -655,36 +655,36 @@  discard block
 block discarded – undo
655 655
  * @return string
656 656
  */
657 657
 function _image_trouver_extension_depuis_mime($mime) {
658
-	switch (strtolower($mime)) {
659
-		case 'image/png':
660
-		case 'image/x-png':
661
-			$terminaison = 'png';
662
-			break;
663
-
664
-		case 'image/jpg':
665
-		case 'image/jpeg':
666
-		case 'image/pjpeg':
667
-			$terminaison = 'jpeg';
668
-			break;
669
-
670
-		case 'image/gif':
671
-			$terminaison = 'gif';
672
-			break;
673
-
674
-		case 'image/webp':
675
-		case 'image/x-webp':
676
-			$terminaison = 'webp';
677
-			break;
678
-
679
-		case 'image/svg+xml':
680
-			$terminaison = 'svg';
681
-			break;
682
-
683
-		default:
684
-			$terminaison = '';
685
-	}
686
-
687
-	return $terminaison;
658
+    switch (strtolower($mime)) {
659
+        case 'image/png':
660
+        case 'image/x-png':
661
+            $terminaison = 'png';
662
+            break;
663
+
664
+        case 'image/jpg':
665
+        case 'image/jpeg':
666
+        case 'image/pjpeg':
667
+            $terminaison = 'jpeg';
668
+            break;
669
+
670
+        case 'image/gif':
671
+            $terminaison = 'gif';
672
+            break;
673
+
674
+        case 'image/webp':
675
+        case 'image/x-webp':
676
+            $terminaison = 'webp';
677
+            break;
678
+
679
+        case 'image/svg+xml':
680
+            $terminaison = 'svg';
681
+            break;
682
+
683
+        default:
684
+            $terminaison = '';
685
+    }
686
+
687
+    return $terminaison;
688 688
 }
689 689
 
690 690
 
@@ -704,18 +704,18 @@  discard block
 block discarded – undo
704 704
  *     Une ressource de type Image GD.
705 705
  */
706 706
 function _imagecreatefrom_func(string $func, string $filename) {
707
-	if (!function_exists($func)) {
708
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
709
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
710
-		return null;
711
-	}
712
-	$img = @$func($filename);
713
-	if (!$img) {
714
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
715
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
716
-		$img = imagecreate(10, 10);
717
-	}
718
-	return $img;
707
+    if (!function_exists($func)) {
708
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
709
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
710
+        return null;
711
+    }
712
+    $img = @$func($filename);
713
+    if (!$img) {
714
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
715
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
716
+        $img = imagecreate(10, 10);
717
+    }
718
+    return $img;
719 719
 }
720 720
 
721 721
 /**
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
  *     Une ressource de type Image GD.
732 732
  */
733 733
 function _imagecreatefromjpeg($filename) {
734
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
734
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
735 735
 }
736 736
 
737 737
 /**
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
  *     Une ressource de type Image GD.
748 748
  */
749 749
 function _imagecreatefrompng($filename) {
750
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
750
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
751 751
 }
752 752
 
753 753
 /**
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
  *     Une ressource de type Image GD.
764 764
  */
765 765
 function _imagecreatefromgif($filename) {
766
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
766
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
767 767
 }
768 768
 
769 769
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
  *     Une ressource de type Image GD.
781 781
  */
782 782
 function _imagecreatefromwebp($filename) {
783
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
783
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
784 784
 }
785 785
 
786 786
 /**
@@ -798,24 +798,24 @@  discard block
 block discarded – undo
798 798
  *     - true si une image est bien retournée.
799 799
  */
800 800
 function _image_imagepng($img, $fichier) {
801
-	if (!function_exists('imagepng')) {
802
-		return false;
803
-	}
804
-	$tmp = $fichier . '.tmp';
805
-	$ret = imagepng($img, $tmp);
806
-	if (file_exists($tmp)) {
807
-		$taille_test = getimagesize($tmp);
808
-		if ($taille_test[0] < 1) {
809
-			return false;
810
-		}
811
-
812
-		spip_unlink($fichier); // le fichier peut deja exister
813
-		@rename($tmp, $fichier);
814
-
815
-		return $ret;
816
-	}
817
-
818
-	return false;
801
+    if (!function_exists('imagepng')) {
802
+        return false;
803
+    }
804
+    $tmp = $fichier . '.tmp';
805
+    $ret = imagepng($img, $tmp);
806
+    if (file_exists($tmp)) {
807
+        $taille_test = getimagesize($tmp);
808
+        if ($taille_test[0] < 1) {
809
+            return false;
810
+        }
811
+
812
+        spip_unlink($fichier); // le fichier peut deja exister
813
+        @rename($tmp, $fichier);
814
+
815
+        return $ret;
816
+    }
817
+
818
+    return false;
819 819
 }
820 820
 
821 821
 /**
@@ -833,24 +833,24 @@  discard block
 block discarded – undo
833 833
  *     - true si une image est bien retournée.
834 834
  */
835 835
 function _image_imagegif($img, $fichier) {
836
-	if (!function_exists('imagegif')) {
837
-		return false;
838
-	}
839
-	$tmp = $fichier . '.tmp';
840
-	$ret = imagegif($img, $tmp);
841
-	if (file_exists($tmp)) {
842
-		$taille_test = getimagesize($tmp);
843
-		if ($taille_test[0] < 1) {
844
-			return false;
845
-		}
846
-
847
-		spip_unlink($fichier); // le fichier peut deja exister
848
-		@rename($tmp, $fichier);
849
-
850
-		return $ret;
851
-	}
852
-
853
-	return false;
836
+    if (!function_exists('imagegif')) {
837
+        return false;
838
+    }
839
+    $tmp = $fichier . '.tmp';
840
+    $ret = imagegif($img, $tmp);
841
+    if (file_exists($tmp)) {
842
+        $taille_test = getimagesize($tmp);
843
+        if ($taille_test[0] < 1) {
844
+            return false;
845
+        }
846
+
847
+        spip_unlink($fichier); // le fichier peut deja exister
848
+        @rename($tmp, $fichier);
849
+
850
+        return $ret;
851
+    }
852
+
853
+    return false;
854 854
 }
855 855
 
856 856
 /**
@@ -873,29 +873,29 @@  discard block
 block discarded – undo
873 873
  *     - true si une image est bien retournée.
874 874
  */
875 875
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
876
-	if (!function_exists('imagejpeg')) {
877
-		return false;
878
-	}
879
-	$tmp = $fichier . '.tmp';
876
+    if (!function_exists('imagejpeg')) {
877
+        return false;
878
+    }
879
+    $tmp = $fichier . '.tmp';
880 880
 
881
-	// Enable interlancing
882
-	imageinterlace($img, true);
881
+    // Enable interlancing
882
+    imageinterlace($img, true);
883 883
 
884
-	$ret = imagejpeg($img, $tmp, $qualite);
884
+    $ret = imagejpeg($img, $tmp, $qualite);
885 885
 
886
-	if (file_exists($tmp)) {
887
-		$taille_test = getimagesize($tmp);
888
-		if ($taille_test[0] < 1) {
889
-			return false;
890
-		}
886
+    if (file_exists($tmp)) {
887
+        $taille_test = getimagesize($tmp);
888
+        if ($taille_test[0] < 1) {
889
+            return false;
890
+        }
891 891
 
892
-		spip_unlink($fichier); // le fichier peut deja exister
893
-		@rename($tmp, $fichier);
892
+        spip_unlink($fichier); // le fichier peut deja exister
893
+        @rename($tmp, $fichier);
894 894
 
895
-		return $ret;
896
-	}
895
+        return $ret;
896
+    }
897 897
 
898
-	return false;
898
+    return false;
899 899
 }
900 900
 
901 901
 /**
@@ -913,9 +913,9 @@  discard block
 block discarded – undo
913 913
  *     true si le fichier a bien été créé ; false sinon.
914 914
  */
915 915
 function _image_imageico($img, $fichier) {
916
-	$gd_image_array = [$img];
916
+    $gd_image_array = [$img];
917 917
 
918
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
918
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
919 919
 }
920 920
 
921 921
 
@@ -934,24 +934,24 @@  discard block
 block discarded – undo
934 934
  *     - true si une image est bien retournée.
935 935
  */
936 936
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
937
-	if (!function_exists('imagewebp')) {
938
-		return false;
939
-	}
940
-	$tmp = $fichier . '.tmp';
941
-	$ret = imagewebp($img, $tmp, $qualite);
942
-	if (file_exists($tmp)) {
943
-		$taille_test = getimagesize($tmp);
944
-		if ($taille_test[0] < 1) {
945
-			return false;
946
-		}
947
-
948
-		spip_unlink($fichier); // le fichier peut deja exister
949
-		@rename($tmp, $fichier);
950
-
951
-		return $ret;
952
-	}
953
-
954
-	return false;
937
+    if (!function_exists('imagewebp')) {
938
+        return false;
939
+    }
940
+    $tmp = $fichier . '.tmp';
941
+    $ret = imagewebp($img, $tmp, $qualite);
942
+    if (file_exists($tmp)) {
943
+        $taille_test = getimagesize($tmp);
944
+        if ($taille_test[0] < 1) {
945
+            return false;
946
+        }
947
+
948
+        spip_unlink($fichier); // le fichier peut deja exister
949
+        @rename($tmp, $fichier);
950
+
951
+        return $ret;
952
+    }
953
+
954
+    return false;
955 955
 }
956 956
 
957 957
 /**
@@ -971,35 +971,35 @@  discard block
 block discarded – undo
971 971
  */
972 972
 function _image_imagesvg($img, $fichier) {
973 973
 
974
-	$tmp = $fichier . '.tmp';
975
-	if (strpos($img, '<') === false) {
976
-		$img = supprimer_timestamp($img);
977
-		if (!file_exists($img)) {
978
-			return false;
979
-		}
980
-		@copy($img, $tmp);
981
-		if (filesize($tmp) == filesize($img)) {
982
-			spip_unlink($fichier); // le fichier peut deja exister
983
-			@rename($tmp, $fichier);
984
-			return true;
985
-		}
986
-		return false;
987
-	}
988
-
989
-	file_put_contents($tmp, $img);
990
-	if (file_exists($tmp)) {
991
-		$taille_test = spip_getimagesize($tmp);
992
-		if ($taille_test[0] < 1) {
993
-			return false;
994
-		}
995
-
996
-		spip_unlink($fichier); // le fichier peut deja exister
997
-		@rename($tmp, $fichier);
998
-
999
-		return true;
1000
-	}
1001
-
1002
-	return false;
974
+    $tmp = $fichier . '.tmp';
975
+    if (strpos($img, '<') === false) {
976
+        $img = supprimer_timestamp($img);
977
+        if (!file_exists($img)) {
978
+            return false;
979
+        }
980
+        @copy($img, $tmp);
981
+        if (filesize($tmp) == filesize($img)) {
982
+            spip_unlink($fichier); // le fichier peut deja exister
983
+            @rename($tmp, $fichier);
984
+            return true;
985
+        }
986
+        return false;
987
+    }
988
+
989
+    file_put_contents($tmp, $img);
990
+    if (file_exists($tmp)) {
991
+        $taille_test = spip_getimagesize($tmp);
992
+        if ($taille_test[0] < 1) {
993
+            return false;
994
+        }
995
+
996
+        spip_unlink($fichier); // le fichier peut deja exister
997
+        @rename($tmp, $fichier);
998
+
999
+        return true;
1000
+    }
1001
+
1002
+    return false;
1003 1003
 }
1004 1004
 
1005 1005
 
@@ -1027,29 +1027,29 @@  discard block
 block discarded – undo
1027 1027
  *     - false sinon.
1028 1028
  */
1029 1029
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1030
-	if (is_null($fonction)) {
1031
-		$fonction = '_image_image' . $valeurs['format_dest'];
1032
-	}
1033
-	$ret = false;
1034
-	#un flag pour reperer les images gravees
1035
-	$lock =
1036
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1037
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1038
-	if (
1039
-		function_exists($fonction)
1040
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1041
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1042
-		&& !$lock
1043
-	) {
1044
-		if (@file_exists($valeurs['fichier_dest'])) {
1045
-			// dans tous les cas mettre a jour la taille de l'image finale
1046
-			list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1047
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1048
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1049
-		}
1050
-	}
1051
-
1052
-	return $ret;
1030
+    if (is_null($fonction)) {
1031
+        $fonction = '_image_image' . $valeurs['format_dest'];
1032
+    }
1033
+    $ret = false;
1034
+    #un flag pour reperer les images gravees
1035
+    $lock =
1036
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1037
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1038
+    if (
1039
+        function_exists($fonction)
1040
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1041
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1042
+        && !$lock
1043
+    ) {
1044
+        if (@file_exists($valeurs['fichier_dest'])) {
1045
+            // dans tous les cas mettre a jour la taille de l'image finale
1046
+            list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1047
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1048
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1049
+        }
1050
+    }
1051
+
1052
+    return $ret;
1053 1053
 }
1054 1054
 
1055 1055
 /**
@@ -1062,27 +1062,27 @@  discard block
 block discarded – undo
1062 1062
  *     Chemin vers le fichier manquant
1063 1063
  **/
1064 1064
 function reconstruire_image_intermediaire($fichier_manquant) {
1065
-	$reconstruire = [];
1066
-	$fichier = $fichier_manquant;
1067
-	while (
1068
-		strpos($fichier, '://') === false
1069
-		and !@file_exists($fichier)
1070
-		and lire_fichier($src = "$fichier.src", $source)
1071
-		and $valeurs = unserialize($source)
1072
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1073
-	) {
1074
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1075
-		$reconstruire[] = $valeurs['reconstruction'];
1076
-	}
1077
-	while (count($reconstruire)) {
1078
-		$r = array_pop($reconstruire);
1079
-		$fonction = $r[0];
1080
-		$args = $r[1];
1081
-		call_user_func_array($fonction, $args);
1082
-	}
1083
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1084
-	// mais l'on peut nettoyer les miettes de sa creation
1085
-	ramasse_miettes($fichier_manquant);
1065
+    $reconstruire = [];
1066
+    $fichier = $fichier_manquant;
1067
+    while (
1068
+        strpos($fichier, '://') === false
1069
+        and !@file_exists($fichier)
1070
+        and lire_fichier($src = "$fichier.src", $source)
1071
+        and $valeurs = unserialize($source)
1072
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1073
+    ) {
1074
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1075
+        $reconstruire[] = $valeurs['reconstruction'];
1076
+    }
1077
+    while (count($reconstruire)) {
1078
+        $r = array_pop($reconstruire);
1079
+        $fonction = $r[0];
1080
+        $args = $r[1];
1081
+        call_user_func_array($fonction, $args);
1082
+    }
1083
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1084
+    // mais l'on peut nettoyer les miettes de sa creation
1085
+    ramasse_miettes($fichier_manquant);
1086 1086
 }
1087 1087
 
1088 1088
 /**
@@ -1102,28 +1102,28 @@  discard block
 block discarded – undo
1102 1102
  *     Chemin du fichier d'image calculé
1103 1103
  **/
1104 1104
 function ramasse_miettes($fichier) {
1105
-	if (
1106
-		strpos($fichier, '://') !== false
1107
-		or !lire_fichier($src = "$fichier.src", $source)
1108
-		or !$valeurs = unserialize($source)
1109
-	) {
1110
-		return;
1111
-	}
1112
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1113
-	while (
1114
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1115
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1116
-		and (lire_fichier(
1117
-			$src = "$fichier.src",
1118
-			$source
1119
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1120
-		and ($valeurs = unserialize($source))  # et valide
1121
-	) {
1122
-		# on efface le fichier
1123
-		spip_unlink($fichier);
1124
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1125
-		#spip_unlink($src);
1126
-	}
1105
+    if (
1106
+        strpos($fichier, '://') !== false
1107
+        or !lire_fichier($src = "$fichier.src", $source)
1108
+        or !$valeurs = unserialize($source)
1109
+    ) {
1110
+        return;
1111
+    }
1112
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1113
+    while (
1114
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1115
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1116
+        and (lire_fichier(
1117
+            $src = "$fichier.src",
1118
+            $source
1119
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1120
+        and ($valeurs = unserialize($source))  # et valide
1121
+    ) {
1122
+        # on efface le fichier
1123
+        spip_unlink($fichier);
1124
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1125
+        #spip_unlink($src);
1126
+    }
1127 1127
 }
1128 1128
 
1129 1129
 
@@ -1148,71 +1148,71 @@  discard block
 block discarded – undo
1148 1148
  *     Code HTML de l'image
1149 1149
  **/
1150 1150
 function image_graver($img) {
1151
-	// appeler le filtre post_image_filtrer qui permet de faire
1152
-	// des traitements auto a la fin d'une serie de filtres
1153
-	$img = pipeline('post_image_filtrer', $img);
1154
-
1155
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1156
-	if (($p = strpos($fichier, '?')) !== false) {
1157
-		$fichier = substr($fichier, 0, $p);
1158
-	}
1159
-	if (strlen($fichier) < 1) {
1160
-		$fichier = $img;
1161
-	}
1162
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1163
-	# et qu'il ne s'agit pas d'une URL
1164
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1165
-		reconstruire_image_intermediaire($fichier);
1166
-	}
1167
-	ramasse_miettes($fichier);
1168
-
1169
-	// ajouter le timestamp si besoin
1170
-	if (strpos($fichier_ori, '?') === false) {
1171
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1172
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1173
-	}
1174
-
1175
-	return $img;
1151
+    // appeler le filtre post_image_filtrer qui permet de faire
1152
+    // des traitements auto a la fin d'une serie de filtres
1153
+    $img = pipeline('post_image_filtrer', $img);
1154
+
1155
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1156
+    if (($p = strpos($fichier, '?')) !== false) {
1157
+        $fichier = substr($fichier, 0, $p);
1158
+    }
1159
+    if (strlen($fichier) < 1) {
1160
+        $fichier = $img;
1161
+    }
1162
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1163
+    # et qu'il ne s'agit pas d'une URL
1164
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1165
+        reconstruire_image_intermediaire($fichier);
1166
+    }
1167
+    ramasse_miettes($fichier);
1168
+
1169
+    // ajouter le timestamp si besoin
1170
+    if (strpos($fichier_ori, '?') === false) {
1171
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1172
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1173
+    }
1174
+
1175
+    return $img;
1176 1176
 }
1177 1177
 
1178 1178
 
1179 1179
 if (!function_exists('imagepalettetotruecolor')) {
1180
-	/**
1181
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1182
-	 *
1183
-	 * @note Pour compatibilité avec PHP < 5.5
1184
-	 *
1185
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1186
-	 *
1187
-	 * @param ressource $img
1188
-	 * @return bool
1189
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
1190
-	 *     - false si la transformation ne peut être faite.
1191
-	 **/
1192
-	function imagepalettetotruecolor(&$img) {
1193
-		if (!$img or !function_exists('imagecreatetruecolor')) {
1194
-			return false;
1195
-		} elseif (!imageistruecolor($img)) {
1196
-			$w = imagesx($img);
1197
-			$h = imagesy($img);
1198
-			$img1 = imagecreatetruecolor($w, $h);
1199
-			//Conserver la transparence si possible
1200
-			if (function_exists('ImageCopyResampled')) {
1201
-				if (function_exists('imageAntiAlias')) {
1202
-					imageAntiAlias($img1, true);
1203
-				}
1204
-				@imagealphablending($img1, false);
1205
-				@imagesavealpha($img1, true);
1206
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1207
-			} else {
1208
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1209
-			}
1210
-
1211
-			$img = $img1;
1212
-		}
1213
-
1214
-		return true;
1215
-	}
1180
+    /**
1181
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1182
+     *
1183
+     * @note Pour compatibilité avec PHP < 5.5
1184
+     *
1185
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1186
+     *
1187
+     * @param ressource $img
1188
+     * @return bool
1189
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
1190
+     *     - false si la transformation ne peut être faite.
1191
+     **/
1192
+    function imagepalettetotruecolor(&$img) {
1193
+        if (!$img or !function_exists('imagecreatetruecolor')) {
1194
+            return false;
1195
+        } elseif (!imageistruecolor($img)) {
1196
+            $w = imagesx($img);
1197
+            $h = imagesy($img);
1198
+            $img1 = imagecreatetruecolor($w, $h);
1199
+            //Conserver la transparence si possible
1200
+            if (function_exists('ImageCopyResampled')) {
1201
+                if (function_exists('imageAntiAlias')) {
1202
+                    imageAntiAlias($img1, true);
1203
+                }
1204
+                @imagealphablending($img1, false);
1205
+                @imagesavealpha($img1, true);
1206
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1207
+            } else {
1208
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1209
+            }
1210
+
1211
+            $img = $img1;
1212
+        }
1213
+
1214
+        return true;
1215
+    }
1216 1216
 }
1217 1217
 
1218 1218
 /**
@@ -1239,32 +1239,32 @@  discard block
 block discarded – undo
1239 1239
  *     Code html modifié de la balise.
1240 1240
  **/
1241 1241
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1242
-	if ($style === false) {
1243
-		$style = extraire_attribut($tag, 'style');
1244
-	}
1245
-
1246
-	// enlever le width et height du style
1247
-	$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1248
-	if ($style and $style[0] == ';') {
1249
-		$style = substr($style, 1);
1250
-	}
1251
-
1252
-	// mettre des attributs de width et height sur les images,
1253
-	// ca accelere le rendu du navigateur
1254
-	// ca permet aux navigateurs de reserver la bonne taille
1255
-	// quand on a desactive l'affichage des images.
1256
-	$tag = inserer_attribut($tag, 'width', round($width));
1257
-	$tag = inserer_attribut($tag, 'height', round($height));
1258
-
1259
-	// attributs deprecies. Transformer en CSS
1260
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1261
-		$style = "margin:${espace}px;" . $style;
1262
-		$tag = inserer_attribut($tag, 'hspace', '');
1263
-	}
1264
-
1265
-	$tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
1266
-
1267
-	return $tag;
1242
+    if ($style === false) {
1243
+        $style = extraire_attribut($tag, 'style');
1244
+    }
1245
+
1246
+    // enlever le width et height du style
1247
+    $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1248
+    if ($style and $style[0] == ';') {
1249
+        $style = substr($style, 1);
1250
+    }
1251
+
1252
+    // mettre des attributs de width et height sur les images,
1253
+    // ca accelere le rendu du navigateur
1254
+    // ca permet aux navigateurs de reserver la bonne taille
1255
+    // quand on a desactive l'affichage des images.
1256
+    $tag = inserer_attribut($tag, 'width', round($width));
1257
+    $tag = inserer_attribut($tag, 'height', round($height));
1258
+
1259
+    // attributs deprecies. Transformer en CSS
1260
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1261
+        $style = "margin:${espace}px;" . $style;
1262
+        $tag = inserer_attribut($tag, 'hspace', '');
1263
+    }
1264
+
1265
+    $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
1266
+
1267
+    return $tag;
1268 1268
 }
1269 1269
 
1270 1270
 
@@ -1290,72 +1290,72 @@  discard block
 block discarded – undo
1290 1290
  *     Retourne le code HTML de l'image
1291 1291
  **/
1292 1292
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1293
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1294
-
1295
-	// fermer les tags img pas bien fermes;
1296
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1297
-
1298
-	// le style
1299
-	$style = $valeurs['style'];
1300
-	if (isset($surcharge['style'])) {
1301
-		$style = $surcharge['style'];
1302
-		unset($surcharge['style']);
1303
-	}
1304
-
1305
-	// traiter specifiquement la largeur et la hauteur
1306
-	$width = $valeurs['largeur'];
1307
-	if (isset($surcharge['width'])) {
1308
-		$width = $surcharge['width'];
1309
-		unset($surcharge['width']);
1310
-	}
1311
-	$height = $valeurs['hauteur'];
1312
-	if (isset($surcharge['height'])) {
1313
-		$height = $surcharge['height'];
1314
-		unset($surcharge['height']);
1315
-	}
1316
-
1317
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1318
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1319
-	// on remplace toute les ref a src dans le tag
1320
-	$src = extraire_attribut($tag, 'src');
1321
-	if (isset($surcharge['src'])) {
1322
-		$tag = str_replace($src, $surcharge['src'], $tag);
1323
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1324
-		// pas garanti comme methode, mais mieux que rien
1325
-		if (strpos($src, '&') !== false) {
1326
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1327
-		}
1328
-		$src = $surcharge['src'];
1329
-		unset($surcharge['src']);
1330
-	}
1331
-
1332
-	$class = $valeurs['class'];
1333
-	if (isset($surcharge['class'])) {
1334
-		$class = $surcharge['class'];
1335
-		unset($surcharge['class']);
1336
-	}
1337
-	if (strlen($class)) {
1338
-		$tag = inserer_attribut($tag, 'class', $class);
1339
-	}
1340
-
1341
-	if (count($surcharge)) {
1342
-		foreach ($surcharge as $attribut => $valeur) {
1343
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1344
-		}
1345
-	}
1346
-
1347
-	$tag = pipeline(
1348
-		'image_ecrire_tag_finir',
1349
-		[
1350
-			'args' => [
1351
-				'valeurs' => $valeurs,
1352
-				'surcharge' => $surcharge,
1353
-			],
1354
-			'data' => $tag
1355
-		]
1356
-	);
1357
-
1358
-	return $tag;
1293
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1294
+
1295
+    // fermer les tags img pas bien fermes;
1296
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1297
+
1298
+    // le style
1299
+    $style = $valeurs['style'];
1300
+    if (isset($surcharge['style'])) {
1301
+        $style = $surcharge['style'];
1302
+        unset($surcharge['style']);
1303
+    }
1304
+
1305
+    // traiter specifiquement la largeur et la hauteur
1306
+    $width = $valeurs['largeur'];
1307
+    if (isset($surcharge['width'])) {
1308
+        $width = $surcharge['width'];
1309
+        unset($surcharge['width']);
1310
+    }
1311
+    $height = $valeurs['hauteur'];
1312
+    if (isset($surcharge['height'])) {
1313
+        $height = $surcharge['height'];
1314
+        unset($surcharge['height']);
1315
+    }
1316
+
1317
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1318
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1319
+    // on remplace toute les ref a src dans le tag
1320
+    $src = extraire_attribut($tag, 'src');
1321
+    if (isset($surcharge['src'])) {
1322
+        $tag = str_replace($src, $surcharge['src'], $tag);
1323
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1324
+        // pas garanti comme methode, mais mieux que rien
1325
+        if (strpos($src, '&') !== false) {
1326
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1327
+        }
1328
+        $src = $surcharge['src'];
1329
+        unset($surcharge['src']);
1330
+    }
1331
+
1332
+    $class = $valeurs['class'];
1333
+    if (isset($surcharge['class'])) {
1334
+        $class = $surcharge['class'];
1335
+        unset($surcharge['class']);
1336
+    }
1337
+    if (strlen($class)) {
1338
+        $tag = inserer_attribut($tag, 'class', $class);
1339
+    }
1340
+
1341
+    if (count($surcharge)) {
1342
+        foreach ($surcharge as $attribut => $valeur) {
1343
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1344
+        }
1345
+    }
1346
+
1347
+    $tag = pipeline(
1348
+        'image_ecrire_tag_finir',
1349
+        [
1350
+            'args' => [
1351
+                'valeurs' => $valeurs,
1352
+                'surcharge' => $surcharge,
1353
+            ],
1354
+            'data' => $tag
1355
+        ]
1356
+    );
1357
+
1358
+    return $tag;
1359 1359
 }
1360 1360
 
1361 1361
 /**
@@ -1378,257 +1378,257 @@  discard block
 block discarded – undo
1378 1378
  *     Description de l'image, sinon null.
1379 1379
  **/
1380 1380
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1381
-	// ordre de preference des formats graphiques pour creer les vignettes
1382
-	// le premier format disponible, selon la methode demandee, est utilise
1383
-	$image = $valeurs['fichier'];
1384
-	$format = $valeurs['format_source'];
1385
-	$destdir = dirname($valeurs['fichier_dest']);
1386
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1387
-
1388
-	$format_sortie = $valeurs['format_dest'];
1389
-
1390
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1391
-		$process = $GLOBALS['meta']['image_process'];
1392
-	}
1393
-
1394
-	// si le doc n'est pas une image dans un format accetpable, refuser
1395
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1396
-		return;
1397
-	}
1398
-	$destination = "$destdir/$destfile";
1399
-
1400
-	// calculer la taille
1401
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1402
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1403
-			list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1404
-		}
1405
-	} elseif ($process == 'convert' or $process == 'imagick') {
1406
-		$destWidth = $maxWidth;
1407
-		$destHeight = $maxHeight;
1408
-	} else {
1409
-		spip_log("echec $process sur $image");
1410
-
1411
-		return;
1412
-	}
1413
-
1414
-	$vignette = '';
1415
-
1416
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1417
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1418
-		$vignette = $destination . '.' . $format;
1419
-		@copy($image, $vignette);
1420
-	}
1421
-
1422
-	elseif ($valeurs['format_source'] === 'svg') {
1423
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1424
-			$format_sortie = 'svg';
1425
-			$vignette = $destination . '.' . $format_sortie;
1426
-			$valeurs['fichier_dest'] = $vignette;
1427
-			_image_gd_output($svg, $valeurs);
1428
-		}
1429
-	}
1430
-
1431
-	// imagemagick en ligne de commande
1432
-	elseif ($process == 'convert') {
1433
-		if (!defined('_CONVERT_COMMAND')) {
1434
-			define('_CONVERT_COMMAND', 'convert');
1435
-		} // Securite : mes_options.php peut preciser le chemin absolu
1436
-		if (!defined('_RESIZE_COMMAND')) {
1437
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1438
-		}
1439
-		$vignette = $destination . '.' . $format_sortie;
1440
-		$commande = str_replace(
1441
-			['%x', '%y', '%src', '%dest'],
1442
-			[
1443
-				$destWidth,
1444
-				$destHeight,
1445
-				escapeshellcmd($image),
1446
-				escapeshellcmd($vignette)
1447
-			],
1448
-			_RESIZE_COMMAND
1449
-		);
1450
-		spip_log($commande);
1451
-		exec($commande);
1452
-		if (!@file_exists($vignette)) {
1453
-			spip_log("echec convert sur $vignette");
1454
-
1455
-			return;  // echec commande
1456
-		}
1457
-	}
1458
-
1459
-	// php5 imagemagick
1460
-	elseif ($process == 'imagick') {
1461
-		$vignette = "$destination." . $format_sortie;
1462
-
1463
-		if (!class_exists('Imagick')) {
1464
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1465
-
1466
-			return;
1467
-		}
1468
-		$imagick = new Imagick();
1469
-		$imagick->readImage($image);
1470
-		$imagick->resizeImage(
1471
-			$destWidth,
1472
-			$destHeight,
1473
-			Imagick::FILTER_LANCZOS,
1474
-			1
1475
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1476
-		$imagick->writeImage($vignette);
1477
-
1478
-		if (!@file_exists($vignette)) {
1479
-			spip_log("echec imagick sur $vignette");
1480
-
1481
-			return;
1482
-		}
1483
-	}
1484
-
1485
-	// netpbm
1486
-	elseif ($process == 'netpbm') {
1487
-		if (!defined('_PNMSCALE_COMMAND')) {
1488
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1489
-		} // Securite : mes_options.php peut preciser le chemin absolu
1490
-		if (_PNMSCALE_COMMAND == '') {
1491
-			return;
1492
-		}
1493
-		$vignette = $destination . '.' . $format_sortie;
1494
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1495
-		if ($format == 'jpg') {
1496
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1497
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1498
-			if (!($s = @filesize($vignette))) {
1499
-				spip_unlink($vignette);
1500
-			}
1501
-			if (!@file_exists($vignette)) {
1502
-				spip_log("echec netpbm-jpg sur $vignette");
1503
-
1504
-				return;
1505
-			}
1506
-		} else {
1507
-			if ($format == 'gif') {
1508
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1509
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1510
-				if (!($s = @filesize($vignette))) {
1511
-					spip_unlink($vignette);
1512
-				}
1513
-				if (!@file_exists($vignette)) {
1514
-					spip_log("echec netpbm-gif sur $vignette");
1515
-
1516
-					return;
1517
-				}
1518
-			} else {
1519
-				if ($format == 'png') {
1520
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1521
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1522
-					if (!($s = @filesize($vignette))) {
1523
-						spip_unlink($vignette);
1524
-					}
1525
-					if (!@file_exists($vignette)) {
1526
-						spip_log("echec netpbm-png sur $vignette");
1527
-
1528
-						return;
1529
-					}
1530
-				}
1531
-			}
1532
-		}
1533
-	}
1534
-
1535
-	// gd ou gd2
1536
-	elseif ($process == 'gd1' or $process == 'gd2') {
1537
-		if (!function_exists('gd_info')) {
1538
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1539
-
1540
-			return;
1541
-		}
1542
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1543
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1544
-
1545
-			return;
1546
-		}
1547
-		$destFormat = $format_sortie;
1548
-		if (!$destFormat) {
1549
-			spip_log("pas de format pour $image");
1550
-
1551
-			return;
1552
-		}
1553
-
1554
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1555
-		if (!function_exists($fonction_imagecreatefrom)) {
1556
-			return '';
1557
-		}
1558
-		$srcImage = @$fonction_imagecreatefrom($image);
1559
-		if (!$srcImage) {
1560
-			spip_log('echec gd1/gd2');
1561
-
1562
-			return;
1563
-		}
1564
-
1565
-		// Initialisation de l'image destination
1566
-		$destImage = null;
1567
-		if ($process == 'gd2' and $destFormat != 'gif') {
1568
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1569
-		}
1570
-		if (!$destImage) {
1571
-			$destImage = ImageCreate($destWidth, $destHeight);
1572
-		}
1573
-
1574
-		// Recopie de l'image d'origine avec adaptation de la taille
1575
-		$ok = false;
1576
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1577
-			if ($format == 'gif') {
1578
-				// Si un GIF est transparent,
1579
-				// fabriquer un PNG transparent
1580
-				$transp = imagecolortransparent($srcImage);
1581
-				if ($transp > 0) {
1582
-					$destFormat = 'png';
1583
-				}
1584
-			}
1585
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1586
-				// Conserver la transparence
1587
-				if (function_exists('imageAntiAlias')) {
1588
-					imageAntiAlias($destImage, true);
1589
-				}
1590
-				@imagealphablending($destImage, false);
1591
-				@imagesavealpha($destImage, true);
1592
-			}
1593
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1594
-		}
1595
-		if (!$ok) {
1596
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1597
-		}
1598
-
1599
-		// Sauvegarde de l'image destination
1600
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1601
-		$valeurs['format_dest'] = $format = $destFormat;
1602
-		_image_gd_output($destImage, $valeurs);
1603
-
1604
-		if ($srcImage) {
1605
-			ImageDestroy($srcImage);
1606
-		}
1607
-		ImageDestroy($destImage);
1608
-	}
1609
-
1610
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1611
-		$size = [$destWidth, $destHeight];
1612
-	}
1613
-
1614
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1615
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1616
-	if ($size[0] < 1) {
1617
-		$size[0] = $destWidth;
1618
-	}
1619
-	if ($size[1] < 1) {
1620
-		$size[1] = $destHeight;
1621
-	}
1622
-
1623
-	$retour['width'] = $largeur = $size[0];
1624
-	$retour['height'] = $hauteur = $size[1];
1625
-
1626
-	$retour['fichier'] = $vignette;
1627
-	$retour['format'] = $format;
1628
-	$retour['date'] = @filemtime($vignette);
1629
-
1630
-	// renvoyer l'image
1631
-	return $retour;
1381
+    // ordre de preference des formats graphiques pour creer les vignettes
1382
+    // le premier format disponible, selon la methode demandee, est utilise
1383
+    $image = $valeurs['fichier'];
1384
+    $format = $valeurs['format_source'];
1385
+    $destdir = dirname($valeurs['fichier_dest']);
1386
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1387
+
1388
+    $format_sortie = $valeurs['format_dest'];
1389
+
1390
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1391
+        $process = $GLOBALS['meta']['image_process'];
1392
+    }
1393
+
1394
+    // si le doc n'est pas une image dans un format accetpable, refuser
1395
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1396
+        return;
1397
+    }
1398
+    $destination = "$destdir/$destfile";
1399
+
1400
+    // calculer la taille
1401
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1402
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1403
+            list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1404
+        }
1405
+    } elseif ($process == 'convert' or $process == 'imagick') {
1406
+        $destWidth = $maxWidth;
1407
+        $destHeight = $maxHeight;
1408
+    } else {
1409
+        spip_log("echec $process sur $image");
1410
+
1411
+        return;
1412
+    }
1413
+
1414
+    $vignette = '';
1415
+
1416
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1417
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1418
+        $vignette = $destination . '.' . $format;
1419
+        @copy($image, $vignette);
1420
+    }
1421
+
1422
+    elseif ($valeurs['format_source'] === 'svg') {
1423
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1424
+            $format_sortie = 'svg';
1425
+            $vignette = $destination . '.' . $format_sortie;
1426
+            $valeurs['fichier_dest'] = $vignette;
1427
+            _image_gd_output($svg, $valeurs);
1428
+        }
1429
+    }
1430
+
1431
+    // imagemagick en ligne de commande
1432
+    elseif ($process == 'convert') {
1433
+        if (!defined('_CONVERT_COMMAND')) {
1434
+            define('_CONVERT_COMMAND', 'convert');
1435
+        } // Securite : mes_options.php peut preciser le chemin absolu
1436
+        if (!defined('_RESIZE_COMMAND')) {
1437
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1438
+        }
1439
+        $vignette = $destination . '.' . $format_sortie;
1440
+        $commande = str_replace(
1441
+            ['%x', '%y', '%src', '%dest'],
1442
+            [
1443
+                $destWidth,
1444
+                $destHeight,
1445
+                escapeshellcmd($image),
1446
+                escapeshellcmd($vignette)
1447
+            ],
1448
+            _RESIZE_COMMAND
1449
+        );
1450
+        spip_log($commande);
1451
+        exec($commande);
1452
+        if (!@file_exists($vignette)) {
1453
+            spip_log("echec convert sur $vignette");
1454
+
1455
+            return;  // echec commande
1456
+        }
1457
+    }
1458
+
1459
+    // php5 imagemagick
1460
+    elseif ($process == 'imagick') {
1461
+        $vignette = "$destination." . $format_sortie;
1462
+
1463
+        if (!class_exists('Imagick')) {
1464
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1465
+
1466
+            return;
1467
+        }
1468
+        $imagick = new Imagick();
1469
+        $imagick->readImage($image);
1470
+        $imagick->resizeImage(
1471
+            $destWidth,
1472
+            $destHeight,
1473
+            Imagick::FILTER_LANCZOS,
1474
+            1
1475
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1476
+        $imagick->writeImage($vignette);
1477
+
1478
+        if (!@file_exists($vignette)) {
1479
+            spip_log("echec imagick sur $vignette");
1480
+
1481
+            return;
1482
+        }
1483
+    }
1484
+
1485
+    // netpbm
1486
+    elseif ($process == 'netpbm') {
1487
+        if (!defined('_PNMSCALE_COMMAND')) {
1488
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1489
+        } // Securite : mes_options.php peut preciser le chemin absolu
1490
+        if (_PNMSCALE_COMMAND == '') {
1491
+            return;
1492
+        }
1493
+        $vignette = $destination . '.' . $format_sortie;
1494
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1495
+        if ($format == 'jpg') {
1496
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1497
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1498
+            if (!($s = @filesize($vignette))) {
1499
+                spip_unlink($vignette);
1500
+            }
1501
+            if (!@file_exists($vignette)) {
1502
+                spip_log("echec netpbm-jpg sur $vignette");
1503
+
1504
+                return;
1505
+            }
1506
+        } else {
1507
+            if ($format == 'gif') {
1508
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1509
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1510
+                if (!($s = @filesize($vignette))) {
1511
+                    spip_unlink($vignette);
1512
+                }
1513
+                if (!@file_exists($vignette)) {
1514
+                    spip_log("echec netpbm-gif sur $vignette");
1515
+
1516
+                    return;
1517
+                }
1518
+            } else {
1519
+                if ($format == 'png') {
1520
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1521
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1522
+                    if (!($s = @filesize($vignette))) {
1523
+                        spip_unlink($vignette);
1524
+                    }
1525
+                    if (!@file_exists($vignette)) {
1526
+                        spip_log("echec netpbm-png sur $vignette");
1527
+
1528
+                        return;
1529
+                    }
1530
+                }
1531
+            }
1532
+        }
1533
+    }
1534
+
1535
+    // gd ou gd2
1536
+    elseif ($process == 'gd1' or $process == 'gd2') {
1537
+        if (!function_exists('gd_info')) {
1538
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1539
+
1540
+            return;
1541
+        }
1542
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1543
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1544
+
1545
+            return;
1546
+        }
1547
+        $destFormat = $format_sortie;
1548
+        if (!$destFormat) {
1549
+            spip_log("pas de format pour $image");
1550
+
1551
+            return;
1552
+        }
1553
+
1554
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1555
+        if (!function_exists($fonction_imagecreatefrom)) {
1556
+            return '';
1557
+        }
1558
+        $srcImage = @$fonction_imagecreatefrom($image);
1559
+        if (!$srcImage) {
1560
+            spip_log('echec gd1/gd2');
1561
+
1562
+            return;
1563
+        }
1564
+
1565
+        // Initialisation de l'image destination
1566
+        $destImage = null;
1567
+        if ($process == 'gd2' and $destFormat != 'gif') {
1568
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1569
+        }
1570
+        if (!$destImage) {
1571
+            $destImage = ImageCreate($destWidth, $destHeight);
1572
+        }
1573
+
1574
+        // Recopie de l'image d'origine avec adaptation de la taille
1575
+        $ok = false;
1576
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1577
+            if ($format == 'gif') {
1578
+                // Si un GIF est transparent,
1579
+                // fabriquer un PNG transparent
1580
+                $transp = imagecolortransparent($srcImage);
1581
+                if ($transp > 0) {
1582
+                    $destFormat = 'png';
1583
+                }
1584
+            }
1585
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1586
+                // Conserver la transparence
1587
+                if (function_exists('imageAntiAlias')) {
1588
+                    imageAntiAlias($destImage, true);
1589
+                }
1590
+                @imagealphablending($destImage, false);
1591
+                @imagesavealpha($destImage, true);
1592
+            }
1593
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1594
+        }
1595
+        if (!$ok) {
1596
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1597
+        }
1598
+
1599
+        // Sauvegarde de l'image destination
1600
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1601
+        $valeurs['format_dest'] = $format = $destFormat;
1602
+        _image_gd_output($destImage, $valeurs);
1603
+
1604
+        if ($srcImage) {
1605
+            ImageDestroy($srcImage);
1606
+        }
1607
+        ImageDestroy($destImage);
1608
+    }
1609
+
1610
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1611
+        $size = [$destWidth, $destHeight];
1612
+    }
1613
+
1614
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1615
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1616
+    if ($size[0] < 1) {
1617
+        $size[0] = $destWidth;
1618
+    }
1619
+    if ($size[1] < 1) {
1620
+        $size[1] = $destHeight;
1621
+    }
1622
+
1623
+    $retour['width'] = $largeur = $size[0];
1624
+    $retour['height'] = $hauteur = $size[1];
1625
+
1626
+    $retour['fichier'] = $vignette;
1627
+    $retour['format'] = $format;
1628
+    $retour['date'] = @filemtime($vignette);
1629
+
1630
+    // renvoyer l'image
1631
+    return $retour;
1632 1632
 }
1633 1633
 
1634 1634
 /**
@@ -1648,25 +1648,25 @@  discard block
 block discarded – undo
1648 1648
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1649 1649
  **/
1650 1650
 function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1651
-	$ratioWidth = $srcWidth / $maxWidth;
1652
-	$ratioHeight = $srcHeight / $maxHeight;
1653
-
1654
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1655
-		$destWidth = $srcWidth;
1656
-		$destHeight = $srcHeight;
1657
-	} elseif ($ratioWidth < $ratioHeight) {
1658
-		$destWidth = $srcWidth / $ratioHeight;
1659
-		$destHeight = $maxHeight;
1660
-	} else {
1661
-		$destWidth = $maxWidth;
1662
-		$destHeight = $srcHeight / $ratioWidth;
1663
-	}
1664
-
1665
-	return [
1666
-		intval(round($destWidth)),
1667
-		intval(round($destHeight)),
1668
-		max($ratioWidth, $ratioHeight)
1669
-	];
1651
+    $ratioWidth = $srcWidth / $maxWidth;
1652
+    $ratioHeight = $srcHeight / $maxHeight;
1653
+
1654
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1655
+        $destWidth = $srcWidth;
1656
+        $destHeight = $srcHeight;
1657
+    } elseif ($ratioWidth < $ratioHeight) {
1658
+        $destWidth = $srcWidth / $ratioHeight;
1659
+        $destHeight = $maxHeight;
1660
+    } else {
1661
+        $destWidth = $maxWidth;
1662
+        $destHeight = $srcHeight / $ratioWidth;
1663
+    }
1664
+
1665
+    return [
1666
+        intval(round($destWidth)),
1667
+        intval(round($destHeight)),
1668
+        max($ratioWidth, $ratioHeight)
1669
+    ];
1670 1670
 }
1671 1671
 
1672 1672
 /**
@@ -1686,25 +1686,25 @@  discard block
 block discarded – undo
1686 1686
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1687 1687
  **/
1688 1688
 function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1689
-	$ratioWidth = $srcWidth / $maxWidth;
1690
-	$ratioHeight = $srcHeight / $maxHeight;
1691
-
1692
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1693
-		$destWidth = $srcWidth;
1694
-		$destHeight = $srcHeight;
1695
-	} elseif ($ratioWidth > $ratioHeight) {
1696
-		$destWidth = $srcWidth / $ratioHeight;
1697
-		$destHeight = $maxHeight;
1698
-	} else {
1699
-		$destWidth = $maxWidth;
1700
-		$destHeight = $srcHeight / $ratioWidth;
1701
-	}
1702
-
1703
-	return [
1704
-		intval(round($destWidth)),
1705
-		intval(round($destHeight)),
1706
-		min($ratioWidth, $ratioHeight)
1707
-	];
1689
+    $ratioWidth = $srcWidth / $maxWidth;
1690
+    $ratioHeight = $srcHeight / $maxHeight;
1691
+
1692
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1693
+        $destWidth = $srcWidth;
1694
+        $destHeight = $srcHeight;
1695
+    } elseif ($ratioWidth > $ratioHeight) {
1696
+        $destWidth = $srcWidth / $ratioHeight;
1697
+        $destHeight = $maxHeight;
1698
+    } else {
1699
+        $destWidth = $maxWidth;
1700
+        $destHeight = $srcHeight / $ratioWidth;
1701
+    }
1702
+
1703
+    return [
1704
+        intval(round($destWidth)),
1705
+        intval(round($destHeight)),
1706
+        min($ratioWidth, $ratioHeight)
1707
+    ];
1708 1708
 }
1709 1709
 
1710 1710
 
@@ -1717,12 +1717,12 @@  discard block
 block discarded – undo
1717 1717
  * @return string
1718 1718
  */
1719 1719
 function process_image_svg_identite($image) {
1720
-	if ($image['creer']) {
1721
-		$source = $image['fichier'];
1722
-		_image_gd_output($source, $image);
1723
-	}
1720
+    if ($image['creer']) {
1721
+        $source = $image['fichier'];
1722
+        _image_gd_output($source, $image);
1723
+    }
1724 1724
 
1725
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1725
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1726 1726
 }
1727 1727
 
1728 1728
 
@@ -1755,111 +1755,111 @@  discard block
 block discarded – undo
1755 1755
  *     Code HTML de la balise img produite
1756 1756
  **/
1757 1757
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1758
-	$image = false;
1759
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1760
-		$process = $GLOBALS['meta']['image_process'];
1761
-	}
1762
-	# determiner le format de sortie
1763
-	$format_sortie = false; // le choix par defaut sera bon
1764
-	if ($process == 'netpbm') {
1765
-		$format_sortie = 'jpg';
1766
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1767
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1768
-		// on verifie que l'extension choisie est bonne (en principe oui)
1769
-		$gd_formats = formats_image_acceptables(true);
1770
-		if (
1771
-			is_array($image)
1772
-			and (!in_array($image['format_dest'], $gd_formats)
1773
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1774
-			)
1775
-		) {
1776
-			if ($image['format_source'] == 'jpg') {
1777
-				$formats_sortie = ['jpg', 'png', 'gif'];
1778
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1779
-			{
1780
-				$formats_sortie = ['png', 'jpg', 'gif'];
1781
-			}
1782
-			// Choisir le format destination
1783
-			// - on sauve de preference en JPEG (meilleure compression)
1784
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1785
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1786
-			# pas *ecrire*
1787
-			$format_sortie = '';
1788
-			foreach ($formats_sortie as $fmt) {
1789
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1790
-					$format_sortie = $fmt;
1791
-					break;
1792
-				}
1793
-			}
1794
-			$image = false;
1795
-		}
1796
-	}
1797
-
1798
-	if (!is_array($image)) {
1799
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1800
-	}
1801
-
1802
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1803
-		spip_log("image_reduire_src:pas de version locale de $img");
1804
-		// on peut resizer en mode html si on dispose des elements
1805
-		if (
1806
-			$srcw = extraire_attribut($img, 'width')
1807
-			and $srch = extraire_attribut($img, 'height')
1808
-		) {
1809
-			list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1810
-
1811
-			return _image_tag_changer_taille($img, $w, $h);
1812
-		}
1813
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1814
-		// sous la forme style='max-width: NNpx;'
1815
-		return inserer_attribut(
1816
-			$img,
1817
-			'style',
1818
-			"max-width: ${taille}px; max-height: ${taille_y}px"
1819
-		);
1820
-	}
1821
-
1822
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1823
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1824
-		if ($image['creer']) {
1825
-			@copy($image['fichier'], $image['fichier_dest']);
1826
-		}
1827
-
1828
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1829
-	}
1830
-
1831
-	if ($image['creer'] == false && !$force) {
1832
-		return _image_ecrire_tag(
1833
-			$image,
1834
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1835
-		);
1836
-	}
1837
-
1838
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1839
-		$destWidth = $image['largeur_dest'];
1840
-		$destHeight = $image['hauteur_dest'];
1841
-		$logo = $image['fichier'];
1842
-		$date = $image['date_src'];
1843
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1844
-
1845
-		if ($preview && $preview['fichier']) {
1846
-			$logo = $preview['fichier'];
1847
-			$destWidth = $preview['width'];
1848
-			$destHeight = $preview['height'];
1849
-			$date = $preview['date'];
1850
-		}
1851
-		// dans l'espace prive mettre un timestamp sur l'adresse
1852
-		// de l'image, de facon a tromper le cache du navigateur
1853
-		// quand on fait supprimer/reuploader un logo
1854
-		// (pas de filemtime si SAFE MODE)
1855
-		$date = test_espace_prive() ? ('?' . $date) : '';
1856
-
1857
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1858
-	}
1859
-	else {
1860
-		# BMP, tiff ... les redacteurs osent tout!
1861
-		return $img;
1862
-	}
1758
+    $image = false;
1759
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1760
+        $process = $GLOBALS['meta']['image_process'];
1761
+    }
1762
+    # determiner le format de sortie
1763
+    $format_sortie = false; // le choix par defaut sera bon
1764
+    if ($process == 'netpbm') {
1765
+        $format_sortie = 'jpg';
1766
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1767
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1768
+        // on verifie que l'extension choisie est bonne (en principe oui)
1769
+        $gd_formats = formats_image_acceptables(true);
1770
+        if (
1771
+            is_array($image)
1772
+            and (!in_array($image['format_dest'], $gd_formats)
1773
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1774
+            )
1775
+        ) {
1776
+            if ($image['format_source'] == 'jpg') {
1777
+                $formats_sortie = ['jpg', 'png', 'gif'];
1778
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1779
+            {
1780
+                $formats_sortie = ['png', 'jpg', 'gif'];
1781
+            }
1782
+            // Choisir le format destination
1783
+            // - on sauve de preference en JPEG (meilleure compression)
1784
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1785
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1786
+            # pas *ecrire*
1787
+            $format_sortie = '';
1788
+            foreach ($formats_sortie as $fmt) {
1789
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1790
+                    $format_sortie = $fmt;
1791
+                    break;
1792
+                }
1793
+            }
1794
+            $image = false;
1795
+        }
1796
+    }
1797
+
1798
+    if (!is_array($image)) {
1799
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1800
+    }
1801
+
1802
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1803
+        spip_log("image_reduire_src:pas de version locale de $img");
1804
+        // on peut resizer en mode html si on dispose des elements
1805
+        if (
1806
+            $srcw = extraire_attribut($img, 'width')
1807
+            and $srch = extraire_attribut($img, 'height')
1808
+        ) {
1809
+            list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1810
+
1811
+            return _image_tag_changer_taille($img, $w, $h);
1812
+        }
1813
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1814
+        // sous la forme style='max-width: NNpx;'
1815
+        return inserer_attribut(
1816
+            $img,
1817
+            'style',
1818
+            "max-width: ${taille}px; max-height: ${taille_y}px"
1819
+        );
1820
+    }
1821
+
1822
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1823
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1824
+        if ($image['creer']) {
1825
+            @copy($image['fichier'], $image['fichier_dest']);
1826
+        }
1827
+
1828
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1829
+    }
1830
+
1831
+    if ($image['creer'] == false && !$force) {
1832
+        return _image_ecrire_tag(
1833
+            $image,
1834
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1835
+        );
1836
+    }
1837
+
1838
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1839
+        $destWidth = $image['largeur_dest'];
1840
+        $destHeight = $image['hauteur_dest'];
1841
+        $logo = $image['fichier'];
1842
+        $date = $image['date_src'];
1843
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1844
+
1845
+        if ($preview && $preview['fichier']) {
1846
+            $logo = $preview['fichier'];
1847
+            $destWidth = $preview['width'];
1848
+            $destHeight = $preview['height'];
1849
+            $date = $preview['date'];
1850
+        }
1851
+        // dans l'espace prive mettre un timestamp sur l'adresse
1852
+        // de l'image, de facon a tromper le cache du navigateur
1853
+        // quand on fait supprimer/reuploader un logo
1854
+        // (pas de filemtime si SAFE MODE)
1855
+        $date = test_espace_prive() ? ('?' . $date) : '';
1856
+
1857
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1858
+    }
1859
+    else {
1860
+        # BMP, tiff ... les redacteurs osent tout!
1861
+        return $img;
1862
+    }
1863 1863
 }
1864 1864
 
1865 1865
 /**
@@ -1874,145 +1874,145 @@  discard block
 block discarded – undo
1874 1874
  */
1875 1875
 class phpthumb_functions {
1876 1876
 
1877
-	/**
1878
-	 * Retourne la couleur d'un pixel dans une image
1879
-	 *
1880
-	 * @param ressource $img
1881
-	 * @param int $x
1882
-	 * @param int $y
1883
-	 * @return array|bool
1884
-	 */
1885
-	public static function GetPixelColor(&$img, $x, $y) {
1886
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1887
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1888
-		}
1889
-		return false;
1890
-	}
1891
-
1892
-	/**
1893
-	 * Retourne un nombre dans une représentation en Little Endian
1894
-	 *
1895
-	 * @param int $number
1896
-	 * @param int $minbytes
1897
-	 * @return string
1898
-	 */
1899
-	public static function LittleEndian2String($number, $minbytes = 1) {
1900
-		$intstring = '';
1901
-		while ($number > 0) {
1902
-			$intstring = $intstring . chr($number & 255);
1903
-			$number >>= 8;
1904
-		}
1905
-
1906
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1907
-	}
1908
-
1909
-	/**
1910
-	 * Transforme une ressource GD en image au format ICO
1911
-	 *
1912
-	 * @param array $gd_image_array
1913
-	 *     Tableau de ressources d'images GD
1914
-	 * @return string
1915
-	 *     Image au format ICO
1916
-	 */
1917
-	public static function GD2ICOstring(&$gd_image_array) {
1918
-		foreach ($gd_image_array as $key => $gd_image) {
1919
-			$ImageWidths[$key] = ImageSX($gd_image);
1920
-			$ImageHeights[$key] = ImageSY($gd_image);
1921
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1922
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1923
-
1924
-			$icXOR[$key] = '';
1925
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1926
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1927
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1928
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1929
-					$r = $argb['red'];
1930
-					$g = $argb['green'];
1931
-					$b = $argb['blue'];
1932
-
1933
-					if ($bpp[$key] == 32) {
1934
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1935
-					} elseif ($bpp[$key] == 24) {
1936
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1937
-					}
1938
-
1939
-					if ($a < 128) {
1940
-						@$icANDmask[$key][$y] .= '1';
1941
-					} else {
1942
-						@$icANDmask[$key][$y] .= '0';
1943
-					}
1944
-				}
1945
-				// mask bits are 32-bit aligned per scanline
1946
-				while (strlen($icANDmask[$key][$y]) % 32) {
1947
-					$icANDmask[$key][$y] .= '0';
1948
-				}
1949
-			}
1950
-			$icAND[$key] = '';
1951
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1952
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1953
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1954
-				}
1955
-			}
1956
-		}
1957
-
1958
-		foreach ($gd_image_array as $key => $gd_image) {
1959
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1960
-
1961
-			// BITMAPINFOHEADER - 40 bytes
1962
-			$BitmapInfoHeader[$key] = '';
1963
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1964
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1965
-			// The biHeight member specifies the combined
1966
-			// height of the XOR and AND masks.
1967
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1968
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1969
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1970
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1971
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1972
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1973
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1974
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1975
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1976
-		}
1977
-
1978
-
1979
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1980
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1981
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1982
-
1983
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1984
-		foreach ($gd_image_array as $key => $gd_image) {
1985
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1986
-
1987
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1988
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1989
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1990
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1991
-
1992
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1993
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1994
-
1995
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1996
-			$icondata .= phpthumb_functions::LittleEndian2String(
1997
-				$dwBytesInRes,
1998
-				4
1999
-			);     // dwBytesInRes;	// How many bytes in this resource?
2000
-
2001
-			$icondata .= phpthumb_functions::LittleEndian2String(
2002
-				$dwImageOffset,
2003
-				4
2004
-			);    // dwImageOffset;   // Where in the file is this image?
2005
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
2006
-			$dwImageOffset += strlen($icXOR[$key]);
2007
-			$dwImageOffset += strlen($icAND[$key]);
2008
-		}
2009
-
2010
-		foreach ($gd_image_array as $key => $gd_image) {
2011
-			$icondata .= $BitmapInfoHeader[$key];
2012
-			$icondata .= $icXOR[$key];
2013
-			$icondata .= $icAND[$key];
2014
-		}
2015
-
2016
-		return $icondata;
2017
-	}
1877
+    /**
1878
+     * Retourne la couleur d'un pixel dans une image
1879
+     *
1880
+     * @param ressource $img
1881
+     * @param int $x
1882
+     * @param int $y
1883
+     * @return array|bool
1884
+     */
1885
+    public static function GetPixelColor(&$img, $x, $y) {
1886
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1887
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1888
+        }
1889
+        return false;
1890
+    }
1891
+
1892
+    /**
1893
+     * Retourne un nombre dans une représentation en Little Endian
1894
+     *
1895
+     * @param int $number
1896
+     * @param int $minbytes
1897
+     * @return string
1898
+     */
1899
+    public static function LittleEndian2String($number, $minbytes = 1) {
1900
+        $intstring = '';
1901
+        while ($number > 0) {
1902
+            $intstring = $intstring . chr($number & 255);
1903
+            $number >>= 8;
1904
+        }
1905
+
1906
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1907
+    }
1908
+
1909
+    /**
1910
+     * Transforme une ressource GD en image au format ICO
1911
+     *
1912
+     * @param array $gd_image_array
1913
+     *     Tableau de ressources d'images GD
1914
+     * @return string
1915
+     *     Image au format ICO
1916
+     */
1917
+    public static function GD2ICOstring(&$gd_image_array) {
1918
+        foreach ($gd_image_array as $key => $gd_image) {
1919
+            $ImageWidths[$key] = ImageSX($gd_image);
1920
+            $ImageHeights[$key] = ImageSY($gd_image);
1921
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1922
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1923
+
1924
+            $icXOR[$key] = '';
1925
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1926
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1927
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1928
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1929
+                    $r = $argb['red'];
1930
+                    $g = $argb['green'];
1931
+                    $b = $argb['blue'];
1932
+
1933
+                    if ($bpp[$key] == 32) {
1934
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1935
+                    } elseif ($bpp[$key] == 24) {
1936
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1937
+                    }
1938
+
1939
+                    if ($a < 128) {
1940
+                        @$icANDmask[$key][$y] .= '1';
1941
+                    } else {
1942
+                        @$icANDmask[$key][$y] .= '0';
1943
+                    }
1944
+                }
1945
+                // mask bits are 32-bit aligned per scanline
1946
+                while (strlen($icANDmask[$key][$y]) % 32) {
1947
+                    $icANDmask[$key][$y] .= '0';
1948
+                }
1949
+            }
1950
+            $icAND[$key] = '';
1951
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1952
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1953
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1954
+                }
1955
+            }
1956
+        }
1957
+
1958
+        foreach ($gd_image_array as $key => $gd_image) {
1959
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1960
+
1961
+            // BITMAPINFOHEADER - 40 bytes
1962
+            $BitmapInfoHeader[$key] = '';
1963
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1964
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1965
+            // The biHeight member specifies the combined
1966
+            // height of the XOR and AND masks.
1967
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1968
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1969
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1970
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1971
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1972
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1973
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1974
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1975
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1976
+        }
1977
+
1978
+
1979
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1980
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1981
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1982
+
1983
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1984
+        foreach ($gd_image_array as $key => $gd_image) {
1985
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1986
+
1987
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1988
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1989
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1990
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1991
+
1992
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1993
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1994
+
1995
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1996
+            $icondata .= phpthumb_functions::LittleEndian2String(
1997
+                $dwBytesInRes,
1998
+                4
1999
+            );     // dwBytesInRes;	// How many bytes in this resource?
2000
+
2001
+            $icondata .= phpthumb_functions::LittleEndian2String(
2002
+                $dwImageOffset,
2003
+                4
2004
+            );    // dwImageOffset;   // Where in the file is this image?
2005
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
2006
+            $dwImageOffset += strlen($icXOR[$key]);
2007
+            $dwImageOffset += strlen($icAND[$key]);
2008
+        }
2009
+
2010
+        foreach ($gd_image_array as $key => $gd_image) {
2011
+            $icondata .= $BitmapInfoHeader[$key];
2012
+            $icondata .= $icXOR[$key];
2013
+            $icondata .= $icAND[$key];
2014
+        }
2015
+
2016
+        return $icondata;
2017
+    }
2018 2018
 }
Please login to merge, or discard this patch.
ecrire/inc/presentation_mini.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Affichage
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * @return string Code HTML
26 26
  */
27 27
 function debut_grand_cadre() {
28
- return "\n<div class = 'table_page'>\n";
28
+    return "\n<div class = 'table_page'>\n";
29 29
 }
30 30
 
31 31
 /**
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @return string Code HTML
35 35
  */
36 36
 function fin_grand_cadre() {
37
- return "\n</div>";
37
+    return "\n</div>";
38 38
 }
39 39
 
40 40
 // Debut de la colonne de gauche
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
  * @return string Code HTML
50 50
  */
51 51
 function debut_gauche() {
52
-	return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n";
52
+    return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n";
53 53
 }
54 54
 
55 55
 /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
  * @return string Code HTML
59 59
  */
60 60
 function fin_gauche() {
61
- return "</div></div><br class = 'nettoyeur' />";
61
+    return "</div></div><br class = 'nettoyeur' />";
62 62
 }
63 63
 
64 64
 /**
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
  * @return string Code HTML
68 68
  */
69 69
 function creer_colonne_droite() {
70
-	static $deja_colonne_droite;
71
-	if ($deja_colonne_droite) {
72
-		return '';
73
-	}
74
-	$deja_colonne_droite = true;
70
+    static $deja_colonne_droite;
71
+    if ($deja_colonne_droite) {
72
+        return '';
73
+    }
74
+    $deja_colonne_droite = true;
75 75
 
76
-	return "\n</div><div id='extra' class='lat' role='complementary'>";
76
+    return "\n</div><div id='extra' class='lat' role='complementary'>";
77 77
 }
78 78
 
79 79
 /**
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
  * @return string Code HTML
83 83
  */
84 84
 function debut_droite() {
85
-	return liste_objets_bloques(_request('exec'))
86
-	. creer_colonne_droite()
87
-	. '</div>'
88
-	. "\n<div id='contenu'>";
85
+    return liste_objets_bloques(_request('exec'))
86
+    . creer_colonne_droite()
87
+    . '</div>'
88
+    . "\n<div id='contenu'>";
89 89
 }
90 90
 
91 91
 /**
@@ -107,31 +107,31 @@  discard block
 block discarded – undo
107 107
  *     Code HTML
108 108
  **/
109 109
 function liste_objets_bloques($exec, $contexte = [], $auteur = null) {
110
-	$res = '';
111
-	if ($GLOBALS['meta']['articles_modif'] != 'non') {
112
-		include_spip('inc/drapeau_edition');
113
-		if (is_null($auteur)) {
114
-			$auteur = $GLOBALS['visiteur_session'];
115
-		}
116
-		if (
117
-			$en_cours = trouver_objet_exec($exec)
118
-			and $en_cours['edition']
119
-			and $type = $en_cours['type']
120
-			and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']])
121
-				or $id = _request($en_cours['id_table_objet']))
122
-		) {
123
-			// marquer le fait que l'objet est ouvert en edition par toto
124
-			// a telle date ; une alerte sera donnee aux autres redacteurs
125
-			signale_edition($id, $auteur, $type);
126
-		}
127
-
128
-		$objets_ouverts = liste_drapeau_edition($auteur['id_auteur']);
129
-		if (count($objets_ouverts)) {
130
-			$res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]);
131
-		}
132
-	}
133
-
134
-	return $res;
110
+    $res = '';
111
+    if ($GLOBALS['meta']['articles_modif'] != 'non') {
112
+        include_spip('inc/drapeau_edition');
113
+        if (is_null($auteur)) {
114
+            $auteur = $GLOBALS['visiteur_session'];
115
+        }
116
+        if (
117
+            $en_cours = trouver_objet_exec($exec)
118
+            and $en_cours['edition']
119
+            and $type = $en_cours['type']
120
+            and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']])
121
+                or $id = _request($en_cours['id_table_objet']))
122
+        ) {
123
+            // marquer le fait que l'objet est ouvert en edition par toto
124
+            // a telle date ; une alerte sera donnee aux autres redacteurs
125
+            signale_edition($id, $auteur, $type);
126
+        }
127
+
128
+        $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']);
129
+        if (count($objets_ouverts)) {
130
+            $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]);
131
+        }
132
+    }
133
+
134
+    return $res;
135 135
 }
136 136
 
137 137
 
@@ -145,20 +145,20 @@  discard block
 block discarded – undo
145 145
  * @return string Code HTML
146 146
  **/
147 147
 function fin_page() {
148
-	include_spip('inc/pipelines');
149
-	// avec &var_profile=1 on a le tableau de mesures SQL
150
-	$debug = ((_request('exec') !== 'valider_xml')
151
-		and ((_request('var_mode') == 'debug')
152
-			or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps'])
153
-			and isset($_COOKIE['spip_admin'])));
154
-	$t = '</div><div id="pied"><div class="largeur">'
155
-		. recuperer_fond('prive/squelettes/inclure/pied')
156
-		. '</div>'
157
-		. '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page()
158
-		. ($debug ? erreur_squelette() : '')
159
-		. "</body></html>\n";
160
-
161
-	return f_queue($t);
148
+    include_spip('inc/pipelines');
149
+    // avec &var_profile=1 on a le tableau de mesures SQL
150
+    $debug = ((_request('exec') !== 'valider_xml')
151
+        and ((_request('var_mode') == 'debug')
152
+            or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps'])
153
+            and isset($_COOKIE['spip_admin'])));
154
+    $t = '</div><div id="pied"><div class="largeur">'
155
+        . recuperer_fond('prive/squelettes/inclure/pied')
156
+        . '</div>'
157
+        . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page()
158
+        . ($debug ? erreur_squelette() : '')
159
+        . "</body></html>\n";
160
+
161
+    return f_queue($t);
162 162
 }
163 163
 
164 164
 /**
@@ -173,22 +173,22 @@  discard block
 block discarded – undo
173 173
  * @return string Code HTML
174 174
  **/
175 175
 function html_tests_js() {
176
-	if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) {
177
-		// pour le pied de page (deja defini si on est validation XML)
178
-		define(
179
-			'_TESTER_NOSCRIPT',
180
-			"<noscript>\n<div style='display:none;'><img src='"
181
-			. generer_url_ecrire('test_ajax', 'js=-1')
182
-			. "' width='1' height='1' alt='' /></div></noscript>\n"
183
-		);
184
-	}
185
-
186
-	$rejouer = '';
187
-	if (defined('_SESSION_REJOUER')) {
188
-		$rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
189
-	}
190
-
191
-	return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
176
+    if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) {
177
+        // pour le pied de page (deja defini si on est validation XML)
178
+        define(
179
+            '_TESTER_NOSCRIPT',
180
+            "<noscript>\n<div style='display:none;'><img src='"
181
+            . generer_url_ecrire('test_ajax', 'js=-1')
182
+            . "' width='1' height='1' alt='' /></div></noscript>\n"
183
+        );
184
+    }
185
+
186
+    $rejouer = '';
187
+    if (defined('_SESSION_REJOUER')) {
188
+        $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
189
+    }
190
+
191
+    return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
192 192
 }
193 193
 
194 194
 /**
@@ -198,25 +198,25 @@  discard block
 block discarded – undo
198 198
  **/
199 199
 function info_maj_spip() {
200 200
 
201
-	$maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null;
202
-	if (!$maj) {
203
-		return '';
204
-	}
201
+    $maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null;
202
+    if (!$maj) {
203
+        return '';
204
+    }
205 205
 
206
-	$maj = explode('|', $maj);
207
-	// c'est une ancienne notif, on a fait la maj depuis !
208
-	if ($GLOBALS['spip_version_branche'] !== reset($maj)) {
209
-		return '';
210
-	}
206
+    $maj = explode('|', $maj);
207
+    // c'est une ancienne notif, on a fait la maj depuis !
208
+    if ($GLOBALS['spip_version_branche'] !== reset($maj)) {
209
+        return '';
210
+    }
211 211
 
212
-	if (!autoriser('webmestre')) {
213
-		return '';
214
-	}
212
+    if (!autoriser('webmestre')) {
213
+        return '';
214
+    }
215 215
 
216
-	array_shift($maj);
217
-	$maj = implode('|', $maj);
216
+    array_shift($maj);
217
+    $maj = implode('|', $maj);
218 218
 
219
-	return "$maj<br />";
219
+    return "$maj<br />";
220 220
 }
221 221
 
222 222
 /**
@@ -227,47 +227,47 @@  discard block
 block discarded – undo
227 227
  **/
228 228
 function info_copyright() {
229 229
 
230
-	$version = $GLOBALS['spip_version_affichee'];
231
-
232
-	//
233
-	// Mention, le cas echeant, de la revision SVN courante
234
-	//
235
-	if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
236
-		if ($vcs['vcs'] === 'GIT') {
237
-			$url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
238
-		} elseif ($vcs['vcs'] === 'SVN') {
239
-			$url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
240
-		} else {
241
-			$url = '';
242
-		}
243
-		// affichage "GIT [master: abcdef]"
244
-		$commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit'];
245
-		if ($url) {
246
-			$commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
247
-		}
248
-		if ($vcs['branch']) {
249
-			$commit = $vcs['branch'] . ': ' . $commit;
250
-		}
251
-		$version .= " {$vcs['vcs']} [$commit]";
252
-	}
253
-
254
-	// et la version de l'ecran de securite
255
-	$secu = defined('_ECRAN_SECURITE')
256
-		? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
257
-		: '';
258
-
259
-	return _T(
260
-		'info_copyright',
261
-		[
262
-			'spip' => "<b>SPIP $version</b> ",
263
-			'lien_gpl' =>
264
-				"<a href='" . generer_url_ecrire(
265
-					'aide',
266
-					'aide=licence&var_lang=' . $GLOBALS['spip_lang']
267
-				) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
268
-		]
269
-	)
270
-	. $secu;
230
+    $version = $GLOBALS['spip_version_affichee'];
231
+
232
+    //
233
+    // Mention, le cas echeant, de la revision SVN courante
234
+    //
235
+    if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
236
+        if ($vcs['vcs'] === 'GIT') {
237
+            $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
238
+        } elseif ($vcs['vcs'] === 'SVN') {
239
+            $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
240
+        } else {
241
+            $url = '';
242
+        }
243
+        // affichage "GIT [master: abcdef]"
244
+        $commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit'];
245
+        if ($url) {
246
+            $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
247
+        }
248
+        if ($vcs['branch']) {
249
+            $commit = $vcs['branch'] . ': ' . $commit;
250
+        }
251
+        $version .= " {$vcs['vcs']} [$commit]";
252
+    }
253
+
254
+    // et la version de l'ecran de securite
255
+    $secu = defined('_ECRAN_SECURITE')
256
+        ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
257
+        : '';
258
+
259
+    return _T(
260
+        'info_copyright',
261
+        [
262
+            'spip' => "<b>SPIP $version</b> ",
263
+            'lien_gpl' =>
264
+                "<a href='" . generer_url_ecrire(
265
+                    'aide',
266
+                    'aide=licence&var_lang=' . $GLOBALS['spip_lang']
267
+                ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
268
+        ]
269
+    )
270
+    . $secu;
271 271
 }
272 272
 
273 273
 /**
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
  * @return string             Code HTML
283 283
  **/
284 284
 function formulaire_recherche($page, $complement = '') {
285
-	$recherche = _request('recherche');
286
-	$recherche_aff = entites_html($recherche);
287
-	if (!strlen($recherche)) {
288
-		$recherche_aff = _T('info_rechercher');
289
-		$onfocus = " onfocus=\"this.value='';\"";
290
-	} else {
291
-		$onfocus = '';
292
-	}
293
-
294
-	$form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
295
-	$form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
296
-
297
-	return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
285
+    $recherche = _request('recherche');
286
+    $recherche_aff = entites_html($recherche);
287
+    if (!strlen($recherche)) {
288
+        $recherche_aff = _T('info_rechercher');
289
+        $onfocus = " onfocus=\"this.value='';\"";
290
+    } else {
291
+        $onfocus = '';
292
+    }
293
+
294
+    $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
295
+    $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
296
+
297
+    return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
298 298
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		$rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
189 189
 	}
190 190
 
191
-	return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
191
+	return $rejouer.(defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
192 192
 }
193 193
 
194 194
 /**
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 	//
235 235
 	if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
236 236
 		if ($vcs['vcs'] === 'GIT') {
237
-			$url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
237
+			$url = 'https://git.spip.net/spip/spip/commit/'.$vcs['commit'];
238 238
 		} elseif ($vcs['vcs'] === 'SVN') {
239
-			$url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
239
+			$url = 'https://core.spip.net/projects/spip/repository/revisions/'.$vcs['commit'];
240 240
 		} else {
241 241
 			$url = '';
242 242
 		}
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 246
 			$commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
247 247
 		}
248 248
 		if ($vcs['branch']) {
249
-			$commit = $vcs['branch'] . ': ' . $commit;
249
+			$commit = $vcs['branch'].': '.$commit;
250 250
 		}
251 251
 		$version .= " {$vcs['vcs']} [$commit]";
252 252
 	}
253 253
 
254 254
 	// et la version de l'ecran de securite
255 255
 	$secu = defined('_ECRAN_SECURITE')
256
-		? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
256
+		? '<br />'._T('ecran_securite', ['version' => _ECRAN_SECURITE])
257 257
 		: '';
258 258
 
259 259
 	return _T(
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
 		[
262 262
 			'spip' => "<b>SPIP $version</b> ",
263 263
 			'lien_gpl' =>
264
-				"<a href='" . generer_url_ecrire(
264
+				"<a href='".generer_url_ecrire(
265 265
 					'aide',
266
-					'aide=licence&var_lang=' . $GLOBALS['spip_lang']
267
-				) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
266
+					'aide=licence&var_lang='.$GLOBALS['spip_lang']
267
+				)."' class=\"aide popin\">"._T('info_copyright_gpl').'</a>'
268 268
 		]
269 269
 	)
270 270
 	. $secu;
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 		$onfocus = '';
292 292
 	}
293 293
 
294
-	$form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
295
-	$form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
294
+	$form = '<input type="text" size="10" value="'.$recherche_aff.'" name="recherche" class="recherche" accesskey="r"'.$onfocus.' />';
295
+	$form .= "<input type='image' src='".chemin_image('rechercher-20.png')."' name='submit' class='submit' alt='"._T('info_rechercher')."' />";
296 296
 
297
-	return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
297
+	return "<div class='spip_recherche'>".generer_form_ecrire($page, $form.$complement, " method='get'").'</div>';
298 298
 }
Please login to merge, or discard this patch.
ecrire/inc/minipres.php 3 patches
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 = isset($GLOBALS['visiteur_session']['statut']) ? $GLOBALS['visiteur_session']['statut'] : '';
188 188
 		$nom = isset($GLOBALS['visiteur_session']['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.
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.
Indentation   +127 added lines, -127 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('compacte')) {
70
-				$file = compacte($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('compacte')) {
70
+                $file = compacte($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,77 +148,77 @@  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 = isset($GLOBALS['visiteur_session']['statut']) ? $GLOBALS['visiteur_session']['statut'] : '';
188
-		$nom = isset($GLOBALS['visiteur_session']['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
-		return install_debut_html($titre, $options['onload'], $options['all_inline'])
213
-		. $corps
214
-		. install_fin_html();
215
-	} else {
216
-		include_spip('inc/headers');
217
-		include_spip('inc/actions');
218
-		$url = self('&', true);
219
-		foreach ($_POST as $v => $c) {
220
-			$url = parametre_url($url, $v, $c, '&');
221
-		}
222
-		ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
223
-	}
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 = isset($GLOBALS['visiteur_session']['statut']) ? $GLOBALS['visiteur_session']['statut'] : '';
188
+        $nom = isset($GLOBALS['visiteur_session']['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
+        return install_debut_html($titre, $options['onload'], $options['all_inline'])
213
+        . $corps
214
+        . install_fin_html();
215
+    } else {
216
+        include_spip('inc/headers');
217
+        include_spip('inc/actions');
218
+        $url = self('&', true);
219
+        foreach ($_POST as $v => $c) {
220
+            $url = parametre_url($url, $v, $c, '&');
221
+        }
222
+        ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
223
+    }
224 224
 }
Please login to merge, or discard this patch.
ecrire/inc/boutons.php 2 patches
Indentation   +82 added lines, -82 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
 /**
@@ -25,51 +25,51 @@  discard block
 block discarded – undo
25 25
  * privée ou dans un de ses sous menus
26 26
  */
27 27
 class Bouton {
28
-	/** @var string L'icone à mettre dans le bouton */
29
-	public $icone;
30
-
31
-	/** @var string Le nom de l'entrée d'i18n associé */
32
-	public $libelle;
33
-
34
-	/** @var null|string L'URL de la page (null => ?exec=nom) */
35
-	public $url = null;
36
-
37
-	/** @var null|string|array Arguments supplementaires de l'URL */
38
-	public $urlArg = null;
39
-
40
-	/** @var null|string URL du javascript */
41
-	public $url2 = null;
42
-
43
-	/** @var null|string Pour ouvrir dans une fenetre a part */
44
-	public $target = null;
45
-
46
-	/** @var null|mixed Sous-barre de boutons / onglets */
47
-	public $sousmenu = null;
48
-
49
-	/**
50
-	 * Définit un bouton
51
-	 *
52
-	 * @param string $icone
53
-	 *    L'icone à mettre dans le bouton
54
-	 * @param string $libelle
55
-	 *    Le nom de l'entrée i18n associé
56
-	 * @param null|string $url
57
-	 *    L'URL de la page
58
-	 * @param null|string|array $urlArg
59
-	 *    Arguments supplémentaires de l'URL
60
-	 * @param null|string $url2
61
-	 *    URL du javascript
62
-	 * @param null|mixed $target
63
-	 *    Pour ouvrir une fenêtre à part
64
-	 */
65
-	public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) {
66
-		$this->icone = $icone;
67
-		$this->libelle = $libelle;
68
-		$this->url = $url;
69
-		$this->urlArg = $urlArg;
70
-		$this->url2 = $url2;
71
-		$this->target = $target;
72
-	}
28
+    /** @var string L'icone à mettre dans le bouton */
29
+    public $icone;
30
+
31
+    /** @var string Le nom de l'entrée d'i18n associé */
32
+    public $libelle;
33
+
34
+    /** @var null|string L'URL de la page (null => ?exec=nom) */
35
+    public $url = null;
36
+
37
+    /** @var null|string|array Arguments supplementaires de l'URL */
38
+    public $urlArg = null;
39
+
40
+    /** @var null|string URL du javascript */
41
+    public $url2 = null;
42
+
43
+    /** @var null|string Pour ouvrir dans une fenetre a part */
44
+    public $target = null;
45
+
46
+    /** @var null|mixed Sous-barre de boutons / onglets */
47
+    public $sousmenu = null;
48
+
49
+    /**
50
+     * Définit un bouton
51
+     *
52
+     * @param string $icone
53
+     *    L'icone à mettre dans le bouton
54
+     * @param string $libelle
55
+     *    Le nom de l'entrée i18n associé
56
+     * @param null|string $url
57
+     *    L'URL de la page
58
+     * @param null|string|array $urlArg
59
+     *    Arguments supplémentaires de l'URL
60
+     * @param null|string $url2
61
+     *    URL du javascript
62
+     * @param null|mixed $target
63
+     *    Pour ouvrir une fenêtre à part
64
+     */
65
+    public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) {
66
+        $this->icone = $icone;
67
+        $this->libelle = $libelle;
68
+        $this->url = $url;
69
+        $this->urlArg = $urlArg;
70
+        $this->url2 = $url2;
71
+        $this->target = $target;
72
+    }
73 73
 }
74 74
 
75 75
 
@@ -86,35 +86,35 @@  discard block
 block discarded – undo
86 86
  */
87 87
 function definir_barre_onglets($script) {
88 88
 
89
-	$onglets = [];
90
-	$liste_onglets = [];
91
-
92
-	// ajouter les onglets issus des plugin via paquet.xml
93
-	if (function_exists('onglets_plugins')) {
94
-		$liste_onglets = onglets_plugins();
95
-	}
96
-
97
-
98
-	foreach ($liste_onglets as $id => $infos) {
99
-		if (
100
-			($parent = $infos['parent'])
101
-			&& $parent == $script
102
-			&& autoriser('onglet', "_$id")
103
-		) {
104
-			$onglets[$id] = new Bouton(
105
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
106
-				$infos['titre'],  // titre
107
-				(isset($infos['action']) and $infos['action'])
108
-					? generer_url_ecrire(
109
-						$infos['action'],
110
-						(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
111
-					)
112
-					: null
113
-			);
114
-		}
115
-	}
116
-
117
-	return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
89
+    $onglets = [];
90
+    $liste_onglets = [];
91
+
92
+    // ajouter les onglets issus des plugin via paquet.xml
93
+    if (function_exists('onglets_plugins')) {
94
+        $liste_onglets = onglets_plugins();
95
+    }
96
+
97
+
98
+    foreach ($liste_onglets as $id => $infos) {
99
+        if (
100
+            ($parent = $infos['parent'])
101
+            && $parent == $script
102
+            && autoriser('onglet', "_$id")
103
+        ) {
104
+            $onglets[$id] = new Bouton(
105
+                isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
106
+                $infos['titre'],  // titre
107
+                (isset($infos['action']) and $infos['action'])
108
+                    ? generer_url_ecrire(
109
+                        $infos['action'],
110
+                        (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
111
+                    )
112
+                    : null
113
+            );
114
+        }
115
+    }
116
+
117
+    return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
118 118
 }
119 119
 
120 120
 
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') {
136
-	include_spip('inc/presentation');
136
+    include_spip('inc/presentation');
137 137
 
138
-	$res = '';
138
+    $res = '';
139 139
 
140
-	foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
141
-		$url = $onglet->url ? $onglet->url : generer_url_ecrire($exec);
142
-		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
143
-	}
140
+    foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
141
+        $url = $onglet->url ? $onglet->url : generer_url_ecrire($exec);
142
+        $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
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.
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.
ecrire/inc/layer.php 2 patches
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -26,41 +26,41 @@  discard block
 block discarded – undo
26 26
  * @return string Code HTML du cadre dépliable
27 27
  **/
28 28
 function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') {
29
-	$bouton = bouton_block_depliable($titre, $deplie, $ids);
30
-
31
-	return
32
-		debut_cadre($style_cadre, $icone, '', $bouton, '', '', false)
33
-		. debut_block_depliable($deplie, $ids)
34
-		. "<div class='cadre_padding'>\n"
35
-		. $contenu
36
-		. "</div>\n"
37
-		. fin_block()
38
-		. fin_cadre();
29
+    $bouton = bouton_block_depliable($titre, $deplie, $ids);
30
+
31
+    return
32
+        debut_cadre($style_cadre, $icone, '', $bouton, '', '', false)
33
+        . debut_block_depliable($deplie, $ids)
34
+        . "<div class='cadre_padding'>\n"
35
+        . $contenu
36
+        . "</div>\n"
37
+        . fin_block()
38
+        . fin_cadre();
39 39
 }
40 40
 
41 41
 // https://code.spip.net/@block_parfois_visible
42 42
 function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) {
43
-	return "\n"
44
-	. bouton_block_depliable($invite, $visible, $nom)
45
-	. debut_block_depliable($visible, $nom)
46
-	. $masque
47
-	. fin_block();
43
+    return "\n"
44
+    . bouton_block_depliable($invite, $visible, $nom)
45
+    . debut_block_depliable($visible, $nom)
46
+    . $masque
47
+    . fin_block();
48 48
 }
49 49
 
50 50
 // https://code.spip.net/@debut_block_depliable
51 51
 function debut_block_depliable($deplie, $id = '') {
52
-	$class = ' blocdeplie';
53
-	// si on n'accepte pas js, ne pas fermer
54
-	if (!$deplie) {
55
-		$class = ' blocreplie';
56
-	}
52
+    $class = ' blocdeplie';
53
+    // si on n'accepte pas js, ne pas fermer
54
+    if (!$deplie) {
55
+        $class = ' blocreplie';
56
+    }
57 57
 
58
-	return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>";
58
+    return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>";
59 59
 }
60 60
 
61 61
 // https://code.spip.net/@fin_block
62 62
 function fin_block() {
63
-	return "<div class='nettoyeur'></div>\n</div>";
63
+    return "<div class='nettoyeur'></div>\n</div>";
64 64
 }
65 65
 
66 66
 // $texte : texte du bouton
@@ -68,32 +68,32 @@  discard block
 block discarded – undo
68 68
 // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit)
69 69
 // https://code.spip.net/@bouton_block_depliable
70 70
 function bouton_block_depliable($texte, $deplie, $ids = '') {
71
-	$bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8);
72
-
73
-	$class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie');
74
-	if (strlen($ids)) {
75
-		$cible = explode(',', $ids);
76
-		$cible = '#' . implode(',#', $cible);
77
-	} else {
78
-		$cible = "#$bouton_id + div.bloc_depliable";
79
-	}
80
-
81
-	$b = (strpos($texte, '<h') === false ? 'h3' : 'div');
82
-
83
-	return "<$b "
84
-	. ($bouton_id ? "id='$bouton_id' " : '')
85
-	. "class='titrem$class'"
86
-	. (($deplie === -1)
87
-		? ''
88
-		: " onmouseover=\"jQuery(this).depliant('$cible');\""
89
-	)
90
-	. '>'
91
-	// une ancre pour rendre accessible au clavier le depliage du sous bloc
92
-	. "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>"
93
-	. "$texte</$b>"
94
-	. http_script(($deplie === 'incertain')
95
-		? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});"
96
-		: '');
71
+    $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8);
72
+
73
+    $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie');
74
+    if (strlen($ids)) {
75
+        $cible = explode(',', $ids);
76
+        $cible = '#' . implode(',#', $cible);
77
+    } else {
78
+        $cible = "#$bouton_id + div.bloc_depliable";
79
+    }
80
+
81
+    $b = (strpos($texte, '<h') === false ? 'h3' : 'div');
82
+
83
+    return "<$b "
84
+    . ($bouton_id ? "id='$bouton_id' " : '')
85
+    . "class='titrem$class'"
86
+    . (($deplie === -1)
87
+        ? ''
88
+        : " onmouseover=\"jQuery(this).depliant('$cible');\""
89
+    )
90
+    . '>'
91
+    // une ancre pour rendre accessible au clavier le depliage du sous bloc
92
+    . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>"
93
+    . "$texte</$b>"
94
+    . http_script(($deplie === 'incertain')
95
+        ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});"
96
+        : '');
97 97
 }
98 98
 
99 99
 //
@@ -102,66 +102,66 @@  discard block
 block discarded – undo
102 102
 // https://code.spip.net/@verif_butineur
103 103
 function verif_butineur() {
104 104
 
105
-	preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match);
106
-	$GLOBALS['browser_name'] = $match[1];
107
-	$GLOBALS['browser_version'] = $match[2];
108
-	$GLOBALS['browser_description'] = $match[3];
109
-	$GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur
110
-	$GLOBALS['browser_barre'] = '';
111
-
112
-	if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) {
113
-		$GLOBALS['browser_name'] = 'Opera';
114
-		$GLOBALS['browser_version'] = $match[2];
115
-		$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
116
-	} else {
117
-		if (preg_match(',opera,i', $GLOBALS['browser_description'])) {
118
-			preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match);
119
-			$GLOBALS['browser_name'] = 'Opera';
120
-			$GLOBALS['browser_version'] = $match[1];
121
-			$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
122
-		} else {
123
-			if (preg_match(',msie,i', $GLOBALS['browser_description'])) {
124
-				preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match);
125
-				$GLOBALS['browser_name'] = 'MSIE';
126
-				$GLOBALS['browser_version'] = $match[1];
127
-				$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5);
128
-			} else {
129
-				if (
130
-					preg_match(',KHTML,i', $GLOBALS['browser_description']) &&
131
-					preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match)
132
-				) {
133
-					$GLOBALS['browser_name'] = 'Safari';
134
-					$GLOBALS['browser_version'] = $match[1];
135
-					$GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0);
136
-				} else {
137
-					if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) {
138
-						// Numero de version pour Mozilla "authentique"
139
-						if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) {
140
-							$GLOBALS['browser_rev'] = doubleval($match[1]);
141
-						} // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.)
142
-						else {
143
-							if (
144
-								strpos($GLOBALS['browser_description'], 'Gecko') and !strpos(
145
-									$GLOBALS['browser_description'],
146
-									'KHTML'
147
-								)
148
-							) {
149
-								$GLOBALS['browser_rev'] = 1.4;
150
-							} // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.)
151
-							else {
152
-								$GLOBALS['browser_rev'] = 1.0;
153
-							}
154
-						}
155
-						$GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3;
156
-					}
157
-				}
158
-			}
159
-		}
160
-	}
161
-
162
-	if (!$GLOBALS['browser_name']) {
163
-		$GLOBALS['browser_name'] = 'Mozilla';
164
-	}
105
+    preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match);
106
+    $GLOBALS['browser_name'] = $match[1];
107
+    $GLOBALS['browser_version'] = $match[2];
108
+    $GLOBALS['browser_description'] = $match[3];
109
+    $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur
110
+    $GLOBALS['browser_barre'] = '';
111
+
112
+    if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) {
113
+        $GLOBALS['browser_name'] = 'Opera';
114
+        $GLOBALS['browser_version'] = $match[2];
115
+        $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
116
+    } else {
117
+        if (preg_match(',opera,i', $GLOBALS['browser_description'])) {
118
+            preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match);
119
+            $GLOBALS['browser_name'] = 'Opera';
120
+            $GLOBALS['browser_version'] = $match[1];
121
+            $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5);
122
+        } else {
123
+            if (preg_match(',msie,i', $GLOBALS['browser_description'])) {
124
+                preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match);
125
+                $GLOBALS['browser_name'] = 'MSIE';
126
+                $GLOBALS['browser_version'] = $match[1];
127
+                $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5);
128
+            } else {
129
+                if (
130
+                    preg_match(',KHTML,i', $GLOBALS['browser_description']) &&
131
+                    preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match)
132
+                ) {
133
+                    $GLOBALS['browser_name'] = 'Safari';
134
+                    $GLOBALS['browser_version'] = $match[1];
135
+                    $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0);
136
+                } else {
137
+                    if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) {
138
+                        // Numero de version pour Mozilla "authentique"
139
+                        if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) {
140
+                            $GLOBALS['browser_rev'] = doubleval($match[1]);
141
+                        } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.)
142
+                        else {
143
+                            if (
144
+                                strpos($GLOBALS['browser_description'], 'Gecko') and !strpos(
145
+                                    $GLOBALS['browser_description'],
146
+                                    'KHTML'
147
+                                )
148
+                            ) {
149
+                                $GLOBALS['browser_rev'] = 1.4;
150
+                            } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.)
151
+                            else {
152
+                                $GLOBALS['browser_rev'] = 1.0;
153
+                            }
154
+                        }
155
+                        $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3;
156
+                    }
157
+                }
158
+            }
159
+        }
160
+    }
161
+
162
+    if (!$GLOBALS['browser_name']) {
163
+        $GLOBALS['browser_name'] = 'Mozilla';
164
+    }
165 165
 }
166 166
 
167 167
 verif_butineur();
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 		$class = ' blocreplie';
56 56
 	}
57 57
 
58
-	return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>";
58
+	return '<div '.($id ? "id='$id' " : '')."class='bloc_depliable$class'>";
59 59
 }
60 60
 
61 61
 // https://code.spip.net/@fin_block
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit)
69 69
 // https://code.spip.net/@bouton_block_depliable
70 70
 function bouton_block_depliable($texte, $deplie, $ids = '') {
71
-	$bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8);
71
+	$bouton_id = 'b'.substr(md5($texte.microtime()), 0, 8);
72 72
 
73 73
 	$class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie');
74 74
 	if (strlen($ids)) {
75 75
 		$cible = explode(',', $ids);
76
-		$cible = '#' . implode(',#', $cible);
76
+		$cible = '#'.implode(',#', $cible);
77 77
 	} else {
78 78
 		$cible = "#$bouton_id + div.bloc_depliable";
79 79
 	}
Please login to merge, or discard this patch.
ecrire/inc/pipelines.php 2 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  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
 if (test_espace_prive()) {
22
-	include_spip('inc/pipelines_ecrire');
22
+    include_spip('inc/pipelines_ecrire');
23 23
 }
24 24
 
25 25
 
@@ -45,29 +45,29 @@  discard block
 block discarded – undo
45 45
  * @return string          Contenu qui sera inséré dans le head HTML
46 46
  **/
47 47
 function f_jQuery($texte) {
48
-	$x = '';
49
-	$jquery_plugins = pipeline(
50
-		'jquery_plugins',
51
-		[
52
-			'javascript/jquery.js',
53
-			'javascript/jquery.form.js',
54
-			'javascript/jquery.autosave.js',
55
-			'javascript/jquery.placeholder-label.js',
56
-			'javascript/ajaxCallback.js',
57
-			'javascript/js.cookie.js',
58
-			'javascript/jquery.cookie.js'
59
-		]
60
-	);
61
-	foreach (array_unique($jquery_plugins) as $script) {
62
-		if ($script = find_in_path(supprimer_timestamp($script))) {
63
-			$script = timestamp($script);
64
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
65
-		}
66
-	}
48
+    $x = '';
49
+    $jquery_plugins = pipeline(
50
+        'jquery_plugins',
51
+        [
52
+            'javascript/jquery.js',
53
+            'javascript/jquery.form.js',
54
+            'javascript/jquery.autosave.js',
55
+            'javascript/jquery.placeholder-label.js',
56
+            'javascript/ajaxCallback.js',
57
+            'javascript/js.cookie.js',
58
+            'javascript/jquery.cookie.js'
59
+        ]
60
+    );
61
+    foreach (array_unique($jquery_plugins) as $script) {
62
+        if ($script = find_in_path(supprimer_timestamp($script))) {
63
+            $script = timestamp($script);
64
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
65
+        }
66
+    }
67 67
 
68
-	$texte = $x . $texte;
68
+    $texte = $x . $texte;
69 69
 
70
-	return $texte;
70
+    return $texte;
71 71
 }
72 72
 
73 73
 
@@ -86,28 +86,28 @@  discard block
 block discarded – undo
86 86
  * @return string         Contenu de la page envoyée au navigateur
87 87
  **/
88 88
 function f_surligne($texte) {
89
-	if (!$GLOBALS['html']) {
90
-		return $texte;
91
-	}
92
-	$rech = _request('var_recherche');
93
-	if (
94
-		!$rech
95
-		and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
96
-			or !_SURLIGNE_RECHERCHE_REFERERS
97
-			or !isset($_SERVER['HTTP_REFERER']))
98
-	) {
99
-		return $texte;
100
-	}
101
-	include_spip('inc/surligne');
89
+    if (!$GLOBALS['html']) {
90
+        return $texte;
91
+    }
92
+    $rech = _request('var_recherche');
93
+    if (
94
+        !$rech
95
+        and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
96
+            or !_SURLIGNE_RECHERCHE_REFERERS
97
+            or !isset($_SERVER['HTTP_REFERER']))
98
+    ) {
99
+        return $texte;
100
+    }
101
+    include_spip('inc/surligne');
102 102
 
103
-	if (isset($_SERVER['HTTP_REFERER'])) {
104
-		$_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
105
-	}
106
-	if ($rech) {
107
-		$rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
108
-	}
103
+    if (isset($_SERVER['HTTP_REFERER'])) {
104
+        $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
105
+    }
106
+    if ($rech) {
107
+        $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
108
+    }
109 109
 
110
-	return surligner_mots($texte, $rech);
110
+    return surligner_mots($texte, $rech);
111 111
 }
112 112
 
113 113
 /**
@@ -124,33 +124,33 @@  discard block
 block discarded – undo
124 124
  * @return string         Contenu de la page envoyée au navigateur
125 125
  **/
126 126
 function f_tidy($texte) {
127
-	/**
128
-	 * Indentation à faire ?
129
-	 *
130
-	 * - true : actif.
131
-	 * - false par défaut.
132
-	 */
127
+    /**
128
+     * Indentation à faire ?
129
+     *
130
+     * - true : actif.
131
+     * - false par défaut.
132
+     */
133 133
 
134
-	if (
135
-		$GLOBALS['xhtml'] # tidy demande
136
-		and $GLOBALS['html'] # verifie que la page avait l'entete text/html
137
-		and strlen($texte)
138
-		and !headers_sent()
139
-	) {
140
-		# Compatibilite ascendante
141
-		if (!is_string($GLOBALS['xhtml'])) {
142
-			$GLOBALS['xhtml'] = 'tidy';
143
-		}
134
+    if (
135
+        $GLOBALS['xhtml'] # tidy demande
136
+        and $GLOBALS['html'] # verifie que la page avait l'entete text/html
137
+        and strlen($texte)
138
+        and !headers_sent()
139
+    ) {
140
+        # Compatibilite ascendante
141
+        if (!is_string($GLOBALS['xhtml'])) {
142
+            $GLOBALS['xhtml'] = 'tidy';
143
+        }
144 144
 
145
-		if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
146
-			spip_log("tidy absent, l'indenteur SPIP le remplace");
147
-			$f = charger_fonction('sax', 'xml');
148
-		}
145
+        if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
146
+            spip_log("tidy absent, l'indenteur SPIP le remplace");
147
+            $f = charger_fonction('sax', 'xml');
148
+        }
149 149
 
150
-		return $f($texte);
151
-	}
150
+        return $f($texte);
151
+    }
152 152
 
153
-	return $texte;
153
+    return $texte;
154 154
 }
155 155
 
156 156
 
@@ -169,21 +169,21 @@  discard block
 block discarded – undo
169 169
  * @return string         Contenu de la page envoyée au navigateur
170 170
  **/
171 171
 function f_insert_head($texte) {
172
-	if (!$GLOBALS['html']) {
173
-		return $texte;
174
-	}
175
-	include_spip('public/admin'); // pour strripos
172
+    if (!$GLOBALS['html']) {
173
+        return $texte;
174
+    }
175
+    include_spip('public/admin'); // pour strripos
176 176
 
177
-	($pos = stripos($texte, '</head>'))
178
-	|| ($pos = stripos($texte, '<body>'))
179
-	|| ($pos = 0);
177
+    ($pos = stripos($texte, '</head>'))
178
+    || ($pos = stripos($texte, '<body>'))
179
+    || ($pos = 0);
180 180
 
181
-	if (false === strpos(substr($texte, 0, $pos), '<!-- insert_head -->')) {
182
-		$insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
183
-		$texte = substr_replace($texte, $insert, $pos, 0);
184
-	}
181
+    if (false === strpos(substr($texte, 0, $pos), '<!-- insert_head -->')) {
182
+        $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
183
+        $texte = substr_replace($texte, $insert, $pos, 0);
184
+    }
185 185
 
186
-	return $texte;
186
+    return $texte;
187 187
 }
188 188
 
189 189
 
@@ -199,34 +199,34 @@  discard block
 block discarded – undo
199 199
  * @return string         Contenu de la page envoyée au navigateur
200 200
  **/
201 201
 function f_admin($texte) {
202
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
203
-		include_spip('inc/filtres'); // pour http_img_pack
204
-		$x = "<div class='spip-previsu' "
205
-			. http_style_background('preview-32.png', '', 32)
206
-			. '>'
207
-			. _T('previsualisation')
208
-			. '</div>';
209
-		if (!$pos = stripos($texte, '</body>')) {
210
-			$pos = strlen($texte);
211
-		}
212
-		$texte = substr_replace($texte, $x, $pos, 0);
213
-		// pas de preview en fenetre enfant
214
-		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
215
-		if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
216
-			$pos = -1;
217
-		}
218
-		$texte = substr_replace($texte, $x, $pos + 1, 0);
219
-	}
202
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
203
+        include_spip('inc/filtres'); // pour http_img_pack
204
+        $x = "<div class='spip-previsu' "
205
+            . http_style_background('preview-32.png', '', 32)
206
+            . '>'
207
+            . _T('previsualisation')
208
+            . '</div>';
209
+        if (!$pos = stripos($texte, '</body>')) {
210
+            $pos = strlen($texte);
211
+        }
212
+        $texte = substr_replace($texte, $x, $pos, 0);
213
+        // pas de preview en fenetre enfant
214
+        $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
215
+        if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
216
+            $pos = -1;
217
+        }
218
+        $texte = substr_replace($texte, $x, $pos + 1, 0);
219
+    }
220 220
 
221
-	if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
222
-		include_spip('public/admin');
223
-		$texte = affiche_boutons_admin($texte);
224
-	}
225
-	if (_request('var_mode') == 'noajax') {
226
-		$texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
227
-	}
221
+    if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
222
+        include_spip('public/admin');
223
+        $texte = affiche_boutons_admin($texte);
224
+    }
225
+    if (_request('var_mode') == 'noajax') {
226
+        $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
227
+    }
228 228
 
229
-	return $texte;
229
+    return $texte;
230 230
 }
231 231
 
232 232
 /**
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
  * @return array $flux  Description et contenu de l'inclusion
245 245
  **/
246 246
 function f_recuperer_fond($flux) {
247
-	if (!test_espace_prive()) {
248
-		return $flux;
249
-	}
247
+    if (!test_espace_prive()) {
248
+        return $flux;
249
+    }
250 250
 
251
-	return f_afficher_blocs_ecrire($flux);
251
+    return f_afficher_blocs_ecrire($flux);
252 252
 }
253 253
 
254 254
 /**
@@ -262,30 +262,30 @@  discard block
 block discarded – undo
262 262
  * @return string         Contenu de la page envoyée au navigateur
263 263
  */
264 264
 function f_queue($texte) {
265
-	// eviter une inclusion si rien a faire
266
-	if (
267
-		_request('action') == 'cron'
268
-		or queue_sleep_time_to_next_job() > 0
269
-		or defined('_DEBUG_BLOCK_QUEUE')
270
-	) {
271
-		return $texte;
272
-	}
265
+    // eviter une inclusion si rien a faire
266
+    if (
267
+        _request('action') == 'cron'
268
+        or queue_sleep_time_to_next_job() > 0
269
+        or defined('_DEBUG_BLOCK_QUEUE')
270
+    ) {
271
+        return $texte;
272
+    }
273 273
 
274
-	include_spip('inc/queue');
275
-	$code = queue_affichage_cron();
274
+    include_spip('inc/queue');
275
+    $code = queue_affichage_cron();
276 276
 
277
-	// si rien a afficher
278
-	// ou si on est pas dans une page html, on ne sait rien faire de mieux
279
-	if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
280
-		return $texte;
281
-	}
277
+    // si rien a afficher
278
+    // ou si on est pas dans une page html, on ne sait rien faire de mieux
279
+    if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
280
+        return $texte;
281
+    }
282 282
 
283
-	// inserer avant le </body> fermant si on peut, a la fin de la page sinon
284
-	if (($p = strpos($texte, '</body>')) !== false) {
285
-		$texte = substr($texte, 0, $p) . $code . substr($texte, $p);
286
-	} else {
287
-		$texte .= $code;
288
-	}
283
+    // inserer avant le </body> fermant si on peut, a la fin de la page sinon
284
+    if (($p = strpos($texte, '</body>')) !== false) {
285
+        $texte = substr($texte, 0, $p) . $code . substr($texte, $p);
286
+    } else {
287
+        $texte .= $code;
288
+    }
289 289
 
290
-	return $texte;
290
+    return $texte;
291 291
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		}
66 66
 	}
67 67
 
68
-	$texte = $x . $texte;
68
+	$texte = $x.$texte;
69 69
 
70 70
 	return $texte;
71 71
 }
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	|| ($pos = 0);
180 180
 
181 181
 	if (false === strpos(substr($texte, 0, $pos), '<!-- insert_head -->')) {
182
-		$insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
182
+		$insert = "\n".pipeline('insert_head', '<!-- f_insert_head -->')."\n";
183 183
 		$texte = substr_replace($texte, $insert, $pos, 0);
184 184
 	}
185 185
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 		}
212 212
 		$texte = substr_replace($texte, $x, $pos, 0);
213 213
 		// pas de preview en fenetre enfant
214
-		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
214
+		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='".addslashes($GLOBALS['meta']['adresse_site'])."';}</script>";
215 215
 		if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
216 216
 			$pos = -1;
217 217
 		}
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 
283 283
 	// inserer avant le </body> fermant si on peut, a la fin de la page sinon
284 284
 	if (($p = strpos($texte, '</body>')) !== false) {
285
-		$texte = substr($texte, 0, $p) . $code . substr($texte, $p);
285
+		$texte = substr($texte, 0, $p).$code.substr($texte, $p);
286 286
 	} else {
287 287
 		$texte .= $code;
288 288
 	}
Please login to merge, or discard this patch.
ecrire/inc/recherche_to_array.php 2 patches
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
-	list($methode, $q, $preg) = expression_recherche($recherche, $options);
55
+    list($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
-					list($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
-					list($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
-				list($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
+                    list($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
+                    list($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
+                list($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.
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.
ecrire/inc/install.php 2 patches
Indentation   +359 added lines, -359 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
 
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
  * @return void
44 44
  **/
45 45
 function install_fichier_connexion($nom, $texte) {
46
-	$texte = '<' . "?php\n"
47
-		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
-		. $texte
49
-		. '?' . '>';
46
+    $texte = '<' . "?php\n"
47
+        . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
+        . $texte
49
+        . '?' . '>';
50 50
 
51
-	ecrire_fichier($nom, $texte);
51
+    ecrire_fichier($nom, $texte);
52 52
 }
53 53
 
54 54
 
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
  *
78 78
  **/
79 79
 function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') {
80
-	$adr = addcslashes($adr, "'\\");
81
-	$port = addcslashes($port, "'\\");
82
-	$login = addcslashes($login, "'\\");
83
-	$pass = addcslashes($pass, "'\\");
84
-	$base = addcslashes($base, "'\\");
85
-	$type = addcslashes($type, "'\\");
86
-	$pref = addcslashes($pref, "'\\");
87
-	$ldap = addcslashes($ldap, "'\\");
88
-	$charset = addcslashes($charset, "'\\");
89
-
90
-	return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
91
-	. 'spip_connect_db('
92
-	. "'$adr','$port','$login','$pass','$base'"
93
-	. ",'$type', '$pref','$ldap','$charset');\n";
80
+    $adr = addcslashes($adr, "'\\");
81
+    $port = addcslashes($port, "'\\");
82
+    $login = addcslashes($login, "'\\");
83
+    $pass = addcslashes($pass, "'\\");
84
+    $base = addcslashes($base, "'\\");
85
+    $type = addcslashes($type, "'\\");
86
+    $pref = addcslashes($pref, "'\\");
87
+    $ldap = addcslashes($ldap, "'\\");
88
+    $charset = addcslashes($charset, "'\\");
89
+
90
+    return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
91
+    . 'spip_connect_db('
92
+    . "'$adr','$port','$login','$pass','$base'"
93
+    . ",'$type', '$pref','$ldap','$charset');\n";
94 94
 }
95 95
 
96 96
 
@@ -106,26 +106,26 @@  discard block
 block discarded – undo
106 106
  *     Tableau des informations sur la connexion
107 107
  **/
108 108
 function analyse_fichier_connection($file) {
109
-	$s = @join('', file($file));
110
-	if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
111
-		array_shift($regs);
112
-
113
-		return $regs;
114
-	} else {
115
-		$ar = '\s*\'([^\']*)\'';
116
-		$r = '\s*,' . $ar;
117
-		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
118
-		if (preg_match($r, $s, $regs)) {
119
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
120
-			array_shift($regs);
121
-			array_shift($regs);
122
-
123
-			return $regs;
124
-		}
125
-	}
126
-	spip_log("$file n'est pas un fichier de connexion");
127
-
128
-	return [];
109
+    $s = @join('', file($file));
110
+    if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
111
+        array_shift($regs);
112
+
113
+        return $regs;
114
+    } else {
115
+        $ar = '\s*\'([^\']*)\'';
116
+        $r = '\s*,' . $ar;
117
+        $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
118
+        if (preg_match($r, $s, $regs)) {
119
+            $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
120
+            array_shift($regs);
121
+            array_shift($regs);
122
+
123
+            return $regs;
124
+        }
125
+    }
126
+    spip_log("$file n'est pas un fichier de connexion");
127
+
128
+    return [];
129 129
 }
130 130
 
131 131
 /**
@@ -142,21 +142,21 @@  discard block
 block discarded – undo
142 142
  *     Liste des noms de connecteurs
143 143
  **/
144 144
 function bases_referencees($exclu = '') {
145
-	$tables = [];
146
-	foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
147
-		if ($f != $exclu and analyse_fichier_connection($f)) {
148
-			$tables[] = basename($f, '.php');
149
-		}
150
-	}
151
-
152
-	return $tables;
145
+    $tables = [];
146
+    foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
147
+        if ($f != $exclu and analyse_fichier_connection($f)) {
148
+            $tables[] = basename($f, '.php');
149
+        }
150
+    }
151
+
152
+    return $tables;
153 153
 }
154 154
 
155 155
 
156 156
 function install_mode_appel($server_db, $tout = true) {
157
-	return ($server_db != 'mysql') ? ''
158
-		: (($tout ? test_rappel_nom_base_mysql($server_db) : '')
159
-			. test_sql_mode_mysql($server_db));
157
+    return ($server_db != 'mysql') ? ''
158
+        : (($tout ? test_rappel_nom_base_mysql($server_db) : '')
159
+            . test_sql_mode_mysql($server_db));
160 160
 }
161 161
 
162 162
 //
@@ -164,52 +164,52 @@  discard block
 block discarded – undo
164 164
 // (sert a l'etape 1 de l'installation)
165 165
 // https://code.spip.net/@tester_compatibilite_hebergement
166 166
 function tester_compatibilite_hebergement() {
167
-	$err = [];
168
-
169
-	$p = phpversion();
170
-	if (version_compare($p, _PHP_MIN, '<')) {
171
-		$err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
-	}
173
-
174
-	// Si on n'a pas la bonne version de PHP, c'est la fin
175
-	if ($err) {
176
-		die("<div class='error'>"
177
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
178
-			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
179
-	}
180
-
181
-	// Il faut une base de donnees tout de meme ...
182
-	$serveurs = install_select_serveur();
183
-	if (!$serveurs) {
184
-		$err[] = _T('install_extension_php_obligatoire')
185
-			. " <a href='http://www.php.net/mysql'>MYSQL</a>"
186
-			. "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
187
-			. "| <a href='http://www.php.net/sqlite'>SQLite</a>";
188
-	}
189
-
190
-	// et il faut preg
191
-	if (!function_exists('preg_match_all')) {
192
-		$err[] = _T('install_extension_php_obligatoire')
193
-			. " <a href='http://se.php.net/pcre'>PCRE</a>";
194
-	}
195
-
196
-	// et surtout pas ce mbstring.overload
197
-	if ($a = @ini_get('mbstring.func_overload')) {
198
-		$err[] = _T('install_extension_mbstring')
199
-			. "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
200
-	}
201
-
202
-	if ($err) {
203
-		echo "<div class='error'>"
204
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
205
-		foreach ($err as $e) {
206
-			echo "<li><strong>$e</strong></li>\n";
207
-		}
208
-
209
-		# a priori ici on pourrait die(), mais il faut laisser la possibilite
210
-		# de forcer malgre tout (pour tester, ou si bug de detection)
211
-		echo "</ul></div>\n";
212
-	}
167
+    $err = [];
168
+
169
+    $p = phpversion();
170
+    if (version_compare($p, _PHP_MIN, '<')) {
171
+        $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
+    }
173
+
174
+    // Si on n'a pas la bonne version de PHP, c'est la fin
175
+    if ($err) {
176
+        die("<div class='error'>"
177
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
178
+            . "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
179
+    }
180
+
181
+    // Il faut une base de donnees tout de meme ...
182
+    $serveurs = install_select_serveur();
183
+    if (!$serveurs) {
184
+        $err[] = _T('install_extension_php_obligatoire')
185
+            . " <a href='http://www.php.net/mysql'>MYSQL</a>"
186
+            . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
187
+            . "| <a href='http://www.php.net/sqlite'>SQLite</a>";
188
+    }
189
+
190
+    // et il faut preg
191
+    if (!function_exists('preg_match_all')) {
192
+        $err[] = _T('install_extension_php_obligatoire')
193
+            . " <a href='http://se.php.net/pcre'>PCRE</a>";
194
+    }
195
+
196
+    // et surtout pas ce mbstring.overload
197
+    if ($a = @ini_get('mbstring.func_overload')) {
198
+        $err[] = _T('install_extension_mbstring')
199
+            . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
200
+    }
201
+
202
+    if ($err) {
203
+        echo "<div class='error'>"
204
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
205
+        foreach ($err as $e) {
206
+            echo "<li><strong>$e</strong></li>\n";
207
+        }
208
+
209
+        # a priori ici on pourrait die(), mais il faut laisser la possibilite
210
+        # de forcer malgre tout (pour tester, ou si bug de detection)
211
+        echo "</ul></div>\n";
212
+    }
213 213
 }
214 214
 
215 215
 
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
  * @note superflu ??
220 220
  */
221 221
 function login_hebergeur() {
222
-	$base_hebergeur = 'localhost'; # par defaut
222
+    $base_hebergeur = 'localhost'; # par defaut
223 223
 
224
-	// Free
225
-	if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
226
-		$base_hebergeur = 'sql.free.fr';
227
-		$login_hebergeur = $regs[1];
228
-	} else {
229
-		$login_hebergeur = '';
230
-	}
224
+    // Free
225
+    if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
226
+        $base_hebergeur = 'sql.free.fr';
227
+        $login_hebergeur = $regs[1];
228
+    } else {
229
+        $login_hebergeur = '';
230
+    }
231 231
 
232
-	return [$base_hebergeur, $login_hebergeur];
232
+    return [$base_hebergeur, $login_hebergeur];
233 233
 }
234 234
 
235 235
 
236 236
 // https://code.spip.net/@info_etape
237 237
 function info_etape($titre, $complement = '') {
238
-	return '<h2>' . $titre . "</h2>\n" .
239
-	($complement ? '' . $complement . "\n" : '');
238
+    return '<h2>' . $titre . "</h2>\n" .
239
+    ($complement ? '' . $complement . "\n" : '');
240 240
 }
241 241
 
242 242
 /**
@@ -246,156 +246,156 @@  discard block
 block discarded – undo
246 246
  * @return string Code HTML du bouton
247 247
  **/
248 248
 function bouton_suivant($code = '') {
249
-	if ($code == '') {
250
-		$code = _T('bouton_suivant');
251
-	}
252
-	static $suivant = 0;
253
-	$id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
254
-	$suivant += 1;
255
-
256
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
257
-	$code .
258
-	" >>\" /></p>\n";
249
+    if ($code == '') {
250
+        $code = _T('bouton_suivant');
251
+    }
252
+    static $suivant = 0;
253
+    $id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
254
+    $suivant += 1;
255
+
256
+    return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
257
+    $code .
258
+    " >>\" /></p>\n";
259 259
 }
260 260
 
261 261
 // https://code.spip.net/@info_progression_etape
262 262
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
263
-	//$en_cours = _request('etape')?_request('etape'):"";
264
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
265
-	$debut = 1;
266
-	$etat = 'ok';
267
-	$last = count($liste);
263
+    //$en_cours = _request('etape')?_request('etape'):"";
264
+    $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
265
+    $debut = 1;
266
+    $etat = 'ok';
267
+    $last = count($liste);
268 268
 //	$texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo'));
269 269
 
270
-	$intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
271
-	$intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
272
-	$intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
273
-	$intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
270
+    $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
271
+    $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
272
+    $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
273
+    $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
274 274
 
275
-	$intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
276
-	$intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
277
-	$intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
278
-	$intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
279
-	$intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
275
+    $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
276
+    $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
277
+    $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
278
+    $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
279
+    $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
280 280
 
281 281
 //	$aff_etapes = "<span id='etapes'>";
282 282
 
283
-	$aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
284
-
285
-	foreach ($liste as $etape => $fichier) {
286
-		if ($debut < $last) {
287
-			if ($debut == $en_cours && $erreur) {
288
-				$class = 'on erreur';
289
-			} else {
290
-				if ($debut == $en_cours) {
291
-					$class = 'on';
292
-				} else {
293
-					if ($debut > $en_cours) {
294
-						$class = 'prochains';
295
-					} else {
296
-						$class = 'valides';
297
-					}
298
-				}
299
-			}
300
-
301
-			$aff_etapes .= "<li class='$class'><div class='fond'>";
302
-			$aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
303
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
304
-			$aff_etapes .= $intitule_etat["$phase"][$debut];
305
-			$aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
306
-			$aff_etapes .= '</div></li>';
307
-		}
308
-		$debut++;
309
-	}
310
-	$aff_etapes .= '</ul>';
311
-	$aff_etapes .= "<br class='nettoyeur' />\n";
312
-
313
-	return $aff_etapes;
283
+    $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
284
+
285
+    foreach ($liste as $etape => $fichier) {
286
+        if ($debut < $last) {
287
+            if ($debut == $en_cours && $erreur) {
288
+                $class = 'on erreur';
289
+            } else {
290
+                if ($debut == $en_cours) {
291
+                    $class = 'on';
292
+                } else {
293
+                    if ($debut > $en_cours) {
294
+                        $class = 'prochains';
295
+                    } else {
296
+                        $class = 'valides';
297
+                    }
298
+                }
299
+            }
300
+
301
+            $aff_etapes .= "<li class='$class'><div class='fond'>";
302
+            $aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
303
+            $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
304
+            $aff_etapes .= $intitule_etat["$phase"][$debut];
305
+            $aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
306
+            $aff_etapes .= '</div></li>';
307
+        }
308
+        $debut++;
309
+    }
310
+    $aff_etapes .= '</ul>';
311
+    $aff_etapes .= "<br class='nettoyeur' />\n";
312
+
313
+    return $aff_etapes;
314 314
 }
315 315
 
316 316
 
317 317
 // https://code.spip.net/@fieldset
318 318
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
319
-	return "<fieldset>\n" .
320
-	$avant .
321
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
322
-	fieldset_champs($champs) .
323
-	$apres .
324
-	"</fieldset>\n";
319
+    return "<fieldset>\n" .
320
+    $avant .
321
+    ($legend ? '<legend>' . $legend . "</legend>\n" : '') .
322
+    fieldset_champs($champs) .
323
+    $apres .
324
+    "</fieldset>\n";
325 325
 }
326 326
 
327 327
 function fieldset_champs($champs = []) {
328
-	$fieldset = '';
329
-	foreach ($champs as $nom => $contenu) {
330
-		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
331
-		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
332
-		if (isset($contenu['alternatives'])) {
333
-			$fieldset .= $contenu['label'] . "\n";
334
-			foreach ($contenu['alternatives'] as $valeur => $label) {
335
-				$fieldset .= "<input type='radio' name='" . $nom .
336
-					"' id='$nom-$valeur' value='$valeur'"
337
-					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
338
-					. "/>\n";
339
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
340
-			}
341
-			$fieldset .= "<br />\n";
342
-		} else {
343
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
344
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
345
-				. (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
346
-				. ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
347
-				. " />\n";
348
-		}
349
-	}
350
-
351
-	return $fieldset;
328
+    $fieldset = '';
329
+    foreach ($champs as $nom => $contenu) {
330
+        $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
331
+        $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
332
+        if (isset($contenu['alternatives'])) {
333
+            $fieldset .= $contenu['label'] . "\n";
334
+            foreach ($contenu['alternatives'] as $valeur => $label) {
335
+                $fieldset .= "<input type='radio' name='" . $nom .
336
+                    "' id='$nom-$valeur' value='$valeur'"
337
+                    . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
338
+                    . "/>\n";
339
+                $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
340
+            }
341
+            $fieldset .= "<br />\n";
342
+        } else {
343
+            $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
344
+            $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
345
+                . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
346
+                . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
347
+                . " />\n";
348
+        }
349
+    }
350
+
351
+    return $fieldset;
352 352
 }
353 353
 
354 354
 function install_select_serveur() {
355
-	$options = [];
356
-	$dir = _DIR_RESTREINT . 'req/';
357
-	$d = opendir($dir);
358
-	if (!$d) {
359
-		return [];
360
-	}
361
-	while (($f = readdir($d)) !== false) {
362
-		if (
363
-			(preg_match('/^(.*)[.]php$/', $f, $s))
364
-			and is_readable($f = $dir . $f)
365
-		) {
366
-			require_once($f);
367
-			$s = $s[1];
368
-			$v = 'spip_versions_' . $s;
369
-			if (function_exists($v) and $v()) {
370
-				$titre = _T("install_select_type_$s");
371
-				// proposer mysql par defaut si dispo
372
-				$checked = ($s == 'mysql' ? " checked='checked'" : '');
373
-				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
374
-					. "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>';
375
-			} else {
376
-				spip_log("$s: portage indisponible");
377
-			}
378
-		}
379
-	}
380
-	sort($options);
381
-
382
-	return $options;
355
+    $options = [];
356
+    $dir = _DIR_RESTREINT . 'req/';
357
+    $d = opendir($dir);
358
+    if (!$d) {
359
+        return [];
360
+    }
361
+    while (($f = readdir($d)) !== false) {
362
+        if (
363
+            (preg_match('/^(.*)[.]php$/', $f, $s))
364
+            and is_readable($f = $dir . $f)
365
+        ) {
366
+            require_once($f);
367
+            $s = $s[1];
368
+            $v = 'spip_versions_' . $s;
369
+            if (function_exists($v) and $v()) {
370
+                $titre = _T("install_select_type_$s");
371
+                // proposer mysql par defaut si dispo
372
+                $checked = ($s == 'mysql' ? " checked='checked'" : '');
373
+                $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
374
+                    . "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>';
375
+            } else {
376
+                spip_log("$s: portage indisponible");
377
+            }
378
+        }
379
+    }
380
+    sort($options);
381
+
382
+    return $options;
383 383
 }
384 384
 
385 385
 // https://code.spip.net/@install_connexion_form
386 386
 function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) {
387
-	$server_db = (is_string($predef[0])) ? $predef[0] : '';
388
-
389
-	return generer_form_ecrire('install', (
390
-		"\n<input type='hidden' name='etape' value='$etape' />"
391
-		. $hidden
392
-		. (_request('echec') ?
393
-			('<p><b>' . _T('avis_connexion_echec_1') .
394
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
-			: '')
396
-
397
-		. ($jquery ? http_script('', 'jquery.js') : '')
398
-		. http_script('
387
+    $server_db = (is_string($predef[0])) ? $predef[0] : '';
388
+
389
+    return generer_form_ecrire('install', (
390
+        "\n<input type='hidden' name='etape' value='$etape' />"
391
+        . $hidden
392
+        . (_request('echec') ?
393
+            ('<p><b>' . _T('avis_connexion_echec_1') .
394
+                '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
+            : '')
396
+
397
+        . ($jquery ? http_script('', 'jquery.js') : '')
398
+        . http_script('
399 399
 		jQuery(function($) {
400 400
 			$details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur");
401 401
 			$("input[type=hidden][name=server_db]").each(function(){
@@ -428,70 +428,70 @@  discard block
 block discarded – undo
428 428
 			});
429 429
 		});')
430 430
 
431
-		. ($server_db
432
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
-			. (($predef[0])
434
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
-				: '')
436
-			: ('<fieldset><legend>'
437
-				. _T('install_select_type_db')
438
-				. '</legend>'
439
-				. '<p class="explication">'
440
-				. _T('install_types_db_connus')
441
-				// Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
-				// . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
-				. '</p>'
444
-				. "\n<div class='p'>\n<ul>\n"
445
-				. join("\n", install_select_serveur())
446
-				. "\n</ul>\n</div></fieldset>")
447
-		)
448
-		. '<div id="install_adresse_base_hebergeur">'
449
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
450
-		. ($predef[1]
451
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
-			: fieldset(
453
-				_T('entree_base_donnee_1'),
454
-				[
455
-					'adresse_db' => [
456
-						'label' => $db[1],
457
-						'valeur' => $db[0]
458
-					],
459
-				]
460
-			)
461
-		)
462
-		. '</div>'
463
-
464
-		. '<div id="install_login_base_hebergeur">'
465
-		. ($predef[2]
466
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
-			: fieldset(
468
-				_T('entree_login_connexion_1'),
469
-				[
470
-					'login_db' => [
471
-						'label' => $login[1],
472
-						'valeur' => $login[0]
473
-					],
474
-				]
475
-			)
476
-		)
477
-		. '</div>'
478
-
479
-		. '<div id="install_pass_base_hebergeur">'
480
-		. ($predef[3]
481
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
-			: fieldset(
483
-				_T('entree_mot_passe_1'),
484
-				[
485
-					'pass_db' => [
486
-						'label' => $pass[1],
487
-						'valeur' => $pass[0]
488
-					],
489
-				]
490
-			)
491
-		)
492
-		. '</div>'
493
-
494
-		. bouton_suivant()));
431
+        . ($server_db
432
+            ? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
+            . (($predef[0])
434
+                ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
+                : '')
436
+            : ('<fieldset><legend>'
437
+                . _T('install_select_type_db')
438
+                . '</legend>'
439
+                . '<p class="explication">'
440
+                . _T('install_types_db_connus')
441
+                // Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
+                // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
+                . '</p>'
444
+                . "\n<div class='p'>\n<ul>\n"
445
+                . join("\n", install_select_serveur())
446
+                . "\n</ul>\n</div></fieldset>")
447
+        )
448
+        . '<div id="install_adresse_base_hebergeur">'
449
+        . '<p>' . _T('texte_connexion_mysql') . '</p>'
450
+        . ($predef[1]
451
+            ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
+            : fieldset(
453
+                _T('entree_base_donnee_1'),
454
+                [
455
+                    'adresse_db' => [
456
+                        'label' => $db[1],
457
+                        'valeur' => $db[0]
458
+                    ],
459
+                ]
460
+            )
461
+        )
462
+        . '</div>'
463
+
464
+        . '<div id="install_login_base_hebergeur">'
465
+        . ($predef[2]
466
+            ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
+            : fieldset(
468
+                _T('entree_login_connexion_1'),
469
+                [
470
+                    'login_db' => [
471
+                        'label' => $login[1],
472
+                        'valeur' => $login[0]
473
+                    ],
474
+                ]
475
+            )
476
+        )
477
+        . '</div>'
478
+
479
+        . '<div id="install_pass_base_hebergeur">'
480
+        . ($predef[3]
481
+            ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
+            : fieldset(
483
+                _T('entree_mot_passe_1'),
484
+                [
485
+                    'pass_db' => [
486
+                        'label' => $pass[1],
487
+                        'valeur' => $pass[0]
488
+                    ],
489
+                ]
490
+            )
491
+        )
492
+        . '</div>'
493
+
494
+        . bouton_suivant()));
495 495
 }
496 496
 
497 497
 // 4 valeurs qu'on reconduit d'un script a l'autre
@@ -499,76 +499,76 @@  discard block
 block discarded – undo
499 499
 
500 500
 // https://code.spip.net/@predef_ou_cache
501 501
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
502
-	return ((defined('_INSTALL_HOST_DB'))
503
-		? ''
504
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
505
-	)
506
-	. ((defined('_INSTALL_USER_DB'))
507
-		? ''
508
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
509
-	)
510
-	. ((defined('_INSTALL_PASS_DB'))
511
-		? ''
512
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
513
-	)
514
-
515
-	. ((defined('_INSTALL_SERVER_DB'))
516
-		? ''
517
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
518
-	);
502
+    return ((defined('_INSTALL_HOST_DB'))
503
+        ? ''
504
+        : "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
505
+    )
506
+    . ((defined('_INSTALL_USER_DB'))
507
+        ? ''
508
+        : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
509
+    )
510
+    . ((defined('_INSTALL_PASS_DB'))
511
+        ? ''
512
+        : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
513
+    )
514
+
515
+    . ((defined('_INSTALL_SERVER_DB'))
516
+        ? ''
517
+        : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
518
+    );
519 519
 }
520 520
 
521 521
 // presentation des bases existantes
522 522
 
523 523
 // https://code.spip.net/@install_etape_liste_bases
524 524
 function install_etape_liste_bases($server_db, $login_db, $disabled = []) {
525
-	$bases = $checked = [];
526
-	$noms = sql_listdbs($server_db);
527
-	if (!$noms) {
528
-		return '';
529
-	}
530
-
531
-	foreach ($noms as $nom) {
532
-		$id = spip_htmlspecialchars($nom);
533
-		$dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
534
-		$base = ' name="choix_db" value="'
535
-			. $nom
536
-			. '"'
537
-			. $dis
538
-			. " type='radio' id='$id'";
539
-		$label = "<label for='$id'>"
540
-			. ($dis ? "<i>$nom</i>" : $nom)
541
-			. '</label>';
542
-
543
-		if (
544
-			!$checked and !$dis and
545
-			(($nom == $login_db) or
546
-				($GLOBALS['table_prefix'] == $nom))
547
-		) {
548
-			$checked = "<input$base checked='checked' />\n$label";
549
-		} else {
550
-			$bases[] = "<input$base />\n$label";
551
-		}
552
-	}
553
-
554
-	if (!$bases && !$checked) {
555
-		return false;
556
-	}
557
-
558
-	if ($checked) {
559
-		array_unshift($bases, $checked);
560
-		$checked = true;
561
-	}
562
-
563
-	return [$checked, $bases];
525
+    $bases = $checked = [];
526
+    $noms = sql_listdbs($server_db);
527
+    if (!$noms) {
528
+        return '';
529
+    }
530
+
531
+    foreach ($noms as $nom) {
532
+        $id = spip_htmlspecialchars($nom);
533
+        $dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
534
+        $base = ' name="choix_db" value="'
535
+            . $nom
536
+            . '"'
537
+            . $dis
538
+            . " type='radio' id='$id'";
539
+        $label = "<label for='$id'>"
540
+            . ($dis ? "<i>$nom</i>" : $nom)
541
+            . '</label>';
542
+
543
+        if (
544
+            !$checked and !$dis and
545
+            (($nom == $login_db) or
546
+                ($GLOBALS['table_prefix'] == $nom))
547
+        ) {
548
+            $checked = "<input$base checked='checked' />\n$label";
549
+        } else {
550
+            $bases[] = "<input$base />\n$label";
551
+        }
552
+    }
553
+
554
+    if (!$bases && !$checked) {
555
+        return false;
556
+    }
557
+
558
+    if ($checked) {
559
+        array_unshift($bases, $checked);
560
+        $checked = true;
561
+    }
562
+
563
+    return [$checked, $bases];
564 564
 }
565 565
 
566 566
 function install_propager($hidden) {
567
-	$res = '';
568
-	foreach ($hidden as $k) {
569
-		$v = spip_htmlentities(_request($k));
570
-		$res .= "<input type='hidden' name='$k' value='$v' />";
571
-	}
567
+    $res = '';
568
+    foreach ($hidden as $k) {
569
+        $v = spip_htmlentities(_request($k));
570
+        $res .= "<input type='hidden' name='$k' value='$v' />";
571
+    }
572 572
 
573
-	return $res;
573
+    return $res;
574 574
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
  * @return void
44 44
  **/
45 45
 function install_fichier_connexion($nom, $texte) {
46
-	$texte = '<' . "?php\n"
46
+	$texte = '<'."?php\n"
47 47
 		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48 48
 		. $texte
49
-		. '?' . '>';
49
+		. '?'.'>';
50 50
 
51 51
 	ecrire_fichier($nom, $texte);
52 52
 }
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
 		return $regs;
114 114
 	} else {
115 115
 		$ar = '\s*\'([^\']*)\'';
116
-		$r = '\s*,' . $ar;
116
+		$r = '\s*,'.$ar;
117 117
 		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
118 118
 		if (preg_match($r, $s, $regs)) {
119
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
119
+			$regs[2] = $regs[1].(!$regs[2] ? '' : ':'.$regs[2].';');
120 120
 			array_shift($regs);
121 121
 			array_shift($regs);
122 122
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	// Si on n'a pas la bonne version de PHP, c'est la fin
175 175
 	if ($err) {
176 176
 		die("<div class='error'>"
177
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
177
+			. '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"
178 178
 			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
179 179
 	}
180 180
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
 	if ($err) {
203 203
 		echo "<div class='error'>"
204
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
204
+			. '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>";
205 205
 		foreach ($err as $e) {
206 206
 			echo "<li><strong>$e</strong></li>\n";
207 207
 		}
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
 
236 236
 // https://code.spip.net/@info_etape
237 237
 function info_etape($titre, $complement = '') {
238
-	return '<h2>' . $titre . "</h2>\n" .
239
-	($complement ? '' . $complement . "\n" : '');
238
+	return '<h2>'.$titre."</h2>\n".
239
+	($complement ? ''.$complement."\n" : '');
240 240
 }
241 241
 
242 242
 /**
@@ -250,18 +250,18 @@  discard block
 block discarded – undo
250 250
 		$code = _T('bouton_suivant');
251 251
 	}
252 252
 	static $suivant = 0;
253
-	$id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
253
+	$id = 'suivant'.(($suivant > 0) ? strval($suivant) : '');
254 254
 	$suivant += 1;
255 255
 
256
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
257
-	$code .
256
+	return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"".
257
+	$code.
258 258
 	" >>\" /></p>\n";
259 259
 }
260 260
 
261 261
 // https://code.spip.net/@info_progression_etape
262 262
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
263 263
 	//$en_cours = _request('etape')?_request('etape'):"";
264
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
264
+	$liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$');
265 265
 	$debut = 1;
266 266
 	$etat = 'ok';
267 267
 	$last = count($liste);
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 
301 301
 			$aff_etapes .= "<li class='$class'><div class='fond'>";
302 302
 			$aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
303
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
303
+			$aff_etapes .= '<em>'._T('etape')." </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
304 304
 			$aff_etapes .= $intitule_etat["$phase"][$debut];
305 305
 			$aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
306 306
 			$aff_etapes .= '</div></li>';
@@ -316,11 +316,11 @@  discard block
 block discarded – undo
316 316
 
317 317
 // https://code.spip.net/@fieldset
318 318
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
319
-	return "<fieldset>\n" .
320
-	$avant .
321
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
322
-	fieldset_champs($champs) .
323
-	$apres .
319
+	return "<fieldset>\n".
320
+	$avant.
321
+	($legend ? '<legend>'.$legend."</legend>\n" : '').
322
+	fieldset_champs($champs).
323
+	$apres.
324 324
 	"</fieldset>\n";
325 325
 }
326 326
 
@@ -330,18 +330,18 @@  discard block
 block discarded – undo
330 330
 		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
331 331
 		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
332 332
 		if (isset($contenu['alternatives'])) {
333
-			$fieldset .= $contenu['label'] . "\n";
333
+			$fieldset .= $contenu['label']."\n";
334 334
 			foreach ($contenu['alternatives'] as $valeur => $label) {
335
-				$fieldset .= "<input type='radio' name='" . $nom .
335
+				$fieldset .= "<input type='radio' name='".$nom.
336 336
 					"' id='$nom-$valeur' value='$valeur'"
337 337
 					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
338 338
 					. "/>\n";
339
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
339
+				$fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n";
340 340
 			}
341 341
 			$fieldset .= "<br />\n";
342 342
 		} else {
343
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
344
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
343
+			$fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n";
344
+			$fieldset .= '<input '.$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'"
345 345
 				. (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
346 346
 				. ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
347 347
 				. " />\n";
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
 function install_select_serveur() {
355 355
 	$options = [];
356
-	$dir = _DIR_RESTREINT . 'req/';
356
+	$dir = _DIR_RESTREINT.'req/';
357 357
 	$d = opendir($dir);
358 358
 	if (!$d) {
359 359
 		return [];
@@ -361,17 +361,17 @@  discard block
 block discarded – undo
361 361
 	while (($f = readdir($d)) !== false) {
362 362
 		if (
363 363
 			(preg_match('/^(.*)[.]php$/', $f, $s))
364
-			and is_readable($f = $dir . $f)
364
+			and is_readable($f = $dir.$f)
365 365
 		) {
366 366
 			require_once($f);
367 367
 			$s = $s[1];
368
-			$v = 'spip_versions_' . $s;
368
+			$v = 'spip_versions_'.$s;
369 369
 			if (function_exists($v) and $v()) {
370 370
 				$titre = _T("install_select_type_$s");
371 371
 				// proposer mysql par defaut si dispo
372 372
 				$checked = ($s == 'mysql' ? " checked='checked'" : '');
373 373
 				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
374
-					. "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>';
374
+					. "<label for='$s'>".($titre ? $titre : $s).'</label></li>';
375 375
 			} else {
376 376
 				spip_log("$s: portage indisponible");
377 377
 			}
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
 		"\n<input type='hidden' name='etape' value='$etape' />"
391 391
 		. $hidden
392 392
 		. (_request('echec') ?
393
-			('<p><b>' . _T('avis_connexion_echec_1') .
394
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
393
+			('<p><b>'._T('avis_connexion_echec_1').
394
+				'</b></p><p>'._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3').'</p>')
395 395
 			: '')
396 396
 
397 397
 		. ($jquery ? http_script('', 'jquery.js') : '')
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
 		});')
430 430
 
431 431
 		. ($server_db
432
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
432
+			? '<input type="hidden" name="server_db" value="'.$server_db.'" />'
433 433
 			. (($predef[0])
434
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
434
+				? ('<h3>'._T('install_serveur_hebergeur').'</h3>')
435 435
 				: '')
436 436
 			: ('<fieldset><legend>'
437 437
 				. _T('install_select_type_db')
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
 				. "\n</ul>\n</div></fieldset>")
447 447
 		)
448 448
 		. '<div id="install_adresse_base_hebergeur">'
449
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
449
+		. '<p>'._T('texte_connexion_mysql').'</p>'
450 450
 		. ($predef[1]
451
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
451
+			? '<h3>'._T('install_adresse_base_hebergeur').'</h3>'
452 452
 			: fieldset(
453 453
 				_T('entree_base_donnee_1'),
454 454
 				[
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 
464 464
 		. '<div id="install_login_base_hebergeur">'
465 465
 		. ($predef[2]
466
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
466
+			? '<h3>'._T('install_login_base_hebergeur').'</h3>'
467 467
 			: fieldset(
468 468
 				_T('entree_login_connexion_1'),
469 469
 				[
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 
479 479
 		. '<div id="install_pass_base_hebergeur">'
480 480
 		. ($predef[3]
481
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
481
+			? '<h3>'._T('install_pass_base_hebergeur').'</h3>'
482 482
 			: fieldset(
483 483
 				_T('entree_mot_passe_1'),
484 484
 				[
@@ -501,20 +501,20 @@  discard block
 block discarded – undo
501 501
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
502 502
 	return ((defined('_INSTALL_HOST_DB'))
503 503
 		? ''
504
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
504
+		: "\n<input type='hidden' name='adresse_db'  value=\"".spip_htmlspecialchars($adresse_db).'" />'
505 505
 	)
506 506
 	. ((defined('_INSTALL_USER_DB'))
507 507
 		? ''
508
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
508
+		: "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db).'" />'
509 509
 	)
510 510
 	. ((defined('_INSTALL_PASS_DB'))
511 511
 		? ''
512
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
512
+		: "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db).'" />'
513 513
 	)
514 514
 
515 515
 	. ((defined('_INSTALL_SERVER_DB'))
516 516
 		? ''
517
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
517
+		: "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db).'" />'
518 518
 	);
519 519
 }
520 520
 
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.