array_pop($e);
$this->baseName = implode('.', $e);
-
$this->copyExternalDir($d['dir'], $d['fdir']);
$this->path = $d['fdir'];
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
*/
{
$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
$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];
}
}
$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);
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']);
}
}
- protected function _slides($slides, $options = [])
+ /**
+ * @throws \Exception
+ */
+ protected static function _slides($slides, $options = [])
{
$default_options = [
'show_captions' => true,
$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
}
$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']) {