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
photonic / Lightboxes / Lightbox.php

Lightbox.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.36, at Lightboxes/Lightbox.php

136 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Photonic_Plugin\Lightboxes;
4
5 use Photonic_Plugin\Components\Photo;
6 use Photonic_Plugin\Core\Photonic;
7 use Photonic_Plugin\Platforms\Base;
8
9 abstract class Lightbox {
10 /** @var array */
11 public array $class;
12
13 public string $library;
14 public string $default_lightbox_text;
15
16 /**
17 * Lightbox constructor.
18 */
19 protected function __construct() {
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'));
23 }
24
25 final public static function get_instance() {
26 static $instances = array();
27 $called_class = get_called_class();
28
29 if (!isset($instances[$called_class])) {
30 $instances[$called_class] = new $called_class();
31 }
32 return $instances[$called_class];
33 }
34
35 /**
36 * @param $rel_id
37 * @param Base $module
38 * @return array
39 */
40 public function get_gallery_attributes($rel_id, Base $module): array {
41 return [
42 'class' => $this->class,
43 'rel' => ['lightbox-photonic-' . $module->provider . '-stream-' . (empty($rel_id) ? $module->gallery_index : esc_attr($rel_id))],
44 'specific' => [],
45 ];
46 }
47
48 public function get_container_classes(): string {
49 return '';
50 }
51
52 /**
53 * Some lightboxes require some additional attributes for individual photos. E.g. LightGallery requires something to show the title etc.
54 * This method returns such additional information. Not to be confused with <code>get_lightbox_attributes</code>, which
55 * returns information for the gallery as a whole.
56 *
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
80 * @return string
81 */
82 public function get_video_markup(Photo $photo, Base $module, string $indent): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
83 return '';
84 }
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 }
136