Gallery WIP

This commit is contained in:
fredtempez 2021-04-09 16:42:13 +02:00
parent 080a601c3f
commit 1c1a97c22a
6 changed files with 106 additions and 96 deletions

View File

@ -1608,7 +1608,7 @@ class common {
){
if(class_exists($parent)) {
$module = new $moduleId;
$module->update($parent);
// $module->update($parent);
}
}
}

View File

@ -149,61 +149,51 @@ class gallery extends common {
*/
private function update() {
// Mise à jour d'une version inférieure, la gallerye existe
if ($this->getData(['module', $this->getUrl(0)]) ) {
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
// Mise à jour d'une version inférieure, la gallery existe mais pas content
if ($this->getData(['module', $this->getUrl(0)]) &&
$this->getData(['module', $this->getUrl(0), 'content']) === NULL ) {
// 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
if (is_array($this->getData(['theme','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']);
}
} else {
//la galerie n'existe pas, initialiser le CSS
$this->initCss($this->getUrl(0));
$this->setData(['module', $this->getUrl(0), 'theme', $data]);
// Nom de la feuille de style
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $moduleId . '.css']);
} else {
// Theme par défaut
$this->init($this->geturl(0));
}
// Nouvelle version
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '3.0']);
}
}
/**
* Initialisation du thème d'un nouveau module
* Initialisation séparément les éléments absents
* Thème
* Config
* Content
*/
private function initCSS($moduleId) {
private function init($moduleId) {
// Variable commune
$fileCSS = self::DATADIRECTORY . $moduleId . '.css' ;
// Check la présence de la config
if ( $this->getData(['module', $moduleId, 'config']) === null ) {
// Check la présence du thème
if ( $this->getData(['module', $moduleId, 'theme']) === null ) {
require_once('module/gallery/ressource/defaultdata.php');
$this->setData(['module', $moduleId, 'config', [
'style' => $fileCSS,
'thumbAlign' => theme::$defaultData['thumbAlign'],
'thumbWidth' => theme::$defaultData['thumbWidth'],
'thumbHeight' => theme::$defaultData['thumbHeight'],
'thumbMargin' => theme::$defaultData['thumbMargin'],
'thumbBorder' => theme::$defaultData['thumbBorder'],
'thumbOpacity' => theme::$defaultData['thumbOpacity'],
'thumbBorderColor' => theme::$defaultData['thumbBorderColor'],
'thumbRadius' => theme::$defaultData['thumbRadius'],
'thumbShadows' => theme::$defaultData['thumbShadows'],
'thumbShadowsColor'=> theme::$defaultData['thumbShadowsColor'],
'legendHeight' => theme::$defaultData['legendHeight'],
'legendAlign' => theme::$defaultData['legendAlign'],
'legendTextColor' => theme::$defaultData['legendTextColor'],
'legendBgColor' => theme::$defaultData['legendBgColor'],
'versionData' => theme::$defaultData['versionData']
]]);
$this->setData(['module', $moduleId, 'theme', theme::$defaultTheme]);
}
// Check la présence de la feuille de style
if ( !file_exists(self::DATADIRECTORY . $moduleId . '.css')) {
@ -212,30 +202,40 @@ class gallery extends common {
mkdir (self::DATADIRECTORY, 0777, true);
}
// Nom de la feuille de style
$this->setData(['module', $moduleId, 'config', 'style', $fileCSS]);
$this->setData(['module', $moduleId, 'theme', 'style', $fileCSS]);
// Générer la feuille de 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', $moduleId, 'config', 'thumbAlign']),$content );
$content = str_replace('#thumbWidth#',$this->getData(['module', $moduleId, 'config', 'thumbWidth']),$content );
$content = str_replace('#thumbHeight#',$this->getData(['module', $moduleId, 'config', 'thumbHeight']),$content );
$content = str_replace('#thumbMargin#',$this->getData(['module', $moduleId, 'config', 'thumbMargin']),$content );
$content = str_replace('#thumbBorder#',$this->getData(['module', $moduleId, 'config', 'thumbBorder']),$content );
$content = str_replace('#thumbBorderColor#',$this->getData(['module', $moduleId, 'config', 'thumbBorderColor']),$content );
$content = str_replace('#thumbOpacity#',$this->getData(['module', $moduleId, 'config', 'thumbOpacity']),$content );
$content = str_replace('#thumbShadows#',$this->getData(['module', $moduleId, 'config', 'thumbShadows']),$content );
$content = str_replace('#thumbShadowsColor#',$this->getData(['module', $moduleId, 'config', 'thumbShadowsColor']),$content );
$content = str_replace('#thumbRadius#',$this->getData(['module', $moduleId, 'config', 'thumbRadius']),$content );
$content = str_replace('#legendAlign#',$this->getData(['module', $moduleId, 'config', 'legendAlign']),$content );
$content = str_replace('#legendHeight#',$this->getData(['module', $moduleId, 'config', 'legendHeight']),$content );
$content = str_replace('#legendTextColor#',$this->getData(['module', $moduleId, 'config', 'legendTextColor']),$content );
$content = str_replace('#legendBgColor#',$this->getData(['module', $moduleId, 'config', 'legendBgColor']),$content );
$content = str_replace('#thumbAlign#',$this->getData(['module', $moduleId, 'theme', 'thumbAlign']),$content );
$content = str_replace('#thumbWidth#',$this->getData(['module', $moduleId, 'theme', 'thumbWidth']),$content );
$content = str_replace('#thumbHeight#',$this->getData(['module', $moduleId, 'theme', 'thumbHeight']),$content );
$content = str_replace('#thumbMargin#',$this->getData(['module', $moduleId, 'theme', 'thumbMargin']),$content );
$content = str_replace('#thumbBorder#',$this->getData(['module', $moduleId, 'theme', 'thumbBorder']),$content );
$content = str_replace('#thumbBorderColor#',$this->getData(['module', $moduleId, 'theme', 'thumbBorderColor']),$content );
$content = str_replace('#thumbOpacity#',$this->getData(['module', $moduleId, 'theme', 'thumbOpacity']),$content );
$content = str_replace('#thumbShadows#',$this->getData(['module', $moduleId, 'theme', 'thumbShadows']),$content );
$content = str_replace('#thumbShadowsColor#',$this->getData(['module', $moduleId, 'theme', 'thumbShadowsColor']),$content );
$content = str_replace('#thumbRadius#',$this->getData(['module', $moduleId, 'theme', 'thumbRadius']),$content );
$content = str_replace('#legendAlign#',$this->getData(['module', $moduleId, 'theme', 'legendAlign']),$content );
$content = str_replace('#legendHeight#',$this->getData(['module', $moduleId, 'theme', 'legendHeight']),$content );
$content = str_replace('#legendTextColor#',$this->getData(['module', $moduleId, 'theme', 'legendTextColor']),$content );
$content = str_replace('#legendBgColor#',$this->getData(['module', $moduleId, 'theme', 'legendBgColor']),$content );
// Ecriture de la feuille de style
file_put_contents(self::DATADIRECTORY . $moduleId . '.css' , $content . $themeCss);
}
// Check Config
if ( $this->getData(['module', $moduleId, 'config']) === null ) {
require_once('module/gallery/ressource/defaultdata.php');
$this->setData(['module', $moduleId, 'config', theme::$defaultData]);
}
// Contenu vide de la galerie
if (!is_array($this->getData(['module', $this->getUrl(0), 'content'])) ) {
$this->setData(['module', $this->getUrl(0), 'content', array() ]);
}
}
@ -250,16 +250,16 @@ class gallery extends common {
for($i=0;$i<count($data);$i++) {
$this->setData(['module', $this->getUrl(0), 'content', $data[$i], [
'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']),
'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),$data[$i],'config','fullScreen'])
'fullScreen' => $this->getData(['module',$this->getUrl(0), 'content',$data[$i],'config','fullScreen'])
],
'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']),
'positions' => $this->getData(['module',$this->getUrl(0),$data[$i],'positions'])
'legend' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'legend']),
'positions' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'positions'])
]]);
}
}
@ -300,6 +300,11 @@ class gallery extends common {
// Mise à jour des données de module
$this->update();
// Initialisation d'un nouveau module
if ($this->getData(['module', $this->getUrl(0)]) === null) {
$this->init($this->getUrl(0));
}
//Affichage de la galerie triée
$g = $this->getData(['module', $this->getUrl(0), 'content']);
$p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position');
@ -583,6 +588,11 @@ class gallery extends common {
// Mise à jour des données de module
$this->update();
// Initialisation d'un nouveau module
if ($this->getData(['module', $this->getUrl(0)]) === null) {
$this->init($this->getUrl(0));
}
// Images d'une galerie
if($this->getUrl(1)) {
// La galerie n'existe pas
@ -641,7 +651,7 @@ class gallery extends common {
'showBarEditButton' => true,
'title' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(1), 'config', 'name']),
'view' => 'gallery',
'style' => $this->getData(['module', $this->getUrl(0), 'config', 'style'])
'style' => $this->getData(['module', $this->getUrl(0), 'theme', 'style'])
]);
}
// Pas d'image dans la galerie
@ -704,7 +714,7 @@ class gallery extends common {
'showBarEditButton' => true,
'showPageContent' => true,
'view' => 'index',
'style' => $this->getData(['module', $this->getUrl(0), 'config', 'style'])
'style' => $this->getData(['module', $this->getUrl(0), 'theme', 'style'])
]);
}
}
@ -730,7 +740,7 @@ class gallery extends common {
}
$fileCSS = self::DATADIRECTORY . $this->getUrl(0) . '.css' ;
// Fin feuille de style
$this->getData(['module', $this->getUrl(0), 'config', [
$this->getData(['module', $this->getUrl(0), 'theme', [
'thumbAlign' => $this->getinput('galleryThemeThumbAlign'),
'thumbWidth' => $this->getinput('galleryThemeThumbWidth'),
'thumbHeight' => $this->getinput('galleryThemeThumbHeight'),
@ -746,9 +756,7 @@ class gallery extends common {
'legendTextColor' => $this->getinput('galleryThemeLegendTextColor'),
'legendBgColor' => $this->getinput('galleryThemeLegendBgColor'),
'style' => $fileCSS,
'version' => $this->getData(['module', $this->getUrl(0), 'config', 'version'])
]
]);
]]);
// Création des fichiers CSS
$content = file_get_contents('module/gallery/ressource/vartheme.css');
$themeCss = file_get_contents('module/gallery/ressource/theme.css');

View File

@ -1,6 +1,6 @@
<?php
class theme extends gallery {
public static $defaultData = [
public static $defaultTheme = [
'thumbAlign' => 'center',
'thumbWidth' => '18em',
'thumbHeight' => '15em',
@ -14,7 +14,9 @@ class theme extends gallery {
'legendHeight' => '.375em',
'legendAlign' => 'center',
'legendTextColor' => 'rgba(255, 255, 255, 1)',
'legendBgColor' => 'rgba(0, 0, 0, .6)',
'versionData' => '3.0'
'legendBgColor' => 'rgba(0, 0, 0, .6)'
];
public static $defaultData = [
'versionData' => '3.0'
];
}

View File

@ -38,22 +38,22 @@
'selected' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'sort']),
'label' => 'Tri des images',
'help' => 'Tri manuel : déplacez le images dans le tableau ci-dessous. L\'ordre est sauvegardé automatiquement.'
]); ?>
]); ?>
</div>
<div clas="row">
<div class="col12">
<?php echo template::checkbox('galleryEditFullscreen', true, 'Mode plein écran automatique' , [
'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'fullScreen']),
'help' => 'A l\'ouverture de la galerie, la première image est affichée en plein écran.'
]); ?>
</div>
]); ?>
</div>
</div>
<div class="row">
<div class="col12">
<?php if($module::$pictures): ?>
<?php echo template::table([1, 4, 1, 5, 1], $module::$pictures, ['','Image', 'Couverture','Légende',''],['id' => 'galleryTable'], $module::$picturesId ); ?>
<?php echo template::hidden('galleryEditFormResponse'); ?>
<?php echo template::hidden('galleryEditFormGalleryName',['value' => $this->getUrl(2)]); ?>
<?php echo template::hidden('galleryEditFormGalleryName',['value' => $this->getUrl(2)]); ?>
<?php else: ?>
<?php echo template::speech('Aucune image.'); ?>
<?php endif; ?>

View File

@ -13,7 +13,7 @@
<div class="colPicture">
<a
href="<?php echo helper::baseUrl(false) . $picture; ?>"
<?php if ( $picture === $this->getdata(['module',$this->getUrl(0),$this->getUrl(1),'config','homePicture']) ) {
<?php if ( $picture === $this->getdata(['module',$this->getUrl(0),'content',$this->getUrl(1),'config','homePicture']) ) {
echo 'id="homePicture"'; } ?>
class="galleryGalleryPicture"
style="background-image:url('<?php echo helper::baseUrl(false) . $module::$thumbs[$picture]; ?>')"

View File

@ -25,25 +25,25 @@
<div class="col3">
<?php echo template::select('galleryThemeThumbWidth', $module::$galleryThemeSizeWidth, [
'label' => 'Largeur',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbWidth'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbWidth'])
]); ?>
</div>
<div class="col3">
<?php echo template::select('galleryThemeThumbHeight', $module::$galleryThemeSizeHeight, [
'label' => 'Hauteur',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbHeight'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbHeight'])
]); ?>
</div>
<div class="col4">
<?php echo template::select('galleryThemeThumbAlign', $module::$galleryThemeFlexAlign, [
'label' => 'Alignement',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbAlign'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbAlign'])
]); ?>
</div>
<div class="col2">
<?php echo template::select('galleryThemeThumbMargin', $module::$galleryThemeMargin, [
'label' => 'Marge',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbMargin'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbMargin'])
]); ?>
</div>
</div>
@ -51,7 +51,7 @@
<div class="col4">
<?php echo template::select('galleryThemeThumbBorder', $module::$galleryThemeBorder, [
'label' => 'Bordure',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbBorder'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbBorder'])
]); ?>
</div>
<div class="col4">
@ -59,13 +59,13 @@
'class' => 'colorPicker',
'help' => 'Le curseur horizontal règle le niveau de transparence.',
'label' => 'Couleur de la bordure',
'value' => $this->getData(['module', $this->getUrl(0), 'config','thumbBorderColor'])
'value' => $this->getData(['module', $this->getUrl(0), 'theme','thumbBorderColor'])
]); ?>
</div>
<div class="col4">
<?php echo template::select('galleryThemeThumbRadius', $module::$galleryThemeRadius, [
'label' => 'Arrondi des angles',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbRadius'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbRadius'])
]); ?>
</div>
</div>
@ -73,7 +73,7 @@
<div class="col4">
<?php echo template::select('galleryThemeThumbShadows', $module::$galleryThemeShadows, [
'label' => 'Ombre',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbShadows'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbShadows'])
]); ?>
</div>
<div class="col4">
@ -81,13 +81,13 @@
'class' => 'colorPicker',
'help' => 'Le curseur horizontal règle le niveau de transparence.',
'label' => 'Couleur de l\'ombre',
'value' => $this->getData(['module', $this->getUrl(0), 'config','thumbShadowsColor'])
'value' => $this->getData(['module', $this->getUrl(0), 'theme','thumbShadowsColor'])
]); ?>
</div>
<div class="col4">
<?php echo template::select('galleryThemeThumbOpacity', $module::$galleryThemeOpacity, [
'label' => 'Opacité au survol',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','thumbOpacity'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','thumbOpacity'])
]); ?>
</div>
</div>
@ -108,7 +108,7 @@
'class' => 'colorPicker',
'help' => 'Le curseur horizontal règle le niveau de transparence.',
'label' => 'Texte',
'value' => $this->getData(['module', $this->getUrl(0), 'config','legendTextColor'])
'value' => $this->getData(['module', $this->getUrl(0), 'theme','legendTextColor'])
]); ?>
</div>
<div class="col3">
@ -116,19 +116,19 @@
'class' => 'colorPicker',
'help' => 'Le curseur horizontal règle le niveau de transparence.',
'label' => 'Fond',
'value' => $this->getData(['module', $this->getUrl(0), 'config','legendBgColor'])
'value' => $this->getData(['module', $this->getUrl(0), 'theme','legendBgColor'])
]); ?>
</div>
<div class="col3">
<?php echo template::select('galleryThemeLegendHeight', $module::$galleryThemeLegendHeight, [
'label' => 'Hauteur',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','legendHeight'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','legendHeight'])
]); ?>
</div>
<div class="col3">
<?php echo template::select('galleryThemeLegendAlign', $module::$galleryThemeAlign, [
'label' => 'Alignement',
'selected' => $this->getData(['module', $this->getUrl(0), 'config','legendAlign'])
'selected' => $this->getData(['module', $this->getUrl(0), 'theme','legendAlign'])
]); ?>
</div>
</div>