ZwiiCMS/module/gallery/gallery.php

782 lines
31 KiB
PHP
Raw Normal View History

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
* @author Frédéric Tempez <frederic.tempez@outlook.com>
2021-02-17 13:49:58 +01:00
* @copyright Copyright (C) 2018-2021, Frédéric Tempez
2018-04-02 08:29:19 +02:00
* @license GNU General Public License, version 3
* @link http://zwiicms.fr/
2018-04-02 08:29:19 +02:00
*/
class gallery extends common {
2021-04-05 08:59:24 +02:00
const VERSION = '3.0';
const REALNAME = 'Galerie';
const DELETE = true;
2021-02-25 07:53:57 +01:00
const UPDATE = '0.0';
2021-02-19 09:08:56 +01:00
const DATADIRECTORY = []; // Contenu localisé inclus par défaut (page.json et module.json)
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 = [];
2018-04-02 08:29:19 +02:00
public static $actions = [
'config' => self::GROUP_MODERATOR,
'delete' => self::GROUP_MODERATOR,
'dirs' => self::GROUP_MODERATOR,
'sortGalleries' => self::GROUP_MODERATOR,
'sortPictures' => self::GROUP_MODERATOR,
'edit' => self::GROUP_MODERATOR,
'theme' => self::GROUP_MODERATOR,
2020-06-03 09:07:00 +02:00
'index' => self::GROUP_VISITOR
2018-04-02 08:29:19 +02:00
];
public static $sort = [
self::SORT_ASC => 'Alphabétique ',
2020-04-15 17:26:26 +02:00
self::SORT_DSC => 'Alphabétique inverse',
self::SORT_HAND => 'Manuel'
];
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 = [
'9em' => 'Très petite',
'12em' => 'Petite',
'15em' => 'Moyenne',
'18em' => 'Grande',
'21em' => 'Très grande',
'100%' => 'Proportionnelle'
];
public static $galleryThemeSizeHeight = [
2020-04-18 19:18:34 +02:00
'9em' => 'Très petite',
'12em' => 'Petite',
'15em' => 'Moyenne',
'18em' => 'Grande',
'21em' => 'Très grande'
2020-04-17 19:02:04 +02:00
];
public static $galleryThemeLegendHeight = [
2020-04-18 19:18:34 +02:00
'.125em' => 'Très petite',
'.25em' => 'Petite',
'.375em' => 'Moyenne',
'.5em' => 'Grande',
'.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',
'.3em' => 'Fine',
'.5em' => 'Moyenne',
'.7em' => 'Epaisse',
2020-04-26 09:54:31 +02:00
'.9em' => 'Très épaisse'
2020-04-17 19:02:04 +02:00
];
public static $galleryThemeOpacity = [
'1' => 'Aucun ',
2020-04-18 19:18:34 +02:00
'.9' => 'Très Discrète',
2020-06-03 09:07:00 +02:00
'.8' => 'Discrète',
2020-04-18 19:18:34 +02:00
'.7' => 'Moyenne',
'.6' => 'Forte',
'.5' => 'Très forte'
2020-04-17 19:02:04 +02:00
];
public static $galleryThemeMargin = [
'0em' => 'Aucune',
2020-04-18 19:18:34 +02:00
'.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
2021-04-05 08:59:24 +02:00
/**
* Mise à jour du module
* Appelée par les fonctions index et config
*/
private function update() {
// Installation des données par défaut
$class = get_called_class();
$moduleId = $this->getUrl(0);
if ( $this->getData(['module', $this->getUrl(0), 'config',]) === null ) {
require_once('module/gallery/ressource/defaultdata.php');
$this->setData(['module', $this->getUrl(0), 'config', theme::$defaultData]);
// Dossier de l'instance
if (!is_dir(self::DATA_DIR . 'modules/' . $class)) {
mkdir (self::DATA_DIR . 'modules/' . $class, 0777, true);
}
// Nom de la feuille de style
$fileCSS = self::DATA_DIR . 'modules/' . $class . '/' . $moduleId . '.css' ;
$this->setData(['module', $this->getUrl(0), 'config', 'style', $fileCSS]);
}
// Générer la feuille de CSS
if (!file_exists(self::DATA_DIR . 'modules/' . $class . '/' . $moduleId . '.css' )) {
$content = file_get_contents('module/gallery/ressource/vartheme.css');
$themeCss = file_get_contents('module/gallery/ressource/theme.css');
// Injection des variables
$content = str_replace('#thumbAlign#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbAlign']),$content );
$content = str_replace('#thumbWidth#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbWidth']),$content );
$content = str_replace('#thumbHeight#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbHeight']),$content );
$content = str_replace('#thumbMargin#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbMargin']),$content );
$content = str_replace('#thumbBorder#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbBorder']),$content );
$content = str_replace('#thumbBorderColor#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbBorderColor']),$content );
$content = str_replace('#thumbOpacity#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbOpacity']),$content );
$content = str_replace('#thumbShadows#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbShadows']),$content );
$content = str_replace('#thumbShadowsColor#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbShadowsColor']),$content );
$content = str_replace('#thumbRadius#',$this->getData(['module', $this->getUrl(0), 'config', 'thumbRadius']),$content );
$content = str_replace('#legendAlign#',$this->getData(['module', $this->getUrl(0), 'config', 'legendAlign']),$content );
$content = str_replace('#legendHeight#',$this->getData(['module', $this->getUrl(0), 'config', 'legendHeight']),$content );
$content = str_replace('#legendTextColor#',$this->getData(['module', $this->getUrl(0), 'config', 'legendTextColor']),$content );
$content = str_replace('#legendBgColor#',$this->getData(['module', $this->getUrl(0), 'config', 'legendBgColor']),$content );
// Ecriture de la feuille de style
$success = file_put_contents(self::DATA_DIR . 'modules/' . $class . '/' . $moduleId . '.css' , $content . $themeCss);
}
// Mise à jour d'une version inférieure
if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '3.0', '<') ) {
// 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
$data = $this->getData(['theme','gallery']);
$this->deleteData(['theme','gallery']);
$this->setData(['module', $this->getUrl(0), 'config', $data]);
// Nouvelle version
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.0']);
}
}
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
*/
public function sortGalleries() {
2020-04-09 22:53:24 +02:00
if($_POST['response']) {
$data = explode('&',$_POST['response']);
$data = str_replace('galleryTable%5B%5D=','',$data);
for($i=0;$i<count($data);$i++) {
2021-04-05 08:59:24 +02:00
$this->setData(['module', $this->getUrl(0), 'content', $data[$i], [
2020-04-09 22:53:24 +02:00
'config' => [
'name' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','name']),
'directory' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','directory']),
'homePicture' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','homePicture']),
'sort' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','sort']),
'position'=> $i,
'fullScreen' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','fullScreen'])
2020-04-09 22:53:24 +02:00
],
'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']),
'positions' => $this->getData(['module',$this->getUrl(0),$data[$i],'positions'])
2020-04-09 22:53:24 +02:00
]]);
2020-06-03 09:07:00 +02:00
}
2020-04-08 22:22:40 +02:00
}
2020-04-09 22:53:24 +02:00
}
/**
* Tri de la liste des images
*
*/
public function sortPictures() {
if($_POST['response']) {
$galleryName = $_POST['gallery'];
$data = explode('&',$_POST['response']);
$data = str_replace('galleryTable%5B%5D=','',$data);
// Sauvegarder
2021-04-05 08:59:24 +02:00
$this->setData(['module', $this->getUrl(0), 'content', $galleryName, [
'config' => [
'name' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','name']),
'directory' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','directory']),
'homePicture' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','homePicture']),
'sort' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','sort']),
2020-09-25 19:34:51 +02:00
'position' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','position']),
'fullScreen' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','fullScreen'])
],
'legend' => $this->getData(['module',$this->getUrl(0),$galleryName,'legend']),
'positions' => array_flip($data)
]]);
}
}
2020-04-09 22:53:24 +02:00
/**
* Configuration
*/
public function config() {
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']);
2020-03-27 15:06:35 +01:00
$p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position');
2020-06-03 09:07:00 +02:00
asort($p,SORT_NUMERIC);
2020-03-27 15:06:35 +01:00
$galleries = [];
foreach ($p as $positionId => $item) {
2020-06-03 09:07:00 +02:00
$galleries [$positionId] = $g[$positionId];
2020-03-27 15:06:35 +01:00
}
// Traitement de l'affichage
2020-06-03 09:07:00 +02:00
if($galleries) {
2018-04-02 08:29:19 +02:00
foreach($galleries as $galleryId => $gallery) {
// Erreur dossier vide
if(is_dir($gallery['config']['directory'])) {
if(count(scandir($gallery['config']['directory'])) === 2) {
$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[] = [
template::ico('sort'),
2018-04-02 08:29:19 +02:00
$gallery['config']['name'],
$gallery['config']['directory'],
template::button('galleryConfigEdit' . $galleryId , [
2019-01-16 19:25:09 +01:00
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'],
2018-04-02 08:29:19 +02:00
'value' => template::ico('pencil')
]),
template::button('galleryConfigDelete' . $galleryId, [
'class' => 'galleryConfigDelete buttonRed',
2019-01-16 19:25:09 +01:00
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $galleryId . '/' . $_SESSION['csrf'],
2018-04-02 08:29:19 +02:00
'value' => template::ico('cancel')
])
];
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
}
}
2020-04-12 19:21:39 +02:00
// Soumission du formulaire d'ajout d'une galerie
if($this->isPost()) {
2020-04-08 22:22:40 +02:00
if (!$this->getInput('galleryConfigFilterResponse')) {
2021-04-05 08:59:24 +02:00
$galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0), 'content']));
2020-04-12 19:21:39 +02:00
// définir une vignette par défaut
$directory = $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true);
2020-06-03 09:07:00 +02:00
$iterator = new DirectoryIterator($directory);
2020-04-12 19:21:39 +02:00
foreach($iterator as $fileInfos) {
2020-06-03 09:07:00 +02:00
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
2020-04-12 19:21:39 +02:00
// Créer la miniature si manquante
2020-04-16 11:50:01 +02:00
if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) {
2020-04-12 19:21:39 +02:00
$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
// Miniatures
$homePicture = strtolower($fileInfos->getFilename());
2020-04-12 19:21:39 +02:00
break;
}
}
2021-04-05 08:59:24 +02:00
$this->setData(['module', $this->getUrl(0), 'content', $galleryId, [
'config' => [
'name' => $this->getInput('galleryConfigName'),
'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => $homePicture,
'sort' => self::SORT_ASC,
2021-04-05 08:59:24 +02:00
'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']),
'fullScreen' => false
],
'legend' => [],
'positions' => []
]]);
2020-04-01 13:43:15 +02:00
// Valeurs en sortie
$this->addOutput([
2020-04-09 08:47:51 +02:00
'redirect' => helper::baseUrl() . $this->getUrl() /*. '#galleryConfigForm'*/,
2020-04-01 13:43:15 +02:00
'notification' => 'Modifications enregistrées',
'state' => true
]);
2020-03-27 15:06:35 +01:00
}
2018-04-02 08:29:19 +02:00
}
// Valeurs en sortie
$this->addOutput([
'title' => 'Configuration du module',
2020-04-01 13:43:15 +02:00
'view' => 'config',
'vendor' => [
'tablednd'
]
2018-04-02 08:29:19 +02:00
]);
}
/**
* Suppression
*/
public function delete() {
2020-06-03 09:07:00 +02:00
// $url prend l'adresse sans le token
2018-04-02 08:29:19 +02:00
// La galerie n'existe pas
2021-04-05 08:59:24 +02: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
]);
}
2019-01-08 17:55:18 +01:00
// Jeton incorrect
if ($this->getUrl(3) !== $_SESSION['csrf']) {
2019-01-08 17:55:18 +01:00
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Suppression non autorisée'
2019-01-08 17:55:18 +01:00
]);
2020-06-03 09:07:00 +02:00
}
2018-04-02 08:29:19 +02:00
// 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',
'notification' => 'Galerie supprimée',
'state' => true
]);
}
}
/**
* Liste des dossiers
*/
public function dirs() {
// Valeurs en sortie
$this->addOutput([
'display' => self::DISPLAY_JSON,
2021-02-10 17:58:08 +01:00
'content' => galleriesHelper::scanDir(self::FILE_DIR.'source')
2018-04-02 08:29:19 +02:00
]);
}
/**
* Édition
*/
public function edit() {
2019-01-16 19:25:09 +01:00
// Jeton incorrect
if ($this->getUrl(3) !== $_SESSION['csrf']) {
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Action non autorisée'
]);
2020-06-03 09:07:00 +02:00
}
2018-04-02 08:29:19 +02:00
// La galerie n'existe pas
2021-04-05 08:59:24 +02: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 {
// Soumission du formulaire
if($this->isPost()) {
2020-04-08 17:46:29 +02:00
// Si l'id a changée
2020-09-22 19:20:35 +02:00
$galleryId = !empty($this->getInput('galleryEditName')) ? $this->getInput('galleryEditName', helper::FILTER_ID, true) : $this->getUrl(2);
2020-04-08 17:46:29 +02:00
if($galleryId !== $this->getUrl(2)) {
// Incrémente le nouvel id de la galerie
2021-04-05 08:59:24 +02:00
$galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0), 'content']));
// Transférer la position des images
2020-06-03 09:07:00 +02:00
$oldPositions = $this->getData(['module',$this->getUrl(0), $this->getUrl(2),'positions']);
2020-04-08 17:46:29 +02:00
// Supprime l'ancienne galerie
2021-04-05 08:59:24 +02:00
$this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]);
2020-04-08 17:46:29 +02:00
}
// légendes
$legends = [];
foreach((array) $this->getInput('legend', null) as $file => $legend) {
2020-06-03 09:07:00 +02:00
// Image de couverture par défaut si non définie
$homePicture = $file;
2020-04-08 17:46:29 +02:00
$file = str_replace('.','',$file);
$legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT);
}
// Photo de la page de garde de l'album définie dans form
if (is_array($this->getInput('homePicture', null)) ) {
$d = array_keys($this->getInput('homePicture', null));
$homePicture = $d[0];
2020-04-08 17:46:29 +02:00
}
2020-06-03 09:07:00 +02:00
// Sauvegarder
2020-09-22 19:20:35 +02:00
if ($this->getInput('galleryEditName')) {
2021-04-05 08:59:24 +02:00
$this->setData(['module', $this->getUrl(0), 'content', $galleryId, [
2020-09-22 19:20:35 +02:00
'config' => [
'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true),
'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => $homePicture,
// pas de positions, on active le tri alpha
'sort' => $this->getInput('galleryEditSort'),
2021-04-05 08:59:24 +02:00
'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']),
2020-09-22 19:20:35 +02:00
'fullScreen' => $this->getInput('galleryEditFullscreen', helper::FILTER_BOOLEAN)
2020-09-22 19:20:35 +02:00
],
'legend' => $legends,
2021-04-05 08:59:24 +02:00
'positions' => empty($oldPositions) ? $this->getdata(['module', $this->getUrl(0), 'content', $galleryId, 'positions']) : $oldPositions
2020-09-22 19:20:35 +02:00
]]);
}
2020-06-03 09:07:00 +02:00
// Valeurs en sortie
2020-04-08 17:46:29 +02:00
$this->addOutput([
2020-04-10 15:57:51 +02:00
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'] ,
2020-04-08 17:46:29 +02:00
'notification' => 'Modifications enregistrées',
'state' => true
]);
2018-04-02 08:29:19 +02:00
}
// 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']);
2018-04-02 08:29:19 +02:00
if(is_dir($directory)) {
$iterator = new DirectoryIterator($directory);
2020-06-03 09:07:00 +02:00
2018-04-02 08:29:19 +02:00
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
// Créer la miniature RFM si manquante
2020-04-16 11:50:01 +02: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-06-03 09:07:00 +02:00
self::$pictures[str_replace('.','',$fileInfos->getFilename())] = [
2020-04-07 19:08:24 +02:00
template::ico('sort'),
2018-04-02 08:29:19 +02:00
$fileInfos->getFilename(),
2020-06-03 09:07:00 +02:00
template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [
2021-04-05 08:59:24 +02:00
'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() . ']', [
2021-04-05 08:59:24 +02:00
'value' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())])
]),
2020-04-15 17:26:26 +02: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
];
2020-04-08 17:46:29 +02: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'])) {
case self::SORT_HAND:
$positions = $this->getdata(['module',$this->getUrl(0), $this->getUrl(2),'positions']);
2020-04-08 17:46:29 +02:00
if ($positions) {
foreach ($positions as $key => $value) {
if (array_key_exists($key,self::$pictures)) {
$tempPictures[$key] = self::$pictures[$key];
$tempPicturesId [] = $key;
}
2020-06-03 09:07:00 +02:00
}
// Images ayant été ajoutées dans le dossier mais non triées
foreach (self::$pictures as $key => $value) {
if (!array_key_exists($key,$tempPictures)) {
$tempPictures[$key] = self::$pictures[$key];
$tempPicturesId [] = $key;
}
}
2020-04-08 17:46:29 +02:00
self::$pictures = $tempPictures;
self::$picturesId = $tempPicturesId;
}
2020-02-22 23:07:12 +01:00
break;
case self::SORT_ASC:
2020-04-08 17:46:29 +02:00
ksort(self::$pictures,SORT_NATURAL);
sort(self::$picturesId,SORT_NATURAL);
2020-06-03 09:07:00 +02:00
break;
case self::SORT_DSC:
2020-02-22 23:07:12 +01:00
krsort(self::$pictures,SORT_NATURAL);
2020-04-08 17:46:29 +02:00
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([
2021-04-05 08:59:24 +02:00
'title' => $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)
*/
public function index() {
2021-04-05 08:59:24 +02:00
// Mise à jour des données de module
$this->update();
2018-04-02 08:29:19 +02:00
// Images d'une galerie
if($this->getUrl(1)) {
// La galerie n'existe pas
2021-04-05 08:59:24 +02:00
if($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1)]) === null) {
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
}
// La galerie existe
else {
// Images de la galerie
2021-04-05 08:59:24 +02:00
$directory = $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'config', 'directory']);
2018-04-02 08:29:19 +02:00
if(is_dir($directory)) {
$iterator = new DirectoryIterator($directory);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
2021-04-05 08:59:24 +02:00
self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]);
$picturesSort[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'positions', str_replace('.','',$fileInfos->getFilename())]);
// Créer la miniature si manquante
2020-04-16 11:50:01 +02: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
}
// Définir la Miniature
2020-06-03 09:07:00 +02:00
self::$thumbs[$directory . '/' . $fileInfos->getFilename()] = file_exists( str_replace('source','thumb',$directory) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))
2020-04-12 19:21:39 +02:00
? str_replace('source','thumb',$directory) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename())
: str_replace('source','thumb',$directory) . '/' . strtolower($fileInfos->getFilename());
2018-04-02 08:29:19 +02:00
}
}
// Tri des images par ordre alphabétique
2021-04-05 08:59:24 +02:00
switch ($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'config', 'sort'])) {
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;
}
case self::SORT_DSC:
krsort(self::$pictures,SORT_NATURAL);
2020-06-03 09:07:00 +02:00
break;
case self::SORT_ASC:
default:
ksort(self::$pictures,SORT_NATURAL);
break;
2020-06-03 09:07:00 +02:00
}
2018-04-02 08:29:19 +02:00
}
// Affichage du template
if(self::$pictures) {
// Valeurs en sortie
$this->addOutput([
'showBarEditButton' => true,
2021-04-05 08:59:24 +02:00
'title' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'config', 'name']),
'view' => 'gallery',
'style' => $this->getData(['module', $this->getUrl(0), 'config', 'style'])
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 {
// Tri des galeries suivant l'ordre défini
2021-04-05 08:59:24 +02:00
$g = $this->getData(['module', $this->getUrl(0), 'content']);
2020-04-01 16:40:37 +02:00
$p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position');
2020-06-03 09:07:00 +02:00
asort($p,SORT_NUMERIC);
2020-04-01 16:40:37 +02:00
$galleries = [];
foreach ($p as $positionId => $item) {
2020-06-03 09:07:00 +02:00
$galleries [$positionId] = $g[$positionId];
}
// Construire le tableau
2020-04-01 16:40:37 +02:00
foreach((array) $galleries as $galleryId => $gallery) {
2018-04-02 08:29:19 +02:00
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())) {
2020-06-03 09:07:00 +02:00
2018-04-02 08:29:19 +02:00
self::$galleries[$galleryId] = $gallery;
// L'image de couverture est-elle supprimée ?
if (file_exists( $gallery['config']['directory'] . '/' . $gallery['config']['homePicture'])) {
// Créer la miniature si manquante
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
}
// Définir l'image de couverture
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 {
// homePicture contient une image invalide, supprimée ou déplacée
// Définir l'image de couverture, première image disponible
$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-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',
'style' => $this->getData(['module', $this->getUrl(0), 'config', 'style'])
2018-04-02 08:29:19 +02:00
]);
}
}
2020-04-17 19:02:04 +02:00
/**
* Thème de la galerie
*/
public function theme() {
// 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'
]);
2020-04-18 16:33:48 +02:00
}
2020-04-17 19:02:04 +02:00
// Soumission du formulaire
2020-04-18 16:33:48 +02:00
if($this->isPost()) {
2021-04-05 08:59:24 +02:00
// Générer la feuille de CSS
$class = get_called_class();
$moduleId = $this->getUrl(0);
// Dossier de l'instance
if (!is_dir(self::DATA_DIR . 'modules/' . $class)) {
mkdir (self::DATA_DIR . 'modules/' . $class, 0777, true);
}
$fileCSS = self::DATA_DIR . 'modules/' . $class . '/' . $moduleId . '.css' ;
// Fin feuille de style
$this->getData(['module', $this->getUrl(0), 'config', [
'thumbAlign' => $this->getinput('galleryThemeThumbAlign'),
'thumbWidth' => $this->getinput('galleryThemeThumbWidth'),
'thumbHeight' => $this->getinput('galleryThemeThumbHeight'),
'thumbMargin' => $this->getinput('galleryThemeThumbMargin'),
'thumbBorder' => $this->getinput('galleryThemeThumbBorder'),
'thumbBorderColor' => $this->getinput('galleryThemeThumbBorderColor'),
'thumbOpacity' => $this->getinput('galleryThemeThumbOpacity'),
'thumbShadows' => $this->getinput('galleryThemeThumbShadows'),
'thumbShadowsColor' => $this->getinput('galleryThemeThumbShadowsColor'),
'thumbRadius' => $this->getinput('galleryThemeThumbRadius'),
'legendHeight' => $this->getinput('galleryThemeLegendHeight'),
'legendAlign' => $this->getinput('galleryThemeLegendAlign'),
'legendTextColor' => $this->getinput('galleryThemeLegendTextColor'),
2021-04-05 08:59:24 +02:00
'legendBgColor' => $this->getinput('galleryThemeLegendBgColor'),
'style' => $fileCSS,
'version' => $this->getData(['module', $this->getUrl(0), 'config', 'version'])
2020-04-17 19:02:04 +02:00
]
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
$content = str_replace('#thumbAlign#',$this->getinput('galleryThemeThumbAlign'),$content );
2020-04-18 16:33:48 +02:00
$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 );
2020-04-18 19:18:34 +02:00
$content = str_replace('#thumbShadows#',$this->getinput('galleryThemeThumbShadows'),$content );
$content = str_replace('#thumbShadowsColor#',$this->getinput('galleryThemeThumbShadowsColor'),$content );
2020-06-03 09:07:00 +02:00
$content = str_replace('#thumbRadius#',$this->getinput('galleryThemeThumbRadius'),$content );
$content = str_replace('#legendAlign#',$this->getinput('galleryThemeLegendAlign'),$content );
2020-04-18 16:33:48 +02:00
$content = str_replace('#legendHeight#',$this->getinput('galleryThemeLegendHeight'),$content );
$content = str_replace('#legendTextColor#',$this->getinput('galleryThemeLegendTextColor'),$content );
$content = str_replace('#legendBgColor#',$this->getinput('galleryThemeLegendBgColor'),$content );
2021-04-05 08:59:24 +02:00
$success = file_put_contents($fileCSS, $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',
2021-04-05 08:59:24 +02:00
'notification' => $success !== FALSE ? 'Modifications enregistrées' : 'Modifications non enregistrées !',
'state' => $success !== FALSE
2020-04-19 13:07:01 +02:00
]);
2020-04-17 19:02:04 +02:00
}
// Valeurs en sortie
$this->addOutput([
'title' => "Thème",
2020-04-17 19:02:04 +02:00
'view' => 'theme',
'vendor' => [
'tinycolorpicker'
]
]);
}
2021-02-10 17:58:08 +01:00
}
class galleriesHelper extends helper {
/**
* Scan le contenu d'un dossier et de ses sous-dossiers
* @param string $dir Dossier à scanner
* @return array
*/
public static function scanDir($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, self::scanDir($dir . '/' . $fileInfos->getBasename()));
}
}
return $dirContent;
}
2021-02-25 07:53:57 +01:00
}