Valider 6a4c7bf8 rédigé par Maïeul's avatar Maïeul Validation de Gitea
Parcourir les fichiers

`http_img_pack()` peut recevoir une clé `'alternative'` dans son tableau d'option.

Cela indique une icone alternative à utiliser si jamais on ne retrouve pas
l'image.

De même `http_style_background()` peut recevoir un dernier argument
`$alternative`.

On se sert de ces alternatives dans `icone_base()` et dans `debut_cadre()`.
`icone_horizontale`).

Icone par @erational

Fix spip-contrib-extensions/champs_extras_interface#5
parent bb79a8ab
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+12 −3
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -3528,6 +3528,7 @@ function http_img_variante_svg_si_possible($img_file) {
 *   utiliser_suffixe_size : utiliser ou non le suffixe de taille dans le nom de fichier de l'image
 *   sous forme -xx.png (pour les icones essentiellement) (oui par defaut)
 *   variante_svg_si_possible: utiliser l'image -xx.svg au lieu de -32.png par exemple (si la variante svg est disponible)
 *   alternative: icone alternative à utiliser si l'icone demandée n'existe pas
 * @return string
 */
function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
@@ -3566,6 +3567,9 @@ function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {

	if (file_exists($img_file)) {
		$img_file = timestamp($img_file);
	} elseif ($alternative = $options['alternative'] ?? '') {
		unset($options['alternative']);
		return http_img_pack($alternative, $alt, $atts, $title, $options);
	}
	if ($alt === false) {
		$alt = '';
@@ -3588,14 +3592,19 @@ function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
 * @param string $img
 * @param string $att
 * @param string $size
 * @param string $alternative
 * @return string
 */
function http_style_background($img, $att = '', $size = null) {
function http_style_background($img, $att = '', $size = null, $alternative = '') {
	if ($size and is_numeric($size)) {
		$size = trim($size) . 'px';
	}

	if (!$img = chemin_image($img)) {
		$img = chemin_image($alternative);
	}
	return " style='background" .
		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
		($att ? '' : '-image') . ': url("' . $img . '")' . ($att ? (' ' . $att) : '') . ';'
		. ($size ? "background-size:{$size};" : '')
		. "'";
}
@@ -4423,7 +4432,7 @@ function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class
	$class_bouton .= " s$size";

	// Icône
	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'",'', ['alternative' => "objet-generique-$size.png"]);
	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";

	// Markup final
+2 −2
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -62,9 +62,9 @@ function debut_cadre($style, $icone = '', $fonction = '', $titre = '', $id = '',
			// 2 images pour composer l'icone : le fond (article) en background,
			// la fonction (new) en image
			$icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
				http_style_background($fond, 'no-repeat center center', $size));
				http_style_background($fond, 'no-repeat center center', $size, "objet-generique-$size.png"));
		} else {
			$icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
			$icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'", '', ['alternative' => "objet-generique-$size.png"]);
		}
		$titre = $icone . $titre;
	}
+1 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64"><path fill="#666" d="M10 10h14V4H6c-1.1 0-2 .9-2 2v18h6V10zm44 0v14h6V6c0-1.1-.9-2-2-2H40v6h14zM10 52V38H4v18c0 1.1.9 2 2 2h18v-6H10zm44 0H40v6h18c1.1 0 2-.9 2-2V38h-6v14z"/></svg>
 No newline at end of file