homePicture et miniatures dans la galerie WIP

This commit is contained in:
Fred Tempez 2020-04-05 18:02:34 +02:00
parent 232e0312fc
commit d235f78689
4 changed files with 47 additions and 17 deletions

View File

@ -0,0 +1,17 @@
/**
* 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>
* @copyright Copyright (C) 2018-2020, Frédéric Tempez
* @license GNU General Public License, version 3
* @link http://zwiicms.com/
*/
@import url("core/layout/admin.css");

View File

@ -39,8 +39,11 @@ class gallery extends common {
public static $pictures = [];
const GALLERY_VERSION = '2.0';
public static $thumbs = [];
const THUMBS_SEPARATOR = 'mini_';
const GALLERY_VERSION = '2.0';
public function filter() {
@ -116,11 +119,24 @@ class gallery extends common {
self::filter();
} else {
$galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)]));
// La première image est celle de la couverture de l'album
$directory = $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true);
$iterator = new DirectoryIterator($directory);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
// Miniatures
$homePicture = file_exists( str_replace('source','thumb',$directory) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))
? self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename())
: strtolower($fileInfos->getFilename());
break;
}
}
$this->setData(['module', $this->getUrl(0), $galleryId, [
'config' => [
'name' => $this->getInput('galleryConfigName'),
'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => '',
'homePicture' => $homePicture,
'sort' => $this->getInput('galleryConfigSort'),
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
],
@ -225,16 +241,13 @@ class gallery extends common {
$legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT);
}
// Photo de la page de garde de l'album
$homePictures = [];
foreach((array) $this->getInput('homePicture', null) as $file => $homePicture) {
// null : pas de variable définie (compatibilité) ou choix non effectif
$homePictures[$file] = $file === 0 ? null : helper::filter($file, helper::FILTER_STRING_SHORT) ;
}
$homePicture = array_keys($this->getInput('homePicture', null));
// Sauvegarder
$this->setData(['module', $this->getUrl(0), $galleryId, [
'config' => [
'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true),
'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => $homePictures[$file],
'homePicture' => $homePicture[0],
'sort' => $this->getInput('galleryEditSort'),
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
],
@ -309,6 +322,10 @@ class gallery extends common {
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), $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]);
// Miniatures
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());
}
}
// Tri des images par ordre alphabétique
@ -363,7 +380,9 @@ class gallery extends common {
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
self::$galleries[$galleryId] = $gallery;
self::$firstPictures[$galleryId] = $gallery['config']['directory'] . '/' . $fileInfos->getFilename();
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']);
continue(2);
}
}

View File

@ -18,7 +18,7 @@
<a
href="<?php echo helper::baseUrl(false) . $picture; ?>"
class="galleryGalleryPicture"
style="background-image:url('<?php echo helper::baseUrl(false) . $picture; ?>')"
style="background-image:url('<?php echo helper::baseUrl(false) . $module::$thumbs[$picture]; ?>')"
data-caption="<?php echo $legend; ?>"
>
<?php if($legend): ?>

View File

@ -9,13 +9,7 @@
<a
href="<?php echo helper::baseUrl() . $this->getUrl(0); ?>/<?php echo $galleryId; ?>"
class="galleryPicture"
style="background-image:url('<?php
if ($this->getData(['module', $this->getUrl(0), $galleryId, 'config', 'homePicture']) === null ) {
echo helper::baseUrl(false) . $module::$firstPictures[$galleryId];
} else {
echo helper::baseUrl(false) . $this->getData(['module', $this->getUrl(0), $galleryId, 'config', 'directory']) . '/' . $this->getData(['module', $this->getUrl(0), $galleryId, 'config', 'homePicture']);
}
?>')"
style="background-image:url('<?php echo $module::$firstPictures[$galleryId];?>')"
>
<div class="galleryName"><?php echo $gallery['config']['name']; ?></div>
</a>