diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php index 4603660ad6c5e0f252d77d81469483a01f3721be..039e6859850150d336ea8b369294eb472d1561e0 100644 --- a/ecrire/inc/filtres.php +++ b/ecrire/inc/filtres.php @@ -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 diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php index 02eb940ef221349621343450715869dba9b1a072..3f272973595449550054486f9dfa74a943590d5b 100644 --- a/ecrire/inc/presentation.php +++ b/ecrire/inc/presentation.php @@ -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; } diff --git a/prive/themes/spip/images/objet-generique-xx.svg b/prive/themes/spip/images/objet-generique-xx.svg new file mode 100644 index 0000000000000000000000000000000000000000..6fb1e3b49ddfef80a60109ff5c2b0122e53f30c6 --- /dev/null +++ b/prive/themes/spip/images/objet-generique-xx.svg @@ -0,0 +1 @@ +<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