| 1 |
<?php |
| 2 |
|
| 3 |
namespace Photonic_Plugin\Layouts; |
| 4 |
|
| 5 |
use Photonic_Plugin\Components\Photo_List; |
| 6 |
use Photonic_Plugin\Platforms\Base; |
| 7 |
|
| 8 |
require_once 'Level_One_Gallery.php'; |
| 9 |
|
| 10 |
/** |
| 11 |
* Generates the slideshow layout for level 1 objects. Level 2 cannot be displayed as slideshows. |
| 12 |
*/ |
| 13 |
class Slideshow extends Core_Layout implements Level_One_Gallery { |
| 14 |
protected function __construct() { |
| 15 |
global $photonic_slideshow_interval; |
| 16 |
|
| 17 |
$this->common_parameters = [ |
| 18 |
'fx' => 'slide', // Splide effects: fade and slide |
| 19 |
'timeout' => !empty($photonic_slideshow_interval) && is_numeric($photonic_slideshow_interval) ? $photonic_slideshow_interval : 5000, // Time between slides in ms |
| 20 |
'speed' => 1000, // Time for each transition |
| 21 |
'pause' => true, // Pause on hover |
| 22 |
'strip-style' => 'thumbs', |
| 23 |
'controls' => 'show', |
| 24 |
]; |
| 25 |
parent::__construct(); |
| 26 |
} |
| 27 |
|
| 28 |
public function generate_level_1_gallery(Photo_List $photo_list, array $short_code, Base $module): string { |
| 29 |
$photos = $photo_list->photos; |
| 30 |
if (empty($photos)) { |
| 31 |
return ''; |
| 32 |
} |
| 33 |
|
| 34 |
$short_code = array_merge($this->common_parameters, $short_code); |
| 35 |
|
| 36 |
global $photonic_wp_slide_adjustment, $photonic_slideshow_interval; |
| 37 |
|
| 38 |
$style = esc_attr(empty($short_code['style']) ? (empty($short_code['layout']) ? '' : $short_code['layout']) : $short_code['style']); |
| 39 |
$title_position = esc_attr(empty($short_code['title_position']) ? $photo_list->title_position : $short_code['title_position']); |
| 40 |
|
| 41 |
global $photonic_slideshow_prevent_autostart; |
| 42 |
if ('wp' === $module->provider) { |
| 43 |
$pager_position = !empty($short_code['style']) ? $short_code['style'] : $short_code['layout']; |
| 44 |
} |
| 45 |
else { |
| 46 |
$pager_position = $short_code['layout']; |
| 47 |
} |
| 48 |
$pager_position = esc_attr($pager_position); |
| 49 |
|
| 50 |
$perPage = (empty($short_code['columns']) || 'auto' === $short_code['columns'] || !is_numeric($short_code['columns'])) ? 1 : $short_code['columns']; |
| 51 |
$splide_options = [ |
| 52 |
'type' => (!empty($short_code['fx']) && 'fade' === $short_code['fx']) ? 'fade' : 'loop', |
| 53 |
'perPage' => esc_attr($perPage), |
| 54 |
'autoplay' => !(isset($photonic_slideshow_prevent_autostart) && 'on' === $photonic_slideshow_prevent_autostart), |
| 55 |
'interval' => esc_attr((empty($short_code['timeout']) || !is_numeric($short_code['timeout'])) ? (empty($photonic_slideshow_interval) || !is_numeric($photonic_slideshow_interval) ? 5000 : $photonic_slideshow_interval) : $short_code['timeout']), |
| 56 |
'speed' => esc_attr((empty($short_code['speed']) || !is_numeric($short_code['speed'])) ? 1000 : $short_code['speed']), |
| 57 |
'drag' => true, |
| 58 |
'pauseOnHover' => !(0 === $short_code['pause'] || '0' === $short_code['pause']), |
| 59 |
'pagination' => ('strip-below' === $pager_position || 'strip-right' === $pager_position) && 'button' === $short_code['strip-style'], |
| 60 |
'slideFocus' => false, |
| 61 |
// 'updateOnMove' => true, |
| 62 |
'arrows' => empty($short_code['controls']) || 'hide' !== $short_code['controls'], |
| 63 |
// 'cover' => $photonic_wp_slide_adjustment !== 'side-white' && $photonic_wp_slide_adjustment !== 'adapt-height', |
| 64 |
// 'heightRatio' => ($photonic_wp_slide_adjustment !== 'side-white' && $photonic_wp_slide_adjustment !== 'adapt-height') ? 0.5 : 0, |
| 65 |
'direction' => 'ltr', |
| 66 |
'breakpoints' => [ |
| 67 |
480 => [ |
| 68 |
'perPage' => 1, |
| 69 |
] |
| 70 |
], |
| 71 |
]; |
| 72 |
|
| 73 |
$splide_options = esc_attr(wp_json_encode($splide_options)); |
| 74 |
$ret = ''; |
| 75 |
if ('strip-above' === $pager_position && 'thumbs' === $short_code['strip-style']) { |
| 76 |
// $ret .= $this->get_thumbnails($photos, $module); |
| 77 |
$ret .= $this->get_secondary_slider($photos, $module); |
| 78 |
} |
| 79 |
|
| 80 |
$ret .= "<div id='photonic-slideshow-$module->provider-$module->gallery_index' class='photonic-slideshow splide $style title-display-$title_position photonic-slideshow-" . esc_attr($photonic_wp_slide_adjustment) . "' data-splide='$splide_options'>\n"; |
| 81 |
|
| 82 |
$ret .= "\t<div class='splide__track'>\n"; |
| 83 |
// $ret .= "\t\t<ul class='photonic-slideshow-content splide__list' $data_attr>\n"; |
| 84 |
$ret .= "\t\t<ul class='photonic-slideshow-content splide__list'>\n"; |
| 85 |
|
| 86 |
foreach ($photos as $photo) { |
| 87 |
// $ret .= "\t\t\t<li class='photonic-slideshow-img splide__slide' data-thumb='{$photo->thumbnail}'>\n"; |
| 88 |
$ret .= "\t\t\t<li class='photonic-slideshow-img splide__slide'>\n"; |
| 89 |
$title = esc_attr(wp_kses_post($photo->title)); |
| 90 |
$alt = esc_attr(wp_kses_post($photo->alt_title)); |
| 91 |
$description = esc_attr(wp_kses_post($photo->description)); |
| 92 |
|
| 93 |
$titles = [ |
| 94 |
'title' => $title, |
| 95 |
'desc' => $description, |
| 96 |
'alt' => $alt, |
| 97 |
]; |
| 98 |
|
| 99 |
$title = $this->get_title($title, $titles, $short_code); |
| 100 |
|
| 101 |
$ret .= "\t\t\t\t<div class='splide__slide__container'>\n"; |
| 102 |
if (empty($photo->video)) { |
| 103 |
if ('tooltip' === $title_position) { |
| 104 |
$tooltip = 'data-photonic-tooltip="' . $title . '" '; |
| 105 |
} |
| 106 |
else { |
| 107 |
$tooltip = ''; |
| 108 |
} |
| 109 |
$ret .= "\t\t\t\t<img src='" . esc_url($photo->main_image) . "' alt='$alt' title='" . (('regular' === $title_position || 'tooltip' === $title_position) ? $title : '') . "' $tooltip id='photonic-slideshow-$module->provider-$module->gallery_index-$photo->id' />\n"; |
| 110 |
} |
| 111 |
else { |
| 112 |
$ret .= "\t\t\t\t<video controls loop><source src='" . esc_url($photo->video) . "' type='video/mp4'><img src='" . esc_url($photo->main_image) . "' alt=''></video>"; |
| 113 |
} |
| 114 |
|
| 115 |
$shown_title = ''; |
| 116 |
if (in_array($title_position, ['below', 'hover-slideup-show', 'hover-slidedown-show', 'slideup-stick'], true) && !empty($title)) { |
| 117 |
$shown_title = "\t\t\t\t" . '<div class="photonic-title-info">' . "\n\t\t\t\t" . '<div class="photonic-photo-title photonic-title">' . wp_specialchars_decode($title, ENT_QUOTES) . '</div>' . "\n\t\t\t" . '</div>' . "\n"; |
| 118 |
} |
| 119 |
|
| 120 |
if (!empty($title)) { |
| 121 |
$ret .= $shown_title; |
| 122 |
} |
| 123 |
|
| 124 |
$ret .= "\t\t\t\t</div>\n"; // .splide__slide__container |
| 125 |
$ret .= "\t\t\t</li>\n"; // .splide__slide |
| 126 |
} |
| 127 |
$ret .= "\t\t</ul>\n"; // .splide__list |
| 128 |
$ret .= "\t</div><!-- splide__track -->\n"; |
| 129 |
|
| 130 |
$ret .= "</div><!-- .photonic-slideshow-->\n"; |
| 131 |
|
| 132 |
if (('strip-below' === $pager_position || 'strip-right' === $pager_position) && 'thumbs' === $short_code['strip-style']) { |
| 133 |
$ret .= $this->get_secondary_slider($photos, $module); |
| 134 |
} |
| 135 |
return $ret; |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* @param array $photos |
| 140 |
* @param Base $module |
| 141 |
* @return string |
| 142 |
*/ |
| 143 |
private function get_secondary_slider(array $photos, Base $module): string { |
| 144 |
$thumb_options = [ |
| 145 |
'fixedWidth' => 100, |
| 146 |
'height' => 60, |
| 147 |
'gap' => 10, |
| 148 |
'cover' => true, |
| 149 |
'isNavigation' => true, |
| 150 |
'pagination' => false, |
| 151 |
'arrows' => false, |
| 152 |
// 'focus' => 'center', |
| 153 |
'breakpoints' => [ |
| 154 |
'600' => [ |
| 155 |
'fixedWidth' => 66, |
| 156 |
'height' => 40, |
| 157 |
], |
| 158 |
], |
| 159 |
]; |
| 160 |
$thumb_options = esc_attr(wp_json_encode($thumb_options)); |
| 161 |
|
| 162 |
$ret = "<div id='photonic-slideshow-$module->provider-$module->gallery_index-thumbs' class='photonic-slideshow-thumbs splide thumbnails js-thumbnails' data-splide='$thumb_options'>\n"; |
| 163 |
$ret .= "\t<div class='splide__track'>\n"; |
| 164 |
$ret .= "\t<ul class='splide__list'>\n"; |
| 165 |
foreach ($photos as $photo) { |
| 166 |
$ret .= "\t\t<li class='splide__slide' tabindex='0'>\n"; |
| 167 |
$ret .= "\t\t\t<img src='" . esc_url($photo->thumbnail) . "' alt=''>\n"; |
| 168 |
$ret .= "\t\t</li>\n"; |
| 169 |
} |
| 170 |
$ret .= "\t</ul>\n"; |
| 171 |
$ret .= "\t</div><!-- photonic-slideshow-thumbs -->\n"; |
| 172 |
$ret .= "</div>\n"; |
| 173 |
return $ret; |
| 174 |
} |
| 175 |
} |
| 176 |
|