]> _ Git - fluidbook_tools.git/commitdiff
wait #6848 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 3 Apr 2024 16:37:15 +0000 (18:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 3 Apr 2024 16:37:15 +0000 (18:37 +0200)
src/Links/ImageLink.php
src/Links/SlideshowLink.php

index e765bd0905dc05e436be1b30c78bd68d74855fce..9a96708c0dc6f646b68c731e851a6e0a820483a2 100644 (file)
@@ -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;
     }
 
index 602831ed6ed0d8f939352623d466516fe7cf285b..f9c3de5ffdaea2cb7da63720d6804d2f76de8d68 100644 (file)
@@ -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 = '<div class="fb-slideshow splide" id="' . $options['id'] . '" data-open-index="' . $options['openIndex'] . '" data-thumbnails="' . ($options['thumbnails'] ? '1' : '0') . '" data-splide=\'' . json_encode($slideshowSettings) . '\'>' . self::_slides($slides, $slidesOptions) . '</div>';
+
+        // Thumbnails slider
+        if ($options['thumbnails']) {
+            $res .= '<div class="fb-slideshow-thumbnails splide" id="' . $options['id'] . '_thumbnails">' . self::_slides($slides, ['show_captions' => false, 'max_height' => $options['thumbnail_height']]) . '</div>';
+        }
+        return '<div class="fb-slideshow-wrapper ' . $options['library'] . ' fb-slideshow-' . $options['library'] . '">' . $res . '</div>';
+    }
+
     /**
      * @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 = '<div class="fb-slideshow splide" data-name="' . $this->baseName . '" id="' . $slideshowID . '" data-open-index="' . $this->extra . '" data-thumbnails="' . ($thumbnails ? '1' : '0') . '" data-splide=\'' . json_encode($slideshow_settings) . '\'>' . $this->_slides($slides, $slides_options) . '</div>';
-
-        // Thumbnails slider
-        if ($thumbnails) {
-            $res .= '<div class="fb-slideshow-thumbnails splide" id="' . $slideshowID . '_thumbnails">' . $this->_slides($slides, ['show_captions' => false, 'max_height' => $this->thumbnail_height]) . '</div>';
-        }
-
-        $lib = $context === 'popup' ? $this->compiler->getSetting('popupSlideshowLibrary', 'splide') : $this->compiler->getSetting('inlineSlideshowLibrary', 'dummy');
-        $res = '<div class="fb-slideshow-wrapper ' . $lib . ' fb-slideshow-' . $context . '">' . $res . '</div>';
+        $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 = '<div class="splide__track">';
         $res .= '<ul class="splide__list">';
 
         foreach ($slides as $slide) {
-            $s = new \SplFileInfo($slide['path']);
-            $image_path_relative = $this->path . '/' . $s->getFilename();
-
-            $image_info = Image::getimagesize($slide['path']);
+            $slide = array_merge($defaultSlide, $slide);
+            $image_info = Image::getimagesize($slide['absolute_path']);
             $image_info_json = ($image_info) ? json_encode(['width' => $image_info[0], 'height' => $image_info[1], 'ratio' => round($image_info[0] / $image_info[1], 4)]) : '';
-
-            $image_dimensions = ($image_info) ? $image_info[3] : '';
+            $image_dimensions = ($image_info && isset($image_info[3])) ? $image_info[3] : '';
 
             // When displaying thumbnails, they are a fixed size, based on height
             // We set dimensions here to avoid extra work on the client side
@@ -189,9 +217,7 @@ class SlideshowLink extends NormalLink
             }
 
             $res .= '<li class="fb-slideshow-slide splide__slide">';
-            //$res .= '<div class="splide__slide__container">';
-            $res .= '<img class="fb-slideshow-slide-image" src="' . $image_path_relative . '" data-meta="' . htmlspecialchars($image_info_json, ENT_QUOTES) . '" ' . $image_dimensions . '>';
-            //$res .= '</div>'; // .splide__slide__container
+            $res .= '<img class="fb-slideshow-slide-image" src="' . $slide['path'] . '" data-meta="' . htmlspecialchars($image_info_json, ENT_QUOTES) . '" ' . $image_dimensions . '>';
 
             if ($options['show_captions'] && null !== $slide['caption']) {