From 0ac2431c452e8c43f582d9f9c33575279d1c33a6 Mon Sep 17 00:00:00 2001 From: Deltacms Date: Wed, 1 Nov 2023 11:17:08 +0100 Subject: [PATCH] album photo V4 --- module/album/album.php | 111 ++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/module/album/album.php b/module/album/album.php index 1dd7ff8..248e0b9 100644 --- a/module/album/album.php +++ b/module/album/album.php @@ -5,7 +5,7 @@ */ setlocale(LC_NUMERIC,'English','en_US','en_US.UTF-8'); class album extends common { - const VERSION = '4.3.2'; + const VERSION = '4.4'; const REALNAME = 'Album Photo'; const DELETE = true; const UPDATE = '0.0'; @@ -30,6 +30,20 @@ class album extends common { 'edit' => self::GROUP_EDITOR, 'index' => self::GROUP_VISITOR ]; + + /** + * Mise à jour du module + * Appelée par la fonction index + */ + private function update() { + // Versions < 4.4 : versionData absent + if( null === $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) ) $this->setData(['module', $this->getUrl(0), 'config', 'versionData', '4.3']); + + // Version 4.4 + if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '4.4', '<') ) { + $this->setData(['module', $this->getUrl(0), 'config', 'versionData','4.4']); + } + } /** * Tri de la liste des galeries sans bouton @@ -128,58 +142,61 @@ class album extends common { // Traitement de l'affichage if($galleries) { foreach($galleries as $galleryId => $gallery) { - // Erreur dossier vide - if(is_dir($gallery['config']['directory'])) { - if(count(scandir($gallery['config']['directory'])) === 2) { - $gallery['config']['directory'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][0].''; + // pour ne pas prendre en compte la fausse galerie 'config' + if(isset($gallery['config']['directory'])){ + // Erreur dossier vide + if(is_dir($gallery['config']['directory'])) { + if(count(scandir($gallery['config']['directory'])) === 2) { + $gallery['config']['directory'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][0].''; + } } + // Erreur dossier supprimé + else { + $gallery['config']['directory'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][1].''; + } + // Met en forme le tableau + self::$galleries[] = [ + template::ico('sort'), + $gallery['config']['name'], + str_replace('site/file/source/','',$gallery['config']['directory']), + template::button('galleryConfigEdit' . $galleryId , [ + 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'], + 'value' => template::ico('pencil') + ]), + template::button('galleryConfigDelete' . $galleryId, [ + 'class' => 'galleryConfigDelete buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $galleryId . '/' . $_SESSION['csrf'], + 'value' => template::ico('cancel'), + 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true + ]) + ]; + // Tableau des id des galleries pour le drag and drop + self::$galleriesId[] = $galleryId; } - // Erreur dossier supprimé - else { - $gallery['config']['directory'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][1].''; - } - // Met en forme le tableau - self::$galleries[] = [ - template::ico('sort'), - $gallery['config']['name'], - str_replace('site/file/source/','',$gallery['config']['directory']), - template::button('galleryConfigEdit' . $galleryId , [ - 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'], - 'value' => template::ico('pencil') - ]), - template::button('galleryConfigDelete' . $galleryId, [ - 'class' => 'galleryConfigDelete buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $galleryId . '/' . $_SESSION['csrf'], - 'value' => template::ico('cancel'), - 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true - ]) - ]; - // Tableau des id des galleries pour le drag and drop - self::$galleriesId[] = $galleryId; } } // Soumission du formulaire d'ajout d'un album if($this->isPost()) { if (!$this->getInput('galleryConfigFilterResponse')) { - $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); - $this->setData(['module', $this->getUrl(0), $galleryId, [ - 'config' => [ - 'name' => $this->getInput('galleryConfigName'), - 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), - 'homePicture' => NULL, // homePicture non préalablement définie - 'sort' => self::SORT_ASC, - 'position' => $this->getData(['module',$this->getUrl(0)]) !== null ? count($this->getData(['module',$this->getUrl(0)])) + 1 : 0 - ], - 'legend' => [], - 'order' => [] - ]]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(), - 'notification' => $text['gallery']['config'][2], - 'state' => true - ]); - } + $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); + $this->setData(['module', $this->getUrl(0), $galleryId, [ + 'config' => [ + 'name' => $this->getInput('galleryConfigName'), + 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), + 'homePicture' => NULL, // homePicture non préalablement définie + 'sort' => self::SORT_ASC, + 'position' => $this->getData(['module',$this->getUrl(0)]) !== null ? count($this->getData(['module',$this->getUrl(0)])) + 1 : 0 + ], + 'legend' => [], + 'order' => [] + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(), + 'notification' => $text['gallery']['config'][2], + 'state' => true + ]); + } } // Valeurs en sortie $this->addOutput([ @@ -410,6 +427,8 @@ class album extends common { * Accueil (deux affichages en un pour éviter une url à rallonge) */ public function index() { + // Mise à jour des données de module + $this->update(); // Images d'une galerie if($this->getUrl(1)) { // La galerie n'existe pas