* @copyright Copyright (C) 2021-2022, Sylvain Lelièvre * @license GNU General Public License, version 3 * @link https://deltacms.fr/ * * Delta was created from version 11.2.00.24 of ZwiiCMS * @author Rémi Jean * @copyright Copyright (C) 2008-2018, Rémi Jean * @author Frédéric Tempez * @copyright Copyright (C) 2018-2021, Frédéric Tempez * * Module slider * Développé par Sylvain Lelièvre */ class slider extends common { public static $actions = [ 'config' => self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR, 'dirs' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR, 'index' => self::GROUP_VISITOR ]; const VERSION = '5.0'; const REALNAME = 'Slider'; const DELETE = true; const UPDATE = '0.0'; const DATADIRECTORY = ''; // Contenu localisé inclus par défaut (page.json et module.json) public static $directories = []; public static $firstPictures = []; public static $galleries = []; public static $pictures = []; public static $pageList = []; public static $view_boutons; //Visibilité des boutons de navigation public static $boutonsVisibles = [ 'slider1' => 'Bouton suivant ou précédent', 'slider2' => 'Zone droite ou gauche de l\'image' ]; public static $boutonsVisibles_en = [ 'slider1' => 'Next or previous button', 'slider2' => 'Right or left area of the image' ]; //Visibilité des puces de navigation ou pager public static $pagerVisible = [ 'true' => 'Puces visibles', 'false' => 'Puces invisibles' ]; public static $pagerVisible_en = [ 'true' => 'Visible bullets', 'false' => 'Invisible bullets' ]; //Largeur du diaporama public static $maxwidth = [ '400' => '400 pixels', '500' => '500 pixels', '600' => '600 pixels', '710' => '710 pixels', '800' => '800 pixels', '920' => '920 pixels', '1130' => '1130 pixels', '10000' => '100%' ]; //Temps de transition entre diapo public static $fadingtime = [ '500' => '500 ms', '1000' => '1000 ms', '1500' => '1.5 s', '2000' => '2 s', '2500' => '2.5 s', '3000' => '3 s', '3500' => '3.5 s' ]; //Temps total entre 2 diapo public static $slidertime = [ '600' => '600 ms', '1000' => '1 s', '1500' => '1.5 s', '2000' => '2 s', '3000' => '3 s', '5000' => '5 s', '7000' => '7 s', '10000' => '10 s' ]; //Visibilité de la lègende public static $visibilite_legende = [ 'survol' => 'Au survol', 'toujours' => 'Toujours visible', 'jamais' => 'Jamais visible' ]; public static $visibilite_legende_en = [ 'survol' => 'On hover', 'toujours' => 'Always visible', 'jamais' => 'Never visible' ]; //Position de la lègende public static $position_legende = [ 'haut' => 'En haut', 'bas' => 'En bas' ]; public static $position_legende_en = [ 'haut' => 'Top', 'bas' => 'Bottom' ]; //Temps d'apparition légende et boutons public static $apparition = [ 'opacity 0.2s ease-in' => '0.2s', 'opacity 0.5s ease-in' => '0.5s', 'opacity 1s ease-in' => '1s', 'opacity 2s ease-in' => '2s' ]; //Type de boutons public static $bouton= [ 'rec_noir' => 'rectangle noir', 'cer_blanc' => 'cercle blanc' ]; public static $bouton_en= [ 'rec_noir' => 'black rectangle', 'cer_blanc' => 'white circle' ]; //Choix du tri public static $sort = [ 'SORT_ASC' => 'Alphabétique naturel', 'SORT_DSC' => 'Alphabétique naturel inverse', 'RAND' => 'Aléatoire', 'NONE' => 'Par défaut, sans tri', ]; public static $sort_en = [ 'SORT_ASC' => 'Natural Alphabetic', 'SORT_DSC' => 'Reverse natural alphabetic', 'RAND' => 'Random', 'NONE' => 'Default, unsorted' ]; /** * Configuration */ public function config() { // Lexique $text = []; $val = $this->getData(['config', 'i18n', 'langAdmin']); switch ($val) { case 'fr' : $text[0] = ' (dossier vide)'; $text[1] = ' (dossier introuvable)'; $text[2] = 'Modifications enregistrées'; $text[3] = 'Configuration du module'; break; case 'en' : $text[0] = ' (empty folder)'; $text[1] = ' (folder not found)'; $text[2] = 'Saved changes'; $text[3] = 'Module configuration'; break; } // Liste des galeries $galleries = $this->getData(['module', $this->getUrl(0)]); if($galleries) { //ksort($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[0] .''; } } // Erreur dossier supprimé else { $gallery['config']['directory'] = '' . $gallery['config']['directory'] . $text[1] .''; } // Met en forme le tableau meilleure solution $galleries[count($galleries)-1] self::$galleries[] = [ $gallery['config']['name'], $gallery['config']['directory'], template::button('galleryConfigEdit' . $galleryId, [ 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'], 'value' => template::ico('pencil') ]) ]; } } // Soumission du formulaire if($this->isPost()) { // Ajout pour effacer les anciens dossiers cible foreach($galleries as $galleryId => $gallery) { $this->deleteData(['module', $this->getUrl(0), $galleryId]); } //Fin d'ajout $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'), //Ajout pour paramétrage par défaut du diaporama 'boutonsVisibles' => 'slider2', 'pagerVisible' => 'true', 'maxiWidth' => '800', 'fadingTime' => '1500', 'sliderTime' => '5000', 'visibiliteLegende' => 'survol', 'positionLegende' => 'bas', 'tempsApparition' => 'opacity 2s ease-in', 'typeBouton' => 'cer_blanc', 'tri' => 'SORT_ASC', //Fin d'ajout 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true) ], 'legend' => [] ]]); // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(), 'notification' => $text[2], 'state' => true ]); } // Valeurs en sortie $this->addOutput([ 'title' => $text[3], 'view' => 'config' ]); } /** * Suppression */ public function delete() { // Lexique $text = []; $val = $this->getData(['config', 'i18n', 'langAdmin']); switch ($val) { case 'fr' : $text[0] = 'Suppression non autorisée'; $text[1] = 'Galerie supprimée'; break; case 'en' : $text[0] = 'Unauthorised deletion'; $text[1] = 'Gallery deleted'; break; } // $url prend l'adresse sans le token // La galerie n'existe pas if($this->getData(['module', $this->getUrl(0), $this->getUrl(2)]) === null) { // Valeurs en sortie $this->addOutput([ 'access' => false ]); } // Jeton incorrect if ($this->getUrl(3) !== $_SESSION['csrf']) { // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', 'notification' => $text[0] ]); } // Suppression else { $this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', 'notification' => $text[1], 'state' => true ]); } } /** * Liste des dossiers */ public function dirs() { // Valeurs en sortie $this->addOutput([ 'display' => self::DISPLAY_JSON, 'content' => $this->scanSubDir(self::FILE_DIR.'source') ]); } /** * Édition */ public function edit() { // Lexique $text = []; $val = $this->getData(['config', 'i18n', 'langAdmin']); switch ($val) { case 'fr' : $text[0] = 'Action non autorisée'; $text[1] = 'Modifications enregistrées'; break; case 'en' : $text[0] = 'Unauthorised action'; $text[1] = 'Changes saved'; break; } // Jeton incorrect if ($this->getUrl(3) !== $_SESSION['csrf']) { // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', 'notification' => $text[0] ]); } // Liste des pages pour les liens sur image self::$pageList[0]=''; foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) { // Exclusions les barres, les pages masquées ou non publiques if ($this->getData(['page',$parentKey,'group']) !== 0 || $this->getData(['page', $parentKey, 'block']) === 'bar' ) { continue; } self::$pageList [] = $parentKey; foreach ($parentValue as $childKey) { self::$pageList [] = $childKey; } } // La galerie n'existe pas if($this->getData(['module', $this->getUrl(0), $this->getUrl(2)]) === null) { // Valeurs en sortie $this->addOutput([ 'access' => false ]); } // La galerie existe else { // Soumission du formulaire if($this->isPost()) { // Si l'id a changée $galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true); if($galleryId !== $this->getUrl(2)) { // Incrémente le nouvel id de la galerie $galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0)])); // Supprime l'ancienne galerie $this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); } $legends = []; foreach((array) $this->getInput('legend', null) as $file => $legend) { $file = str_replace('.','',$file); $legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT); } $hrefs = []; foreach((array) $this->getInput('sliderHref', null) as $file => $href) { $file = str_replace('.','',$file); $hrefs[$file] = self::$pageList[helper::filter($href, helper::FILTER_STRING_SHORT)]; } $this->setData(['module', $this->getUrl(0), $galleryId, [ 'config' => [ 'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true), //Ajout pour paramétrage du diaporama 'boutonsVisibles' => $this->getInput('sliderBoutonsVisibles', helper::FILTER_STRING_SHORT, true), 'pagerVisible' => $this->getInput('sliderPagerVisible', helper::FILTER_STRING_SHORT, true), 'maxiWidth' => $this->getInput('sliderMaxiWidth', helper::FILTER_STRING_SHORT, true), 'fadingTime' => $this->getInput('sliderFadingTime', helper::FILTER_STRING_SHORT, true), 'sliderTime' => $this->getInput('sliderDiapoTime', helper::FILTER_STRING_SHORT, true), 'visibiliteLegende' => $this->getInput('sliderVisibiliteLegende', helper::FILTER_STRING_SHORT, true), 'positionLegende' => $this->getInput('sliderPositionLegende', helper::FILTER_STRING_SHORT, true), 'tempsApparition' => $this->getInput('sliderTempsApparition', helper::FILTER_STRING_SHORT, true), 'typeBouton' => $this->getInput('sliderTypeBouton', helper::FILTER_STRING_SHORT, true), 'tri' => $this->getInput('sliderTri', helper::FILTER_STRING_SHORT, true), //Fin d'ajout 'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true) ], 'legend' => $legends, 'href' => $hrefs ]]); // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', 'notification' => $text[1], 'state' => true ]); } // Met en forme le tableau $directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']); if(is_dir($directory)) { $iterator = new DirectoryIterator($directory); foreach($iterator as $fileInfos) { if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { self::$pictures[$fileInfos->getFilename()] = [ $fileInfos->getFilename(), template::text('legend[' . $fileInfos->getFilename() . ']', [ 'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())]) ]), template::select('sliderHref[' . $fileInfos->getFilename() . ']', self::$pageList,[ 'selected' => array_flip(self::$pageList)[$this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'href', str_replace('.','',$fileInfos->getFilename())])] ]) ]; } } // Tri des images pour affichage de la liste dans la page d'édition switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'tri'])) { case 'SORT_DSC': krsort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); break; case 'SORT_ASC': ksort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); break; case 'RAND': // sans intérêt ici break; case 'NONE': break; default: break; } } // Valeurs en sortie $this->addOutput([ 'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']), 'view' => 'edit' ]); } } /** * Fonction index() modifiée par rapport au module Gallery */ public function index() { // Liste des galeries foreach((array) $this->getData(['module', $this->getUrl(0)]) as $galleryId => $gallery) { if(is_dir($gallery['config']['directory'])) { $iterator = new DirectoryIterator($gallery['config']['directory']); foreach($iterator as $fileInfos) { if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { self::$galleries[$galleryId] = $gallery; self::$firstPictures[$galleryId] = $gallery['config']['directory'] . '/' . $fileInfos->getFilename(); continue(2); } } } } if( isset($gallery['config']['directory'])){ $directory = $gallery['config']['directory']; // Images de la galerie if(is_dir($directory)) { $iterator = new DirectoryIterator($directory); foreach($iterator as $fileInfos) { if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $galleryId,'legend', str_replace('.','',$fileInfos->getFilename())]); } } // Tri des images par ordre alphabétique, alphabétique inverse, aléatoire ou pas switch ($this->getData(['module', $this->getUrl(0), $galleryId, 'config', 'tri'])) { case 'SORT_DSC': krsort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); break; case 'SORT_ASC': ksort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); break; case 'RAND': $tab1 = self::$pictures; // si absence de légende on en place une provisoire foreach($tab1 as $key1=>$value1){ if($value1 == ''){ $tab1[$key1] = $key1; } } $tab2 = array_flip($tab1); shuffle($tab2); $tab1 = array_flip($tab2); foreach($tab1 as $key1=>$value1){ $tab1[$key1] = self::$pictures[$key1]; } self::$pictures = $tab1; break; case 'NONE': break; default: break; } // Information sur la visibilité des boutons self::$view_boutons = $this->getData(['module', $this->getUrl(0), $galleryId, 'config','boutonsVisibles']); } } // Valeurs en sortie $this->addOutput([ 'showBarEditButton' => true, 'showPageContent' => true, 'vendor' => [ 'js' ], 'view' => 'index' ]); } /** * Scan le contenu d'un dossier et de ses sous-dossiers * @param string $dir Dossier à scanner * @return array */ private function scanSubDir($dir) { $dirContent = []; $iterator = new DirectoryIterator($dir); foreach($iterator as $fileInfos) { if($fileInfos->isDot() === false AND $fileInfos->isDir()) { $dirContent[] = $dir . '/' . $fileInfos->getBasename(); $dirContent = array_merge($dirContent, $this->scanSubDir($dir . '/' . $fileInfos->getBasename())); } } return $dirContent; } }