Merge pull request #17155 from Hystepik/develop#4

NEW #17113 : Can upload a favicon in website module
This commit is contained in:
Laurent Destailleur 2021-04-08 15:44:45 +02:00 committed by GitHub
commit 91847a1783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -141,7 +141,11 @@ GenerateSitemaps=Generate website sitemap file
ConfirmGenerateSitemaps=If you confirm, you will erase the existing sitemap file...
ConfirmSitemapsCreation=Confirm sitemap generation
SitemapGenerated=Sitemap Generated
ImportFavicon=Favicon
ErrorFaviconType=Favicon must be png
ErrorFaviconSize=Favicon must be of size 32x32
FaviconTooltip=Upload an image which needs to be a png of 32x32
GenerateImgWebp=Convert all images into webp
ConfirmGenerateImgWebp=If you confirm, you will generate all website's images in webp format...
ConfirmImgWebpCreation=Confirm all images convertion
SucessConvertImgWebp=Images successfully converted
SucessConvertImgWebp=Images successfully converted

View File

@ -34,6 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
@ -1313,6 +1314,37 @@ if ($action == 'updatecss' && $usercanedit) {
}
}
if (!$error) {
if (($_FILES['addedfile']["name"] != '')) {
$uploadfolder = $conf->website->dir_output.'/'.$websitekey;
if ($_FILES['addedfile']['type'] != 'image/png') {
$error++;
setEventMessages($langs->trans('ErrorFaviconType'), array(), 'errors');
}
$filetoread = realpath(dol_osencode($_FILES['addedfile']['tmp_name']));
$filesize = getimagesize($filetoread);
if ($filesize[0] != 32 || $filesize[1] != 32) {
$error++;
setEventMessages($langs->trans('ErrorFaviconSize'), array(), 'errors');
}
if (!$error) {
dol_add_file_process($uploadfolder, 1, 0, 'addedfile', 'favicon.png');
}
}
if ($error) {
if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
$action = 'preview';
if ($backtopage) {
$backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
header("Location: ".$backtopage);
exit;
}
} else {
$action = 'editcss';
}
}
}
if (!$error) {
// Save master.inc.php file
dol_syslog("Save master file ".$filemaster);
@ -3152,6 +3184,13 @@ if ($action == 'editcss') {
print '</td>';
print '</tr>';
// Favicon
print '<tr><td>';
print $form->textwithpicto($langs->trans('ImportFavicon'), $langs->trans('FaviconTooltip'));
print '</td><td>';
print '<input type="file" class="flat minwidth300" name="addedfile" id="addedfile"/>';
print '</tr></td>';
// CSS file
print '<tr><td class="tdtop">';
$htmlhelp = $langs->trans("CSSContentTooltipHelp");