Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1086 [JS] fix: media gallery error and config medias #1087

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 90 additions & 1 deletion admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
*/
Expand Down Expand Up @@ -136,6 +163,68 @@
// End of the table
print '</table>';

print load_fiche_titre($langs->trans('Configs', $langs->transnoentities('MediasMin')), '', '');

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" name="media_data">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="set_media_infos">';
print '<table class="noborder centpercent editmode">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans('Name') . '</td>';
print '<td>' . $langs->trans('Description') . '</td>';
print '<td>' . $langs->trans('Value') . '</td>';
print '</tr>';

print '<tr class="oddeven"><td><label for="MediaMaxWidthMini">' . $langs->trans('MediaMaxWidthMini') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxWidthMiniDescription') . '</td>';
print '<td><input type="number" name="MediaMaxWidthMini" min="0" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_WIDTH_MINI') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="MediaMaxHeightMini">' . $langs->trans('MediaMaxHeightMini') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxHeightMiniDescription') . '</td>';
print '<td><input type="number" name="MediaMaxHeightMini" min="0" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_HEIGHT_MINI') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="MediaMaxWidthSmall">' . $langs->trans('MediaMaxWidthSmall') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxWidthSmallDescription') . '</td>';
print '<td><input type="number" name="MediaMaxWidthSmall" min="0" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_WIDTH_SMALL') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="MediaMaxHeightSmall">' . $langs->trans('MediaMaxHeightSmall') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxHeightSmallDescription') . '</td>';
print '<td><input type="number" name="MediaMaxHeightSmall" min="0" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_HEIGHT_SMALL') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="MediaMaxWidthMedium">' . $langs->trans('MediaMaxWidthMedium') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxWidthMediumDescription') . '</td>';
print '<td><input type="number" name="MediaMaxWidthMedium" min="0" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_WIDTH_MEDIUM') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="MediaMaxHeightMedium">' . $langs->trans('MediaMaxHeightMedium') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxHeightMediumDescription') . '</td>';
print '<td><input type="number" name="MediaMaxHeightMedium" min="0" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_HEIGHT_MEDIUM') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="MediaMaxWidthLarge">' . $langs->trans('MediaMaxWidthLarge') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxWidthLargeDescription') . '</td>';
print '<td><input type="number" name="MediaMaxWidthLarge" min="0" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_WIDTH_LARGE') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="MediaMaxHeightLarge">' . $langs->trans('MediaMaxHeightLarge') . '</label></td>';
print '<td>' . $langs->trans('MediaMaxHeightLargeDescription') . '</td>';
print '<td><input type="number" name="MediaMaxHeightLarge" value="' . getDolGlobalInt('SATURNE_MEDIA_MAX_HEIGHT_LARGE') . '" required></td>';
print '</td></tr>';

print '<tr class="oddeven"><td><label for="DisplayNumberMediaGallery">' . $langs->trans('DisplayNumberMediaGallery') . '</label></td>';
print '<td>' . $langs->trans('DisplayNumberMediaGalleryDescription') . '</td>';
print '<td><input type="number" name="DisplayNumberMediaGallery" value="' . getDolGlobalInt('SATURNE_DISPLAY_NUMBER_MEDIA_GALLERY') . '" required></td>';
print '</td></tr>';

// End of the table
print '</table>';
print $form->buttonsSaveCancel('Save', '');
print '</form>';

// Page end
print dol_get_fiche_end();
llxFooter();
Expand Down
9 changes: 9 additions & 0 deletions core/modules/modSaturne.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
62 changes: 34 additions & 28 deletions core/tpl/medias/medias_gallery_modal.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
Expand All @@ -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)) {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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'];
Expand All @@ -273,40 +279,40 @@
$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;

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;

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 '<input class="error-medias" value="'. htmlspecialchars(json_encode($submitFileErrorText)) .'">';
}

require_once __DIR__ . '/media_editor_modal.tpl.php'; ?>

<!-- START MEDIA GALLERY MODAL -->
<div class="wpeo-modal modal-photo" id="media_gallery" data-id="<?php echo $object->id ?: 0?>">
<div class="wpeo-modal modal-photo" id="media_gallery" data-id="<?php echo (isset($object) && $object) ? $object->id : 0 ?>">
<div class="modal-container wpeo-modal-event">
<!-- Modal-Header -->
<div class="modal-header">
Expand Down Expand Up @@ -336,7 +342,7 @@
<div class="modal-add-media">
<?php
print '<input type="hidden" name="token" value="'.newToken().'">';
if (( ! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) || ! empty($section)) {
if (( ! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) && !empty($section)) {
$sectiondir = GETPOST('file', 'alpha') ? GETPOST('file', 'alpha') : GETPOST('section_dir', 'alpha');
print '<!-- Start form to attach new file in '. $moduleNameLowerCase .'_photo_view.tpl.php sectionid=' . $section . ' sectiondir=' . $sectiondir . ' -->' . "\n";
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
Expand All @@ -360,15 +366,15 @@
<div>
<div>
<?php print img_picto($langs->trans('Link'), 'link') . ' ' . $form->textwithpicto($langs->trans('UnlinkedMedias'), $langs->trans('ShowOnlyUnlinkedMedias'));
if ($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) {
if (isset($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) && $user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) {
print '<span id="del_unlinked_medias" value="0" class="valignmiddle linkobject toggle-unlinked-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) ? '' : 'hideobject') . '">' . img_picto($langs->trans('Enabled'), 'switch_on') . '</span>';
} else {
print '<span id="set_unlinked_medias" value="1" class="valignmiddle linkobject toggle-unlinked-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) ? 'hideobject' : '') . '">' . img_picto($langs->trans('Disabled'), 'switch_off') . '</span>';
} ?>
</div>
<div>
<?php print img_picto($langs->trans('Calendar'), 'calendar') . ' ' . $form->textwithpicto($langs->trans('Today'), $langs->trans('ShowOnlyMediasAddedToday'));
if ($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) {
if (isset($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) && $user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) {
print '<span id="del_today_medias" value="0" class="valignmiddle linkobject toggle-today-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) ? '' : 'hideobject') . '">' . img_picto($langs->trans('Enabled'), 'switch_on') . '</span>';
} else {
print '<span id="set_today_medias" value="1" class="valignmiddle linkobject toggle-today-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) ? 'hideobject' : '') . '">' . img_picto($langs->trans('Disabled'), 'switch_off') . '</span>';
Expand All @@ -391,13 +397,13 @@
<?php
$filearray = dol_dir_list($conf->ecm->multidir_output[$conf->entity] . '/'. $moduleNameLowerCase .'/medias/', "files", 0, '', '(\.meta|_preview.*\.png)$', 'date', SORT_DESC);
$moduleImageNumberPerPageConf = strtoupper($moduleNameLowerCase) . '_DISPLAY_NUMBER_MEDIA_GALLERY';
if ($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS == 1) {
if (isset($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) && $user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS == 1) {
$yesterdayTimeStamp = dol_time_plus_duree(dol_now(), -1, 'd');
$filearray = array_filter($filearray, function($file) use ($yesterdayTimeStamp) {
return $file['date'] > $yesterdayTimeStamp;
});
}
if ($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS == 1) {
if (isset($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) && $user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS == 1) {
$filearray = array_filter($filearray, function($file) use ($conf, $moduleNameLowerCase) {
$regexFormattedFileName = preg_quote($file['name'], '/');
$fileArrays = dol_dir_list($conf->$moduleNameLowerCase->multidir_output[$conf->entity ?? 1], 'files', 1, $regexFormattedFileName, '.odt|.pdf|barcode|_mini|_medium|_small|_large');
Expand All @@ -407,9 +413,9 @@
}
$allMediasNumber = count($filearray);
$pagesCounter = $conf->global->$moduleImageNumberPerPageConf ? ceil($allMediasNumber/($conf->global->$moduleImageNumberPerPageConf ?: 1)) : 1;
$page_array = saturne_load_pagination($pagesCounter, $loadedPageArray, $offset);
$page_array = saturne_load_pagination($pagesCounter, $loadedPageArray ?? [], $offset ?? 0);

print saturne_show_pagination($pagesCounter, $page_array, $offset); ?>
print saturne_show_pagination($pagesCounter, $page_array, $offset ?? 0); ?>
<div class="save-photo wpeo-button button-blue button-disable" value="">
<span><?php echo $langs->trans('Add'); ?></span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion js/modules/mediaGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ window.saturne.mediaGallery.fastUpload = function( typeFrom ) {
$('.photo.'+objectPhotoClass).replaceWith($(resp).find('.photo.'+objectPhotoClass).first())
$('.linked-medias.'+objectPhotoClass).replaceWith($(resp).find('.linked-medias.'+objectPhotoClass))
} else {
$('.linked-medias.'+objectSubtype).html($(resp).find('.linked-medias.'+objectSubtype).children())
$('.linked-medias.'+objectSubtype).replaceWith($(resp).find('.linked-medias.'+objectSubtype))
}

//refresh media gallery & unselect selected medias
Expand Down
2 changes: 1 addition & 1 deletion js/saturne.min.js

Large diffs are not rendered by default.

Loading