From ed4dd9b5fad4c9c56eb09703c96ea8df2b81e581 Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Fri, 27 Sep 2024 08:49:25 +0200 Subject: [PATCH] #1086 [JS] fix: media gallery error and config medias --- admin/setup.php | 91 +++++++++++++++++++- core/modules/modSaturne.class.php | 9 ++ core/tpl/medias/medias_gallery_modal.tpl.php | 62 +++++++------ js/modules/mediaGallery.js | 2 +- js/saturne.min.js | 2 +- langs/en_US/medias.lang | 25 +++--- langs/fr_FR/medias.lang | 27 +++--- 7 files changed, 158 insertions(+), 60 deletions(-) diff --git a/admin/setup.php b/admin/setup.php index 0f38928a..bd45b5b1 100644 --- a/admin/setup.php +++ b/admin/setup.php @@ -37,11 +37,14 @@ require_once __DIR__ . '/../lib/saturne.lib.php'; // Global variables definitions -global $db, $langs, $user; +global $conf, $db, $langs, $user; // Load translation files required by the page saturne_load_langs(['admin']); +// Initialize view objects +$form = new Form($db); + // Parameters $action = GETPOST('action', 'alpha'); $value = GETPOST('value', 'alpha'); @@ -51,6 +54,30 @@ $permissiontoread = $user->rights->saturne->adminpage->read; saturne_check_access($permissiontoread); +/* + * Actions + */ + +if ($action == 'set_media_infos') { + $mediasMax['SATURNE_MEDIA_MAX_WIDTH_MINI'] = GETPOST('MediaMaxWidthMini', 'alpha'); + $mediasMax['SATURNE_MEDIA_MAX_HEIGHT_MINI'] = GETPOST('MediaMaxHeightMini', 'alpha'); + $mediasMax['SATURNE_MEDIA_MAX_WIDTH_SMALL'] = GETPOST('MediaMaxWidthSmall', 'alpha'); + $mediasMax['SATURNE_MEDIA_MAX_HEIGHT_SMALL'] = GETPOST('MediaMaxHeightSmall', 'alpha'); + $mediasMax['SATURNE_MEDIA_MAX_WIDTH_MEDIUM'] = GETPOST('MediaMaxWidthMedium', 'alpha'); + $mediasMax['SATURNE_MEDIA_MAX_HEIGHT_MEDIUM'] = GETPOST('MediaMaxHeightMedium', 'alpha'); + $mediasMax['SATURNE_MEDIA_MAX_WIDTH_LARGE'] = GETPOST('MediaMaxWidthLarge', 'alpha'); + $mediasMax['SATURNE_MEDIA_MAX_HEIGHT_LARGE'] = GETPOST('MediaMaxHeightLarge', 'alpha'); + $mediasMax['SATURNE_DISPLAY_NUMBER_MEDIA_GALLERY'] = GETPOST('DisplayNumberMediaGallery', 'alpha'); + + foreach($mediasMax as $key => $valueMax) { + dolibarr_set_const($db, $key, $valueMax, 'integer', 0, '', $conf->entity); + } + + setEventMessage('SavedConfig'); + header('Location: ' . $_SERVER['PHP_SELF']); + exit; +} + /* * View */ @@ -136,6 +163,68 @@ // End of the table print ''; +print load_fiche_titre($langs->trans('Configs', $langs->transnoentities('MediasMin')), '', ''); + +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +// End of the table +print '
' . $langs->trans('Name') . '' . $langs->trans('Description') . '' . $langs->trans('Value') . '
' . $langs->trans('MediaMaxWidthMiniDescription') . '
' . $langs->trans('MediaMaxHeightMiniDescription') . '
' . $langs->trans('MediaMaxWidthSmallDescription') . '
' . $langs->trans('MediaMaxHeightSmallDescription') . '
' . $langs->trans('MediaMaxWidthMediumDescription') . '
' . $langs->trans('MediaMaxHeightMediumDescription') . '
' . $langs->trans('MediaMaxWidthLargeDescription') . '
' . $langs->trans('MediaMaxHeightLargeDescription') . '
' . $langs->trans('DisplayNumberMediaGalleryDescription') . '
'; +print $form->buttonsSaveCancel('Save', ''); +print '
'; + // Page end print dol_get_fiche_end(); llxFooter(); diff --git a/core/modules/modSaturne.class.php b/core/modules/modSaturne.class.php index 70e4fea7..aeb411d9 100644 --- a/core/modules/modSaturne.class.php +++ b/core/modules/modSaturne.class.php @@ -181,6 +181,15 @@ public function __construct($db) $i++ => ['SATURNE_USE_CAPTCHA', 'integer', 0, '', 0, 'current'], $i++ => ['SATURNE_USE_ALL_EMAIL_MODE', 'integer', 1, '', 0, 'current'], $i++ => ['SATURNE_USE_CREATE_DOCUMENT_ON_ARCHIVE', 'integer', 1, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_WIDTH_MINI', 'integer', 128, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_HEIGHT_MINI', 'integer', 72, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_WIDTH_SMALL', 'integer', 480, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_HEIGHT_SMALL', 'integer', 270, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_WIDTH_MEDIUM', 'integer', 854, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_HEIGHT_MEDIUM', 'integer', 480, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_WIDTH_LARGE', 'integer', 1280, '', 0, 'current'], + $i++ => ['SATURNE_MEDIA_MAX_HEIGHT_LARGE', 'integer', 720, '', 0, 'current'], + $i++ => ['SATURNE_DISPLAY_NUMBER_MEDIA_GALLERY', 'integer', 8, '', 0, 'current'], // CONST DOLIBARR $i => ['MAIN_ALLOW_SVG_FILES_AS_IMAGES', 'integer', 1, '', 0, 'current'] diff --git a/core/tpl/medias/medias_gallery_modal.tpl.php b/core/tpl/medias/medias_gallery_modal.tpl.php index 4d484e64..0b01f89b 100644 --- a/core/tpl/medias/medias_gallery_modal.tpl.php +++ b/core/tpl/medias/medias_gallery_modal.tpl.php @@ -41,7 +41,7 @@ // Array for the sizes of thumbs $mediaSizes = ['mini', 'small', 'medium', 'large']; -if ( ! $error && $subaction == 'uploadPhoto' && ! empty($conf->global->MAIN_UPLOAD_DOC)) { +if (!(isset($error) && $error) && $subaction == 'uploadPhoto' && ! empty($conf->global->MAIN_UPLOAD_DOC)) { // Define relativepath and upload_dir $relativepath = $moduleNameLowerCase . '/medias'; @@ -108,10 +108,13 @@ } } else { $modObjectName = dol_strtoupper($moduleNameLowerCase) . '_' . dol_strtoupper($object->element) . '_ADDON'; - $numberingModuleName = [$object->element => $conf->global->$modObjectName]; - list($modObject) = saturne_require_objects_mod($numberingModuleName, $moduleNameLowerCase); - - $pathToObjectImg = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/' . $object->element . '/tmp/' . $modObject->prefix . '0/' . $data['objectSubdir']; + $numberingModuleName = [$object->element => getDolGlobalString($modObjectName)]; + if ($numberingModuleName[$data['objectType']] != '') { + list($modObject) = saturne_require_objects_mod($numberingModuleName, $moduleNameLowerCase); + $pathToObjectImg = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/' . $object->element . '/tmp/' . $modObject->prefix . '0/' . $data['objectSubdir']; + } else { + $pathToObjectImg = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/' . $data['objectType'] . '/tmp/' . $data['objectSubdir'] . '/'; + } } if (!dol_is_dir($pathToObjectImg)) { @@ -122,8 +125,8 @@ // Create thumbs foreach($mediaSizes as $size) { - $confWidth = $moduleNameUpperCase . '_MEDIA_MAX_WIDTH_' . dol_strtoupper($size); - $confHeight = $moduleNameUpperCase . '_MEDIA_MAX_HEIGHT_' . dol_strtoupper($size); + $confWidth = 'SATURNE_MEDIA_MAX_WIDTH_' . dol_strtoupper($size); + $confHeight = 'SATURNE_MEDIA_MAX_HEIGHT_' . dol_strtoupper($size); vignette($pathToECMImg . '/' . $fileName, $conf->global->$confWidth, $conf->global->$confHeight, '_' . $size); vignette($pathToObjectImg . '/' . $fileName, $conf->global->$confWidth, $conf->global->$confHeight, '_' . $size); } @@ -148,10 +151,13 @@ $pathToObjectImg = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/' . $objectType . '/' . $object->ref . '/' . $data['objectSubdir']; } else { $modObjectName = dol_strtoupper($moduleNameLowerCase) . '_' . dol_strtoupper($objectType) . '_ADDON'; - $numberingModuleName = [$objectType => $conf->global->$modObjectName]; - list($modObject) = saturne_require_objects_mod($numberingModuleName, $moduleNameLowerCase); - - $pathToObjectImg = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/' . $objectType . '/tmp/' . $modObject->prefix . '0/' . $data['objectSubdir']; + $numberingModuleName = [$objectType => getDolGlobalString($modObjectName)]; + if ($numberingModuleName[$objectType] != '') { + list($modObject) = saturne_require_objects_mod($numberingModuleName, $moduleNameLowerCase); + $pathToObjectImg = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/' . $objectType . '/tmp/' . $modObject->prefix . '0/' . $data['objectSubdir']; + } else { + $pathToObjectImg = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/' . $objectType . '/tmp/' . $data['objectSubdir'] . '/'; + } } if (!dol_is_dir($pathToObjectImg)) { @@ -176,8 +182,8 @@ // Create thumbs foreach($mediaSizes as $size) { - $confWidth = $moduleNameUpperCase . '_MEDIA_MAX_WIDTH_' . dol_strtoupper($size); - $confHeight = $moduleNameUpperCase . '_MEDIA_MAX_HEIGHT_' . dol_strtoupper($size); + $confWidth = 'SATURNE_MEDIA_MAX_WIDTH_' . dol_strtoupper($size); + $confHeight = 'SATURNE_MEDIA_MAX_HEIGHT_' . dol_strtoupper($size); vignette($pathToObjectImg . '/' . $fileName, $conf->global->$confWidth, $conf->global->$confHeight, '_' . $size); } } @@ -264,7 +270,7 @@ } } -if ( ! $error && $subaction == 'pagination') { +if (!(isset($error) && $error) && $subaction == 'pagination') { $data = json_decode(file_get_contents('php://input'), true); $offset = $data['offset']; @@ -273,7 +279,7 @@ $loadedPageArray = saturne_load_pagination($pagesCounter, [], $offset); } -if ( ! $error && $subaction == 'toggleTodayMedias') { +if (!(isset($error) && $error) && $subaction == 'toggleTodayMedias') { $toggleValue = GETPOST('toggle_today_medias'); $tabparam['SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS'] = $toggleValue; @@ -281,7 +287,7 @@ dol_set_user_param($db, $conf,$user, $tabparam); } -if ( ! $error && $subaction == 'toggleUnlinkedMedias') { +if (!(isset($error) && $error) && $subaction == 'toggleUnlinkedMedias') { $toggleValue = GETPOST('toggle_unlinked_medias'); $tabparam['SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS'] = $toggleValue; @@ -289,24 +295,24 @@ dol_set_user_param($db, $conf,$user, $tabparam); } -if (!$error && $subaction == 'regenerate_thumbs') { +if (!(isset($error) && $error) && $subaction == 'regenerate_thumbs') { $data = json_decode(file_get_contents('php://input'), true); foreach($mediaSizes as $size) { - $confWidth = $moduleNameUpperCase . '_MEDIA_MAX_WIDTH_' . dol_strtoupper($size); - $confHeight = $moduleNameUpperCase . '_MEDIA_MAX_HEIGHT_' . dol_strtoupper($size); + $confWidth = 'SATURNE_MEDIA_MAX_WIDTH_' . dol_strtoupper($size); + $confHeight = 'SATURNE_MEDIA_MAX_HEIGHT_' . dol_strtoupper($size); vignette($data['fullname'], $conf->global->$confWidth, $conf->global->$confHeight, '_' . $size); } } -if (is_array($submitFileErrorText)) { +if (!empty($submitFileErrorText) && is_array($submitFileErrorText)) { print ''; } require_once __DIR__ . '/media_editor_modal.tpl.php'; ?> -