galerie avec nouvelles options

This commit is contained in:
Fred Tempez 2022-03-28 18:57:06 +02:00
parent aea20bb2ae
commit 8da52e715a
8 changed files with 352 additions and 127 deletions

View File

@ -51,7 +51,9 @@ class gallery extends common {
'sortGalleries' => self::GROUP_MODERATOR, 'sortGalleries' => self::GROUP_MODERATOR,
'sortPictures' => self::GROUP_MODERATOR, 'sortPictures' => self::GROUP_MODERATOR,
'edit' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR,
'add' => self::GROUP_MODERATOR,
'theme' => self::GROUP_MODERATOR, 'theme' => self::GROUP_MODERATOR,
'option' => self::GROUP_MODERATOR,
'index' => self::GROUP_VISITOR 'index' => self::GROUP_VISITOR
]; ];
@ -411,6 +413,58 @@ class gallery extends common {
]); ]);
} }
/**
* Ajout d'une galerie
*/
public function add() {
// Soumission du formulaire d'ajout d'une galerie
if($this->isPost()) {
if (!$this->getInput('galleryAddFilterResponse')) {
$galleryId = helper::increment($this->getInput('galleryAddName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0), 'content']));
// définir une vignette par défaut
$directory = $this->getInput('galleryAddDirectory', helper::FILTER_STRING_SHORT, true);
$iterator = new DirectoryIterator($directory);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
// Créer la miniature si manquante
if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) {
$this->makeThumb($fileInfos->getPathname(),
str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()),
self::THUMBS_WIDTH);
}
// Miniatures
$homePicture = strtolower($fileInfos->getFilename());
break;
}
}
$this->setData(['module', $this->getUrl(0), 'content', $galleryId, [
'config' => [
'name' => $this->getInput('galleryAddName'),
'directory' => $this->getInput('galleryAddDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => $homePicture,
'sort' => $this->getInput('galleryAddSort'),
'position' => count($this->getData(['module', $this->getUrl(0), 'content'])) + 1,
'fullScreen' => $this->getInput('galleryAddFullscreen', helper::FILTER_BOOLEAN),
'showPageContent' => $this->getInput('galleryAddShowPageContent', helper::FILTER_BOOLEAN)
],
'legend' => [],
'positions' => []
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', // '#galleryAddForm'*/,
'notification' => 'Modifications enregistrées',
'state' => true
]);
}
} else {
// Valeurs en sortie
$this->addOutput([
'title' => 'Ajout d\'une galerie',
'view' => 'add'
]);
}
}
/** /**
* Suppression * Suppression
*/ */
@ -815,6 +869,41 @@ class gallery extends common {
]); ]);
} }
/**
* Option de configuration de la galerie
*/
public function option() {
// Jeton incorrect
if ($this->getUrl(2) !== $_SESSION['csrf']) {
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Action non autorisée'
]);
}
// Soumission du formulaire
if($this->isPost()) {
// Dossier de l'instance
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0) )) {
mkdir (self::DATADIRECTORY . $this->getUrl(0), 0755, true);
}
$this->setData(['module', $this->getUrl(0), 'config', [
'showUniqueGallery' => $this->getinput('galleryOptionShowUniqueGallery', helper::FILTER_BOOLEAN)
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl() . '/option',
'notification' => 'Modifications enregistrées',
'state' => true
]);
}
// Valeurs en sortie
$this->addOutput([
'title' => "Options",
'view' => 'option'
]);
}
} }
class galleriesHelper extends helper { class galleriesHelper extends helper {

View File

@ -0,0 +1,19 @@
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2022, Frédéric Tempez
* @license GNU General Public License, version 3
* @link http://zwiicms.fr/
*/
/** NE PAS EFFACER
* admin.css
*/

View File

@ -0,0 +1,87 @@
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2022, Frédéric Tempez
* @license GNU General Public License, version 3
* @link http://zwiicms.fr/
*/
$( document ).ready(function() {
/**
* Tri de la galerie avec drag and drop
*/
$("#galleryTable").tableDnD({
onDrop: function(table, row) {
$("#galleryAddFilterResponse").val($.tableDnD.serialize());
},
onDragStop : function(table, row) {
// Affiche le bouton de tri après un déplacement
//$(":input[type='submit']").prop('disabled', false);
// Sauvegarde le tri
sortGalleries();
},
// Supprime le tiret des séparateurs
serializeRegexp: ""
});
/**
* Confirmation de suppression
*/
$(".galleryAddDelete").on("click", function() {
var _this = $(this);
return core.confirm("Êtes-vous sûr de vouloir supprimer cette galerie ?", function() {
$(location).attr("href", _this.attr("href"));
});
});
});
/**
* Liste des dossiers
*/
var oldResult = [];
var directoryDOM = $("#galleryAddDirectory");
var directoryOldDOM = $("#galleryAddDirectoryOld");
function dirs() {
$.ajax({
type: "POST",
url: "<?php echo helper::baseUrl() . $this->getUrl(0); ?>/dirs",
success: function(result) {
if($(result).not(oldResult).length !== 0 || $(oldResult).not(result).length !== 0) {
directoryDOM.empty();
for(var i = 0; i < result.length; i++) {
directoryDOM.append(function(i) {
var option = $("<option>").val(result[i]).text(result[i]);
if(directoryOldDOM.val() === result[i]) {
option.prop("selected", true);
}
return option;
}(i))
}
oldResult = result;
}
}
});
}
dirs();
// Actualise la liste des dossiers toutes les trois secondes
setInterval(function() {
dirs();
}, 3000);
/**
* Stock le dossier choisi pour le re-sélectionner en cas d'actualisation ajax de la liste des dossiers
*/
directoryDOM.on("change", function() {
directoryOldDOM.val($(this).val());
});

View File

@ -0,0 +1,68 @@
<?php echo template::formOpen('galleryAddForm'); ?>
<div class="row">
<div class="col2">
<?php echo template::button('galleryAddBack', [
'href' => helper::baseUrl() . $this->getUrl(0) . '/config' ,
'ico' => 'left',
'value' => 'Retour'
]); ?>
</div>
<div class="col2 offset8">
<?php echo template::submit('galleryAddSubmit', [
'ico' => 'plus',
'value' => ' Ajouter',
'class' => 'gallerySubmit'
]); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Ajouter une galerie</h4>
<div class="row">
<div class="col6">
<?php echo template::text('galleryAddName', [
'label' => 'Nom'
]); ?>
</div>
<div class="col5">
<?php echo template::hidden('galleryAddDirectoryOld', [
'noDirty' => true // Désactivé à cause des modifications en ajax
]); ?>
<?php echo template::select('galleryAddDirectory', [], [
'label' => 'Dossier cible',
'noDirty' => true // Désactivé à cause des modifications en ajax
]); ?>
</div>
</div>
<div class="row">
<div class="col3">
<?php echo template::select('galleryAddSort', $module::$sort, [
'selected' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'sort']),
'label' => 'Tri des images',
'help' => 'Tri manuel : déplacez le images dans le tableau ci-dessous. L\'ordre est sauvegardé automatiquement.'
]); ?>
</div>
<div class="col7 verticalAlignBottom">
<div class="row">
<div class="col12">
<?php echo template::checkbox('galleryAddFullscreen', true, 'Mode plein écran automatique' , [
'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'fullScreen']),
'help' => 'A l\'ouverture de la galerie, la première image est affichée en plein écran.'
]); ?>
</div>
</div>
<div class="row">
<div class="col12">
<?php echo template::checkbox('galleryAddShowPageContent', true, 'Afficher le contenu de la page dans les galeries' , [
'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'showPageContent']),
'help' => 'Le contenu de la page est toujours affiché dans la liste des galeries. Quand une seule galerie est disponible, il est possible de l\'afficher directement, cette option est utile dans ce cas précis.'
]); ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>

View File

@ -17,9 +17,9 @@ $( document ).ready(function() {
/** /**
* Tri de la galerie avec drag and drop * Tri de la galerie avec drag and drop
*/ */
$("#galleryTable").tableDnD({ $("#galleryTable").tableDnD({
onDrop: function(table, row) { onDrop: function(table, row) {
$("#galleryConfigFilterResponse").val($.tableDnD.serialize()); $("#galleryConfigFilterResponse").val($.tableDnD.serialize());
}, },
onDragStop : function(table, row) { onDragStop : function(table, row) {
@ -31,59 +31,6 @@ $( document ).ready(function() {
// Supprime le tiret des séparateurs // Supprime le tiret des séparateurs
serializeRegexp: "" serializeRegexp: ""
}); });
/**
* Confirmation de suppression
*/
$(".galleryConfigDelete").on("click", function() {
var _this = $(this);
return core.confirm("Êtes-vous sûr de vouloir supprimer cette galerie ?", function() {
$(location).attr("href", _this.attr("href"));
});
});
});
/**
* Liste des dossiers
*/
var oldResult = [];
var directoryDOM = $("#galleryConfigDirectory");
var directoryOldDOM = $("#galleryConfigDirectoryOld");
function dirs() {
$.ajax({
type: "POST",
url: "<?php echo helper::baseUrl() . $this->getUrl(0); ?>/dirs",
success: function(result) {
if($(result).not(oldResult).length !== 0 || $(oldResult).not(result).length !== 0) {
directoryDOM.empty();
for(var i = 0; i < result.length; i++) {
directoryDOM.append(function(i) {
var option = $("<option>").val(result[i]).text(result[i]);
if(directoryOldDOM.val() === result[i]) {
option.prop("selected", true);
}
return option;
}(i))
}
oldResult = result;
}
}
});
}
dirs();
// Actualise la liste des dossiers toutes les trois secondes
setInterval(function() {
dirs();
}, 3000);
/**
* Stock le dossier choisi pour le re-sélectionner en cas d'actualisation ajax de la liste des dossiers
*/
directoryDOM.on("change", function() {
directoryOldDOM.val($(this).val());
}); });
@ -93,7 +40,7 @@ directoryDOM.on("change", function() {
function sortGalleries() { function sortGalleries() {
var url = "<?php echo helper::baseUrl() . $this->getUrl(0); ?>/sortGalleries"; var url = "<?php echo helper::baseUrl() . $this->getUrl(0); ?>/sortGalleries";
var data = $("#galleryConfigFilterResponse").val(); var data = $("#galleryConfigFilterResponse").val();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: url , url: url ,

View File

@ -1,76 +1,34 @@
<?php echo template::formOpen('galleryConfigForm'); ?> <?php echo template::formOpen('galleryConfigForm'); ?>
<div class="row"> <div class="row">
<div class="col2"> <div class="col2">
<?php echo template::button('galleryConfigBack', [ <?php echo template::button('galleryConfigBack', [
'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0), 'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0),
'ico' => 'left', 'ico' => 'left',
'value' => 'Retour' 'value' => 'Retour'
]); ?> ]); ?>
</div>
<div class="col2 offset8">
<?php echo template::button('galleryConfigBack', [
'href' => helper::baseUrl() . $this->getUrl(0) . '/theme/' . $_SESSION['csrf'],
'value' => template::ico('brush','right') . 'Thème'
]); ?>
</div>
</div> </div>
<div class="row"> <div class="col1 offset7">
<div class="col12"> <?php echo template::button('galleryConfigOption', [
<div class="block"> 'href' => helper::baseUrl() . $this->getUrl(0) . '/option/' . $_SESSION['csrf'],
<h4>Ajouter une galerie</h4> 'value' => '',
<div class="row"> 'ico' => 'sliders',
<div class="col6"> ]); ?>
<?php echo template::text('galleryConfigName', [
'label' => 'Nom'
]); ?>
</div>
<div class="col5">
<?php echo template::hidden('galleryConfigDirectoryOld', [
'noDirty' => true // Désactivé à cause des modifications en ajax
]); ?>
<?php echo template::select('galleryConfigDirectory', [], [
'label' => 'Dossier cible',
'noDirty' => true // Désactivé à cause des modifications en ajax
]); ?>
</div>
<div class="col1 verticalAlignBottom">
<?php echo template::submit('galleryConfigSubmit', [
'ico' => '',
'value' => template::ico('plus'),
'class' => 'gallerySubmit'
]); ?>
</div>
</div>
<div class="row">
<div class="col3">
<?php echo template::select('galleryConfigSort', $module::$sort, [
'selected' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'sort']),
'label' => 'Tri des images',
'help' => 'Tri manuel : déplacez le images dans le tableau ci-dessous. L\'ordre est sauvegardé automatiquement.'
]); ?>
</div>
<div class="col7 verticalAlignBottom">
<div class="row">
<div class="col12">
<?php echo template::checkbox('galleryConfigFullscreen', true, 'Mode plein écran automatique' , [
'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'fullScreen']),
'help' => 'A l\'ouverture de la galerie, la première image est affichée en plein écran.'
]); ?>
</div>
</div>
<div class="row">
<div class="col12">
<?php echo template::checkbox('galleryConfigShowPageContent', true, 'Afficher le contenu de la page dans les galeries' , [
'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'showPageContent']),
'help' => 'Le contenu de la page est toujours affiché dans la liste des galeries. Quand une seule galerie est disponible, il est possible de l\'afficher directement, cette option est utile dans ce cas précis.'
]); ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
<div class="col1">
<?php echo template::button('galleryConfigTheme', [
'href' => helper::baseUrl() . $this->getUrl(0) . '/theme/' . $_SESSION['csrf'],
'value' => '',
'ico' => 'brush',
]); ?>
</div>
<div class="col1">
<?php echo template::button('galleryAdd', [
'ico' => '',
'value' => template::ico('plus'),
'href' => helper::baseUrl() . $this->getUrl(0) . '/add/',
]); ?>
</div>
</div>
<?php echo template::formClose(); ?> <?php echo template::formClose(); ?>
<div class="row"> <div class="row">
<div class="col12"> <div class="col12">

View File

@ -0,0 +1,39 @@
<?php echo template::formOpen('galleryOptionForm'); ?>
<div class="row">
<div class="col2">
<?php echo template::button('galleryOptionBack', [
'href' => helper::baseUrl() . $this->getUrl(0) . '/config',
'ico' => 'left',
'value' => 'Retour'
]); ?>
</div>
<div class="col2 offset8">
<?php echo template::submit('galleryOptionSubmit'); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Galerie unique</h4>
<div class="row">
<div class="col12 verticalAlignBottom">
<?php echo template::checkbox('galleryOptionShowUniqueGallery', true, 'Masquer l\'index des galeries lorsque le module ne contient qu\'une galerie' , [
'checked' => count($this->getData(['module', $this->getUrl(0), 'content'])) === 1
? $this->getData(['module', $this->getUrl(0), 'theme', 'showUniqueGallery'])
: false,
'disabled' => count($this->getData(['module', $this->getUrl(0), 'content'])) > 1,
'help' => 'Cette option est active lorsque le module ne contient qu\'une seule galerie, elle permet d\'éviter la page listant toutes les galeries et affiche directement la galerie'
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>
<div class="row">
<div class="col12">
<div class="moduleVersion">Version
<?php echo $module::VERSION; ?>
</div>
</div>
</div>

View File

@ -0,0 +1,18 @@
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2022, Frédéric Tempez
* @license GNU General Public License, version 3
* @link http://zwiicms.fr/
*/
/** NE PAS EFFACER
* admin.css
*/