PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.36
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.36
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
← All changes | Lightboxes/Lightbox.php +94 -16 2.433.36 View file →
@@ -1,23 +1,26 @@
1 1 <?php
2 +
2 3 namespace Photonic_Plugin\Lightboxes;
3 4
4 -use Photonic_Plugin\Modules\Core;
5 +use Photonic_Plugin\Components\Photo;
6 +use Photonic_Plugin\Core\Photonic;
7 +use Photonic_Plugin\Platforms\Base;
5 8
6 9 abstract class Lightbox {
7 10 /** @var array */
8 - var $class;
11 + public array $class;
9 12
10 - var $supports_video;
13 + public string $library;
14 + public string $default_lightbox_text;
11 15
12 - var $library;
13 -
14 16 /**
15 17 * Lightbox constructor.
16 18 */
17 19 protected function __construct() {
18 - require_once(PHOTONIC_PATH.'/Modules/Core.php');
19 - $this->class = ['photonic-launch-gallery', 'launch-gallery-'.$this->library, $this->library];
20 + require_once PHOTONIC_PATH . '/Platforms/Base.php';
21 + $this->class = ['photonic-lb', sanitize_html_class('photonic-' . $this->library), sanitize_html_class($this->library)];
22 + $this->default_lightbox_text = apply_filters('photonic_default_lightbox_text', esc_attr__('View', 'photonic'));
20 23 }
21 24
22 25 final public static function get_instance() {
23 26 static $instances = array();
@@ -30,28 +33,103 @@
30 33 }
31 34
32 35 /**
33 36 * @param $rel_id
34 - * @param Core $module
37 + * @param Base $module
35 38 * @return array
36 39 */
37 - function get_gallery_attributes($rel_id, $module) {
40 + public function get_gallery_attributes($rel_id, Base $module): array {
38 41 return [
39 - 'class' => $this->class,
40 - 'rel' => ['lightbox-photonic-'.$module->provider.'-stream-'.(empty($rel_id) ? $module->gallery_index : $rel_id)],
42 + 'class' => $this->class,
43 + 'rel' => ['lightbox-photonic-' . $module->provider . '-stream-' . (empty($rel_id) ? $module->gallery_index : esc_attr($rel_id))],
41 44 'specific' => [],
42 45 ];
43 46 }
44 47
48 + public function get_container_classes(): string {
49 + return '';
50 + }
51 +
45 52 /**
46 - * Some lightboxes require some additional attributes for individual photos. E.g. Lightgallery requires something to show the title etc.
53 + * Some lightboxes require some additional attributes for individual photos. E.g. LightGallery requires something to show the title etc.
47 54 * This method returns such additional information. Not to be confused with <code>get_lightbox_attributes</code>, which
48 55 * returns information for the gallery as a whole.
49 56 *
50 - * @param $photo_data
51 - * @param Core $module
57 + * @param array $photo_data
58 + * @param Base $module
59 + * @return array
60 + */
61 + public function get_photo_attributes(array $photo_data, Base $module): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
62 + $out = [];
63 + if (!empty($photo_data['video'])) {
64 + $out['data-photonic-media-type'] = 'video';
65 + }
66 + else {
67 + $out['data-photonic-media-type'] = 'image';
68 + }
69 + return $out;
70 + }
71 +
72 + /**
73 + * Used to generate markup for video elements in a grid so that they may be processed in a lightbox. If a lightbox handles videos
74 + * without any special handling, the default method suffices. But in some cases the lightbox may need to display video as an inline
75 + * element, in which case the respective lightbox file overrides this (typically via the Show_Videos_Inline trait).
76 + *
77 + * @param Photo $photo
78 + * @param Base $module
79 + * @param string $indent
52 80 * @return string
53 81 */
54 - function get_photo_attributes($photo_data, $module) {
82 + public function get_video_markup(Photo $photo, Base $module, string $indent): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
55 83 return '';
56 84 }
57 -}
85 +
86 + public function get_lightbox_title(Photo $photo, Base $module, $title, $alt_title, $target) {
87 + $url = $this->get_title_link($photo);
88 + if (empty($title)) {
89 + $shown_title = $module->link_lightbox_title ? $this->default_lightbox_text : $alt_title;
90 + }
91 + else {
92 + $shown_title = $title;
93 + }
94 +
95 + if (!empty($shown_title)) {
96 + // In the following esc_attr() is correct, because this information is used within attributes.
97 + if ($module->link_lightbox_title && !empty($url)) {
98 + // $title_markup = esc_attr("<a href='$url' $target>") . esc_attr(stripslashes(wp_filter_nohtml_kses($shown_title))) . esc_attr("</a>");
99 + $title_markup = esc_attr("<a href='$url' $target>") . esc_attr(stripslashes(wp_kses($shown_title, Photonic::$safe_title_tags))) . esc_attr("</a>");
100 +
101 + if ($module->show_buy_link && !empty($photo->buy_link)) {
102 + $title_markup .= esc_attr('<a class="photonic-buy-link" href="' . esc_url_raw($photo->buy_link) . '" target="_blank" title="' . __('Buy', 'photonic') . '"><div class="icon-buy"></div></a>');
103 + }
104 + }
105 + else {
106 + $title_markup = esc_attr(stripslashes(wp_filter_nohtml_kses($shown_title)));
107 + }
108 + }
109 + else {
110 + $title_markup = '';
111 + }
112 + return apply_filters('photonic_lightbox_title_markup', $title_markup);
113 + }
114 +
115 + /**
116 + * @param Photo $photo
117 + * @param array $short_code
118 + * @param Base $module
119 + * @return mixed
120 + */
121 + public function get_grid_link(Photo $photo, array $short_code, Base $module): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
122 + if ('none' === $this->library && !empty($photo->main_page) && !empty($short_code['link']) && 'page' === $short_code['link']) {
123 + return esc_url($photo->main_page);
124 + }
125 + return esc_url($photo->video ?: $photo->main_image);
126 + }
127 +
128 + /**
129 + * @param $photo
130 + * @return string
131 + */
132 + public function get_title_link($photo): string {
133 + return esc_url($photo->main_page ?: '');
134 + }
135 +}