From 2ebe9c4b6a80e35b1835973fb3352be742959e13 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 3 Apr 2024 18:37:15 +0200 Subject: [PATCH] wait #6848 @1.5 --- src/Links/ImageLink.php | 3 +- src/Links/SlideshowLink.php | 78 ++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src/Links/ImageLink.php b/src/Links/ImageLink.php index e765bd0..9a96708 100644 --- a/src/Links/ImageLink.php +++ b/src/Links/ImageLink.php @@ -21,9 +21,10 @@ class ImageLink extends ContentLink { $res = parent::getAdditionnalContent(); $res .= ' data-image="' . $this->getImageUrl() . '"'; - if (isset($this->rollover)) { + if (isset($this->rollover) && $this->rollover) { $res .= ' data-rollover="' . $this->rollover . '"'; } + $res.=' data-rrr="1" '; return $res; } diff --git a/src/Links/SlideshowLink.php b/src/Links/SlideshowLink.php index 602831e..f9c3de5 100644 --- a/src/Links/SlideshowLink.php +++ b/src/Links/SlideshowLink.php @@ -28,7 +28,6 @@ class SlideshowLink extends NormalLink array_pop($e); $this->baseName = implode('.', $e); - $this->copyExternalDir($d['dir'], $d['fdir']); $this->path = $d['fdir']; @@ -47,6 +46,37 @@ class SlideshowLink extends NormalLink return 'view slideshow'; } + public static function generateSlideshowHtml($slides, $options = [], $slideshowSettings = [], $slidesOptions = []) + { + // Default Slick settings (can be overridden by slideshow.xml) + $slideshowDefaultSettings = [ + 'autoplay' => false, + 'fade' => false, + 'type' => 'slide', + 'rewind' => false, + ]; + + $defaultOptions = [ + 'library' => 'splide', + 'openIndex' => 0, + 'thumbnails' => false, + 'id' => 'slideshow_' . rand(1000, 1000000), + 'context' => 'popup', + 'thumbnail_height' => 80, + ]; + $options = array_merge($defaultOptions, $options); + $slideshowSettings = array_merge($slideshowDefaultSettings, $slideshowSettings); + + // Main slider + $res = '
' . self::_slides($slides, $slidesOptions) . '
'; + + // Thumbnails slider + if ($options['thumbnails']) { + $res .= '
' . self::_slides($slides, ['show_captions' => false, 'max_height' => $options['thumbnail_height']]) . '
'; + } + return '
' . $res . '
'; + } + /** * @throws \Exception */ @@ -54,7 +84,7 @@ class SlideshowLink extends NormalLink { $this->compiler->addSlideshowLibrary($context === 'inline'); - $this->allowed_extensions = ['jpg', 'png', 'jpeg', 'gif', 'svg']; + $this->allowed_extensions = ['jpg', 'png', 'jpeg', 'gif', 'svg', 'webp', 'avif']; $slideshowID = 'slideshow_' . $this->uid; $XML_path = $this->path_absolute . '/slideshow.xml'; // Optional file so it may not exist @@ -102,8 +132,7 @@ class SlideshowLink extends NormalLink $images = [$slideshowData->image]; } foreach ($images as $img) { - $full_path = $this->path_absolute . '/' . $img->_name; - $slides[] = ['caption' => $img->_caption, 'path' => $full_path]; + $slides[] = ['caption' => $img->_caption, 'path' => $this->path . '/' . $img->_name, 'absolute_path' => $this->path_absolute . '/' . $img->_name]; } } @@ -120,20 +149,17 @@ class SlideshowLink extends NormalLink $thumbnails = (count($slides) > 1); } - // Main slider - $res = '
' . $this->_slides($slides, $slides_options) . '
'; - - // Thumbnails slider - if ($thumbnails) { - $res .= '
' . $this->_slides($slides, ['show_captions' => false, 'max_height' => $this->thumbnail_height]) . '
'; - } - - $lib = $context === 'popup' ? $this->compiler->getSetting('popupSlideshowLibrary', 'splide') : $this->compiler->getSetting('inlineSlideshowLibrary', 'dummy'); - $res = '
' . $res . '
'; + $options = ['openIndex' => $this->extra, + 'thumbnails' => $thumbnails, + 'thumbnail_height' => $this->thumbnail_height, + 'id' => $slideshowID, + 'library' => ($context === 'popup' ? $this->compiler->getSetting('popupSlideshowLibrary', 'splide') : $this->compiler->getSetting('inlineSlideshowLibrary', 'dummy')) + ]; - return $res; + return self::generateSlideshowHtml($slides, $options, $slideshow_settings, $slides_options); } + protected function _getSlidesFromDirectory($path) { $files = Files::getRecursiveDirectoryIterator($path); @@ -151,7 +177,7 @@ class SlideshowLink extends NormalLink if (!in_array($ext, $this->allowed_extensions)) { continue; } - $slides[] = ['path' => $file->getPathname(), 'caption' => null]; + $slides[] = ['path' => $this->path . '/' . $file->getFilename(), 'absolute_path' => $file->getPathname(), 'caption' => null]; uasort($slides, [$this, '_orderSlidesByFilename']); } @@ -159,7 +185,10 @@ class SlideshowLink extends NormalLink } - protected function _slides($slides, $options = []) + /** + * @throws \Exception + */ + protected static function _slides($slides, $options = []) { $default_options = [ 'show_captions' => true, @@ -169,17 +198,16 @@ class SlideshowLink extends NormalLink $options = array_merge($default_options, $options); + $defaultSlide = ['caption' => null]; + $res = '
'; $res .= '