diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php index 9b3e063411179dc74f64abaaf1662f6f6a55e550..7ae74fa5e63d7010b97b2a072aa2dc4ef21c1ae2 100644 --- a/ecrire/inc/filtres.php +++ b/ecrire/inc/filtres.php @@ -3296,20 +3296,31 @@ function charge_scripts($files, $script = true) { * chemin_image : utiliser chemin_image sur $img fourni, ou non (oui par dafaut) * 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) * @return string */ function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) { + $img_file = $img; if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { - $img = chemin_image($img); + $img_file = chemin_image($img); + } + else { + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){ + if (preg_match(',-\d+[.](png|gif|svg)$,', $img_file, $m) + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg" + and file_exists($variante_svg_generique)){ + $img_file = $variante_svg_generique; + } + } } if (stripos($atts, 'width') === false) { // utiliser directement l'info de taille presente dans le nom if ((!isset($options['utiliser_suffixe_size']) or $options['utiliser_suffixe_size'] == true) - and preg_match(',-([0-9]+)[.](png|gif)$,', $img, $regs) + and preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) ) { $largeur = $hauteur = intval($regs[1]); } else { - $taille = taille_image($img); + $taille = taille_image($img_file); list($hauteur, $largeur) = $taille; if (!$hauteur or !$largeur) { return ""; @@ -3318,7 +3329,7 @@ function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; } - return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'" + return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'" . ($title ? ' title="' . attribut_html($title) . '"' : '') . " " . ltrim($atts) . " />"; diff --git a/ecrire/inc/icone_renommer.php b/ecrire/inc/icone_renommer.php index f5ef5bbde63a441c46c14d7bab24831466984f6e..134ad2b14848dd7d2db4b0dd30953ae5fd692646 100644 --- a/ecrire/inc/icone_renommer.php +++ b/ecrire/inc/icone_renommer.php @@ -19,7 +19,7 @@ include_spip('base/objets'); function inc_icone_renommer_dist($fond, $fonction) { $size = 24; - if (preg_match("/(?:-([0-9]{1,3}))?([.](gif|png))?$/i", $fond, $match) + if (preg_match("/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i", $fond, $match) and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1])) ) { if (isset($match[1]) and $match[1]) { diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php index b223241549f3b0b5fbe9ab976c8a435d2f8b0739..89fb15c7e29d10d5ecc088aa5eb1e21ada88ba63 100644 --- a/ecrire/inc/utils.php +++ b/ecrire/inc/utils.php @@ -1385,6 +1385,13 @@ function find_in_theme($file, $subdir = '', $include = false) { if (isset($themefiles["$subdir$file"])) { return $themefiles["$subdir$file"]; } + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire + if (preg_match(',-\d+[.](png|gif|svg)$,', $file, $m) + and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg" + and $f = find_in_theme("$file_svg_generique")) { + return $themefiles["$subdir$file"] = $f; + } + $themes = lister_themes_prives(); foreach ($themes as $theme) { if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {