diff --git a/htdocs/core/tpl/filemanager.tpl.php b/htdocs/core/tpl/filemanager.tpl.php
index 6ff7bba2390..bfd10e25424 100644
--- a/htdocs/core/tpl/filemanager.tpl.php
+++ b/htdocs/core/tpl/filemanager.tpl.php
@@ -86,6 +86,9 @@ if ($module == 'ecm') {
print '
';
print '';
}
+if ($permtoadd) {
+ print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateImgWebp")).'">';
+}
// Start "Add new file" area
$nameforformuserfile = 'formuserfileecm';
@@ -133,6 +136,45 @@ if ($action == 'delete_section') {
}
// End confirm
+if ($action == 'confirmconvertimgwebp') {
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$website->ref, $langs->trans('ConfirmImgWebpCreation'), $langs->trans('ConfirmGenerateImgWebp', $object->ref), 'convertimgwebp', '', "yes", 1);
+ $action = 'file_manager';
+}
+
+if ($action == 'convertimgwebp' && $permtoadd) {
+ if ($module == 'medias') {
+ $imagefolder = $conf->website->dir_output.'/'.$websitekey.'/medias/image/'.$websitekey.'/';
+ } else {
+ $imagefolder = $conf->ecm->dir_output;
+ }
+
+ include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
+
+ $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)) {
+ if (image_format_supported($filepath) == 1) {
+ $filepathnoext = preg_replace("/\..*/", "", $filepath);
+ $result = dol_imageResizeOrCrop($filepath, 0, 0, 0, 0, 0, $filepathnoext.'.webp');
+ if (!dol_is_file($result)) {
+ $error++;
+ setEventMessages($result, null, 'errors');
+ }
+ }
+ }
+ if ($error) {
+ break;
+ }
+ }
+ if (!$error) {
+ setEventMessages($langs->trans('SucessConvertImgWebp'), null);
+ }
+ $action = 'file_manager';
+}
if (empty($action) || $action == 'editfile' || $action == 'file_manager' || preg_match('/refresh/i', $action) || $action == 'delete') {
$langs->load("ecm");
diff --git a/htdocs/langs/en_US/ecm.lang b/htdocs/langs/en_US/ecm.lang
index 71df60734fb..2bac434deb0 100644
--- a/htdocs/langs/en_US/ecm.lang
+++ b/htdocs/langs/en_US/ecm.lang
@@ -41,3 +41,7 @@ FileNotYetIndexedInDatabase=File not yet indexed into database (try to re-upload
ExtraFieldsEcmFiles=Extrafields Ecm Files
ExtraFieldsEcmDirectories=Extrafields Ecm Directories
ECMSetup=ECM Setup
+GenerateImgWebp=Convert all images into webp
+ConfirmGenerateImgWebp=If you confirm, you will generate all images in this folder and subfolder in webp format...
+ConfirmImgWebpCreation=Confirm all images convertion
+SucessConvertImgWebp=Images successfully converted
diff --git a/htdocs/website/index.php b/htdocs/website/index.php
index b7609878196..60e4b514e01 100644
--- a/htdocs/website/index.php
+++ b/htdocs/website/index.php
@@ -2275,36 +2275,6 @@ 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';
-
- $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)) {
- if (image_format_supported($filepath) == 1) {
- $filepathnoext = preg_replace("/\..*/", "", $filepath);
- $result = dol_imageResizeOrCrop($filepath, 0, 0, 0, 0, 0, $filepathnoext.'.webp');
- if (!dol_is_file($result)) {
- $error++;
- setEventMessages($result, null, 'errors');
- }
- }
- }
- if ($error) {
- break;
- }
- }
- if (!$error) {
- setEventMessages($langs->trans('SucessConvertImgWebp'), null);
- }
- $action = 'preview';
-}
/*
* View
@@ -2320,10 +2290,6 @@ if ($action == 'confirmgeneratesitemaps') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$website->ref, $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref), 'generatesitemaps', '', "yes", 1);
$action = 'preview';
}
-if ($action == 'confirmconvertimgwebp') {
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$website->ref, $langs->trans('ConfirmImgWebpCreation'), $langs->trans('ConfirmGenerateImgWebp', $object->ref), 'convertimgwebp', '', "yes", 1);
- $action = 'preview';
-}
$helpurl = 'EN:Module_Website|FR:Module_Website_FR|ES:Módulo_Website';
$arrayofjs = array(
@@ -2542,7 +2508,6 @@ if (!GETPOST('hide_websitemenu')) {
// Generate site map
print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'">';
- print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateImgWebp")).'">';
print ' ';
print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'">';
@@ -3882,7 +3847,7 @@ if ($action == 'preview') {
print $formconfirm;
}
-if ($action == 'editfile' || $action == 'file_manager') {
+if ($action == 'editfile' || $action == 'file_manager' || $action == 'convertimgwebp' || $action == 'confirmconvertimgwebp') {
print ''."\n";
print '