From f8b5bee9eb0ea24156fb79272b8dde2374651366 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Apr 2021 14:20:59 +0200 Subject: [PATCH] Add function getListOfPossibleImageExt --- htdocs/core/lib/images.lib.php | 24 ++++++++++++++++++------ htdocs/website/index.php | 8 +++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/images.lib.php b/htdocs/core/lib/images.lib.php index 4803b5e0770..36e8cef6bfe 100644 --- a/htdocs/core/lib/images.lib.php +++ b/htdocs/core/lib/images.lib.php @@ -30,6 +30,23 @@ $maxheightmini = 72; // 16/9eme $quality = 80; +/** + * Return if a filename is file name of a supported image format + * + * @param int $acceptsvg 0=Default (depends on setup), 1=Always accept SVG as image files + * @return string Return list fo image format + */ +function getListOfPossibleImageExt($acceptsvg = 0) +{ + global $conf; + + $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into product.class.php + if ($acceptsvg || !empty($conf->global->MAIN_ALLOW_SVG_FILES_AS_IMAGES)) { + $regeximgext .= '|\.svg'; // Not allowed by default. SVG can contains javascript + } + + return $regeximgext; +} /** * Return if a filename is file name of a supported image format @@ -40,12 +57,7 @@ $quality = 80; */ function image_format_supported($file, $acceptsvg = 0) { - global $conf; - - $regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into product.class.php - if ($acceptsvg || !empty($conf->global->MAIN_ALLOW_SVG_FILES_AS_IMAGES)) { - $regeximgext .= '|\.svg'; // Not allowed by default. SVG can contains javascript - } + $regeximgext = getListOfPossibleImageExt(); // Case filename is not a format image $reg = array(); diff --git a/htdocs/website/index.php b/htdocs/website/index.php index fd24f202a1c..405369ce26f 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -2230,10 +2230,16 @@ if ($action == 'generatesitemaps' && $usercanedit) { } $action = 'preview'; } + $imagefolder = $conf->website->dir_output.'/'.$websitekey.'/medias/image/'.$websitekey.'/'; + if ($action == 'convertimgwebp' && $usercanedit) { include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; - $filelist = dol_dir_list($imagefolder, "all", 1); + + $regeximgext = getListOfPossibleImageExt(); + + $filelist = dol_dir_list($imagefolder, "all", 1, $regeximgext); + foreach ($filelist as $filename) { $filepath = $filename['fullname']; if (!(substr_compare($filepath, 'webp', -strlen('webp')) === 0)) {