Close #17193 : Move button convert in webp

This commit is contained in:
lmarcouiller 2021-04-09 15:44:47 +02:00
parent 42ddb6e5f0
commit 19ee78e123
3 changed files with 47 additions and 36 deletions

View File

@ -86,6 +86,9 @@ if ($module == 'ecm') {
print '<img id="refreshbutton" class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
print '</a>';
}
if ($permtoadd) {
print '<a href="'.$_SERVER["PHP_SELF"].'?action=confirmconvertimgwebp&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateImgWebp")).'"><span class="fa fa-cogs"><span></a>';
}
// 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");

View File

@ -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

View File

@ -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&oacute;dulo_Website';
$arrayofjs = array(
@ -2542,7 +2508,6 @@ if (!GETPOST('hide_websitemenu')) {
// Generate site map
print '<a href="'.$_SERVER["PHP_SEFL"].'?action=confirmgeneratesitemaps&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'"><span class="fa fa-sitemap"><span></a>';
print '<a href="'.$_SERVER["PHP_SEFL"].'?action=confirmconvertimgwebp&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateImgWebp")).'"><span class="fa fa-cogs"><span></a>';
print ' &nbsp; ';
print '<a href="'.$_SERVER["PHP_SEFL"].'?action=replacesite&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'"><span class="fa fa-search"><span></a>';
@ -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 '<!-- Edit Media -->'."\n";
print '<div class="fiche"><br>';
//print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';