PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.33
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.33
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.33, at Lightboxes/Lightbox.php

138 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 $class;
12
13 public $supports_video;
14
15 public $library;
16 public $default_lightbox_text;
17
18 /**
19 * Lightbox constructor.
20 */
21 protected function __construct() {
22 require_once PHOTONIC_PATH . '/Platforms/Base.php';
23 $this->class = ['photonic-lb', sanitize_html_class('photonic-' . $this->library), sanitize_html_class($this->library)];
24 $this->default_lightbox_text = apply_filters('photonic_default_lightbox_text', esc_attr__('View', 'photonic'));
25 }
26
27 final public static function get_instance() {
28 static $instances = array();
29 $called_class = get_called_class();
30
31 if (!isset($instances[$called_class])) {
32 $instances[$called_class] = new $called_class();
33 }
34 return $instances[$called_class];
35 }
36
37 /**
38 * @param $rel_id
39 * @param Base $module
40 * @return array
41 */
42 public function get_gallery_attributes($rel_id, Base $module): array {
43 return [
44 'class' => $this->class,
45 'rel' => ['lightbox-photonic-' . $module->provider . '-stream-' . (empty($rel_id) ? $module->gallery_index : esc_attr($rel_id))],
46 'specific' => [],
47 ];
48 }
49
50 public function get_container_classes(): string {
51 return '';
52 }
53
54 /**
55 * Some lightboxes require some additional attributes for individual photos. E.g. LightGallery requires something to show the title etc.
56 * This method returns such additional information. Not to be confused with <code>get_lightbox_attributes</code>, which
57 * returns information for the gallery as a whole.
58 *
59 * @param array $photo_data
60 * @param Base $module
61 * @return array
62 */
63 public function get_photo_attributes(array $photo_data, Base $module): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
64 $out = [];
65 if (!empty($photo_data['video'])) {
66 $out['data-photonic-media-type'] = 'video';
67 }
68 else {
69 $out['data-photonic-media-type'] = 'image';
70 }
71 return $out;
72 }
73
74 /**
75 * Used to generate markup for video elements in a grid so that they may be processed in a lightbox. If a lightbox handles videos
76 * without any special handling, the default method suffices. But in some cases the lightbox may need to display video as an inline
77 * element, in which case the respective lightbox file overrides this (typically via the Show_Videos_Inline trait).
78 *
79 * @param Photo $photo
80 * @param Base $module
81 * @param string $indent
82 * @return string
83 */
84 public function get_video_markup(Photo $photo, Base $module, string $indent): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
85 return '';
86 }
87
88 public function get_lightbox_title(Photo $photo, Base $module, $title, $alt_title, $target) {
89 $url = $this->get_title_link($photo);
90 if (empty($title)) {
91 $shown_title = $module->link_lightbox_title ? $this->default_lightbox_text : $alt_title;
92 }
93 else {
94 $shown_title = $title;
95 }
96
97 if (!empty($shown_title)) {
98 // In the following esc_attr() is correct, because this information is used within attributes.
99 if ($module->link_lightbox_title && !empty($url)) {
100 // $title_markup = esc_attr("<a href='$url' $target>") . esc_attr(stripslashes(wp_filter_nohtml_kses($shown_title))) . esc_attr("</a>");
101 $title_markup = esc_attr("<a href='$url' $target>") . esc_attr(stripslashes(wp_kses($shown_title, Photonic::$safe_title_tags))) . esc_attr("</a>");
102
103 if ($module->show_buy_link && !empty($photo->buy_link)) {
104 $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>');
105 }
106 }
107 else {
108 $title_markup = esc_attr(stripslashes(wp_filter_nohtml_kses($shown_title)));
109 }
110 }
111 else {
112 $title_markup = '';
113 }
114 return apply_filters('photonic_lightbox_title_markup', $title_markup);
115 }
116
117 /**
118 * @param Photo $photo
119 * @param array $short_code
120 * @param Base $module
121 * @return mixed
122 */
123 public function get_grid_link(Photo $photo, array $short_code, Base $module): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
124 if ('none' === $this->library && !empty($photo->main_page) && !empty($short_code['link']) && 'page' === $short_code['link']) {
125 return esc_url($photo->main_page);
126 }
127 return esc_url($photo->video ?: $photo->main_image);
128 }
129
130 /**
131 * @param $photo
132 * @return string
133 */
134 public function get_title_link($photo): string {
135 return esc_url($photo->main_page ?: '');
136 }
137 }
138