2018-04-02 08:29:19 +02:00
< ? php
/**
* 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
2020-04-16 22:34:59 +02:00
* @ author Frédéric Tempez < frederic . tempez @ outlook . com >
2023-01-09 10:23:32 +01:00
* @ copyright Copyright ( C ) 2018 - 2023 , Frédéric Tempez
2022-12-29 17:02:20 +01:00
* @ license CC Attribution - NonCommercial - NoDerivatives 4.0 International
2020-09-01 20:48:40 +02:00
* @ link http :// zwiicms . fr /
2018-04-02 08:29:19 +02:00
*/
2023-03-07 14:55:00 +01:00
class gallery extends common
{
2018-04-02 08:29:19 +02:00
2021-02-18 10:07:05 +01:00
2023-07-21 21:48:41 +02:00
const VERSION = '4.0' ;
2021-02-18 10:07:05 +01:00
const REALNAME = 'Galerie' ;
2021-05-03 16:32:36 +02:00
const DATADIRECTORY = self :: DATA_DIR . 'gallery/' ;
2021-02-18 10:07:05 +01:00
2020-04-13 18:13:01 +02:00
const SORT_ASC = 'SORT_ASC' ;
const SORT_DSC = 'SORT_DSC' ;
const SORT_HAND = 'SORT_HAND' ;
2021-02-09 18:04:24 +01:00
2020-04-18 19:18:34 +02:00
public static $directories = [];
public static $firstPictures = [];
public static $galleries = [];
public static $galleriesId = [];
public static $pictures = [];
public static $picturesId = [];
2020-06-03 09:07:00 +02:00
public static $thumbs = [];
2020-04-13 18:13:01 +02:00
2022-03-22 16:53:01 +01:00
public static $config = [];
2018-04-02 08:29:19 +02:00
public static $actions = [
2023-07-05 18:04:42 +02:00
'config' => self :: GROUP_EDITOR ,
'delete' => self :: GROUP_EDITOR ,
'dirs' => self :: GROUP_EDITOR ,
'sortGalleries' => self :: GROUP_EDITOR ,
'sortPictures' => self :: GROUP_EDITOR ,
'edit' => self :: GROUP_EDITOR ,
'add' => self :: GROUP_EDITOR ,
'theme' => self :: GROUP_EDITOR ,
'option' => self :: GROUP_EDITOR ,
2023-03-07 14:55:00 +01:00
'index' => self :: GROUP_VISITOR
2018-04-02 08:29:19 +02:00
];
2020-02-23 17:32:39 +01:00
public static $sort = [
2023-03-07 14:55:00 +01:00
self :: SORT_ASC => 'Alphabétique ' ,
self :: SORT_DSC => 'Alphabétique inverse' ,
2020-04-15 17:26:26 +02:00
self :: SORT_HAND => 'Manuel'
2020-02-22 22:51:46 +01:00
];
2020-04-18 16:33:48 +02:00
public static $galleryThemeFlexAlign = [
'flex-start' => 'À gauche' ,
'center' => 'Au centre' ,
'flex-end' => 'À droite' ,
'space-around' => 'Distribué avec marges' ,
'space-between' => 'Distribué sans marge' ,
];
2020-04-17 19:02:04 +02:00
public static $galleryThemeAlign = [
'left' => 'À gauche' ,
'center' => 'Au centre' ,
'right' => 'À droite'
];
2020-06-16 12:43:54 +02:00
public static $galleryThemeSizeWidth = [
2023-03-07 14:55:00 +01:00
'9em' => 'Très petite' ,
2020-06-16 12:43:54 +02:00
'12em' => 'Petite' ,
'15em' => 'Moyenne' ,
'18em' => 'Grande' ,
'21em' => 'Très grande' ,
'100%' => 'Proportionnelle'
];
public static $galleryThemeSizeHeight = [
2023-03-07 14:55:00 +01:00
'9em' => 'Très petite' ,
2020-04-18 19:18:34 +02:00
'12em' => 'Petite' ,
'15em' => 'Moyenne' ,
'18em' => 'Grande' ,
'21em' => 'Très grande'
2020-04-17 19:02:04 +02:00
];
public static $galleryThemeLegendHeight = [
2023-03-07 14:55:00 +01:00
'.125em' => 'Très petite' ,
'.25em' => 'Petite' ,
'.375em' => 'Moyenne' ,
'.5em' => 'Grande' ,
2020-04-18 19:18:34 +02:00
'.625em' => 'Très grande'
2020-04-17 19:02:04 +02:00
];
public static $galleryThemeBorder = [
'0em' => 'Aucune' ,
2020-04-19 14:58:38 +02:00
'.1em' => 'Très fine' ,
2020-04-19 19:43:37 +02:00
'.3em' => 'Fine' ,
2023-03-07 14:55:00 +01:00
'.5em' => 'Moyenne' ,
2020-04-19 19:43:37 +02:00
'.7em' => 'Epaisse' ,
2023-03-07 14:55:00 +01:00
'.9em' => 'Très épaisse'
2020-04-17 19:02:04 +02:00
];
public static $galleryThemeOpacity = [
2023-03-07 14:55:00 +01:00
'1' => 'Aucun ' ,
'.9' => 'Très Discrète' ,
'.8' => 'Discrète' ,
'.7' => 'Moyenne' ,
'.6' => 'Forte' ,
'.5' => 'Très forte'
2020-04-17 19:02:04 +02:00
];
public static $galleryThemeMargin = [
2023-03-07 14:55:00 +01:00
'0em' => 'Aucune' ,
'.1em' => 'Très petite' ,
'.3em' => 'Petite' ,
'.5em' => 'Moyenne' ,
'.7em' => 'Grande' ,
'.9em' => 'Très grande'
2020-04-17 19:02:04 +02:00
];
2020-04-18 19:18:34 +02:00
public static $galleryThemeRadius = [
2020-04-19 14:58:38 +02:00
'0em' => 'Aucun' ,
'.3em' => 'Très léger' ,
'.6em' => 'Léger' ,
'.9em' => 'Moyen' ,
2020-04-20 18:21:26 +02:00
'1.2em' => 'Important' ,
'1.5em' => 'Très important'
2020-04-18 19:18:34 +02:00
];
2020-04-01 13:43:15 +02:00
2020-04-18 19:18:34 +02:00
public static $galleryThemeShadows = [
'0px' => 'Aucune' ,
'1px 1px 5px' => 'Très légère' ,
'1px 1px 10px' => 'Légère' ,
'1px 1px 15px' => 'Moyenne' ,
'1px 1px 25px' => 'Importante' ,
'1px 1px 50px' => 'Très importante'
];
2020-04-07 19:08:24 +02:00
2022-03-31 20:07:52 +02:00
public static $galleryOptionBackPosition = [
2023-03-07 14:55:00 +01:00
'none' => 'Masqué' ,
'top' => 'Au-dessus' ,
'both' => 'Au-dessus et en dessous' ,
'bottom' => 'En dessous' ,
2022-03-31 20:07:52 +02:00
];
public static $galleryOptionBackAlign = [
2023-03-07 14:55:00 +01:00
'left' => 'A gauche' ,
'center' => 'Au centre' ,
'right' => 'A droite' ,
2022-03-31 20:07:52 +02:00
];
2022-04-02 18:13:55 +02:00
public static $formOptionSelect = '' ;
2023-03-07 14:55:00 +01:00
/**
2021-04-05 08:59:24 +02:00
* Mise à jour du module
* Appelée par les fonctions index et config
*/
2023-03-07 14:55:00 +01:00
private function update ()
{
2021-04-05 08:59:24 +02:00
2021-09-29 14:50:25 +02:00
// Initialisation du module, créer les données si elles sont manquantes.
$this -> init ();
2023-03-07 14:55:00 +01:00
$versionData = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]);
2021-09-29 14:50:25 +02:00
// Mise à jour 3.1
2023-03-07 14:55:00 +01:00
if ( version_compare ( $versionData , '3.1' , '<' )) {
2021-09-29 14:50:25 +02:00
if ( is_dir ( self :: DATADIRECTORY . 'pages/' )) {
// Déplacer les données du dossier Pages
$this -> copyDir ( self :: DATADIRECTORY . 'pages/' . $this -> getUrl ( 0 ), self :: DATADIRECTORY . $this -> getUrl ( 0 ));
2023-07-19 18:07:12 +02:00
$this -> deleteDir ( self :: DATADIRECTORY . 'pages/' );
2021-09-29 14:50:25 +02:00
$style = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' ]);
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' , str_replace ( 'pages/' , '' , $style )]);
}
// Mettre à jour la version
2023-03-07 14:55:00 +01:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' , '3.1' ]);
2021-09-29 14:50:25 +02:00
}
}
/**
* Initialisation séparée des éléments absents
* Thème
* Config
* Content
*/
2023-03-07 14:55:00 +01:00
private function init ()
{
2021-09-29 14:50:25 +02:00
// Mise à jour d'une version inférieure, la gallery existe mais pas la variable content
2023-03-07 14:55:00 +01:00
if (
$this -> getData ([ 'module' , $this -> getUrl ( 0 )]) &&
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ]) === NULL
) {
2021-04-09 16:42:13 +02:00
// Changement de l'arborescence dans module.json
$data = $this -> getData ([ 'module' , $this -> getUrl ( 0 )]);
$this -> deleteData ([ 'module' , $this -> getUrl ( 0 )]);
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data ]);
// Effacer les fichiers CSS de l'ancienne version
if ( file_exists ( 'module/gallery/view/index/index.css' )) {
unlink ( 'module/gallery/view/index/index.css' );
}
if ( file_exists ( 'module/gallery/view/gallery/gallery.css' )) {
unlink ( 'module/gallery/view/gallery/gallery.css' );
}
// Stockage des données du thème de la gallery existant
2023-03-07 14:55:00 +01:00
if ( is_array ( $this -> getData ([ 'theme' , 'gallery' ]))) {
$data = $this -> getData ([ 'theme' , 'gallery' ]);
$this -> deleteData ([ 'theme' , 'gallery' ]);
2021-04-09 16:42:13 +02:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , $data ]);
// Nom de la feuille de style
2021-06-05 17:21:07 +02:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' , self :: DATADIRECTORY . $this -> getUrl ( 0 ) . '/theme.css' ]);
2021-04-09 16:42:13 +02:00
}
2021-06-05 17:38:11 +02:00
}
2021-04-05 15:38:07 +02:00
2021-04-07 14:06:07 +02:00
// Variable commune
2023-03-07 14:55:00 +01:00
$fileCSS = self :: DATADIRECTORY . $this -> getUrl ( 0 ) . '/theme.css' ;
2021-09-29 14:50:25 +02:00
// Check la présence des données de thème
2023-03-07 14:55:00 +01:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' ]) === null ) {
2021-04-05 08:59:24 +02:00
require_once ( 'module/gallery/ressource/defaultdata.php' );
2023-03-07 14:55:00 +01:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , theme :: $defaultTheme ]);
2021-04-12 17:54:31 +02:00
// Nom de la feuille de style
2023-03-07 14:55:00 +01:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' , $fileCSS ]);
2021-04-06 09:56:26 +02:00
}
2021-09-29 14:50:25 +02:00
2021-04-07 14:06:07 +02:00
// Check la présence de la feuille de style
2023-03-07 14:55:00 +01:00
if ( ! file_exists ( self :: DATADIRECTORY . $this -> getUrl ( 0 ) . '/theme.css' )) {
2021-04-05 08:59:24 +02:00
// Dossier de l'instance
2023-03-07 14:55:00 +01:00
if ( ! is_dir ( self :: DATADIRECTORY . $this -> getUrl ( 0 ))) {
mkdir ( self :: DATADIRECTORY . $this -> getUrl ( 0 ), 0755 , true );
2021-04-05 08:59:24 +02:00
}
2021-04-05 14:38:31 +02:00
// Générer la feuille de CSS
2021-04-05 08:59:24 +02:00
$content = file_get_contents ( 'module/gallery/ressource/vartheme.css' );
$themeCss = file_get_contents ( 'module/gallery/ressource/theme.css' );
2021-04-05 15:38:07 +02:00
2021-04-05 08:59:24 +02:00
// Injection des variables
2023-03-07 14:55:00 +01:00
$content = str_replace ( '#thumbAlign#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbAlign' ]), $content );
$content = str_replace ( '#thumbWidth#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbWidth' ]), $content );
$content = str_replace ( '#thumbHeight#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbHeight' ]), $content );
$content = str_replace ( '#thumbMargin#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbMargin' ]), $content );
$content = str_replace ( '#thumbBorder#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbBorder' ]), $content );
$content = str_replace ( '#thumbBorderColor#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbBorderColor' ]), $content );
$content = str_replace ( '#thumbOpacity#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbOpacity' ]), $content );
$content = str_replace ( '#thumbShadows#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbShadows' ]), $content );
$content = str_replace ( '#thumbShadowsColor#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbShadowsColor' ]), $content );
$content = str_replace ( '#thumbRadius#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'thumbRadius' ]), $content );
$content = str_replace ( '#legendAlign#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'legendAlign' ]), $content );
$content = str_replace ( '#legendHeight#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'legendHeight' ]), $content );
$content = str_replace ( '#legendTextColor#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'legendTextColor' ]), $content );
$content = str_replace ( '#legendBgColor#' , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'legendBgColor' ]), $content );
2022-10-05 07:20:18 +02:00
2021-04-05 08:59:24 +02:00
// Ecriture de la feuille de style
2023-03-07 14:55:00 +01:00
file_put_contents ( self :: DATADIRECTORY . $this -> getUrl ( 0 ) . '/theme.css' , $content . $themeCss );
2021-04-12 17:54:31 +02:00
// Nom de la feuille de style
2023-03-07 14:55:00 +01:00
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' , $fileCSS ]);
2021-04-05 08:59:24 +02:00
}
2021-09-29 14:50:25 +02:00
// Check la présence de la config
2023-03-07 14:55:00 +01:00
if (
is_null ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'showUniqueGallery' ]))
|| is_null ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'backPosition' ]))
|| is_null ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'backAlign' ]))
|| is_null ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]))
2022-10-05 07:20:18 +02:00
) {
2023-03-07 14:55:00 +01:00
require_once ( 'module/gallery/ressource/defaultdata.php' );
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'config' , theme :: $defaultData ]);
2021-04-09 16:42:13 +02:00
}
// Contenu vide de la galerie
2023-03-07 14:55:00 +01:00
if ( ! is_array ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ]))) {
$this -> setData ([ 'module' , $this -> getUrl ( 0 ), 'content' , array ()]);
2021-04-09 16:42:13 +02:00
}
2021-04-05 08:59:24 +02:00
}
2018-04-02 08:29:19 +02:00
/**
2020-04-18 16:56:12 +02:00
* Tri de la liste des galeries
*
2018-04-02 08:29:19 +02:00
*/
2023-03-07 14:55:00 +01:00
public function sortGalleries ()
{
if ( isset ( $_POST [ 'response' ])) {
$data = explode ( '&' , $_POST [ 'response' ]);
$data = str_replace ( 'galleryTable%5B%5D=' , '' , $data );
for ( $i = 0 ; $i < count ( $data ); $i ++ ) {
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'content' , $data [ $i ],
[
'config' => [
'name' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'config' , 'name' ]),
'directory' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'config' , 'directory' ]),
'homePicture' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'config' , 'homePicture' ]),
'sort' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'config' , 'sort' ]),
'position' => $i ,
'fullScreen' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'config' , 'fullScreen' ]),
'showPageContent' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'config' , 'showPageContent' ])
2020-04-16 22:34:59 +02:00
2023-03-07 14:55:00 +01:00
],
'legend' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'legend' ]),
'positions' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $data [ $i ], 'positions' ])
]
]);
2020-06-03 09:07:00 +02:00
}
2020-04-08 22:22:40 +02:00
}
2020-04-09 22:53:24 +02:00
}
2020-04-28 19:29:24 +02:00
/**
* Tri de la liste des images
*
*/
2023-03-07 14:55:00 +01:00
public function sortPictures ()
{
if ( isset ( $_POST [ 'response' ])) {
2020-04-28 19:29:24 +02:00
$galleryName = $_POST [ 'gallery' ];
2023-03-07 14:55:00 +01:00
$data = explode ( '&' , $_POST [ 'response' ]);
$data = str_replace ( 'galleryTable%5B%5D=' , '' , $data );
2020-04-28 19:29:24 +02:00
// Sauvegarder
2023-03-07 14:55:00 +01:00
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'content' ,
$galleryName ,
[
'config' => [
'name' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $galleryName , 'config' , 'name' ]),
'directory' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $galleryName , 'config' , 'directory' ]),
'homePicture' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $galleryName , 'config' , 'homePicture' ]),
'sort' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $galleryName , 'config' , 'sort' ]),
'position' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $galleryName , 'config' , 'position' ]),
'fullScreen' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $galleryName , 'config' , 'fullScreen' ])
],
'legend' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $galleryName , 'legend' ]),
'positions' => array_flip ( $data )
]
]);
2020-04-28 19:29:24 +02:00
}
}
2020-04-09 22:53:24 +02:00
/**
* Configuration
*/
2023-03-07 14:55:00 +01:00
public function config ()
{
2021-04-05 15:38:07 +02:00
2021-04-05 08:59:24 +02:00
// Mise à jour des données de module
$this -> update ();
2020-04-09 22:53:24 +02:00
//Affichage de la galerie triée
2021-04-05 08:59:24 +02:00
$g = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ]);
2023-03-07 14:55:00 +01:00
$p = helper :: arrayColumn ( helper :: arrayColumn ( $g , 'config' ), 'position' );
asort ( $p , SORT_NUMERIC );
2020-03-27 15:06:35 +01:00
$galleries = [];
foreach ( $p as $positionId => $item ) {
2023-03-07 14:55:00 +01:00
$galleries [ $positionId ] = $g [ $positionId ];
2020-03-27 15:06:35 +01:00
}
// Traitement de l'affichage
2023-03-07 14:55:00 +01:00
if ( $galleries ) {
foreach ( $galleries as $galleryId => $gallery ) {
2018-04-02 08:29:19 +02:00
// Erreur dossier vide
2023-03-07 14:55:00 +01:00
if ( is_dir ( $gallery [ 'config' ][ 'directory' ])) {
if ( count ( scandir ( $gallery [ 'config' ][ 'directory' ])) === 2 ) {
2018-04-02 08:29:19 +02:00
$gallery [ 'config' ][ 'directory' ] = '<span class="galleryConfigError">' . $gallery [ 'config' ][ 'directory' ] . ' (dossier vide)</span>' ;
}
}
// Erreur dossier supprimé
else {
$gallery [ 'config' ][ 'directory' ] = '<span class="galleryConfigError">' . $gallery [ 'config' ][ 'directory' ] . ' (dossier introuvable)</span>' ;
}
// Met en forme le tableau
2020-06-03 09:07:00 +02:00
self :: $galleries [] = [
2022-03-30 12:30:27 +02:00
$gallery [ 'config' ][ 'position' ] + 1 ,
2018-04-02 08:29:19 +02:00
$gallery [ 'config' ][ 'name' ],
$gallery [ 'config' ][ 'directory' ],
2023-03-07 14:55:00 +01:00
template :: button ( 'galleryConfigEdit' . $galleryId , [
2023-06-19 19:46:00 +02:00
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/edit/' . $galleryId ,
2022-02-18 12:43:48 +01:00
'value' => template :: ico ( 'pencil' ),
'help' => 'Configuration de la galerie '
2018-04-02 08:29:19 +02:00
]),
template :: button ( 'galleryConfigDelete' . $galleryId , [
'class' => 'galleryConfigDelete buttonRed' ,
2023-06-19 19:46:00 +02:00
'href' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/delete/' . $galleryId ,
2022-02-25 10:04:46 +01:00
'value' => template :: ico ( 'trash' ),
2022-02-18 12:43:48 +01:00
'help' => 'Supprimer cette galerie'
2018-04-02 08:29:19 +02:00
])
];
2020-03-27 15:06:35 +01:00
// Tableau des id des galleries pour le drag and drop
self :: $galleriesId [] = $galleryId ;
2018-04-02 08:29:19 +02:00
}
}
2022-04-05 13:46:44 +02:00
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
2023-01-24 11:51:47 +01:00
'title' => helper :: translate ( 'Configuration des galeries' ),
2020-04-01 13:43:15 +02:00
'view' => 'config' ,
'vendor' => [
'tablednd'
]
2018-04-02 08:29:19 +02:00
]);
}
2022-03-28 18:57:06 +02:00
/**
* Ajout d ' une galerie
*/
2023-03-07 14:55:00 +01:00
public function add ()
{
2022-03-28 18:57:06 +02:00
// Soumission du formulaire d'ajout d'une galerie
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:09:39 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2022-04-05 15:50:48 +02:00
$galleryId = $this -> getInput ( 'galleryAddName' , null , true );
2023-03-07 14:55:00 +01:00
$success = false ;
if ( $galleryId ) {
2022-04-05 15:50:48 +02:00
$galleryId = helper :: increment ( $this -> getInput ( 'galleryAddName' , helper :: FILTER_ID , true ), ( array ) $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ]));
$homePicture = '' ;
// définir une vignette par défaut
$directory = $this -> getInput ( 'galleryAddDirectory' , helper :: FILTER_STRING_SHORT , true );
$iterator = new DirectoryIterator ( $directory );
$i = 0 ;
2023-03-07 14:55:00 +01:00
foreach ( $iterator as $fileInfos ) {
if ( $fileInfos -> isDot () === false and $fileInfos -> isFile () and @ getimagesize ( $fileInfos -> getPathname ())) {
2022-04-05 15:50:48 +02:00
$i += 1 ;
// Créer la miniature si manquante
2023-03-07 14:55:00 +01:00
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
);
2022-04-05 15:50:48 +02:00
}
// Miniatures
$homePicture = strtolower ( $fileInfos -> getFilename ());
2023-03-07 14:55:00 +01:00
break ;
2022-03-28 18:57:06 +02:00
}
2022-04-05 15:50:48 +02:00
}
// Le dossier de la galerie est vide
if ( $i > 0 ) {
2023-03-07 14:55:00 +01:00
$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' => []
]
]);
2022-04-05 15:50:48 +02:00
$success = true ;
} else {
self :: $inputNotices [ 'galleryAddDirectory' ] = " Le dossier sélectionné ne contient aucune image " ;
$success = false ;
2022-03-28 18:57:06 +02:00
}
}
2022-04-05 15:50:48 +02:00
if ( $success ) {
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2023-01-24 11:51:47 +01:00
'notification' => helper :: translate ( 'Galerie ajoutée' ),
2022-04-05 15:50:48 +02:00
'state' => true
]);
} else {
// Valeurs en sortie
$this -> addOutput ([
2023-01-24 11:51:47 +01:00
'title' => helper :: translate ( 'Création d\'une galerie' ),
2022-04-05 15:50:48 +02:00
'view' => 'add'
]);
}
2022-03-28 18:57:06 +02:00
} else {
// Valeurs en sortie
$this -> addOutput ([
2023-01-24 11:51:47 +01:00
'title' => helper :: translate ( 'Création d\'une galerie' ),
2022-03-28 18:57:06 +02:00
'view' => 'add'
]);
}
}
2018-04-02 08:29:19 +02:00
/**
* Suppression
*/
2023-03-07 14:55:00 +01:00
public function delete ()
{
2018-04-02 08:29:19 +02:00
// La galerie n'existe pas
2023-06-29 17:01:27 +02:00
if (
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) !== true ||
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 )]) === null
) {
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
}
// Suppression
else {
2021-04-05 08:59:24 +02:00
$this -> deleteData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 )]);
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2023-01-24 11:51:47 +01:00
'notification' => helper :: translate ( 'Galerie effacée' ),
2018-04-02 08:29:19 +02:00
'state' => true
]);
}
}
/**
* Liste des dossiers
*/
2023-03-07 14:55:00 +01:00
public function dirs ()
{
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'display' => self :: DISPLAY_JSON ,
2023-03-07 14:55:00 +01:00
'content' => galleriesHelper :: scanDir ( self :: FILE_DIR . 'source' )
2018-04-02 08:29:19 +02:00
]);
}
/**
* Édition
*/
2023-03-07 14:55:00 +01:00
public function edit ()
{
2022-04-04 16:36:59 +02:00
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:09:39 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2022-04-05 13:46:44 +02:00
2022-04-04 16:36:59 +02:00
// légendes
2023-03-07 14:55:00 +01:00
foreach (( array ) $this -> getInput ( 'legend' , null ) as $file => $legend ) {
2022-04-04 16:36:59 +02:00
// Image de couverture par défaut si non définie
$homePicture = $file ;
2023-03-07 14:55:00 +01:00
$file = str_replace ( '.' , '' , $file );
2022-04-04 16:36:59 +02:00
$legends [ $file ] = helper :: filter ( $legend , helper :: FILTER_STRING_SHORT );
}
2022-04-05 13:46:44 +02:00
// Photo de la page de garde de l'album définie dans form
2023-03-07 14:55:00 +01:00
if ( is_array ( $this -> getInput ( 'homePicture' , null ))) {
2022-04-05 13:46:44 +02:00
// Extrait la couverture sélectionnée
$homePicture = array_keys ( $this -> getInput ( 'homePicture' , null ))[ 0 ];
}
2022-04-04 16:36:59 +02:00
// Sauvegarder
2023-03-07 14:55:00 +01:00
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'content' , $this -> getUrl ( 2 ),
[
'config' => [
'homePicture' => $homePicture ,
// Données mises à jour par les options
'name' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'name' ]),
'directory' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'directory' ]),
'sort' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'sort' ]),
'position' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'position' ]),
'fullScreen' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'fullScreen' ]),
'showPageContent' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'showPageContent' ])
],
'legend' => $legends ,
'positions' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'positions' ])
]
]);
2022-04-04 16:36:59 +02:00
// Valeurs en sortie
$this -> addOutput ([
2023-06-19 19:46:00 +02:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/edit/' . $this -> getUrl ( 2 ),
2023-01-24 11:51:47 +01:00
'notification' => helper :: translate ( 'Modifications enregistrées' ),
2022-04-04 16:36:59 +02:00
'state' => true
]);
}
2018-04-02 08:29:19 +02:00
// La galerie n'existe pas
2023-03-07 14:55:00 +01:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 )]) === null ) {
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
}
// La galerie existe
else {
// Met en forme le tableau
2021-04-05 08:59:24 +02:00
$directory = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'directory' ]);
2023-03-07 14:55:00 +01:00
if ( is_dir ( $directory )) {
2018-04-02 08:29:19 +02:00
$iterator = new DirectoryIterator ( $directory );
2023-03-07 14:55:00 +01:00
foreach ( $iterator as $fileInfos ) {
if ( $fileInfos -> isDot () === false and $fileInfos -> isFile () and @ getimagesize ( $fileInfos -> getPathname ())) {
2020-04-13 18:58:09 +02:00
// Créer la miniature RFM si manquante
2023-03-07 14:55:00 +01:00
if ( ! file_exists ( str_replace ( 'source' , 'thumb' , $fileInfos -> getPath ()) . '/' . strtolower ( $fileInfos -> getFilename ()))) {
$this -> makeThumb (
$fileInfos -> getPathname (),
str_replace ( 'source' , 'thumb' , $fileInfos -> getPath ()) . '/' . strtolower ( $fileInfos -> getFilename ()),
122
);
2020-04-07 09:22:38 +02:00
}
2023-03-07 14:55:00 +01:00
self :: $pictures [ str_replace ( '.' , '' , $fileInfos -> getFilename ())] = [
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'positions' , str_replace ( '.' , '' , $fileInfos -> getFilename ())]) + 1 ,
2018-04-02 08:29:19 +02:00
$fileInfos -> getFilename (),
2023-03-07 14:55:00 +01:00
template :: checkbox ( 'homePicture[' . $fileInfos -> getFilename () . ']' , true , '' , [
'checked' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'homePicture' ]) === $fileInfos -> getFilename () ? true : false ,
2020-02-22 22:18:49 +01:00
'class' => 'homePicture'
2020-06-03 09:07:00 +02:00
]),
2018-04-02 08:29:19 +02:00
template :: text ( 'legend[' . $fileInfos -> getFilename () . ']' , [
2023-03-07 14:55:00 +01:00
'value' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'legend' , str_replace ( '.' , '' , $fileInfos -> getFilename ())])
2020-04-05 19:00:02 +02:00
]),
2023-03-07 14:55:00 +01:00
'<a href="' . str_replace ( 'source' , 'thumb' , $directory ) . '/' . self :: THUMBS_SEPARATOR . $fileInfos -> getFilename () . '" rel="data-lity" data-lity=""><img src="' . str_replace ( 'source' , 'thumb' , $directory ) . '/' . $fileInfos -> getFilename () . '"></a>'
2018-04-02 08:29:19 +02:00
];
2023-03-07 14:55:00 +01:00
self :: $picturesId [] = str_replace ( '.' , '' , $fileInfos -> getFilename ());
2018-04-02 08:29:19 +02:00
}
}
2020-06-03 09:07:00 +02:00
// Tri des images
2021-04-05 08:59:24 +02:00
switch ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'sort' ])) {
2020-04-13 18:13:01 +02:00
case self :: SORT_HAND :
2023-03-07 14:55:00 +01:00
$positions = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'positions' ]);
2020-04-08 17:46:29 +02:00
if ( $positions ) {
2020-04-16 14:15:49 +02:00
foreach ( $positions as $key => $value ) {
2023-03-07 14:55:00 +01:00
if ( array_key_exists ( $key , self :: $pictures )) {
2020-04-16 14:15:49 +02:00
$tempPictures [ $key ] = self :: $pictures [ $key ];
2023-03-07 14:55:00 +01:00
$tempPicturesId [] = $key ;
2020-04-16 14:15:49 +02:00
}
2020-06-03 09:07:00 +02:00
}
2020-04-16 14:15:49 +02:00
// Images ayant été ajoutées dans le dossier mais non triées
foreach ( self :: $pictures as $key => $value ) {
2023-03-07 14:55:00 +01:00
if ( ! array_key_exists ( $key , $tempPictures )) {
2020-04-16 14:15:49 +02:00
$tempPictures [ $key ] = self :: $pictures [ $key ];
2023-03-07 14:55:00 +01:00
$tempPicturesId [] = $key ;
2020-04-16 14:15:49 +02:00
}
}
2020-04-08 17:46:29 +02:00
self :: $pictures = $tempPictures ;
2023-03-07 14:55:00 +01:00
self :: $picturesId = $tempPicturesId ;
2020-04-08 17:46:29 +02:00
}
2020-02-22 23:07:12 +01:00
break ;
2020-04-13 18:13:01 +02:00
case self :: SORT_ASC :
2023-03-07 14:55:00 +01:00
ksort ( self :: $pictures , SORT_NATURAL );
sort ( self :: $picturesId , SORT_NATURAL );
2020-06-03 09:07:00 +02:00
break ;
2020-04-13 18:13:01 +02:00
case self :: SORT_DSC :
2023-03-07 14:55:00 +01:00
krsort ( self :: $pictures , SORT_NATURAL );
rsort ( self :: $picturesId , SORT_NATURAL );
2020-06-03 09:07:00 +02:00
break ;
}
2018-04-02 08:29:19 +02:00
}
// Valeurs en sortie
$this -> addOutput ([
2023-01-24 11:51:47 +01:00
'title' => sprintf ( helper :: translate ( 'Configuration de la galerie %s ' ), $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 2 ), 'config' , 'name' ])),
2020-04-07 19:08:24 +02:00
'view' => 'edit' ,
'vendor' => [
'tablednd'
]
2018-04-02 08:29:19 +02:00
]);
}
}
/**
* Accueil ( deux affichages en un pour éviter une url à rallonge )
*/
2023-03-07 14:55:00 +01:00
public function index ()
{
2021-04-08 09:44:13 +02:00
2021-04-05 08:59:24 +02:00
// Mise à jour des données de module
$this -> update ();
2022-03-21 19:16:11 +01:00
// Une seule galerie, bifurquer sur celle-ci
2023-03-07 14:55:00 +01:00
$gallery = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'showUniqueGallery' ]) === true &&
count ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ])) === 1
? array_key_first ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ]))
: $this -> getUrl ( 1 );
if ( $gallery ) {
2018-04-02 08:29:19 +02:00
// La galerie n'existe pas
2023-03-07 14:55:00 +01:00
if ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery ]) === null ) {
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
}
// La galerie existe
else {
// Images de la galerie
2022-03-21 19:16:11 +01:00
$directory = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery , 'config' , 'directory' ]);
2022-03-22 16:53:01 +01:00
// Définir les options
2023-03-07 14:55:00 +01:00
self :: $config [ 'homePicture' ] = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery , 'config' , 'homePicture' ]);
self :: $config [ 'fullScreen' ] = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery , 'config' , 'fullScreen' ]) === true ? 'fullScreen' : '' ;
2023-06-29 17:01:27 +02:00
self :: $config [ 'backPositionTop' ] = ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'backPosition' ]) === 'top' ||
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'backPosition' ]) === 'both' )
? ''
: 'displayNone' ;
self :: $config [ 'backPositionBottom' ] = ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'backPosition' ]) === 'bottom' ||
$this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'backPosition' ]) === 'both' )
? ''
: 'displayNone' ;
2023-03-07 14:55:00 +01:00
self :: $config [ 'backAlign' ] = 'textAlign' . ucfirst ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'backAlign' ]));
// Annulation de l'apparition des boutons si la galerie est unique
self :: $config [ 'backPositionTop' ] = ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'showUniqueGallery' ]) === true
2023-06-29 17:01:27 +02:00
&& count ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ])) === 1 )
? 'displayNone'
: self :: $config [ 'backPositionTop' ];
2023-03-07 14:55:00 +01:00
self :: $config [ 'backPositionBottom' ] = ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'showUniqueGallery' ]) === true
2023-06-29 17:01:27 +02:00
&& count ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ])) === 1 )
? 'displayNone'
: self :: $config [ 'backPositionBottom' ];
2023-03-07 14:55:00 +01:00
if ( is_dir ( $directory )) {
2018-04-02 08:29:19 +02:00
$iterator = new DirectoryIterator ( $directory );
2023-03-07 14:55:00 +01:00
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 ), 'content' , $gallery , 'legend' , str_replace ( '.' , '' , $fileInfos -> getFilename ())]);
$picturesSort [ $directory . '/' . $fileInfos -> getFilename ()] = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery , 'positions' , str_replace ( '.' , '' , $fileInfos -> getFilename ())]);
2020-04-07 09:22:38 +02:00
// Créer la miniature si manquante
2023-03-07 14:55:00 +01:00
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
);
2020-06-03 09:07:00 +02:00
}
2020-04-07 09:22:38 +02:00
// Définir la Miniature
2023-03-07 14:55:00 +01:00
self :: $thumbs [ $directory . '/' . $fileInfos -> getFilename ()] = file_exists ( str_replace ( 'source' , 'thumb' , $directory ) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $fileInfos -> getFilename ()))
? str_replace ( 'source' , 'thumb' , $directory ) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $fileInfos -> getFilename ())
: str_replace ( 'source' , 'thumb' , $directory ) . '/' . strtolower ( $fileInfos -> getFilename ());
2022-03-22 16:53:01 +01:00
2018-04-02 08:29:19 +02:00
}
}
// Tri des images par ordre alphabétique
2022-03-21 19:16:11 +01:00
switch ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery , 'config' , 'sort' ])) {
2020-04-13 18:13:01 +02:00
case self :: SORT_HAND :
2020-04-08 17:46:29 +02:00
asort ( $picturesSort );
if ( $picturesSort ) {
foreach ( $picturesSort as $name => $position ) {
$temp [ $name ] = self :: $pictures [ $name ];
2020-06-03 09:07:00 +02:00
}
2020-04-08 17:46:29 +02:00
self :: $pictures = $temp ;
break ;
}
2020-04-13 18:13:01 +02:00
case self :: SORT_DSC :
2023-03-07 14:55:00 +01:00
krsort ( self :: $pictures , SORT_NATURAL );
2020-06-03 09:07:00 +02:00
break ;
2020-04-13 18:13:01 +02:00
case self :: SORT_ASC :
2020-02-22 22:51:46 +01:00
default :
2023-03-07 14:55:00 +01:00
ksort ( self :: $pictures , SORT_NATURAL );
2020-02-22 22:51:46 +01:00
break ;
2020-06-03 09:07:00 +02:00
}
2018-04-02 08:29:19 +02:00
}
// Affichage du template
2023-03-07 14:55:00 +01:00
if ( self :: $pictures ) {
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this -> addOutput ([
'showBarEditButton' => true ,
2022-03-21 19:16:11 +01:00
'title' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery , 'config' , 'name' ]),
2021-04-05 08:59:24 +02:00
'view' => 'gallery' ,
2022-04-05 13:46:44 +02:00
'style' => file_exists ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' ]))
2023-03-07 14:55:00 +01:00
? $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' ])
: '' ,
2022-03-23 18:18:48 +01:00
'showPageContent' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $gallery , 'config' , 'showPageContent' ]),
2018-04-02 08:29:19 +02:00
]);
}
// Pas d'image dans la galerie
else {
// Valeurs en sortie
$this -> addOutput ([
'access' => false
]);
}
}
}
// Liste des galeries
2020-04-01 16:40:37 +02:00
else {
2020-04-05 19:00:02 +02:00
// Tri des galeries suivant l'ordre défini
2021-04-05 08:59:24 +02:00
$g = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ]);
2023-03-07 14:55:00 +01:00
$p = helper :: arrayColumn ( helper :: arrayColumn ( $g , 'config' ), 'position' );
asort ( $p , SORT_NUMERIC );
2020-04-01 16:40:37 +02:00
$galleries = [];
foreach ( $p as $positionId => $item ) {
2023-03-07 14:55:00 +01:00
$galleries [ $positionId ] = $g [ $positionId ];
2020-04-05 19:00:02 +02:00
}
// Construire le tableau
2023-03-07 14:55:00 +01:00
foreach (( array ) $galleries as $galleryId => $gallery ) {
if ( is_dir ( $gallery [ 'config' ][ 'directory' ])) {
2018-04-02 08:29:19 +02:00
$iterator = new DirectoryIterator ( $gallery [ 'config' ][ 'directory' ]);
2023-03-07 14:55:00 +01:00
foreach ( $iterator as $fileInfos ) {
if ( $fileInfos -> isDot () === false and $fileInfos -> isFile () and @ getimagesize ( $fileInfos -> getPathname ())) {
2020-06-03 09:07:00 +02:00
2018-04-02 08:29:19 +02:00
self :: $galleries [ $galleryId ] = $gallery ;
2020-04-16 14:56:30 +02:00
// L'image de couverture est-elle supprimée ?
2023-03-07 14:55:00 +01:00
if ( file_exists ( $gallery [ 'config' ][ 'directory' ] . '/' . $gallery [ 'config' ][ 'homePicture' ])) {
2020-04-16 14:56:30 +02:00
// Créer la miniature si manquante
2023-03-07 14:55:00 +01:00
if ( ! file_exists ( str_replace ( 'source' , 'thumb' , $gallery [ 'config' ][ 'directory' ]) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $gallery [ 'config' ][ 'homePicture' ]))) {
$this -> makeThumb (
$gallery [ 'config' ][ 'directory' ] . '/' . str_replace ( self :: THUMBS_SEPARATOR , '' , $gallery [ 'config' ][ 'homePicture' ]),
str_replace ( 'source' , 'thumb' , $gallery [ 'config' ][ 'directory' ]) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $gallery [ 'config' ][ 'homePicture' ]),
self :: THUMBS_WIDTH
);
2020-06-03 09:07:00 +02:00
}
2020-04-16 14:56:30 +02:00
// Définir l'image de couverture
2023-03-07 14:55:00 +01:00
self :: $firstPictures [ $galleryId ] = file_exists ( str_replace ( 'source' , 'thumb' , $gallery [ 'config' ][ 'directory' ]) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $gallery [ 'config' ][ 'homePicture' ]))
? str_replace ( 'source' , 'thumb' , $gallery [ 'config' ][ 'directory' ]) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $gallery [ 'config' ][ 'homePicture' ])
: str_replace ( 'source' , 'thumb' , $gallery [ 'config' ][ 'directory' ]) . '/' . strtolower ( $gallery [ 'config' ][ 'homePicture' ]);
2020-06-03 09:07:00 +02:00
} else {
2020-04-16 14:56:30 +02:00
// homePicture contient une image invalide, supprimée ou déplacée
// Définir l'image de couverture, première image disponible
2023-03-07 14:55:00 +01:00
$this -> makeThumb (
$fileInfos -> getPath () . '/' . $fileInfos -> getFilename (),
str_replace ( 'source' , 'thumb' , $fileInfos -> getPath ()) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $fileInfos -> getFilename ()),
self :: THUMBS_WIDTH
);
self :: $firstPictures [ $galleryId ] = file_exists ( str_replace ( 'source' , 'thumb' , $fileInfos -> getPath ()) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $fileInfos -> getFilename ()))
? str_replace ( 'source' , 'thumb' , $fileInfos -> getPath ()) . '/' . self :: THUMBS_SEPARATOR . strtolower ( $fileInfos -> getFilename ())
: str_replace ( 'source' , 'thumb' , $fileInfos -> getPath ()) . '/' . strtolower ( $fileInfos -> getFilename ());
2020-04-16 14:56:30 +02:00
}
2020-06-03 09:07:00 +02:00
}
2020-04-16 19:27:52 +02:00
continue ( 1 );
2018-04-02 08:29:19 +02:00
}
}
}
// Valeurs en sortie
$this -> addOutput ([
'showBarEditButton' => true ,
'showPageContent' => true ,
2021-04-05 08:59:24 +02:00
'view' => 'index' ,
2022-04-05 13:46:44 +02:00
'style' => file_exists ( $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' ]))
2023-03-07 14:55:00 +01:00
? $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'theme' , 'style' ])
: ''
2018-04-02 08:29:19 +02:00
]);
}
}
2020-04-17 19:02:04 +02:00
/**
* Thème de la galerie
*/
2023-03-07 14:55:00 +01:00
public function theme ()
{
2020-04-17 19:02:04 +02:00
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:09:39 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2021-04-05 08:59:24 +02:00
// Dossier de l'instance
2023-03-07 14:55:00 +01:00
if ( ! is_dir ( self :: DATADIRECTORY . $this -> getUrl ( 0 ))) {
mkdir ( self :: DATADIRECTORY . $this -> getUrl ( 0 ), 0755 , true );
2021-04-05 08:59:24 +02:00
}
2023-03-07 14:55:00 +01:00
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'theme' ,
[
'thumbAlign' => $this -> getinput ( 'galleryThemeThumbAlign' , helper :: FILTER_STRING_SHORT ),
'thumbWidth' => $this -> getinput ( 'galleryThemeThumbWidth' , helper :: FILTER_STRING_SHORT ),
'thumbHeight' => $this -> getinput ( 'galleryThemeThumbHeight' , helper :: FILTER_STRING_SHORT ),
'thumbMargin' => $this -> getinput ( 'galleryThemeThumbMargin' , helper :: FILTER_STRING_SHORT ),
'thumbBorder' => $this -> getinput ( 'galleryThemeThumbBorder' , helper :: FILTER_STRING_SHORT ),
'thumbBorderColor' => $this -> getinput ( 'galleryThemeThumbBorderColor' , helper :: FILTER_STRING_SHORT ),
'thumbOpacity' => $this -> getinput ( 'galleryThemeThumbOpacity' , helper :: FILTER_STRING_SHORT ),
'thumbShadows' => $this -> getinput ( 'galleryThemeThumbShadows' , helper :: FILTER_STRING_SHORT ),
2021-04-12 17:54:31 +02:00
'thumbShadowsColor' => $this -> getinput ( 'galleryThemeThumbShadowsColor' , helper :: FILTER_STRING_SHORT ),
2023-03-07 14:55:00 +01:00
'thumbRadius' => $this -> getinput ( 'galleryThemeThumbRadius' , helper :: FILTER_STRING_SHORT ),
'legendHeight' => $this -> getinput ( 'galleryThemeLegendHeight' , helper :: FILTER_STRING_SHORT ),
'legendAlign' => $this -> getinput ( 'galleryThemeLegendAlign' , helper :: FILTER_STRING_SHORT ),
'legendTextColor' => $this -> getinput ( 'galleryThemeLegendTextColor' , helper :: FILTER_STRING_SHORT ),
'legendBgColor' => $this -> getinput ( 'galleryThemeLegendBgColor' , helper :: FILTER_STRING_SHORT ),
2022-03-28 16:57:53 +02:00
'showUniqueGallery' => $this -> getinput ( 'galleryThemeShowUniqueGallery' , helper :: FILTER_BOOLEAN ),
2023-03-07 14:55:00 +01:00
'style' => self :: DATADIRECTORY . $this -> getUrl ( 0 ) . '/theme.css' ,
]
]);
2020-04-18 16:33:48 +02:00
// Création des fichiers CSS
$content = file_get_contents ( 'module/gallery/ressource/vartheme.css' );
$themeCss = file_get_contents ( 'module/gallery/ressource/theme.css' );
2020-06-03 09:07:00 +02:00
// Injection des variables
2023-03-07 14:55:00 +01:00
$content = str_replace ( '#thumbAlign#' , $this -> getinput ( 'galleryThemeThumbAlign' ), $content );
$content = str_replace ( '#thumbWidth#' , $this -> getinput ( 'galleryThemeThumbWidth' ), $content );
$content = str_replace ( '#thumbHeight#' , $this -> getinput ( 'galleryThemeThumbHeight' ), $content );
$content = str_replace ( '#thumbMargin#' , $this -> getinput ( 'galleryThemeThumbMargin' ), $content );
$content = str_replace ( '#thumbBorder#' , $this -> getinput ( 'galleryThemeThumbBorder' ), $content );
$content = str_replace ( '#thumbBorderColor#' , $this -> getinput ( 'galleryThemeThumbBorderColor' ), $content );
$content = str_replace ( '#thumbOpacity#' , $this -> getinput ( 'galleryThemeThumbOpacity' ), $content );
$content = str_replace ( '#thumbShadows#' , $this -> getinput ( 'galleryThemeThumbShadows' ), $content );
$content = str_replace ( '#thumbShadowsColor#' , $this -> getinput ( 'galleryThemeThumbShadowsColor' ), $content );
$content = str_replace ( '#thumbRadius#' , $this -> getinput ( 'galleryThemeThumbRadius' ), $content );
$content = str_replace ( '#legendAlign#' , $this -> getinput ( 'galleryThemeLegendAlign' ), $content );
$content = str_replace ( '#legendHeight#' , $this -> getinput ( 'galleryThemeLegendHeight' ), $content );
$content = str_replace ( '#legendTextColor#' , $this -> getinput ( 'galleryThemeLegendTextColor' ), $content );
$content = str_replace ( '#legendBgColor#' , $this -> getinput ( 'galleryThemeLegendBgColor' ), $content );
2022-10-19 10:31:31 +02:00
$success = is_int ( file_put_contents ( self :: DATADIRECTORY . $this -> getUrl ( 0 ) . '/theme.css' , $content . $themeCss ));
2020-06-03 09:07:00 +02:00
// Valeurs en sortie
2020-04-19 13:07:01 +02:00
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl () . '/theme' ,
2022-10-19 10:31:31 +02:00
'notification' => $success ? 'Modifications enregistrées' : 'Modifications non enregistrées !' ,
'state' => $success
2020-04-19 13:07:01 +02:00
]);
2020-04-17 19:02:04 +02:00
}
// Valeurs en sortie
$this -> addOutput ([
2023-02-14 08:26:45 +01:00
'title' => helper :: translate ( 'Thème' ),
2020-04-17 19:02:04 +02:00
'view' => 'theme' ,
'vendor' => [
'tinycolorpicker'
]
]);
}
2022-03-28 18:57:06 +02:00
/**
* Option de configuration de la galerie
*/
2023-03-07 14:55:00 +01:00
public function option ()
{
2022-04-01 15:45:14 +02:00
/**
2022-04-05 13:46:44 +02:00
* Options applicables à toutes les galeries du module
2022-04-01 15:45:14 +02:00
*/
if ( $this -> getUrl ( 2 ) === 'galleries' ) {
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:15:15 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2022-04-05 13:46:44 +02:00
// Sauver la configuration de la galerie
2023-03-07 14:55:00 +01:00
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'config' ,
[
2022-05-19 18:47:49 +02:00
'showUniqueGallery' => $this -> getinput ( 'galleriesOptionShowUniqueGallery' , helper :: FILTER_BOOLEAN ),
2023-03-07 14:55:00 +01:00
'backPosition' => $this -> getinput ( 'galleryOptionBackPosition' ),
'backAlign' => $this -> getinput ( 'galleryOptionBackAlign' ),
'versionData' => $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'config' , 'versionData' ]),
]
]);
2022-04-04 16:36:59 +02:00
2022-04-01 15:45:14 +02:00
// Valeurs en sortie
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl () . '/option' ,
'notification' => 'Modifications enregistrées' ,
'state' => true
]);
}
2022-04-02 18:13:55 +02:00
// Routage du formulaire
self :: $formOptionSelect = 'galleries' ;
2022-03-28 18:57:06 +02:00
// Valeurs en sortie
$this -> addOutput ([
2023-02-13 15:24:28 +01:00
'title' => helper :: translate ( 'Options de configuration' ),
2022-04-01 15:45:14 +02:00
'view' => 'option'
2022-03-28 18:57:06 +02:00
]);
2022-04-05 13:46:44 +02:00
/**
* Enregistre les options de configuration de la galerie d ' images sélectionnée
*/
2022-04-01 15:45:14 +02:00
} elseif ( $this -> getUrl ( 2 ) === 'gallery' ) {
// Soumission du formulaire
2023-06-29 17:01:27 +02:00
if (
2023-06-30 09:15:15 +02:00
$this -> getUser ( 'permission' , __CLASS__ , __FUNCTION__ ) === true &&
2023-06-29 17:01:27 +02:00
$this -> isPost ()
) {
2022-04-05 13:46:44 +02:00
// Le nom de la galerie est vide c'est le nom dans l'url qui est pris en compte
$galleryId = ! empty ( $this -> getInput ( 'galleryEditName' )) ? $this -> getInput ( 'galleryEditName' , helper :: FILTER_ID , true ) : $this -> getUrl ( 3 );
// Sauvegarde des Valeurs non affectées par ce formulaire
2023-03-07 14:55:00 +01:00
$homePicture = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 3 ), 'config' , 'homePicture' ]);
$position = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 3 ), 'config' , 'position' ]);
$legend = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 3 ), 'legend' ]);
$positions = $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 3 ), 'positions' ]);
2022-04-05 13:46:44 +02:00
// Le nom de la galerie n'est pas celui dans la BDD
2023-03-07 14:55:00 +01:00
if ( $galleryId !== $this -> getUrl ( 3 )) {
2022-04-01 15:45:14 +02:00
// Incrémente le nouvel id de la galerie
$galleryId = helper :: increment ( $galleryId , $this -> getData ([ 'module' , $this -> getUrl ( 0 ), 'content' ]));
// Supprime l'ancienne galerie
2022-04-05 13:46:44 +02:00
$this -> deleteData ([ 'module' , $this -> getUrl ( 0 ), 'content' , $this -> getUrl ( 3 )]);
2022-04-01 15:45:14 +02:00
}
// Sauvegarder
if ( $this -> getInput ( 'galleryEditName' )) {
2023-03-07 14:55:00 +01:00
$this -> setData ([
'module' , $this -> getUrl ( 0 ),
'content' ,
$galleryId ,
[
'config' => [
'name' => $this -> getInput ( 'galleryEditName' , helper :: FILTER_STRING_SHORT , true ),
'directory' => $this -> getInput ( 'galleryEditDirectory' , helper :: FILTER_STRING_SHORT , true ),
'sort' => $this -> getInput ( 'galleryEditSort' ),
'fullScreen' => $this -> getInput ( 'galleryEditFullscreen' , helper :: FILTER_BOOLEAN ),
'showPageContent' => $this -> getInput ( 'galleryEditShowPageContent' , helper :: FILTER_BOOLEAN ),
// Données lues à partir du formulaire edit de la galerie avec la liste des images
'homePicture' => $homePicture ,
'position' => $position
],
'legend' => $legend ,
'positions' => $positions
]
]);
2022-04-01 15:45:14 +02:00
}
// Valeurs en sortie
$this -> addOutput ([
2023-06-19 19:46:00 +02:00
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/edit/' . $galleryId ,
2023-01-24 11:51:47 +01:00
'notification' => helper :: translate ( 'Modifications enregistrées' ),
2022-04-01 15:45:14 +02:00
'state' => true
]);
2022-03-28 18:57:06 +02:00
}
2022-04-02 18:13:55 +02:00
// Routage du formulaire
self :: $formOptionSelect = 'gallery' ;
2022-03-28 18:57:06 +02:00
// Valeurs en sortie
$this -> addOutput ([
2023-03-07 14:55:00 +01:00
'title' => sprintf ( helper :: translate ( 'Options de la galerie %s' ), ucfirst ( $this -> getUrl ( 3 ))),
2022-04-01 15:45:14 +02:00
'view' => 'option'
]);
} else {
// Valeurs en sortie par défaut
$this -> addOutput ([
'redirect' => helper :: baseUrl () . $this -> getUrl ( 0 ) . '/config' ,
2023-01-24 11:51:47 +01:00
'notification' => helper :: translate ( 'Action interdite' )
2022-03-28 18:57:06 +02:00
]);
}
}
2021-02-10 17:58:08 +01:00
}
2023-03-07 14:55:00 +01:00
class galleriesHelper extends helper
{
2021-02-10 17:58:08 +01:00
/**
* Scan le contenu d ' un dossier et de ses sous - dossiers
* @ param string $dir Dossier à scanner
* @ return array
*/
2023-03-07 14:55:00 +01:00
public static function scanDir ( $dir )
{
2021-02-10 17:58:08 +01:00
$dirContent = [];
$iterator = new DirectoryIterator ( $dir );
2023-03-07 14:55:00 +01:00
foreach ( $iterator as $fileInfos ) {
if ( $fileInfos -> isDot () === false and $fileInfos -> isDir ()) {
2021-02-10 17:58:08 +01:00
$dirContent [] = $dir . '/' . $fileInfos -> getBasename ();
$dirContent = array_merge ( $dirContent , self :: scanDir ( $dir . '/' . $fileInfos -> getBasename ()));
}
}
return $dirContent ;
}
2023-03-07 14:55:00 +01:00
}