}
$this->config->product_zoom_references = [];
- $files = ['360°', 'Image supplémentaire', 'Fiche technique'];
+ $fileCols = ['360°', 'Image supplémentaire', 'Fiche technique'];
foreach ($this->config->basketReferences as $ref => $data) {
$r = [];
- foreach ($files as $file) {
- if (!isset($data[$file])) {
- $data[$file] = '';
- }
- $fname = trim($data[$file]);
- if ($fname !== '') {
- $fname = str_replace(' ', '-', $fname);
- $wfile = $this->wdir . 'commerce/' . $fname;
+ foreach ($fileCols as $col) {
+ $slides = [];
+ $button = '';
+ if (!isset($data[$col]) || !trim($data[$col])) {
+ $files = [];
+ $this->config->basketReferences[$ref][$col] = '';
+ } else {
+ $files = explode(',', $data[$col]);
- if (file_exists($wfile)) {
+ $files = array_map(function ($v) {
+ return str_replace([' ', '(', ')'], ['-', '', ''], trim($v));
+ }, $files);
+
+ $files = array_filter($files, function ($v) {
+ if (!$v) {
+ return false;
+ }
+ return file_exists($this->wdir . 'commerce/' . $v);
+ });
+
+ foreach ($files as $fname) {
+ $wfile = $this->wdir . 'commerce/' . $fname;
if (stristr($wfile, '.png') || stristr($wfile, '.jpg')) {
$s = CubeIT_Image::getimagesize($wfile);
- $html = '<img src="data/commerce/' . $fname . '" style="background:white;" data-width="' . $s[0] . '" data-height="' . $s[1] . '" />';
+ if (count($files) <= 1) {
+ $button .= '<img src="data/commerce/' . $fname . '" style="background:white;" data-width="' . $s[0] . '" data-height="' . $s[1] . '" />';
+ } else {
+ $slides[] = ['path' => 'data/commerce/' . $fname, 'absolute_path' => $wfile];
+ }
} else {
- $html = 'data/commerce/' . $fname;
+ $button = 'data/commerce/' . $fname;
}
$this->vdir->copy($wfile, 'data/commerce/' . $fname);
- $fname = $html;
- } else {
- $fname = '';
}
}
- $r[] = $fname;
+ if (count($files) > 1) {
+ $button = slideshowLink::generateSlideshowHtml($slides, [], ['type' => 'loop']);
+ $this->addSlideshowLibrary(false);
+ }
+ $r[] = $button;
}
+
$this->config->product_zoom_references[$ref] = $r;
}
}
}
-
$this->config->pagesOfCustomLinks = $pagesOfCustomLinks;
$i = 1;
$allLinksData = [];
$gamifyCoins = [];
-
usort($links, array($this, '_sortLinks'));
- $this->log('Links 3.5');
-
foreach ($links as $linkData) {
+
if (in_array($linkData['type'], $ignore)) {
continue;
}
$linksToAdd[] = $link->getRightClone();
}
+
foreach ($linksToAdd as $lta) {
/** @var $lta wsLink */
// Keep this line because some properties of the link (like blend mode) are parsed with this function
if ($link->keep()) {
$this->hiddenContents[] = $link->getHTMLContainer();
}
- $this->log('Links 4 :: ' . $link->to);
}
$this->log('Links 4');
return 'data-slideshow="' . rawurlencode($this->generateSlideshow('popup')) . '" ';
}
-// public function keep() {
-// return true;
-// }
-
public function getDefaultTooltip()
{
return 'view slideshow';
$slideshowID = 'slideshow_' . $this->uid;
$XML_path = $this->path_absolute . '/slideshow.xml'; // Optional file so it may not exist
- // Default Slick settings (can be overridden by slideshow.xml)
- $slideshow_settings = [
- 'autoplay' => false,
- 'fade' => false,
- ];
-
-
$slides = [];
$slides_options = [];
$thumbnails = (count($slides) > 1);
}
+ $options = ['openIndex' => $this->extra,
+ 'thumbnails' => $thumbnails,
+ 'thumbnail_height' => $this->thumbnail_height,
+ 'id' => $slideshowID,
+ 'library' => ($context === 'popup' ? $this->compiler->book->parametres->popupSlideshowLibrary : $this->compiler->book->parametres->inlineSlideshowLibrary)
+ ];
+
+ return self::generateSlideshowHtml($slides, $options, $slideshow_settings, $slides_options);
+
+ }
+
+
+ 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="' . $slideshowID . '" data-open-index="' . $this->extra . '" data-thumbnails="' . ($thumbnails ? '1' : '0') . '" data-splide=\'' . json_encode($slideshow_settings) . '\'>' . $this->_slides($slides, $slides_options) . '</div>';
+ $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 ($thumbnails) {
- $res .= '<div class="fb-slideshow-thumbnails splide" id="' . $slideshowID . '_thumbnails">' . $this->_slides($slides, ['show_captions' => false, 'max_height' => $this->thumbnail_height]) . '</div>';
+ 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>';
}
-
- $lib = $context === 'popup' ? $this->compiler->book->parametres->popupSlideshowLibrary : $this->compiler->book->parametres->inlineSlideshowLibrary;
- return '<div class="fb-slideshow-wrapper ' . $lib . ' fb-slideshow-' . $context . '">' . $res . '</div>';
+ return '<div class="fb-slideshow-wrapper ' . $options['library'] . ' fb-slideshow-' . $options['library'] . '">' . $res . '</div>';
}
protected function _getSlidesFromDirectory($path)
if (!in_array($ext, $this->allowed_extensions)) {
continue;
}
- $slides[] = ['path' => $this->path . '/' . $file->getFilename(), 'absolute_path' => $file->getPathname(), 'caption' => null];
+ $slides[] = ['path' => $this->path . '/' . $file->getFilename(), 'absolute_path' => $file->getPathname(), 'caption' => null];
uasort($slides, [$this, '_orderSlidesByFilename']);
}
return $slides;
}
- protected function _slides($slides, $options = [])
+ 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) {
+ $slide = array_merge($defaultSlide, $slide);
$image_info = CubeIT_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 && isset($image_info[3])) ? $image_info[3] : '';
}
$res .= '<li class="fb-slideshow-slide splide__slide">';
- //$res .= '<div class="splide__slide__container">';
$res .= '<img class="fb-slideshow-slide-image" src="' . $slide['path'] . '" data-meta="' . htmlspecialchars($image_info_json, ENT_QUOTES) . '" ' . $image_dimensions . '>';
- //$res .= '</div>'; // .splide__slide__container
if ($options['show_captions'] && null !== $slide['caption']) {
return $res;
}
-
protected function _orderSlidesByFilename($a, $b)
{
return strcmp($a['path'], $b['path']);