Completed
Push — master ( a418a7...d593dc )
by cam
01:12
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   +1342 added lines, -1342 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,239 +306,239 @@  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 ($extension = _image_trouver_extension($fichier)
346
-		  and $sanitizer = charger_fonction($extension, 'sanitizer', true)) {
347
-			$sanitizer($fichier);
348
-		}
349
-	} else {
350
-		// enlever le timestamp eventuel
351
-		if (strpos($source, '?') !== false) {
352
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
353
-		}
354
-		if (
355
-			strpos($source, '?') !== false
356
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
357
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
358
-		) {
359
-			$source = $f;
360
-		}
361
-		$fichier = $source;
362
-	}
363
-
364
-	$terminaison_dest = '';
365
-	if ($terminaison = _image_trouver_extension($fichier)) {
366
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
367
-	}
368
-
369
-	if (
370
-		$forcer_format !== false
371
-		// 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
372
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
373
-	) {
374
-		$terminaison_dest = $forcer_format;
375
-	}
376
-
377
-	if (!$terminaison_dest) {
378
-		return false;
379
-	}
380
-
381
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
382
-	$fichier_dest = $nom_fichier;
383
-	if (
384
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
385
-		or @file_exists($f = $fichier)
386
-	) {
387
-		// on passe la balise img a taille image qui exraira les attributs si possible
388
-		// au lieu de faire un acces disque sur le fichier
389
-		list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img);
390
-		$date_src = @filemtime($f);
391
-	} elseif (
392
-		@file_exists($f = "$fichier.src")
393
-		and lire_fichier($f, $valeurs)
394
-		and $valeurs = unserialize($valeurs)
395
-		and isset($valeurs['hauteur_dest'])
396
-		and isset($valeurs['largeur_dest'])
397
-	) {
398
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
399
-		$ret['largeur'] = $valeurs['largeur_dest'];
400
-		$date_src = $valeurs['date'];
401
-	} // pas de fichier source par la
402
-	else {
403
-		return false;
404
-	}
405
-
406
-	// pas de taille mesurable
407
-	if (!($ret['hauteur'] or $ret['largeur'])) {
408
-		return false;
409
-	}
410
-
411
-	// les images calculees dependent du chemin du fichier source
412
-	// 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
413
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
414
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
415
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
416
-	// alors que ca concerne peu de site au final
417
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
418
-	$identifiant = $fichier;
419
-
420
-	// cas general :
421
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
422
-	// cas particulier de reduire :
423
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
424
-	$cache = 'cache-gd2';
425
-	if (substr($effet, 0, 7) == 'reduire') {
426
-		list(, $maxWidth, $maxHeight) = explode('-', $effet);
427
-		list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
428
-		$ret['largeur_dest'] = $destWidth;
429
-		$ret['hauteur_dest'] = $destHeight;
430
-		$effet = "L{$destWidth}xH$destHeight";
431
-		$cache = 'cache-vignettes';
432
-		$fichier_dest = basename($fichier_dest);
433
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
434
-			// on garde la terminaison initiale car image simplement copiee
435
-			// et on postfixe son nom avec un md5 du path
436
-			$terminaison_dest = $terminaison;
437
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
438
-		} else {
439
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
440
-		}
441
-		$cache = sous_repertoire(_DIR_VAR, $cache);
442
-		$cache = sous_repertoire($cache, $effet);
443
-	} else {
444
-		$fichier_dest = md5("$identifiant-$effet");
445
-		$cache = sous_repertoire(_DIR_VAR, $cache);
446
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
447
-		$fichier_dest = substr($fichier_dest, 2);
448
-	}
449
-
450
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
451
-
452
-	$GLOBALS['images_calculees'][] = $fichier_dest;
453
-
454
-	$creer = true;
455
-	// si recalcul des images demande, recalculer chaque image une fois
456
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
457
-		$images_recalcul[$fichier_dest] = true;
458
-	} else {
459
-		if (@file_exists($f = $fichier_dest)) {
460
-			if (filemtime($f) >= $date_src) {
461
-				$creer = false;
462
-			}
463
-		} else {
464
-			if (
465
-				@file_exists($f = "$fichier_dest.src")
466
-				and lire_fichier($f, $valeurs)
467
-				and $valeurs = unserialize($valeurs)
468
-				and $valeurs['date'] >= $date_src
469
-			) {
470
-				$creer = false;
471
-			}
472
-		}
473
-	}
474
-	if ($creer) {
475
-		if (!@file_exists($fichier)) {
476
-			if (!@file_exists("$fichier.src")) {
477
-				spip_log("Image absente : $fichier");
478
-
479
-				return false;
480
-			}
481
-			# on reconstruit l'image source absente a partir de la chaine des .src
482
-			reconstruire_image_intermediaire($fichier);
483
-		}
484
-	}
485
-
486
-	if ($creer) {
487
-		spip_log(
488
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
489
-			'images' . _LOG_DEBUG
490
-		);
491
-	}
492
-
493
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
494
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
495
-	$ret['fichier'] = $fichier;
496
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
497
-	$ret['fichier_dest'] = $fichier_dest;
498
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
499
-	$ret['format_dest'] = $terminaison_dest;
500
-	$ret['date_src'] = $date_src;
501
-	$ret['creer'] = $creer;
502
-	$ret['class'] = extraire_attribut($img, 'class');
503
-	$ret['alt'] = extraire_attribut($img, 'alt');
504
-	$ret['style'] = extraire_attribut($img, 'style');
505
-	$ret['tag'] = $img;
506
-	if ($fonction_creation) {
507
-		$ret['reconstruction'] = $fonction_creation;
508
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
509
-		# cas de image_reduire qui finalement ne reduit pas l'image source
510
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
511
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
512
-	}
513
-
514
-	$ret = pipeline('image_preparer_filtre', [
515
-			'args' => [
516
-				'img' => $img,
517
-				'effet' => $effet,
518
-				'forcer_format' => $forcer_format,
519
-				'fonction_creation' => $fonction_creation,
520
-				'find_in_path' => $find_in_path,
521
-			],
522
-			'data' => $ret
523
-		]);
524
-
525
-	// une globale pour le debug en cas de crash memoire
526
-	$GLOBALS['derniere_image_calculee'] = $ret;
527
-
528
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
529
-	if ($term_fonction === 'svg') {
530
-		if ($creer and !$support_svg) {
531
-			process_image_svg_identite($ret);
532
-			$ret['creer'] = false;
533
-		}
534
-	}
535
-	else {
536
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
537
-			return false;
538
-		}
539
-	}
540
-
541
-	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 ($extension = _image_trouver_extension($fichier)
346
+          and $sanitizer = charger_fonction($extension, 'sanitizer', true)) {
347
+            $sanitizer($fichier);
348
+        }
349
+    } else {
350
+        // enlever le timestamp eventuel
351
+        if (strpos($source, '?') !== false) {
352
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
353
+        }
354
+        if (
355
+            strpos($source, '?') !== false
356
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
357
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
358
+        ) {
359
+            $source = $f;
360
+        }
361
+        $fichier = $source;
362
+    }
363
+
364
+    $terminaison_dest = '';
365
+    if ($terminaison = _image_trouver_extension($fichier)) {
366
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
367
+    }
368
+
369
+    if (
370
+        $forcer_format !== false
371
+        // 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
372
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
373
+    ) {
374
+        $terminaison_dest = $forcer_format;
375
+    }
376
+
377
+    if (!$terminaison_dest) {
378
+        return false;
379
+    }
380
+
381
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
382
+    $fichier_dest = $nom_fichier;
383
+    if (
384
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
385
+        or @file_exists($f = $fichier)
386
+    ) {
387
+        // on passe la balise img a taille image qui exraira les attributs si possible
388
+        // au lieu de faire un acces disque sur le fichier
389
+        list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img);
390
+        $date_src = @filemtime($f);
391
+    } elseif (
392
+        @file_exists($f = "$fichier.src")
393
+        and lire_fichier($f, $valeurs)
394
+        and $valeurs = unserialize($valeurs)
395
+        and isset($valeurs['hauteur_dest'])
396
+        and isset($valeurs['largeur_dest'])
397
+    ) {
398
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
399
+        $ret['largeur'] = $valeurs['largeur_dest'];
400
+        $date_src = $valeurs['date'];
401
+    } // pas de fichier source par la
402
+    else {
403
+        return false;
404
+    }
405
+
406
+    // pas de taille mesurable
407
+    if (!($ret['hauteur'] or $ret['largeur'])) {
408
+        return false;
409
+    }
410
+
411
+    // les images calculees dependent du chemin du fichier source
412
+    // 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
413
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
414
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
415
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
416
+    // alors que ca concerne peu de site au final
417
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
418
+    $identifiant = $fichier;
419
+
420
+    // cas general :
421
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
422
+    // cas particulier de reduire :
423
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
424
+    $cache = 'cache-gd2';
425
+    if (substr($effet, 0, 7) == 'reduire') {
426
+        list(, $maxWidth, $maxHeight) = explode('-', $effet);
427
+        list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
428
+        $ret['largeur_dest'] = $destWidth;
429
+        $ret['hauteur_dest'] = $destHeight;
430
+        $effet = "L{$destWidth}xH$destHeight";
431
+        $cache = 'cache-vignettes';
432
+        $fichier_dest = basename($fichier_dest);
433
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
434
+            // on garde la terminaison initiale car image simplement copiee
435
+            // et on postfixe son nom avec un md5 du path
436
+            $terminaison_dest = $terminaison;
437
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
438
+        } else {
439
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
440
+        }
441
+        $cache = sous_repertoire(_DIR_VAR, $cache);
442
+        $cache = sous_repertoire($cache, $effet);
443
+    } else {
444
+        $fichier_dest = md5("$identifiant-$effet");
445
+        $cache = sous_repertoire(_DIR_VAR, $cache);
446
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
447
+        $fichier_dest = substr($fichier_dest, 2);
448
+    }
449
+
450
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
451
+
452
+    $GLOBALS['images_calculees'][] = $fichier_dest;
453
+
454
+    $creer = true;
455
+    // si recalcul des images demande, recalculer chaque image une fois
456
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
457
+        $images_recalcul[$fichier_dest] = true;
458
+    } else {
459
+        if (@file_exists($f = $fichier_dest)) {
460
+            if (filemtime($f) >= $date_src) {
461
+                $creer = false;
462
+            }
463
+        } else {
464
+            if (
465
+                @file_exists($f = "$fichier_dest.src")
466
+                and lire_fichier($f, $valeurs)
467
+                and $valeurs = unserialize($valeurs)
468
+                and $valeurs['date'] >= $date_src
469
+            ) {
470
+                $creer = false;
471
+            }
472
+        }
473
+    }
474
+    if ($creer) {
475
+        if (!@file_exists($fichier)) {
476
+            if (!@file_exists("$fichier.src")) {
477
+                spip_log("Image absente : $fichier");
478
+
479
+                return false;
480
+            }
481
+            # on reconstruit l'image source absente a partir de la chaine des .src
482
+            reconstruire_image_intermediaire($fichier);
483
+        }
484
+    }
485
+
486
+    if ($creer) {
487
+        spip_log(
488
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
489
+            'images' . _LOG_DEBUG
490
+        );
491
+    }
492
+
493
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
494
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
495
+    $ret['fichier'] = $fichier;
496
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
497
+    $ret['fichier_dest'] = $fichier_dest;
498
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
499
+    $ret['format_dest'] = $terminaison_dest;
500
+    $ret['date_src'] = $date_src;
501
+    $ret['creer'] = $creer;
502
+    $ret['class'] = extraire_attribut($img, 'class');
503
+    $ret['alt'] = extraire_attribut($img, 'alt');
504
+    $ret['style'] = extraire_attribut($img, 'style');
505
+    $ret['tag'] = $img;
506
+    if ($fonction_creation) {
507
+        $ret['reconstruction'] = $fonction_creation;
508
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
509
+        # cas de image_reduire qui finalement ne reduit pas l'image source
510
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
511
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
512
+    }
513
+
514
+    $ret = pipeline('image_preparer_filtre', [
515
+            'args' => [
516
+                'img' => $img,
517
+                'effet' => $effet,
518
+                'forcer_format' => $forcer_format,
519
+                'fonction_creation' => $fonction_creation,
520
+                'find_in_path' => $find_in_path,
521
+            ],
522
+            'data' => $ret
523
+        ]);
524
+
525
+    // une globale pour le debug en cas de crash memoire
526
+    $GLOBALS['derniere_image_calculee'] = $ret;
527
+
528
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
529
+    if ($term_fonction === 'svg') {
530
+        if ($creer and !$support_svg) {
531
+            process_image_svg_identite($ret);
532
+            $ret['creer'] = false;
533
+        }
534
+    }
535
+    else {
536
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
537
+            return false;
538
+        }
539
+    }
540
+
541
+    return $ret;
542 542
 }
543 543
 
544 544
 
@@ -547,53 +547,53 @@  discard block
 block discarded – undo
547 547
  * @return array
548 548
  */
549 549
 function _image_extensions_acceptees_en_entree() {
550
-	static $extensions = null;
551
-	if (empty($extensions)) {
552
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
553
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
554
-			// action=tester renseigne gd_formats et detecte le support de webp
555
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
556
-			$extensions = array_map('trim', $extensions);
557
-			$extensions = array_filter($extensions);
558
-			$extensions = array_unique($extensions);
559
-			if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
560
-			}
561
-		}
562
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
563
-	}
564
-
565
-	return $extensions;
550
+    static $extensions = null;
551
+    if (empty($extensions)) {
552
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
553
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
554
+            // action=tester renseigne gd_formats et detecte le support de webp
555
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
556
+            $extensions = array_map('trim', $extensions);
557
+            $extensions = array_filter($extensions);
558
+            $extensions = array_unique($extensions);
559
+            if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
560
+            }
561
+        }
562
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
563
+    }
564
+
565
+    return $extensions;
566 566
 }
567 567
 
568 568
 /**
569 569
  * @return array|string[]|null
570 570
  */
571 571
 function _image_extensions_acceptees_en_sortie() {
572
-	static $extensions = null;
573
-	if (empty($extensions)) {
574
-		$extensions = _image_extensions_acceptees_en_entree();
575
-		$extensions = array_diff($extensions, ['jpeg']);
576
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
577
-			$extensions = array_diff($extensions, ['gif']);
578
-		}
579
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
580
-			$extensions = array_diff($extensions, ['webp']);
581
-		}
582
-	}
583
-
584
-	return $extensions;
572
+    static $extensions = null;
573
+    if (empty($extensions)) {
574
+        $extensions = _image_extensions_acceptees_en_entree();
575
+        $extensions = array_diff($extensions, ['jpeg']);
576
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
577
+            $extensions = array_diff($extensions, ['gif']);
578
+        }
579
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
580
+            $extensions = array_diff($extensions, ['webp']);
581
+        }
582
+    }
583
+
584
+    return $extensions;
585 585
 }
586 586
 
587 587
 function _image_extension_normalisee($extension) {
588
-	$extension = strtolower($extension);
589
-	if ($extension === 'jpeg') {
590
-		$extension = 'jpg';
591
-	}
592
-	return $extension;
588
+    $extension = strtolower($extension);
589
+    if ($extension === 'jpeg') {
590
+        $extension = 'jpg';
591
+    }
592
+    return $extension;
593 593
 }
594 594
 
595 595
 function _image_extensions_conservent_transparence() {
596
-	return ['png', 'webp'];
596
+    return ['png', 'webp'];
597 597
 }
598 598
 
599 599
 
@@ -603,12 +603,12 @@  discard block
 block discarded – undo
603 603
  * @return string
604 604
  */
605 605
 function _image_trouver_extension($path) {
606
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
607
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
608
-		$terminaison = strtolower($regs[1]);
609
-		return $terminaison;
610
-	}
611
-	return '';
606
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
607
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
608
+        $terminaison = strtolower($regs[1]);
609
+        return $terminaison;
610
+    }
611
+    return '';
612 612
 }
613 613
 
614 614
 /**
@@ -619,33 +619,33 @@  discard block
 block discarded – undo
619 619
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
620 620
  */
621 621
 function _image_trouver_extension_pertinente($path) {
622
-	$path = supprimer_timestamp($path);
623
-	$terminaison = _image_trouver_extension($path);
624
-	if ($terminaison == 'jpg') {
625
-		$terminaison = 'jpeg';
626
-	}
627
-
628
-	if (!file_exists($path)) {
629
-		return $terminaison;
630
-	}
631
-
632
-	if (!$info = @spip_getimagesize($path)) {
633
-		return $terminaison;
634
-	}
635
-
636
-	if (isset($info['mime'])) {
637
-		$mime = $info['mime'];
638
-	}
639
-	else {
640
-		$mime = image_type_to_mime_type($info[2]);
641
-	}
642
-
643
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
644
-	if ($_terminaison and $_terminaison !== $terminaison) {
645
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
646
-		$terminaison = $_terminaison;
647
-	}
648
-	return $terminaison;
622
+    $path = supprimer_timestamp($path);
623
+    $terminaison = _image_trouver_extension($path);
624
+    if ($terminaison == 'jpg') {
625
+        $terminaison = 'jpeg';
626
+    }
627
+
628
+    if (!file_exists($path)) {
629
+        return $terminaison;
630
+    }
631
+
632
+    if (!$info = @spip_getimagesize($path)) {
633
+        return $terminaison;
634
+    }
635
+
636
+    if (isset($info['mime'])) {
637
+        $mime = $info['mime'];
638
+    }
639
+    else {
640
+        $mime = image_type_to_mime_type($info[2]);
641
+    }
642
+
643
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
644
+    if ($_terminaison and $_terminaison !== $terminaison) {
645
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
646
+        $terminaison = $_terminaison;
647
+    }
648
+    return $terminaison;
649 649
 }
650 650
 
651 651
 /**
@@ -653,36 +653,36 @@  discard block
 block discarded – undo
653 653
  * @return string
654 654
  */
655 655
 function _image_trouver_extension_depuis_mime($mime) {
656
-	switch (strtolower($mime)) {
657
-		case 'image/png':
658
-		case 'image/x-png':
659
-			$terminaison = 'png';
660
-			break;
661
-
662
-		case 'image/jpg':
663
-		case 'image/jpeg':
664
-		case 'image/pjpeg':
665
-			$terminaison = 'jpeg';
666
-			break;
667
-
668
-		case 'image/gif':
669
-			$terminaison = 'gif';
670
-			break;
671
-
672
-		case 'image/webp':
673
-		case 'image/x-webp':
674
-			$terminaison = 'webp';
675
-			break;
676
-
677
-		case 'image/svg+xml':
678
-			$terminaison = 'svg';
679
-			break;
680
-
681
-		default:
682
-			$terminaison = '';
683
-	}
684
-
685
-	return $terminaison;
656
+    switch (strtolower($mime)) {
657
+        case 'image/png':
658
+        case 'image/x-png':
659
+            $terminaison = 'png';
660
+            break;
661
+
662
+        case 'image/jpg':
663
+        case 'image/jpeg':
664
+        case 'image/pjpeg':
665
+            $terminaison = 'jpeg';
666
+            break;
667
+
668
+        case 'image/gif':
669
+            $terminaison = 'gif';
670
+            break;
671
+
672
+        case 'image/webp':
673
+        case 'image/x-webp':
674
+            $terminaison = 'webp';
675
+            break;
676
+
677
+        case 'image/svg+xml':
678
+            $terminaison = 'svg';
679
+            break;
680
+
681
+        default:
682
+            $terminaison = '';
683
+    }
684
+
685
+    return $terminaison;
686 686
 }
687 687
 
688 688
 
@@ -702,18 +702,18 @@  discard block
 block discarded – undo
702 702
  *     Une ressource de type Image GD.
703 703
  */
704 704
 function _imagecreatefrom_func(string $func, string $filename) {
705
-	if (!function_exists($func)) {
706
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
707
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
708
-		return null;
709
-	}
710
-	$img = @$func($filename);
711
-	if (!$img) {
712
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
713
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
714
-		$img = imagecreate(10, 10);
715
-	}
716
-	return $img;
705
+    if (!function_exists($func)) {
706
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
707
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
708
+        return null;
709
+    }
710
+    $img = @$func($filename);
711
+    if (!$img) {
712
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
713
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
714
+        $img = imagecreate(10, 10);
715
+    }
716
+    return $img;
717 717
 }
718 718
 
719 719
 /**
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
  *     Une ressource de type Image GD.
730 730
  */
731 731
 function _imagecreatefromjpeg($filename) {
732
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
732
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
733 733
 }
734 734
 
735 735
 /**
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
  *     Une ressource de type Image GD.
746 746
  */
747 747
 function _imagecreatefrompng($filename) {
748
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
748
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
749 749
 }
750 750
 
751 751
 /**
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
  *     Une ressource de type Image GD.
762 762
  */
763 763
 function _imagecreatefromgif($filename) {
764
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
764
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
765 765
 }
766 766
 
767 767
 
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
  *     Une ressource de type Image GD.
779 779
  */
780 780
 function _imagecreatefromwebp($filename) {
781
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
781
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
782 782
 }
783 783
 
784 784
 /**
@@ -796,24 +796,24 @@  discard block
 block discarded – undo
796 796
  *     - true si une image est bien retournée.
797 797
  */
798 798
 function _image_imagepng($img, $fichier) {
799
-	if (!function_exists('imagepng')) {
800
-		return false;
801
-	}
802
-	$tmp = $fichier . '.tmp';
803
-	$ret = imagepng($img, $tmp);
804
-	if (file_exists($tmp)) {
805
-		$taille_test = getimagesize($tmp);
806
-		if ($taille_test[0] < 1) {
807
-			return false;
808
-		}
809
-
810
-		spip_unlink($fichier); // le fichier peut deja exister
811
-		@rename($tmp, $fichier);
812
-
813
-		return $ret;
814
-	}
815
-
816
-	return false;
799
+    if (!function_exists('imagepng')) {
800
+        return false;
801
+    }
802
+    $tmp = $fichier . '.tmp';
803
+    $ret = imagepng($img, $tmp);
804
+    if (file_exists($tmp)) {
805
+        $taille_test = getimagesize($tmp);
806
+        if ($taille_test[0] < 1) {
807
+            return false;
808
+        }
809
+
810
+        spip_unlink($fichier); // le fichier peut deja exister
811
+        @rename($tmp, $fichier);
812
+
813
+        return $ret;
814
+    }
815
+
816
+    return false;
817 817
 }
818 818
 
819 819
 /**
@@ -831,24 +831,24 @@  discard block
 block discarded – undo
831 831
  *     - true si une image est bien retournée.
832 832
  */
833 833
 function _image_imagegif($img, $fichier) {
834
-	if (!function_exists('imagegif')) {
835
-		return false;
836
-	}
837
-	$tmp = $fichier . '.tmp';
838
-	$ret = imagegif($img, $tmp);
839
-	if (file_exists($tmp)) {
840
-		$taille_test = getimagesize($tmp);
841
-		if ($taille_test[0] < 1) {
842
-			return false;
843
-		}
844
-
845
-		spip_unlink($fichier); // le fichier peut deja exister
846
-		@rename($tmp, $fichier);
847
-
848
-		return $ret;
849
-	}
850
-
851
-	return false;
834
+    if (!function_exists('imagegif')) {
835
+        return false;
836
+    }
837
+    $tmp = $fichier . '.tmp';
838
+    $ret = imagegif($img, $tmp);
839
+    if (file_exists($tmp)) {
840
+        $taille_test = getimagesize($tmp);
841
+        if ($taille_test[0] < 1) {
842
+            return false;
843
+        }
844
+
845
+        spip_unlink($fichier); // le fichier peut deja exister
846
+        @rename($tmp, $fichier);
847
+
848
+        return $ret;
849
+    }
850
+
851
+    return false;
852 852
 }
853 853
 
854 854
 /**
@@ -871,29 +871,29 @@  discard block
 block discarded – undo
871 871
  *     - true si une image est bien retournée.
872 872
  */
873 873
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
874
-	if (!function_exists('imagejpeg')) {
875
-		return false;
876
-	}
877
-	$tmp = $fichier . '.tmp';
874
+    if (!function_exists('imagejpeg')) {
875
+        return false;
876
+    }
877
+    $tmp = $fichier . '.tmp';
878 878
 
879
-	// Enable interlancing
880
-	imageinterlace($img, true);
879
+    // Enable interlancing
880
+    imageinterlace($img, true);
881 881
 
882
-	$ret = imagejpeg($img, $tmp, $qualite);
882
+    $ret = imagejpeg($img, $tmp, $qualite);
883 883
 
884
-	if (file_exists($tmp)) {
885
-		$taille_test = getimagesize($tmp);
886
-		if ($taille_test[0] < 1) {
887
-			return false;
888
-		}
884
+    if (file_exists($tmp)) {
885
+        $taille_test = getimagesize($tmp);
886
+        if ($taille_test[0] < 1) {
887
+            return false;
888
+        }
889 889
 
890
-		spip_unlink($fichier); // le fichier peut deja exister
891
-		@rename($tmp, $fichier);
890
+        spip_unlink($fichier); // le fichier peut deja exister
891
+        @rename($tmp, $fichier);
892 892
 
893
-		return $ret;
894
-	}
893
+        return $ret;
894
+    }
895 895
 
896
-	return false;
896
+    return false;
897 897
 }
898 898
 
899 899
 /**
@@ -911,9 +911,9 @@  discard block
 block discarded – undo
911 911
  *     true si le fichier a bien été créé ; false sinon.
912 912
  */
913 913
 function _image_imageico($img, $fichier) {
914
-	$gd_image_array = [$img];
914
+    $gd_image_array = [$img];
915 915
 
916
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
916
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
917 917
 }
918 918
 
919 919
 
@@ -932,24 +932,24 @@  discard block
 block discarded – undo
932 932
  *     - true si une image est bien retournée.
933 933
  */
934 934
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
935
-	if (!function_exists('imagewebp')) {
936
-		return false;
937
-	}
938
-	$tmp = $fichier . '.tmp';
939
-	$ret = imagewebp($img, $tmp, $qualite);
940
-	if (file_exists($tmp)) {
941
-		$taille_test = getimagesize($tmp);
942
-		if ($taille_test[0] < 1) {
943
-			return false;
944
-		}
945
-
946
-		spip_unlink($fichier); // le fichier peut deja exister
947
-		@rename($tmp, $fichier);
948
-
949
-		return $ret;
950
-	}
951
-
952
-	return false;
935
+    if (!function_exists('imagewebp')) {
936
+        return false;
937
+    }
938
+    $tmp = $fichier . '.tmp';
939
+    $ret = imagewebp($img, $tmp, $qualite);
940
+    if (file_exists($tmp)) {
941
+        $taille_test = getimagesize($tmp);
942
+        if ($taille_test[0] < 1) {
943
+            return false;
944
+        }
945
+
946
+        spip_unlink($fichier); // le fichier peut deja exister
947
+        @rename($tmp, $fichier);
948
+
949
+        return $ret;
950
+    }
951
+
952
+    return false;
953 953
 }
954 954
 
955 955
 /**
@@ -969,35 +969,35 @@  discard block
 block discarded – undo
969 969
  */
970 970
 function _image_imagesvg($img, $fichier) {
971 971
 
972
-	$tmp = $fichier . '.tmp';
973
-	if (strpos($img, '<') === false) {
974
-		$img = supprimer_timestamp($img);
975
-		if (!file_exists($img)) {
976
-			return false;
977
-		}
978
-		@copy($img, $tmp);
979
-		if (filesize($tmp) == filesize($img)) {
980
-			spip_unlink($fichier); // le fichier peut deja exister
981
-			@rename($tmp, $fichier);
982
-			return true;
983
-		}
984
-		return false;
985
-	}
986
-
987
-	file_put_contents($tmp, $img);
988
-	if (file_exists($tmp)) {
989
-		$taille_test = spip_getimagesize($tmp);
990
-		if ($taille_test[0] < 1) {
991
-			return false;
992
-		}
993
-
994
-		spip_unlink($fichier); // le fichier peut deja exister
995
-		@rename($tmp, $fichier);
996
-
997
-		return true;
998
-	}
999
-
1000
-	return false;
972
+    $tmp = $fichier . '.tmp';
973
+    if (strpos($img, '<') === false) {
974
+        $img = supprimer_timestamp($img);
975
+        if (!file_exists($img)) {
976
+            return false;
977
+        }
978
+        @copy($img, $tmp);
979
+        if (filesize($tmp) == filesize($img)) {
980
+            spip_unlink($fichier); // le fichier peut deja exister
981
+            @rename($tmp, $fichier);
982
+            return true;
983
+        }
984
+        return false;
985
+    }
986
+
987
+    file_put_contents($tmp, $img);
988
+    if (file_exists($tmp)) {
989
+        $taille_test = spip_getimagesize($tmp);
990
+        if ($taille_test[0] < 1) {
991
+            return false;
992
+        }
993
+
994
+        spip_unlink($fichier); // le fichier peut deja exister
995
+        @rename($tmp, $fichier);
996
+
997
+        return true;
998
+    }
999
+
1000
+    return false;
1001 1001
 }
1002 1002
 
1003 1003
 
@@ -1025,29 +1025,29 @@  discard block
 block discarded – undo
1025 1025
  *     - false sinon.
1026 1026
  */
1027 1027
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1028
-	if (is_null($fonction)) {
1029
-		$fonction = '_image_image' . $valeurs['format_dest'];
1030
-	}
1031
-	$ret = false;
1032
-	#un flag pour reperer les images gravees
1033
-	$lock =
1034
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1035
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1036
-	if (
1037
-		function_exists($fonction)
1038
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1039
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1040
-		&& !$lock
1041
-	) {
1042
-		if (@file_exists($valeurs['fichier_dest'])) {
1043
-			// dans tous les cas mettre a jour la taille de l'image finale
1044
-			list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1045
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1046
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1047
-		}
1048
-	}
1049
-
1050
-	return $ret;
1028
+    if (is_null($fonction)) {
1029
+        $fonction = '_image_image' . $valeurs['format_dest'];
1030
+    }
1031
+    $ret = false;
1032
+    #un flag pour reperer les images gravees
1033
+    $lock =
1034
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1035
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1036
+    if (
1037
+        function_exists($fonction)
1038
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1039
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1040
+        && !$lock
1041
+    ) {
1042
+        if (@file_exists($valeurs['fichier_dest'])) {
1043
+            // dans tous les cas mettre a jour la taille de l'image finale
1044
+            list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1045
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1046
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1047
+        }
1048
+    }
1049
+
1050
+    return $ret;
1051 1051
 }
1052 1052
 
1053 1053
 /**
@@ -1060,27 +1060,27 @@  discard block
 block discarded – undo
1060 1060
  *     Chemin vers le fichier manquant
1061 1061
  **/
1062 1062
 function reconstruire_image_intermediaire($fichier_manquant) {
1063
-	$reconstruire = [];
1064
-	$fichier = $fichier_manquant;
1065
-	while (
1066
-		strpos($fichier, '://') === false
1067
-		and !@file_exists($fichier)
1068
-		and lire_fichier($src = "$fichier.src", $source)
1069
-		and $valeurs = unserialize($source)
1070
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1071
-	) {
1072
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1073
-		$reconstruire[] = $valeurs['reconstruction'];
1074
-	}
1075
-	while (count($reconstruire)) {
1076
-		$r = array_pop($reconstruire);
1077
-		$fonction = $r[0];
1078
-		$args = $r[1];
1079
-		call_user_func_array($fonction, $args);
1080
-	}
1081
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1082
-	// mais l'on peut nettoyer les miettes de sa creation
1083
-	ramasse_miettes($fichier_manquant);
1063
+    $reconstruire = [];
1064
+    $fichier = $fichier_manquant;
1065
+    while (
1066
+        strpos($fichier, '://') === false
1067
+        and !@file_exists($fichier)
1068
+        and lire_fichier($src = "$fichier.src", $source)
1069
+        and $valeurs = unserialize($source)
1070
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1071
+    ) {
1072
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1073
+        $reconstruire[] = $valeurs['reconstruction'];
1074
+    }
1075
+    while (count($reconstruire)) {
1076
+        $r = array_pop($reconstruire);
1077
+        $fonction = $r[0];
1078
+        $args = $r[1];
1079
+        call_user_func_array($fonction, $args);
1080
+    }
1081
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1082
+    // mais l'on peut nettoyer les miettes de sa creation
1083
+    ramasse_miettes($fichier_manquant);
1084 1084
 }
1085 1085
 
1086 1086
 /**
@@ -1100,28 +1100,28 @@  discard block
 block discarded – undo
1100 1100
  *     Chemin du fichier d'image calculé
1101 1101
  **/
1102 1102
 function ramasse_miettes($fichier) {
1103
-	if (
1104
-		strpos($fichier, '://') !== false
1105
-		or !lire_fichier($src = "$fichier.src", $source)
1106
-		or !$valeurs = unserialize($source)
1107
-	) {
1108
-		return;
1109
-	}
1110
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1111
-	while (
1112
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1113
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1114
-		and (lire_fichier(
1115
-			$src = "$fichier.src",
1116
-			$source
1117
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1118
-		and ($valeurs = unserialize($source))  # et valide
1119
-	) {
1120
-		# on efface le fichier
1121
-		spip_unlink($fichier);
1122
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1123
-		#spip_unlink($src);
1124
-	}
1103
+    if (
1104
+        strpos($fichier, '://') !== false
1105
+        or !lire_fichier($src = "$fichier.src", $source)
1106
+        or !$valeurs = unserialize($source)
1107
+    ) {
1108
+        return;
1109
+    }
1110
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1111
+    while (
1112
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1113
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1114
+        and (lire_fichier(
1115
+            $src = "$fichier.src",
1116
+            $source
1117
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1118
+        and ($valeurs = unserialize($source))  # et valide
1119
+    ) {
1120
+        # on efface le fichier
1121
+        spip_unlink($fichier);
1122
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1123
+        #spip_unlink($src);
1124
+    }
1125 1125
 }
1126 1126
 
1127 1127
 
@@ -1146,71 +1146,71 @@  discard block
 block discarded – undo
1146 1146
  *     Code HTML de l'image
1147 1147
  **/
1148 1148
 function image_graver($img) {
1149
-	// appeler le filtre post_image_filtrer qui permet de faire
1150
-	// des traitements auto a la fin d'une serie de filtres
1151
-	$img = pipeline('post_image_filtrer', $img);
1152
-
1153
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1154
-	if (($p = strpos($fichier, '?')) !== false) {
1155
-		$fichier = substr($fichier, 0, $p);
1156
-	}
1157
-	if (strlen($fichier) < 1) {
1158
-		$fichier = $img;
1159
-	}
1160
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1161
-	# et qu'il ne s'agit pas d'une URL
1162
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1163
-		reconstruire_image_intermediaire($fichier);
1164
-	}
1165
-	ramasse_miettes($fichier);
1166
-
1167
-	// ajouter le timestamp si besoin
1168
-	if (strpos($fichier_ori, '?') === false) {
1169
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1170
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1171
-	}
1172
-
1173
-	return $img;
1149
+    // appeler le filtre post_image_filtrer qui permet de faire
1150
+    // des traitements auto a la fin d'une serie de filtres
1151
+    $img = pipeline('post_image_filtrer', $img);
1152
+
1153
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1154
+    if (($p = strpos($fichier, '?')) !== false) {
1155
+        $fichier = substr($fichier, 0, $p);
1156
+    }
1157
+    if (strlen($fichier) < 1) {
1158
+        $fichier = $img;
1159
+    }
1160
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1161
+    # et qu'il ne s'agit pas d'une URL
1162
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1163
+        reconstruire_image_intermediaire($fichier);
1164
+    }
1165
+    ramasse_miettes($fichier);
1166
+
1167
+    // ajouter le timestamp si besoin
1168
+    if (strpos($fichier_ori, '?') === false) {
1169
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1170
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1171
+    }
1172
+
1173
+    return $img;
1174 1174
 }
1175 1175
 
1176 1176
 
1177 1177
 if (!function_exists('imagepalettetotruecolor')) {
1178
-	/**
1179
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1180
-	 *
1181
-	 * @note Pour compatibilité avec PHP < 5.5
1182
-	 *
1183
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1184
-	 *
1185
-	 * @param ressource $img
1186
-	 * @return bool
1187
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
1188
-	 *     - false si la transformation ne peut être faite.
1189
-	 **/
1190
-	function imagepalettetotruecolor(&$img) {
1191
-		if (!$img or !function_exists('imagecreatetruecolor')) {
1192
-			return false;
1193
-		} elseif (!imageistruecolor($img)) {
1194
-			$w = imagesx($img);
1195
-			$h = imagesy($img);
1196
-			$img1 = imagecreatetruecolor($w, $h);
1197
-			//Conserver la transparence si possible
1198
-			if (function_exists('ImageCopyResampled')) {
1199
-				if (function_exists('imageAntiAlias')) {
1200
-					imageAntiAlias($img1, true);
1201
-				}
1202
-				@imagealphablending($img1, false);
1203
-				@imagesavealpha($img1, true);
1204
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1205
-			} else {
1206
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1207
-			}
1208
-
1209
-			$img = $img1;
1210
-		}
1211
-
1212
-		return true;
1213
-	}
1178
+    /**
1179
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1180
+     *
1181
+     * @note Pour compatibilité avec PHP < 5.5
1182
+     *
1183
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1184
+     *
1185
+     * @param ressource $img
1186
+     * @return bool
1187
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
1188
+     *     - false si la transformation ne peut être faite.
1189
+     **/
1190
+    function imagepalettetotruecolor(&$img) {
1191
+        if (!$img or !function_exists('imagecreatetruecolor')) {
1192
+            return false;
1193
+        } elseif (!imageistruecolor($img)) {
1194
+            $w = imagesx($img);
1195
+            $h = imagesy($img);
1196
+            $img1 = imagecreatetruecolor($w, $h);
1197
+            //Conserver la transparence si possible
1198
+            if (function_exists('ImageCopyResampled')) {
1199
+                if (function_exists('imageAntiAlias')) {
1200
+                    imageAntiAlias($img1, true);
1201
+                }
1202
+                @imagealphablending($img1, false);
1203
+                @imagesavealpha($img1, true);
1204
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1205
+            } else {
1206
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1207
+            }
1208
+
1209
+            $img = $img1;
1210
+        }
1211
+
1212
+        return true;
1213
+    }
1214 1214
 }
1215 1215
 
1216 1216
 /**
@@ -1237,32 +1237,32 @@  discard block
 block discarded – undo
1237 1237
  *     Code html modifié de la balise.
1238 1238
  **/
1239 1239
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1240
-	if ($style === false) {
1241
-		$style = extraire_attribut($tag, 'style');
1242
-	}
1243
-
1244
-	// enlever le width et height du style
1245
-	$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1246
-	if ($style and $style[0] == ';') {
1247
-		$style = substr($style, 1);
1248
-	}
1249
-
1250
-	// mettre des attributs de width et height sur les images,
1251
-	// ca accelere le rendu du navigateur
1252
-	// ca permet aux navigateurs de reserver la bonne taille
1253
-	// quand on a desactive l'affichage des images.
1254
-	$tag = inserer_attribut($tag, 'width', round($width));
1255
-	$tag = inserer_attribut($tag, 'height', round($height));
1256
-
1257
-	// attributs deprecies. Transformer en CSS
1258
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1259
-		$style = "margin:${espace}px;" . $style;
1260
-		$tag = inserer_attribut($tag, 'hspace', '');
1261
-	}
1262
-
1263
-	$tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
1264
-
1265
-	return $tag;
1240
+    if ($style === false) {
1241
+        $style = extraire_attribut($tag, 'style');
1242
+    }
1243
+
1244
+    // enlever le width et height du style
1245
+    $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1246
+    if ($style and $style[0] == ';') {
1247
+        $style = substr($style, 1);
1248
+    }
1249
+
1250
+    // mettre des attributs de width et height sur les images,
1251
+    // ca accelere le rendu du navigateur
1252
+    // ca permet aux navigateurs de reserver la bonne taille
1253
+    // quand on a desactive l'affichage des images.
1254
+    $tag = inserer_attribut($tag, 'width', round($width));
1255
+    $tag = inserer_attribut($tag, 'height', round($height));
1256
+
1257
+    // attributs deprecies. Transformer en CSS
1258
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1259
+        $style = "margin:${espace}px;" . $style;
1260
+        $tag = inserer_attribut($tag, 'hspace', '');
1261
+    }
1262
+
1263
+    $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
1264
+
1265
+    return $tag;
1266 1266
 }
1267 1267
 
1268 1268
 
@@ -1288,72 +1288,72 @@  discard block
 block discarded – undo
1288 1288
  *     Retourne le code HTML de l'image
1289 1289
  **/
1290 1290
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1291
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1292
-
1293
-	// fermer les tags img pas bien fermes;
1294
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1295
-
1296
-	// le style
1297
-	$style = $valeurs['style'];
1298
-	if (isset($surcharge['style'])) {
1299
-		$style = $surcharge['style'];
1300
-		unset($surcharge['style']);
1301
-	}
1302
-
1303
-	// traiter specifiquement la largeur et la hauteur
1304
-	$width = $valeurs['largeur'];
1305
-	if (isset($surcharge['width'])) {
1306
-		$width = $surcharge['width'];
1307
-		unset($surcharge['width']);
1308
-	}
1309
-	$height = $valeurs['hauteur'];
1310
-	if (isset($surcharge['height'])) {
1311
-		$height = $surcharge['height'];
1312
-		unset($surcharge['height']);
1313
-	}
1314
-
1315
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1316
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1317
-	// on remplace toute les ref a src dans le tag
1318
-	$src = extraire_attribut($tag, 'src');
1319
-	if (isset($surcharge['src'])) {
1320
-		$tag = str_replace($src, $surcharge['src'], $tag);
1321
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1322
-		// pas garanti comme methode, mais mieux que rien
1323
-		if (strpos($src, '&') !== false) {
1324
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1325
-		}
1326
-		$src = $surcharge['src'];
1327
-		unset($surcharge['src']);
1328
-	}
1329
-
1330
-	$class = $valeurs['class'];
1331
-	if (isset($surcharge['class'])) {
1332
-		$class = $surcharge['class'];
1333
-		unset($surcharge['class']);
1334
-	}
1335
-	if (strlen($class)) {
1336
-		$tag = inserer_attribut($tag, 'class', $class);
1337
-	}
1338
-
1339
-	if (count($surcharge)) {
1340
-		foreach ($surcharge as $attribut => $valeur) {
1341
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1342
-		}
1343
-	}
1344
-
1345
-	$tag = pipeline(
1346
-		'image_ecrire_tag_finir',
1347
-		[
1348
-			'args' => [
1349
-				'valeurs' => $valeurs,
1350
-				'surcharge' => $surcharge,
1351
-			],
1352
-			'data' => $tag
1353
-		]
1354
-	);
1355
-
1356
-	return $tag;
1291
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1292
+
1293
+    // fermer les tags img pas bien fermes;
1294
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1295
+
1296
+    // le style
1297
+    $style = $valeurs['style'];
1298
+    if (isset($surcharge['style'])) {
1299
+        $style = $surcharge['style'];
1300
+        unset($surcharge['style']);
1301
+    }
1302
+
1303
+    // traiter specifiquement la largeur et la hauteur
1304
+    $width = $valeurs['largeur'];
1305
+    if (isset($surcharge['width'])) {
1306
+        $width = $surcharge['width'];
1307
+        unset($surcharge['width']);
1308
+    }
1309
+    $height = $valeurs['hauteur'];
1310
+    if (isset($surcharge['height'])) {
1311
+        $height = $surcharge['height'];
1312
+        unset($surcharge['height']);
1313
+    }
1314
+
1315
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1316
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1317
+    // on remplace toute les ref a src dans le tag
1318
+    $src = extraire_attribut($tag, 'src');
1319
+    if (isset($surcharge['src'])) {
1320
+        $tag = str_replace($src, $surcharge['src'], $tag);
1321
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1322
+        // pas garanti comme methode, mais mieux que rien
1323
+        if (strpos($src, '&') !== false) {
1324
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1325
+        }
1326
+        $src = $surcharge['src'];
1327
+        unset($surcharge['src']);
1328
+    }
1329
+
1330
+    $class = $valeurs['class'];
1331
+    if (isset($surcharge['class'])) {
1332
+        $class = $surcharge['class'];
1333
+        unset($surcharge['class']);
1334
+    }
1335
+    if (strlen($class)) {
1336
+        $tag = inserer_attribut($tag, 'class', $class);
1337
+    }
1338
+
1339
+    if (count($surcharge)) {
1340
+        foreach ($surcharge as $attribut => $valeur) {
1341
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1342
+        }
1343
+    }
1344
+
1345
+    $tag = pipeline(
1346
+        'image_ecrire_tag_finir',
1347
+        [
1348
+            'args' => [
1349
+                'valeurs' => $valeurs,
1350
+                'surcharge' => $surcharge,
1351
+            ],
1352
+            'data' => $tag
1353
+        ]
1354
+    );
1355
+
1356
+    return $tag;
1357 1357
 }
1358 1358
 
1359 1359
 /**
@@ -1376,257 +1376,257 @@  discard block
 block discarded – undo
1376 1376
  *     Description de l'image, sinon null.
1377 1377
  **/
1378 1378
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1379
-	// ordre de preference des formats graphiques pour creer les vignettes
1380
-	// le premier format disponible, selon la methode demandee, est utilise
1381
-	$image = $valeurs['fichier'];
1382
-	$format = $valeurs['format_source'];
1383
-	$destdir = dirname($valeurs['fichier_dest']);
1384
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1385
-
1386
-	$format_sortie = $valeurs['format_dest'];
1387
-
1388
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1389
-		$process = $GLOBALS['meta']['image_process'];
1390
-	}
1391
-
1392
-	// si le doc n'est pas une image dans un format accetpable, refuser
1393
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1394
-		return;
1395
-	}
1396
-	$destination = "$destdir/$destfile";
1397
-
1398
-	// calculer la taille
1399
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1400
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1401
-			list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1402
-		}
1403
-	} elseif ($process == 'convert' or $process == 'imagick') {
1404
-		$destWidth = $maxWidth;
1405
-		$destHeight = $maxHeight;
1406
-	} else {
1407
-		spip_log("echec $process sur $image");
1408
-
1409
-		return;
1410
-	}
1411
-
1412
-	$vignette = '';
1413
-
1414
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1415
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1416
-		$vignette = $destination . '.' . $format;
1417
-		@copy($image, $vignette);
1418
-	}
1419
-
1420
-	elseif ($valeurs['format_source'] === 'svg') {
1421
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1422
-			$format_sortie = 'svg';
1423
-			$vignette = $destination . '.' . $format_sortie;
1424
-			$valeurs['fichier_dest'] = $vignette;
1425
-			_image_gd_output($svg, $valeurs);
1426
-		}
1427
-	}
1428
-
1429
-	// imagemagick en ligne de commande
1430
-	elseif ($process == 'convert') {
1431
-		if (!defined('_CONVERT_COMMAND')) {
1432
-			define('_CONVERT_COMMAND', 'convert');
1433
-		} // Securite : mes_options.php peut preciser le chemin absolu
1434
-		if (!defined('_RESIZE_COMMAND')) {
1435
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1436
-		}
1437
-		$vignette = $destination . '.' . $format_sortie;
1438
-		$commande = str_replace(
1439
-			['%x', '%y', '%src', '%dest'],
1440
-			[
1441
-				$destWidth,
1442
-				$destHeight,
1443
-				escapeshellcmd($image),
1444
-				escapeshellcmd($vignette)
1445
-			],
1446
-			_RESIZE_COMMAND
1447
-		);
1448
-		spip_log($commande);
1449
-		exec($commande);
1450
-		if (!@file_exists($vignette)) {
1451
-			spip_log("echec convert sur $vignette");
1452
-
1453
-			return;  // echec commande
1454
-		}
1455
-	}
1456
-
1457
-	// php5 imagemagick
1458
-	elseif ($process == 'imagick') {
1459
-		$vignette = "$destination." . $format_sortie;
1460
-
1461
-		if (!class_exists('Imagick')) {
1462
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1463
-
1464
-			return;
1465
-		}
1466
-		$imagick = new Imagick();
1467
-		$imagick->readImage($image);
1468
-		$imagick->resizeImage(
1469
-			$destWidth,
1470
-			$destHeight,
1471
-			Imagick::FILTER_LANCZOS,
1472
-			1
1473
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1474
-		$imagick->writeImage($vignette);
1475
-
1476
-		if (!@file_exists($vignette)) {
1477
-			spip_log("echec imagick sur $vignette");
1478
-
1479
-			return;
1480
-		}
1481
-	}
1482
-
1483
-	// netpbm
1484
-	elseif ($process == 'netpbm') {
1485
-		if (!defined('_PNMSCALE_COMMAND')) {
1486
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1487
-		} // Securite : mes_options.php peut preciser le chemin absolu
1488
-		if (_PNMSCALE_COMMAND == '') {
1489
-			return;
1490
-		}
1491
-		$vignette = $destination . '.' . $format_sortie;
1492
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1493
-		if ($format == 'jpg') {
1494
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1495
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1496
-			if (!($s = @filesize($vignette))) {
1497
-				spip_unlink($vignette);
1498
-			}
1499
-			if (!@file_exists($vignette)) {
1500
-				spip_log("echec netpbm-jpg sur $vignette");
1501
-
1502
-				return;
1503
-			}
1504
-		} else {
1505
-			if ($format == 'gif') {
1506
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1507
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1508
-				if (!($s = @filesize($vignette))) {
1509
-					spip_unlink($vignette);
1510
-				}
1511
-				if (!@file_exists($vignette)) {
1512
-					spip_log("echec netpbm-gif sur $vignette");
1513
-
1514
-					return;
1515
-				}
1516
-			} else {
1517
-				if ($format == 'png') {
1518
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1519
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1520
-					if (!($s = @filesize($vignette))) {
1521
-						spip_unlink($vignette);
1522
-					}
1523
-					if (!@file_exists($vignette)) {
1524
-						spip_log("echec netpbm-png sur $vignette");
1525
-
1526
-						return;
1527
-					}
1528
-				}
1529
-			}
1530
-		}
1531
-	}
1532
-
1533
-	// gd ou gd2
1534
-	elseif ($process == 'gd1' or $process == 'gd2') {
1535
-		if (!function_exists('gd_info')) {
1536
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1537
-
1538
-			return;
1539
-		}
1540
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1541
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1542
-
1543
-			return;
1544
-		}
1545
-		$destFormat = $format_sortie;
1546
-		if (!$destFormat) {
1547
-			spip_log("pas de format pour $image");
1548
-
1549
-			return;
1550
-		}
1551
-
1552
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1553
-		if (!function_exists($fonction_imagecreatefrom)) {
1554
-			return '';
1555
-		}
1556
-		$srcImage = @$fonction_imagecreatefrom($image);
1557
-		if (!$srcImage) {
1558
-			spip_log('echec gd1/gd2');
1559
-
1560
-			return;
1561
-		}
1562
-
1563
-		// Initialisation de l'image destination
1564
-		$destImage = null;
1565
-		if ($process == 'gd2' and $destFormat != 'gif') {
1566
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1567
-		}
1568
-		if (!$destImage) {
1569
-			$destImage = ImageCreate($destWidth, $destHeight);
1570
-		}
1571
-
1572
-		// Recopie de l'image d'origine avec adaptation de la taille
1573
-		$ok = false;
1574
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1575
-			if ($format == 'gif') {
1576
-				// Si un GIF est transparent,
1577
-				// fabriquer un PNG transparent
1578
-				$transp = imagecolortransparent($srcImage);
1579
-				if ($transp > 0) {
1580
-					$destFormat = 'png';
1581
-				}
1582
-			}
1583
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1584
-				// Conserver la transparence
1585
-				if (function_exists('imageAntiAlias')) {
1586
-					imageAntiAlias($destImage, true);
1587
-				}
1588
-				@imagealphablending($destImage, false);
1589
-				@imagesavealpha($destImage, true);
1590
-			}
1591
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1592
-		}
1593
-		if (!$ok) {
1594
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1595
-		}
1596
-
1597
-		// Sauvegarde de l'image destination
1598
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1599
-		$valeurs['format_dest'] = $format = $destFormat;
1600
-		_image_gd_output($destImage, $valeurs);
1601
-
1602
-		if ($srcImage) {
1603
-			ImageDestroy($srcImage);
1604
-		}
1605
-		ImageDestroy($destImage);
1606
-	}
1607
-
1608
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1609
-		$size = [$destWidth, $destHeight];
1610
-	}
1611
-
1612
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1613
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1614
-	if ($size[0] < 1) {
1615
-		$size[0] = $destWidth;
1616
-	}
1617
-	if ($size[1] < 1) {
1618
-		$size[1] = $destHeight;
1619
-	}
1620
-
1621
-	$retour['width'] = $largeur = $size[0];
1622
-	$retour['height'] = $hauteur = $size[1];
1623
-
1624
-	$retour['fichier'] = $vignette;
1625
-	$retour['format'] = $format;
1626
-	$retour['date'] = @filemtime($vignette);
1627
-
1628
-	// renvoyer l'image
1629
-	return $retour;
1379
+    // ordre de preference des formats graphiques pour creer les vignettes
1380
+    // le premier format disponible, selon la methode demandee, est utilise
1381
+    $image = $valeurs['fichier'];
1382
+    $format = $valeurs['format_source'];
1383
+    $destdir = dirname($valeurs['fichier_dest']);
1384
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1385
+
1386
+    $format_sortie = $valeurs['format_dest'];
1387
+
1388
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1389
+        $process = $GLOBALS['meta']['image_process'];
1390
+    }
1391
+
1392
+    // si le doc n'est pas une image dans un format accetpable, refuser
1393
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1394
+        return;
1395
+    }
1396
+    $destination = "$destdir/$destfile";
1397
+
1398
+    // calculer la taille
1399
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1400
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1401
+            list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1402
+        }
1403
+    } elseif ($process == 'convert' or $process == 'imagick') {
1404
+        $destWidth = $maxWidth;
1405
+        $destHeight = $maxHeight;
1406
+    } else {
1407
+        spip_log("echec $process sur $image");
1408
+
1409
+        return;
1410
+    }
1411
+
1412
+    $vignette = '';
1413
+
1414
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1415
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1416
+        $vignette = $destination . '.' . $format;
1417
+        @copy($image, $vignette);
1418
+    }
1419
+
1420
+    elseif ($valeurs['format_source'] === 'svg') {
1421
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1422
+            $format_sortie = 'svg';
1423
+            $vignette = $destination . '.' . $format_sortie;
1424
+            $valeurs['fichier_dest'] = $vignette;
1425
+            _image_gd_output($svg, $valeurs);
1426
+        }
1427
+    }
1428
+
1429
+    // imagemagick en ligne de commande
1430
+    elseif ($process == 'convert') {
1431
+        if (!defined('_CONVERT_COMMAND')) {
1432
+            define('_CONVERT_COMMAND', 'convert');
1433
+        } // Securite : mes_options.php peut preciser le chemin absolu
1434
+        if (!defined('_RESIZE_COMMAND')) {
1435
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1436
+        }
1437
+        $vignette = $destination . '.' . $format_sortie;
1438
+        $commande = str_replace(
1439
+            ['%x', '%y', '%src', '%dest'],
1440
+            [
1441
+                $destWidth,
1442
+                $destHeight,
1443
+                escapeshellcmd($image),
1444
+                escapeshellcmd($vignette)
1445
+            ],
1446
+            _RESIZE_COMMAND
1447
+        );
1448
+        spip_log($commande);
1449
+        exec($commande);
1450
+        if (!@file_exists($vignette)) {
1451
+            spip_log("echec convert sur $vignette");
1452
+
1453
+            return;  // echec commande
1454
+        }
1455
+    }
1456
+
1457
+    // php5 imagemagick
1458
+    elseif ($process == 'imagick') {
1459
+        $vignette = "$destination." . $format_sortie;
1460
+
1461
+        if (!class_exists('Imagick')) {
1462
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1463
+
1464
+            return;
1465
+        }
1466
+        $imagick = new Imagick();
1467
+        $imagick->readImage($image);
1468
+        $imagick->resizeImage(
1469
+            $destWidth,
1470
+            $destHeight,
1471
+            Imagick::FILTER_LANCZOS,
1472
+            1
1473
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1474
+        $imagick->writeImage($vignette);
1475
+
1476
+        if (!@file_exists($vignette)) {
1477
+            spip_log("echec imagick sur $vignette");
1478
+
1479
+            return;
1480
+        }
1481
+    }
1482
+
1483
+    // netpbm
1484
+    elseif ($process == 'netpbm') {
1485
+        if (!defined('_PNMSCALE_COMMAND')) {
1486
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1487
+        } // Securite : mes_options.php peut preciser le chemin absolu
1488
+        if (_PNMSCALE_COMMAND == '') {
1489
+            return;
1490
+        }
1491
+        $vignette = $destination . '.' . $format_sortie;
1492
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1493
+        if ($format == 'jpg') {
1494
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1495
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1496
+            if (!($s = @filesize($vignette))) {
1497
+                spip_unlink($vignette);
1498
+            }
1499
+            if (!@file_exists($vignette)) {
1500
+                spip_log("echec netpbm-jpg sur $vignette");
1501
+
1502
+                return;
1503
+            }
1504
+        } else {
1505
+            if ($format == 'gif') {
1506
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1507
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1508
+                if (!($s = @filesize($vignette))) {
1509
+                    spip_unlink($vignette);
1510
+                }
1511
+                if (!@file_exists($vignette)) {
1512
+                    spip_log("echec netpbm-gif sur $vignette");
1513
+
1514
+                    return;
1515
+                }
1516
+            } else {
1517
+                if ($format == 'png') {
1518
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1519
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1520
+                    if (!($s = @filesize($vignette))) {
1521
+                        spip_unlink($vignette);
1522
+                    }
1523
+                    if (!@file_exists($vignette)) {
1524
+                        spip_log("echec netpbm-png sur $vignette");
1525
+
1526
+                        return;
1527
+                    }
1528
+                }
1529
+            }
1530
+        }
1531
+    }
1532
+
1533
+    // gd ou gd2
1534
+    elseif ($process == 'gd1' or $process == 'gd2') {
1535
+        if (!function_exists('gd_info')) {
1536
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1537
+
1538
+            return;
1539
+        }
1540
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1541
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1542
+
1543
+            return;
1544
+        }
1545
+        $destFormat = $format_sortie;
1546
+        if (!$destFormat) {
1547
+            spip_log("pas de format pour $image");
1548
+
1549
+            return;
1550
+        }
1551
+
1552
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1553
+        if (!function_exists($fonction_imagecreatefrom)) {
1554
+            return '';
1555
+        }
1556
+        $srcImage = @$fonction_imagecreatefrom($image);
1557
+        if (!$srcImage) {
1558
+            spip_log('echec gd1/gd2');
1559
+
1560
+            return;
1561
+        }
1562
+
1563
+        // Initialisation de l'image destination
1564
+        $destImage = null;
1565
+        if ($process == 'gd2' and $destFormat != 'gif') {
1566
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1567
+        }
1568
+        if (!$destImage) {
1569
+            $destImage = ImageCreate($destWidth, $destHeight);
1570
+        }
1571
+
1572
+        // Recopie de l'image d'origine avec adaptation de la taille
1573
+        $ok = false;
1574
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1575
+            if ($format == 'gif') {
1576
+                // Si un GIF est transparent,
1577
+                // fabriquer un PNG transparent
1578
+                $transp = imagecolortransparent($srcImage);
1579
+                if ($transp > 0) {
1580
+                    $destFormat = 'png';
1581
+                }
1582
+            }
1583
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1584
+                // Conserver la transparence
1585
+                if (function_exists('imageAntiAlias')) {
1586
+                    imageAntiAlias($destImage, true);
1587
+                }
1588
+                @imagealphablending($destImage, false);
1589
+                @imagesavealpha($destImage, true);
1590
+            }
1591
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1592
+        }
1593
+        if (!$ok) {
1594
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1595
+        }
1596
+
1597
+        // Sauvegarde de l'image destination
1598
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1599
+        $valeurs['format_dest'] = $format = $destFormat;
1600
+        _image_gd_output($destImage, $valeurs);
1601
+
1602
+        if ($srcImage) {
1603
+            ImageDestroy($srcImage);
1604
+        }
1605
+        ImageDestroy($destImage);
1606
+    }
1607
+
1608
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1609
+        $size = [$destWidth, $destHeight];
1610
+    }
1611
+
1612
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1613
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1614
+    if ($size[0] < 1) {
1615
+        $size[0] = $destWidth;
1616
+    }
1617
+    if ($size[1] < 1) {
1618
+        $size[1] = $destHeight;
1619
+    }
1620
+
1621
+    $retour['width'] = $largeur = $size[0];
1622
+    $retour['height'] = $hauteur = $size[1];
1623
+
1624
+    $retour['fichier'] = $vignette;
1625
+    $retour['format'] = $format;
1626
+    $retour['date'] = @filemtime($vignette);
1627
+
1628
+    // renvoyer l'image
1629
+    return $retour;
1630 1630
 }
1631 1631
 
1632 1632
 /**
@@ -1646,25 +1646,25 @@  discard block
 block discarded – undo
1646 1646
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1647 1647
  **/
1648 1648
 function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1649
-	$ratioWidth = $srcWidth / $maxWidth;
1650
-	$ratioHeight = $srcHeight / $maxHeight;
1651
-
1652
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1653
-		$destWidth = $srcWidth;
1654
-		$destHeight = $srcHeight;
1655
-	} elseif ($ratioWidth < $ratioHeight) {
1656
-		$destWidth = $srcWidth / $ratioHeight;
1657
-		$destHeight = $maxHeight;
1658
-	} else {
1659
-		$destWidth = $maxWidth;
1660
-		$destHeight = $srcHeight / $ratioWidth;
1661
-	}
1662
-
1663
-	return [
1664
-		intval(round($destWidth)),
1665
-		intval(round($destHeight)),
1666
-		max($ratioWidth, $ratioHeight)
1667
-	];
1649
+    $ratioWidth = $srcWidth / $maxWidth;
1650
+    $ratioHeight = $srcHeight / $maxHeight;
1651
+
1652
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1653
+        $destWidth = $srcWidth;
1654
+        $destHeight = $srcHeight;
1655
+    } elseif ($ratioWidth < $ratioHeight) {
1656
+        $destWidth = $srcWidth / $ratioHeight;
1657
+        $destHeight = $maxHeight;
1658
+    } else {
1659
+        $destWidth = $maxWidth;
1660
+        $destHeight = $srcHeight / $ratioWidth;
1661
+    }
1662
+
1663
+    return [
1664
+        intval(round($destWidth)),
1665
+        intval(round($destHeight)),
1666
+        max($ratioWidth, $ratioHeight)
1667
+    ];
1668 1668
 }
1669 1669
 
1670 1670
 /**
@@ -1684,25 +1684,25 @@  discard block
 block discarded – undo
1684 1684
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1685 1685
  **/
1686 1686
 function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1687
-	$ratioWidth = $srcWidth / $maxWidth;
1688
-	$ratioHeight = $srcHeight / $maxHeight;
1689
-
1690
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1691
-		$destWidth = $srcWidth;
1692
-		$destHeight = $srcHeight;
1693
-	} elseif ($ratioWidth > $ratioHeight) {
1694
-		$destWidth = $srcWidth / $ratioHeight;
1695
-		$destHeight = $maxHeight;
1696
-	} else {
1697
-		$destWidth = $maxWidth;
1698
-		$destHeight = $srcHeight / $ratioWidth;
1699
-	}
1700
-
1701
-	return [
1702
-		intval(round($destWidth)),
1703
-		intval(round($destHeight)),
1704
-		min($ratioWidth, $ratioHeight)
1705
-	];
1687
+    $ratioWidth = $srcWidth / $maxWidth;
1688
+    $ratioHeight = $srcHeight / $maxHeight;
1689
+
1690
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1691
+        $destWidth = $srcWidth;
1692
+        $destHeight = $srcHeight;
1693
+    } elseif ($ratioWidth > $ratioHeight) {
1694
+        $destWidth = $srcWidth / $ratioHeight;
1695
+        $destHeight = $maxHeight;
1696
+    } else {
1697
+        $destWidth = $maxWidth;
1698
+        $destHeight = $srcHeight / $ratioWidth;
1699
+    }
1700
+
1701
+    return [
1702
+        intval(round($destWidth)),
1703
+        intval(round($destHeight)),
1704
+        min($ratioWidth, $ratioHeight)
1705
+    ];
1706 1706
 }
1707 1707
 
1708 1708
 
@@ -1715,12 +1715,12 @@  discard block
 block discarded – undo
1715 1715
  * @return string
1716 1716
  */
1717 1717
 function process_image_svg_identite($image) {
1718
-	if ($image['creer']) {
1719
-		$source = $image['fichier'];
1720
-		_image_gd_output($source, $image);
1721
-	}
1718
+    if ($image['creer']) {
1719
+        $source = $image['fichier'];
1720
+        _image_gd_output($source, $image);
1721
+    }
1722 1722
 
1723
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1723
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1724 1724
 }
1725 1725
 
1726 1726
 
@@ -1753,111 +1753,111 @@  discard block
 block discarded – undo
1753 1753
  *     Code HTML de la balise img produite
1754 1754
  **/
1755 1755
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1756
-	$image = false;
1757
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1758
-		$process = $GLOBALS['meta']['image_process'];
1759
-	}
1760
-	# determiner le format de sortie
1761
-	$format_sortie = false; // le choix par defaut sera bon
1762
-	if ($process == 'netpbm') {
1763
-		$format_sortie = 'jpg';
1764
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1765
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1766
-		// on verifie que l'extension choisie est bonne (en principe oui)
1767
-		$gd_formats = formats_image_acceptables(true);
1768
-		if (
1769
-			is_array($image)
1770
-			and (!in_array($image['format_dest'], $gd_formats)
1771
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1772
-			)
1773
-		) {
1774
-			if ($image['format_source'] == 'jpg') {
1775
-				$formats_sortie = ['jpg', 'png', 'gif'];
1776
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1777
-			{
1778
-				$formats_sortie = ['png', 'jpg', 'gif'];
1779
-			}
1780
-			// Choisir le format destination
1781
-			// - on sauve de preference en JPEG (meilleure compression)
1782
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1783
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1784
-			# pas *ecrire*
1785
-			$format_sortie = '';
1786
-			foreach ($formats_sortie as $fmt) {
1787
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1788
-					$format_sortie = $fmt;
1789
-					break;
1790
-				}
1791
-			}
1792
-			$image = false;
1793
-		}
1794
-	}
1795
-
1796
-	if (!is_array($image)) {
1797
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1798
-	}
1799
-
1800
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1801
-		spip_log("image_reduire_src:pas de version locale de $img");
1802
-		// on peut resizer en mode html si on dispose des elements
1803
-		if (
1804
-			$srcw = extraire_attribut($img, 'width')
1805
-			and $srch = extraire_attribut($img, 'height')
1806
-		) {
1807
-			list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1808
-
1809
-			return _image_tag_changer_taille($img, $w, $h);
1810
-		}
1811
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1812
-		// sous la forme style='max-width: NNpx;'
1813
-		return inserer_attribut(
1814
-			$img,
1815
-			'style',
1816
-			"max-width: ${taille}px; max-height: ${taille_y}px"
1817
-		);
1818
-	}
1819
-
1820
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1821
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1822
-		if ($image['creer']) {
1823
-			@copy($image['fichier'], $image['fichier_dest']);
1824
-		}
1825
-
1826
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1827
-	}
1828
-
1829
-	if ($image['creer'] == false && !$force) {
1830
-		return _image_ecrire_tag(
1831
-			$image,
1832
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1833
-		);
1834
-	}
1835
-
1836
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1837
-		$destWidth = $image['largeur_dest'];
1838
-		$destHeight = $image['hauteur_dest'];
1839
-		$logo = $image['fichier'];
1840
-		$date = $image['date_src'];
1841
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1842
-
1843
-		if ($preview && $preview['fichier']) {
1844
-			$logo = $preview['fichier'];
1845
-			$destWidth = $preview['width'];
1846
-			$destHeight = $preview['height'];
1847
-			$date = $preview['date'];
1848
-		}
1849
-		// dans l'espace prive mettre un timestamp sur l'adresse
1850
-		// de l'image, de facon a tromper le cache du navigateur
1851
-		// quand on fait supprimer/reuploader un logo
1852
-		// (pas de filemtime si SAFE MODE)
1853
-		$date = test_espace_prive() ? ('?' . $date) : '';
1854
-
1855
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1856
-	}
1857
-	else {
1858
-		# BMP, tiff ... les redacteurs osent tout!
1859
-		return $img;
1860
-	}
1756
+    $image = false;
1757
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1758
+        $process = $GLOBALS['meta']['image_process'];
1759
+    }
1760
+    # determiner le format de sortie
1761
+    $format_sortie = false; // le choix par defaut sera bon
1762
+    if ($process == 'netpbm') {
1763
+        $format_sortie = 'jpg';
1764
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1765
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1766
+        // on verifie que l'extension choisie est bonne (en principe oui)
1767
+        $gd_formats = formats_image_acceptables(true);
1768
+        if (
1769
+            is_array($image)
1770
+            and (!in_array($image['format_dest'], $gd_formats)
1771
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1772
+            )
1773
+        ) {
1774
+            if ($image['format_source'] == 'jpg') {
1775
+                $formats_sortie = ['jpg', 'png', 'gif'];
1776
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1777
+            {
1778
+                $formats_sortie = ['png', 'jpg', 'gif'];
1779
+            }
1780
+            // Choisir le format destination
1781
+            // - on sauve de preference en JPEG (meilleure compression)
1782
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1783
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1784
+            # pas *ecrire*
1785
+            $format_sortie = '';
1786
+            foreach ($formats_sortie as $fmt) {
1787
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1788
+                    $format_sortie = $fmt;
1789
+                    break;
1790
+                }
1791
+            }
1792
+            $image = false;
1793
+        }
1794
+    }
1795
+
1796
+    if (!is_array($image)) {
1797
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1798
+    }
1799
+
1800
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1801
+        spip_log("image_reduire_src:pas de version locale de $img");
1802
+        // on peut resizer en mode html si on dispose des elements
1803
+        if (
1804
+            $srcw = extraire_attribut($img, 'width')
1805
+            and $srch = extraire_attribut($img, 'height')
1806
+        ) {
1807
+            list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1808
+
1809
+            return _image_tag_changer_taille($img, $w, $h);
1810
+        }
1811
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1812
+        // sous la forme style='max-width: NNpx;'
1813
+        return inserer_attribut(
1814
+            $img,
1815
+            'style',
1816
+            "max-width: ${taille}px; max-height: ${taille_y}px"
1817
+        );
1818
+    }
1819
+
1820
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1821
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1822
+        if ($image['creer']) {
1823
+            @copy($image['fichier'], $image['fichier_dest']);
1824
+        }
1825
+
1826
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1827
+    }
1828
+
1829
+    if ($image['creer'] == false && !$force) {
1830
+        return _image_ecrire_tag(
1831
+            $image,
1832
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1833
+        );
1834
+    }
1835
+
1836
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1837
+        $destWidth = $image['largeur_dest'];
1838
+        $destHeight = $image['hauteur_dest'];
1839
+        $logo = $image['fichier'];
1840
+        $date = $image['date_src'];
1841
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1842
+
1843
+        if ($preview && $preview['fichier']) {
1844
+            $logo = $preview['fichier'];
1845
+            $destWidth = $preview['width'];
1846
+            $destHeight = $preview['height'];
1847
+            $date = $preview['date'];
1848
+        }
1849
+        // dans l'espace prive mettre un timestamp sur l'adresse
1850
+        // de l'image, de facon a tromper le cache du navigateur
1851
+        // quand on fait supprimer/reuploader un logo
1852
+        // (pas de filemtime si SAFE MODE)
1853
+        $date = test_espace_prive() ? ('?' . $date) : '';
1854
+
1855
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1856
+    }
1857
+    else {
1858
+        # BMP, tiff ... les redacteurs osent tout!
1859
+        return $img;
1860
+    }
1861 1861
 }
1862 1862
 
1863 1863
 /**
@@ -1872,145 +1872,145 @@  discard block
 block discarded – undo
1872 1872
  */
1873 1873
 class phpthumb_functions {
1874 1874
 
1875
-	/**
1876
-	 * Retourne la couleur d'un pixel dans une image
1877
-	 *
1878
-	 * @param ressource $img
1879
-	 * @param int $x
1880
-	 * @param int $y
1881
-	 * @return array|bool
1882
-	 */
1883
-	public static function GetPixelColor(&$img, $x, $y) {
1884
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1885
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1886
-		}
1887
-		return false;
1888
-	}
1889
-
1890
-	/**
1891
-	 * Retourne un nombre dans une représentation en Little Endian
1892
-	 *
1893
-	 * @param int $number
1894
-	 * @param int $minbytes
1895
-	 * @return string
1896
-	 */
1897
-	public static function LittleEndian2String($number, $minbytes = 1) {
1898
-		$intstring = '';
1899
-		while ($number > 0) {
1900
-			$intstring = $intstring . chr($number & 255);
1901
-			$number >>= 8;
1902
-		}
1903
-
1904
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1905
-	}
1906
-
1907
-	/**
1908
-	 * Transforme une ressource GD en image au format ICO
1909
-	 *
1910
-	 * @param array $gd_image_array
1911
-	 *     Tableau de ressources d'images GD
1912
-	 * @return string
1913
-	 *     Image au format ICO
1914
-	 */
1915
-	public static function GD2ICOstring(&$gd_image_array) {
1916
-		foreach ($gd_image_array as $key => $gd_image) {
1917
-			$ImageWidths[$key] = ImageSX($gd_image);
1918
-			$ImageHeights[$key] = ImageSY($gd_image);
1919
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1920
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1921
-
1922
-			$icXOR[$key] = '';
1923
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1924
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1925
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1926
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1927
-					$r = $argb['red'];
1928
-					$g = $argb['green'];
1929
-					$b = $argb['blue'];
1930
-
1931
-					if ($bpp[$key] == 32) {
1932
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1933
-					} elseif ($bpp[$key] == 24) {
1934
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1935
-					}
1936
-
1937
-					if ($a < 128) {
1938
-						@$icANDmask[$key][$y] .= '1';
1939
-					} else {
1940
-						@$icANDmask[$key][$y] .= '0';
1941
-					}
1942
-				}
1943
-				// mask bits are 32-bit aligned per scanline
1944
-				while (strlen($icANDmask[$key][$y]) % 32) {
1945
-					$icANDmask[$key][$y] .= '0';
1946
-				}
1947
-			}
1948
-			$icAND[$key] = '';
1949
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1950
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1951
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1952
-				}
1953
-			}
1954
-		}
1955
-
1956
-		foreach ($gd_image_array as $key => $gd_image) {
1957
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1958
-
1959
-			// BITMAPINFOHEADER - 40 bytes
1960
-			$BitmapInfoHeader[$key] = '';
1961
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1962
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1963
-			// The biHeight member specifies the combined
1964
-			// height of the XOR and AND masks.
1965
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1966
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1967
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1968
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1969
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1970
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1971
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1972
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1973
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1974
-		}
1975
-
1976
-
1977
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1978
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1979
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1980
-
1981
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1982
-		foreach ($gd_image_array as $key => $gd_image) {
1983
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1984
-
1985
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1986
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1987
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1988
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1989
-
1990
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1991
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1992
-
1993
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1994
-			$icondata .= phpthumb_functions::LittleEndian2String(
1995
-				$dwBytesInRes,
1996
-				4
1997
-			);     // dwBytesInRes;	// How many bytes in this resource?
1998
-
1999
-			$icondata .= phpthumb_functions::LittleEndian2String(
2000
-				$dwImageOffset,
2001
-				4
2002
-			);    // dwImageOffset;   // Where in the file is this image?
2003
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
2004
-			$dwImageOffset += strlen($icXOR[$key]);
2005
-			$dwImageOffset += strlen($icAND[$key]);
2006
-		}
2007
-
2008
-		foreach ($gd_image_array as $key => $gd_image) {
2009
-			$icondata .= $BitmapInfoHeader[$key];
2010
-			$icondata .= $icXOR[$key];
2011
-			$icondata .= $icAND[$key];
2012
-		}
2013
-
2014
-		return $icondata;
2015
-	}
1875
+    /**
1876
+     * Retourne la couleur d'un pixel dans une image
1877
+     *
1878
+     * @param ressource $img
1879
+     * @param int $x
1880
+     * @param int $y
1881
+     * @return array|bool
1882
+     */
1883
+    public static function GetPixelColor(&$img, $x, $y) {
1884
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1885
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1886
+        }
1887
+        return false;
1888
+    }
1889
+
1890
+    /**
1891
+     * Retourne un nombre dans une représentation en Little Endian
1892
+     *
1893
+     * @param int $number
1894
+     * @param int $minbytes
1895
+     * @return string
1896
+     */
1897
+    public static function LittleEndian2String($number, $minbytes = 1) {
1898
+        $intstring = '';
1899
+        while ($number > 0) {
1900
+            $intstring = $intstring . chr($number & 255);
1901
+            $number >>= 8;
1902
+        }
1903
+
1904
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1905
+    }
1906
+
1907
+    /**
1908
+     * Transforme une ressource GD en image au format ICO
1909
+     *
1910
+     * @param array $gd_image_array
1911
+     *     Tableau de ressources d'images GD
1912
+     * @return string
1913
+     *     Image au format ICO
1914
+     */
1915
+    public static function GD2ICOstring(&$gd_image_array) {
1916
+        foreach ($gd_image_array as $key => $gd_image) {
1917
+            $ImageWidths[$key] = ImageSX($gd_image);
1918
+            $ImageHeights[$key] = ImageSY($gd_image);
1919
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1920
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1921
+
1922
+            $icXOR[$key] = '';
1923
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1924
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1925
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1926
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1927
+                    $r = $argb['red'];
1928
+                    $g = $argb['green'];
1929
+                    $b = $argb['blue'];
1930
+
1931
+                    if ($bpp[$key] == 32) {
1932
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1933
+                    } elseif ($bpp[$key] == 24) {
1934
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1935
+                    }
1936
+
1937
+                    if ($a < 128) {
1938
+                        @$icANDmask[$key][$y] .= '1';
1939
+                    } else {
1940
+                        @$icANDmask[$key][$y] .= '0';
1941
+                    }
1942
+                }
1943
+                // mask bits are 32-bit aligned per scanline
1944
+                while (strlen($icANDmask[$key][$y]) % 32) {
1945
+                    $icANDmask[$key][$y] .= '0';
1946
+                }
1947
+            }
1948
+            $icAND[$key] = '';
1949
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1950
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1951
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1952
+                }
1953
+            }
1954
+        }
1955
+
1956
+        foreach ($gd_image_array as $key => $gd_image) {
1957
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1958
+
1959
+            // BITMAPINFOHEADER - 40 bytes
1960
+            $BitmapInfoHeader[$key] = '';
1961
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1962
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1963
+            // The biHeight member specifies the combined
1964
+            // height of the XOR and AND masks.
1965
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1966
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1967
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1968
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1969
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1970
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1971
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1972
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1973
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1974
+        }
1975
+
1976
+
1977
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1978
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1979
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1980
+
1981
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1982
+        foreach ($gd_image_array as $key => $gd_image) {
1983
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1984
+
1985
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1986
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1987
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1988
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1989
+
1990
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1991
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1992
+
1993
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1994
+            $icondata .= phpthumb_functions::LittleEndian2String(
1995
+                $dwBytesInRes,
1996
+                4
1997
+            );     // dwBytesInRes;	// How many bytes in this resource?
1998
+
1999
+            $icondata .= phpthumb_functions::LittleEndian2String(
2000
+                $dwImageOffset,
2001
+                4
2002
+            );    // dwImageOffset;   // Where in the file is this image?
2003
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
2004
+            $dwImageOffset += strlen($icXOR[$key]);
2005
+            $dwImageOffset += strlen($icAND[$key]);
2006
+        }
2007
+
2008
+        foreach ($gd_image_array as $key => $gd_image) {
2009
+            $icondata .= $BitmapInfoHeader[$key];
2010
+            $icondata .= $icXOR[$key];
2011
+            $icondata .= $icAND[$key];
2012
+        }
2013
+
2014
+        return $icondata;
2015
+    }
2016 2016
 }
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.