diff --git a/application/src/View/Helper/LightGalleryOutput.php b/application/src/View/Helper/LightGalleryOutput.php index 4443d1cdc..eb4fdc741 100644 --- a/application/src/View/Helper/LightGalleryOutput.php +++ b/application/src/View/Helper/LightGalleryOutput.php @@ -25,15 +25,16 @@ public function __invoke($files = null) $mediaCaption = $view->themeSetting('media_caption'); foreach ($files as $file) { + $attribs = []; $media = $file['media']; - $source = ($media->originalUrl()) ? $media->originalUrl() : $media->source(); - $mediaCaptionOptions = [ - 'none' => '', - 'title' => 'data-sub-html="' . $media->displayTitle() . '"', - 'description' => 'data-sub-html="' . $media->displayDescription() . '"', - ]; - $mediaCaptionAttribute = ($mediaCaption) ? $mediaCaptionOptions[$mediaCaption] : ''; - $mediaType = $media->mediatype(); + if (!empty($file['forceThumbnail'])) { + $source = $media->thumbnailUrl('large'); + $downloadUrl = $media->originalUrl() ?: $source; + } else { + $source = $downloadUrl = $media->originalUrl() ?: $media->source(); + } + + $mediaType = $media->mediaType(); if (null !== $mediaType && strpos($mediaType, 'video') !== false) { $videoSrcObject = [ 'source' => [ @@ -60,14 +61,35 @@ public function __invoke($files = null) } } $videoSrcJson = json_encode($videoSrcObject); - $html .= '
'; + $attribs['data-video'] = $videoSrcJson; } elseif ($mediaType == 'application/pdf') { - $html .= '
'; + $attribs['data-iframe'] = $source; + $attribs['data-src'] = $source; } else { - $html .= '
'; + $attribs['data-src'] = $source; + } + + switch ($mediaCaption) { + case 'title': + $attribs['data-sub-html'] = $media->displayTitle(); + break; + case 'description': + $attribs['data-sub-html'] = $media->displayDescription(); + break; + case 'none': + default: + // no action + } + + $attribs['data-thumb'] = $media->thumbnailDisplayUrl('medium'); + $attribs['data-download-url'] = $downloadUrl; + $attribs['class'] = 'media resource'; + + $html .= ' $attribValue) { + $html .= ' ' . $attribName . '="' . $escape($attribValue) . '"'; } - $html .= $media->render(); - $html .= '
'; + $html .= '>
'; } $html .= '
'; diff --git a/application/src/View/Helper/SortMedia.php b/application/src/View/Helper/SortMedia.php index d62b0b3b3..d22f6349c 100644 --- a/application/src/View/Helper/SortMedia.php +++ b/application/src/View/Helper/SortMedia.php @@ -9,7 +9,7 @@ public function __invoke($files = null) { $sortedMedia = []; $whitelist = ['image/bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/svg+xml', 'image/webp', 'video/flv', 'video/x-flv', 'video/mp4', 'video/m4v', - 'video/webm', 'video/wmv', 'video/quicktime', 'application/pdf', ]; + 'video/webm', 'video/wmv', 'video/quicktime', 'application/pdf', ]; $html5videos = []; $mediaCount = 0; @@ -23,6 +23,10 @@ public function __invoke($files = null) $sortedMedia['lightMedia'][$mediaCount]['tracks'] = []; } $mediaCount++; + } elseif (strpos($mediaType ?? '', 'image/') === 0 && $media->hasThumbnails()) { + $sortedMedia['lightMedia'][$mediaCount]['media'] = $media; + $sortedMedia['lightMedia'][$mediaCount]['forceThumbnail'] = true; + $mediaCount++; } else { $sortedMedia['otherMedia'][] = $media; } diff --git a/application/view/common/resource-page-block-layout/lightbox-gallery-media.phtml b/application/view/common/resource-page-block-layout/lightbox-gallery-media.phtml index da89929c5..fc1f0d0d9 100644 --- a/application/view/common/resource-page-block-layout/lightbox-gallery-media.phtml +++ b/application/view/common/resource-page-block-layout/lightbox-gallery-media.phtml @@ -1,5 +1,9 @@ mediaType(); -?> -lightGalleryOutput([['media' => $media]]); ?> +$sortedMedia = $this->sortMedia([$media]); + +if (isset($sortedMedia['lightMedia'])): + echo $this->lightGalleryOutput($sortedMedia['lightMedia']); +else: + echo $this->partial('common/resource-page-block-layout/media-render'); +endif;