Merge pull request #24210 from Hystepik/develop#1
NEW : add convertion of images to webp for single image
This commit is contained in:
commit
8af6f29cec
@ -1445,7 +1445,25 @@ class FormFile
|
||||
if (in_array($modulepart, array('product', 'produit', 'service'))) {
|
||||
$newmodulepart = 'produit|service';
|
||||
}
|
||||
|
||||
if (image_format_supported($file['name']) > 0) {
|
||||
if ($permtoeditline) {
|
||||
$moreparaminurl = '';
|
||||
if (!empty($object->id) && $object->id > 0) {
|
||||
$moreparaminurl .= '&id='.$object->id;
|
||||
} elseif (GETPOST('website', 'alpha')) {
|
||||
$moreparaminurl .= '&website='.GETPOST('website', 'alpha');
|
||||
}
|
||||
// Set the backtourl
|
||||
if ($modulepart == 'medias' && !GETPOST('website')) {
|
||||
$moreparaminurl .= '&backtourl='.urlencode(DOL_URL_ROOT.'/ecm/index_medias.php?file_manager=1&modulepart='.$modulepart.'§ion_dir='.$relativepath);
|
||||
}
|
||||
if ($modulepart == 'medias' && !GETPOST('website')) {
|
||||
print '<a href="'.DOL_URL_ROOT.'/ecm/index_medias.php?action=confirmconvertimgwebp&token='.newToken().'§ion_dir='.urlencode($relativepath).'&filetoregenerate='.urlencode($fileinfo['basename']).'&module='.$modulepart.$param.$moreparaminurl.'" title="'.dol_escape_htmltag($langs->trans("GenerateChosenImgWebp")).'">'.img_picto('', 'images', 'class="flip marginrightonly"').'</a>';
|
||||
} elseif ($modulepart == 'medias' && GETPOST('website')) {
|
||||
print '<a href="'.DOL_URL_ROOT.'/website/index.php?action=confirmconvertimgwebp&token='.newToken().'§ion_dir='.urlencode($relativepath).'&filetoregenerate='.urlencode($fileinfo['basename']).'&module='.$modulepart.$param.$moreparaminurl.'" title="'.dol_escape_htmltag($langs->trans("GenerateChosenImgWebp")).'">'.img_picto('', 'images', 'class="flip marginrightonly"').'</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$disablecrop && image_format_supported($file['name']) > 0) {
|
||||
if ($permtoeditline) {
|
||||
// Link to resize
|
||||
|
||||
@ -197,18 +197,22 @@ if ($action == 'confirmconvertimgwebp') {
|
||||
|
||||
$section_dir=GETPOST('section_dir', 'alpha');
|
||||
$section=GETPOST('section', 'alpha');
|
||||
$file=GETPOST('filetoregenerate', 'alpha');
|
||||
$form = new Form($db);
|
||||
$formquestion['section_dir']=array('type'=>'hidden', 'value'=>$section_dir, 'name'=>'section_dir');
|
||||
$formquestion['section']=array('type'=>'hidden', 'value'=>$section, 'name'=>'section');
|
||||
$formquestion['filetoregenerate']=array('type'=>'hidden', 'value'=>$file, 'name'=>'filetoregenerate');
|
||||
if ($module == 'medias') {
|
||||
$formquestion['website']=array('type'=>'hidden', 'value'=>$website->ref, 'name'=>'website');
|
||||
}
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('ConfirmImgWebpCreation'), $langs->trans('ConfirmGenerateImgWebp', $object->ref), 'convertimgwebp', $formquestion, "yes", 1);
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"], empty($file) ? $langs->trans('ConfirmImgWebpCreation') : $langs->trans('ConfirmChosenImgWebpCreation'), empty($file) ? $langs->trans('ConfirmGenerateImgWebp') : $langs->trans('ConfirmGenerateChosenImgWebp'), 'convertimgwebp', $formquestion, "yes", 1);
|
||||
$action = 'file_manager';
|
||||
}
|
||||
|
||||
// Duplicate images into .webp
|
||||
if ($action == 'convertimgwebp' && $permtoadd) {
|
||||
$file = GETPOST('filetoregenerate', 'alpha');
|
||||
|
||||
if ($module == 'medias') {
|
||||
$imagefolder = $conf->website->dir_output.'/'.$websitekey.'/medias/'.dol_sanitizePathName(GETPOST('section_dir', 'alpha'));
|
||||
} else {
|
||||
@ -217,9 +221,14 @@ if ($action == 'convertimgwebp' && $permtoadd) {
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
|
||||
|
||||
$regeximgext = getListOfPossibleImageExt();
|
||||
if (!empty($file)) {
|
||||
$filelist = array();
|
||||
$filelist[]["fullname"] = dol_osencode($imagefolder.'/'.$file); // get $imagefolder.'/'.$file infos
|
||||
} else {
|
||||
$regeximgext = getListOfPossibleImageExt();
|
||||
|
||||
$filelist = dol_dir_list($imagefolder, "files", 0, $regeximgext);
|
||||
$filelist = dol_dir_list($imagefolder, "files", 0, $regeximgext);
|
||||
}
|
||||
|
||||
$nbconverted = 0;
|
||||
|
||||
@ -245,7 +254,11 @@ if ($action == 'convertimgwebp' && $permtoadd) {
|
||||
}
|
||||
}
|
||||
if (!$error) {
|
||||
setEventMessages($langs->trans('SucessConvertImgWebp'), null);
|
||||
if (!empty($file)) {
|
||||
setEventMessages($langs->trans('SucessConvertChosenImgWebp'), null);
|
||||
} else {
|
||||
setEventMessages($langs->trans('SucessConvertImgWebp'), null);
|
||||
}
|
||||
}
|
||||
$action = 'file_manager';
|
||||
}
|
||||
|
||||
@ -47,6 +47,10 @@ ECMSetup=ECM Setup
|
||||
GenerateImgWebp=Duplicate all images with another version with .webp format
|
||||
ConfirmGenerateImgWebp=If you confirm, you will generate an image in .webp format for all images currently into this folder (subfolders are not included)...
|
||||
ConfirmImgWebpCreation=Confirm all images duplication
|
||||
GenerateChosenImgWebp=Duplicate chosen image with another version with .webp format
|
||||
ConfirmGenerateChosenImgWebp=If you confirm, you will generate an image in .webp format for chosen image
|
||||
ConfirmChosenImgWebpCreation=Confirm chosen images duplication
|
||||
SucessConvertImgWebp=Images successfully duplicated
|
||||
SucessConvertChosenImgWebp=Chosen image successfully duplicated
|
||||
ECMDirName=Dir name
|
||||
ECMParentDirectory=Parent directory
|
||||
|
||||
Loading…
Reference in New Issue
Block a user