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 / Core / Front_End.php

Front_End.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.33, at Core/Front_End.php

340 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Photonic_Plugin\Core;
3
4 class Front_End {
5 private static ?Front_End $instance = null;
6
7 private function __construct() {
8 // Blank constructor, for now. Setting it up for singleton.
9 }
10
11 public static function get_instance(): Front_End {
12 if (null === self::$instance) {
13 self::$instance = new Front_End();
14 }
15 return self::$instance;
16 }
17
18 /**
19 * @return array
20 */
21 public function get_localized_js_variables(): array {
22 global $photonic_lightbox_no_loop, $photonic_slideshow_mode, $photonic_slideshow_interval,
23 $photonic_cb_transition_effect, $photonic_cb_transition_speed,
24 $photonic_fbox_title_position, $photonic_fb3_transition_effect, $photonic_fb3_transition_speed, $photonic_fb3_show_fullscreen, $photonic_enable_fb3_fullscreen,
25 $photonic_fb3_hide_thumbs, $photonic_enable_fb3_thumbnail, $photonic_fb3_disable_zoom, $photonic_fb3_disable_slideshow, $photonic_fb3_enable_download, $photonic_fb3_disable_right_click,
26 $photonic_lc_transition_effect, $photonic_lc_transition_speed_in, $photonic_lc_transition_speed_out, $photonic_lc_enable_shrink,
27 $photonic_lg_transition_effect, $photonic_lg_transition_speed, $photonic_disable_lg_download, $photonic_lg_hide_bars_delay,
28 $photonic_lg_mobile_show_controls, $photonic_lg_mobile_show_close, $photonic_lg_mobile_show_download,
29 $photonic_tile_spacing, $photonic_tile_min_height, $photonic_pphoto_theme, $photonic_pp_animation_speed,
30 $photonic_sp_download, $photonic_sp_hide_bars,
31 $photonic_enable_swipebox_mobile_bars, $photonic_sb_hide_mobile_close, $photonic_sb_hide_bars_delay,
32 $photonic_vb_display_vertical_scroll, $photonic_vb_title_position, $photonic_vb_title_style,
33 $photonic_lightbox_for_all, $photonic_lightbox_for_videos, $photonic_popup_panel_width, $photonic_deep_linking, $photonic_social_media,
34 $photonic_slideshow_prevent_autostart, $photonic_wp_slide_adjustment, $photonic_masonry_min_width, $photonic_mosaic_trigger_width,
35 $photonic_debug_on;
36
37 global $photonic_js_variables;
38
39 $slideshow_library = esc_js(Photonic::$library);
40 $js_array = [
41 'ajaxurl' => admin_url('admin-ajax.php'),
42 'plugin_url' => PHOTONIC_URL,
43 'debug_on' => !empty($photonic_debug_on),
44
45 'slide_adjustment' => esc_js($photonic_wp_slide_adjustment ?: 'adapt-height-width'),
46
47 'deep_linking' => esc_js($photonic_deep_linking ?? 'none'),
48 'social_media' => isset($photonic_deep_linking) ? 'none' !== $photonic_deep_linking && empty($photonic_social_media) : '',
49
50 'lightbox_library' => $slideshow_library,
51 'tile_spacing' => (empty($photonic_tile_spacing) || !absint($photonic_tile_spacing)) ? 0 : absint($photonic_tile_spacing),
52 'tile_min_height' => (empty($photonic_tile_min_height) || !absint($photonic_tile_min_height)) ? 200 : absint($photonic_tile_min_height),
53 'masonry_min_width' => (empty($photonic_masonry_min_width) || !absint($photonic_masonry_min_width)) ? 200 : absint($photonic_masonry_min_width),
54 'mosaic_trigger_width' => (empty($photonic_mosaic_trigger_width) || !absint($photonic_mosaic_trigger_width)) ? 200 : absint($photonic_mosaic_trigger_width),
55
56 'slideshow_mode' => isset($photonic_slideshow_mode) && 'on' === $photonic_slideshow_mode,
57 'slideshow_interval' => (isset($photonic_slideshow_interval) && absint($photonic_slideshow_interval)) ? absint($photonic_slideshow_interval) : 5000,
58 'lightbox_loop' => empty($photonic_lightbox_no_loop),
59
60 'gallery_panel_width' => (empty($photonic_popup_panel_width) || !absint($photonic_popup_panel_width) || absint($photonic_popup_panel_width) > 100) ? 80 : absint($photonic_popup_panel_width),
61
62 'lightbox_for_all' => !empty($photonic_lightbox_for_all),
63 'lightbox_for_videos' => !empty($photonic_lightbox_for_videos),
64
65 'slideshow_autostart' => !(isset($photonic_slideshow_prevent_autostart) && 'on' === $photonic_slideshow_prevent_autostart),
66
67 'password_failed' => esc_attr__('This album is password-protected. Please provide a valid password.', 'photonic'),
68 'incorrect_password' => esc_attr__('Incorrect password.', 'photonic'),
69 'maximize_panel' => esc_attr__('Show', 'photonic'),
70 'minimize_panel' => esc_attr__('Hide', 'photonic'),
71 ];
72
73 if ('colorbox' === $slideshow_library) {
74 $lb_options = [
75 'cb_transition_effect' => esc_js($photonic_cb_transition_effect ?: 'elastic'),
76 'cb_transition_speed' => (isset($photonic_cb_transition_speed) && absint($photonic_cb_transition_speed)) ? absint($photonic_cb_transition_speed) : 350,
77 ];
78 }
79 elseif ('fancybox' === $slideshow_library || 'fancybox2' === $slideshow_library) {
80 $lb_options = [
81 'fbox_show_title' => 'none' !== $photonic_fbox_title_position,
82 'fbox_title_position' => 'none' === $photonic_fbox_title_position ? 'outside' : esc_js($photonic_fbox_title_position),
83 ];
84 }
85 elseif ('fancybox3' === $slideshow_library) {
86 $lb_options = [
87 'fb3_transition_effect' => esc_js($photonic_fb3_transition_effect ?: 'zoom'),
88 'fb3_transition_speed' => (isset($photonic_fb3_transition_speed) && absint($photonic_fb3_transition_speed)) ? absint($photonic_fb3_transition_speed) : 366,
89 'fb3_fullscreen_button' => !empty($photonic_fb3_show_fullscreen),
90 'fb3_fullscreen' => isset($photonic_enable_fb3_fullscreen) && 'on' === $photonic_enable_fb3_fullscreen ? true : false,
91 'fb3_thumbs_button' => empty($photonic_fb3_hide_thumbs),
92 'fb3_thumbs' => isset($photonic_enable_fb3_thumbnail) && 'on' === $photonic_enable_fb3_thumbnail ? true : false,
93 'fb3_zoom' => empty($photonic_fb3_disable_zoom),
94 'fb3_slideshow' => empty($photonic_fb3_disable_slideshow),
95 'fb3_download' => !empty($photonic_fb3_enable_download),
96 'fb3_disable_right_click' => !empty($photonic_fb3_disable_right_click),
97 ];
98 }
99 elseif ('lightcase' === $slideshow_library) {
100 $lb_options = [
101 'lc_transition_effect' => esc_js($photonic_lc_transition_effect ?: 'scrollHorizontal'),
102 'lc_transition_speed_in' => (isset($photonic_lc_transition_speed_in) && absint($photonic_lc_transition_speed_in)) ? absint($photonic_lc_transition_speed_in) : 350,
103 'lc_transition_speed_out' => (isset($photonic_lc_transition_speed_out) && absint($photonic_lc_transition_speed_out)) ? absint($photonic_lc_transition_speed_out) : 250,
104 'lc_disable_shrink' => empty($photonic_lc_enable_shrink),
105 ];
106 }
107 elseif ('lightgallery' === $slideshow_library) {
108 $lightgallery_plugins = Photonic::get_lightgallery_plugins();
109 $lightgallery_plugins = implode(',', $lightgallery_plugins);
110
111 $lb_options = [
112 'lg_plugins' => $lightgallery_plugins,
113 'lg_transition_effect' => esc_js($photonic_lg_transition_effect ?: 'lg-slide'),
114 'lg_enable_download' => empty($photonic_disable_lg_download),
115 'lg_hide_bars_delay' => (isset($photonic_lg_hide_bars_delay) && absint($photonic_lg_hide_bars_delay)) ? absint($photonic_lg_hide_bars_delay) : 6000,
116 'lg_transition_speed' => (isset($photonic_lg_transition_speed) && absint($photonic_lg_transition_speed)) ? absint($photonic_lg_transition_speed) : 600,
117 'lg_mobile_controls' => !empty($photonic_lg_mobile_show_controls),
118 'lg_mobile_close' => !empty($photonic_lg_mobile_show_close),
119 'lg_mobile_download' => !empty($photonic_lg_mobile_show_download),
120 ];
121 }
122 elseif ('prettyphoto' === $slideshow_library) {
123 $lb_options = [
124 'pphoto_theme' => esc_js($photonic_pphoto_theme ?? 'pp_default'),
125 'pphoto_animation_speed' => esc_js($photonic_pp_animation_speed ?: 'fast'),
126 ];
127 }
128 elseif ('spotlight' === $slideshow_library) {
129 $lb_options = [
130 'sp_download' => !empty($photonic_sp_download),
131 'sp_hide_bars' => $photonic_sp_hide_bars,
132 ];
133 }
134 elseif ('swipebox' === $slideshow_library) {
135 $lb_options = [
136 'enable_swipebox_mobile_bars' => !empty($photonic_enable_swipebox_mobile_bars),
137 'sb_hide_mobile_close' => !empty($photonic_sb_hide_mobile_close),
138 'sb_hide_bars_delay' => (isset($photonic_sb_hide_bars_delay) && absint($photonic_sb_hide_bars_delay)) ? absint($photonic_sb_hide_bars_delay) : 0,
139 ];
140 }
141 elseif ('venobox' === $slideshow_library) {
142 $lb_options = [
143 'vb_disable_vertical_scroll' => empty($photonic_vb_display_vertical_scroll),
144 'vb_title_position' => esc_js($photonic_vb_title_position),
145 'vb_title_style' => esc_js($photonic_vb_title_style),
146 ];
147 }
148
149 if (!empty($lb_options)) {
150 $js_array = array_merge($js_array, $lb_options);
151 }
152
153 $photonic_js_variables = $js_array;
154 return $js_array;
155 }
156
157 /**
158 * @param array $attr
159 * @return string
160 */
161 public function get_gallery_images(array $attr): string {
162 global $photonic_nested_shortcodes, $photonic_load_mode, $photonic_thumbnail_style;
163 $attr = array_merge(
164 [
165 // Especially for Photonic
166 'type' => 'default', // default, flickr, smugmug, google, zenfolio, instagram
167 'style' => 'default', // default, strip-below, strip-above, strip-right, strip-left, no-strip, launch
168 'display' => 'local',
169 ],
170 $attr
171 );
172
173 if ($photonic_nested_shortcodes) {
174 $attr = array_map('do_shortcode', $attr);
175 }
176
177 $type = strtolower($attr['type']);
178
179 if ('picasa' === $type) {
180 $message = esc_html__('Google has deprecated the Picasa API. Please consider switching over to Google Photos', 'photonic');
181 return "<div class='photonic-error'>\n\t<span class='photonic-error-icon photonic-icon'>&nbsp;</span>\n\t<div class='photonic-message'>\n\t\t$message\n\t</div>\n</div>\n";
182 }
183
184 if ('500px' === $type) {
185 $message = esc_html__('The API for 500px.com is no longer available for public use.', 'photonic');
186 return "<div class='photonic-error'>\n\t<span class='photonic-error-icon photonic-icon'>&nbsp;</span>\n\t<div class='photonic-message'>\n\t\t$message\n\t</div>\n</div>\n";
187 }
188
189 $layout = ('default' === $type || 'wp' === $type)
190 ? $attr['style']
191 : (!empty($attr['layout'])
192 ? $attr['layout']
193 : $photonic_thumbnail_style);
194 $layout = esc_attr($layout);
195
196 $lazy_allowed = in_array($type, ['flickr', 'smugmug', 'google', 'zenfolio', 'instagram'], true)
197 && in_array($layout, ['square', 'circle', 'random', 'masonry', 'mosaic'], true);
198
199 if (!empty($attr['show_gallery']) && $lazy_allowed) { // Lazy button not for WP galleries
200 $images = $this->get_lazy_load_button($attr, 'show_gallery');
201 }
202 elseif ((('js' === $photonic_load_mode && (empty($attr['load_mode']) || 'js' === trim(esc_attr($attr['load_mode'])))) || ('php' === $photonic_load_mode && (!empty($attr['load_mode']) && 'js' === trim(sanitize_text_field($attr['load_mode'])))))
203 && $lazy_allowed) { // Lazy button not for WP galleries
204 $attr['load_mode'] = 'js'; // Need to set this for cases where the shortcode didn't have the setting; get_lazy_load_button fails
205 $images = $this->get_lazy_load_button($attr, 'js_load');
206 }
207 else {
208 $gallery = new Gallery($attr);
209 $images = $gallery->get_contents();
210 }
211
212 return $images;
213 }
214
215 public function get_lazy_load_button($attr = [], $button_type = 'show_gallery'): string {
216 $types = [
217 'show_gallery' => 'show_gallery',
218 'js_load' => 'load_mode'
219 ];
220 $type = $types[$button_type];
221 $button = esc_attr($attr[$type]);
222 $button_attr = [];
223
224 if (!empty($attr["{$type}_button_type"]) && 'image' === $attr["{$type}_button_type"] && !empty($attr["{$type}_button_image"])) {
225 $button_attr['type'] = 'image';
226 $button_attr['alt'] = $button;
227 $button_attr['src'] = esc_url($attr["{$type}_button_image"]);
228 }
229 else {
230 $button_attr['type'] = 'button';
231 $button_attr['value'] = $button;
232 }
233
234 $class = str_replace('_', '-', $button_type);
235 $button_attr['class'] = "photonic-{$class}-button";
236
237 unset($attr["{$type}"]);
238 unset($attr["{$type}_button_type"]);
239 unset($attr["{$type}_button_image"]);
240
241 $attr['load_mode'] = 'php'; // doesn't matter what the $button_type is.
242
243 $attr_str = http_build_query($attr);
244 $button_attr['data-photonic-shortcode'] = $attr_str;
245
246 $input_attr = [];
247 foreach ($button_attr as $name => $value) {
248 $input_attr[] = "$name='$value'";
249 }
250 $input_attr = implode(' ', $input_attr);
251
252 return "<input $input_attr/>";
253 }
254
255 /**
256 * Constructs the CSS for a "background" option
257 *
258 * @param $option
259 * @return string
260 */
261 public function get_bg_css($option): string {
262 global ${$option};
263 $option_val = ${$option};
264 if (!is_array($option_val)) {
265 $val_array = [];
266 $vals = explode(';', $option_val);
267 foreach ($vals as $val) {
268 if ('' === trim($val)) {
269 continue;
270 }
271 $pair = explode('=', $val);
272 $val_array[$pair[0]] = $pair[1];
273 }
274 $option_val = $val_array;
275 }
276 $bg_string = "";
277 $bg_rgba_string = "";
278 if (!isset($option_val['colortype']) || 'transparent' === $option_val['colortype']) {
279 $bg_string .= " transparent ";
280 }
281 else {
282 if (isset($option_val['color'])) {
283 if ('#' === substr($option_val['color'], 0, 1)) {
284 $color_string = sanitize_hex_color_no_hash(substr($option_val['color'], 1));
285 }
286 else {
287 $color_string = sanitize_hex_color($option_val['color']);
288 }
289 $rgb_str_array = [];
290 if (3 === strlen($color_string)) {
291 $rgb_str_array[] = substr($color_string, 0, 1) . substr($color_string, 0, 1);
292 $rgb_str_array[] = substr($color_string, 1, 1) . substr($color_string, 1, 1);
293 $rgb_str_array[] = substr($color_string, 2, 1) . substr($color_string, 2, 1);
294 }
295 else {
296 $rgb_str_array[] = substr($color_string, 0, 2);
297 $rgb_str_array[] = substr($color_string, 2, 2);
298 $rgb_str_array[] = substr($color_string, 4, 2);
299 }
300 $rgb_array = [];
301 $rgb_array[] = hexdec($rgb_str_array[0]);
302 $rgb_array[] = hexdec($rgb_str_array[1]);
303 $rgb_array[] = hexdec($rgb_str_array[2]);
304 $rgb_string = implode(',', $rgb_array);
305 $rgb_string = ' rgb(' . $rgb_string . ') ';
306
307 if (isset($option_val['trans'])) {
308 $bg_rgba_string = $bg_string;
309 $transparency = (int) $option_val['trans'];
310 if (0 !== $transparency) {
311 $trans_dec = $transparency / 100;
312 $rgba_string = implode(',', $rgb_array);
313 $rgba_string = ' rgba(' . $rgba_string . ',' . $trans_dec . ') ';
314 $bg_rgba_string .= $rgba_string;
315 }
316 }
317
318 $bg_string .= $rgb_string;
319 }
320 }
321 if (isset($option_val['image']) && '' !== trim($option_val['image'])) {
322 $bg_string .= " url(" . esc_url($option_val['image']) . ") ";
323 $bg_string .= $option_val['position'] . " " . $option_val['repeat'];
324
325 if ('' !== trim($bg_rgba_string)) {
326 $bg_rgba_string .= " url(" . esc_url($option_val['image']) . ") ";
327 $bg_rgba_string .= $option_val['position'] . " " . $option_val['repeat'];
328 }
329 }
330
331 if ('' !== trim($bg_string)) {
332 $bg_string = "background: " . $bg_string . " !important;\n";
333 if ('' !== trim($bg_rgba_string)) {
334 $bg_string .= "\tbackground: " . $bg_rgba_string . " !important;\n";
335 }
336 }
337 return $bg_string;
338 }
339 }
340