From 8da52e715aa0494275d4dd0f441113637f51d07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tempez?= Date: Mon, 28 Mar 2022 18:57:06 +0200 Subject: [PATCH] galerie avec nouvelles options --- module/gallery/gallery.php | 89 +++++++++++++++++++++ module/gallery/view/add/add.css | 19 +++++ module/gallery/view/add/add.js.php | 87 +++++++++++++++++++++ module/gallery/view/add/add.php | 68 ++++++++++++++++ module/gallery/view/config/config.js.php | 61 +-------------- module/gallery/view/config/config.php | 98 +++++++----------------- module/gallery/view/option/option.php | 39 ++++++++++ module/gallery/view/option/options.css | 18 +++++ 8 files changed, 352 insertions(+), 127 deletions(-) create mode 100644 module/gallery/view/add/add.css create mode 100644 module/gallery/view/add/add.js.php create mode 100644 module/gallery/view/add/add.php create mode 100644 module/gallery/view/option/option.php create mode 100644 module/gallery/view/option/options.css diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index 00db305b..aad375f0 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -51,7 +51,9 @@ class gallery extends common { 'sortGalleries' => self::GROUP_MODERATOR, 'sortPictures' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR, + 'add' => self::GROUP_MODERATOR, 'theme' => self::GROUP_MODERATOR, + 'option' => self::GROUP_MODERATOR, '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 */ @@ -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 { diff --git a/module/gallery/view/add/add.css b/module/gallery/view/add/add.css new file mode 100644 index 00000000..56181936 --- /dev/null +++ b/module/gallery/view/add/add.css @@ -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 + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @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 +*/ \ No newline at end of file diff --git a/module/gallery/view/add/add.js.php b/module/gallery/view/add/add.js.php new file mode 100644 index 00000000..46d48000 --- /dev/null +++ b/module/gallery/view/add/add.js.php @@ -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 + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @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: "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 = $("