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

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

330 lines 14.3 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,
91 'fb3_thumbs_button' => empty($photonic_fb3_hide_thumbs),
92 'fb3_thumbs' => isset($photonic_enable_fb3_thumbnail) && 'on' === $photonic_enable_fb3_thumbnail,
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 $layout = ('default' === $type || 'wp' === $type)
180 ? $attr['style']
181 : (!empty($attr['layout'])
182 ? $attr['layout']
183 : $photonic_thumbnail_style);
184 $layout = esc_attr($layout);
185
186 $lazy_allowed = in_array($type, ['flickr', 'smugmug', 'google', 'zenfolio', 'instagram'], true)
187 && in_array($layout, ['square', 'circle', 'random', 'masonry', 'mosaic'], true);
188
189 if (!empty($attr['show_gallery']) && $lazy_allowed) { // Lazy button not for WP galleries
190 $images = $this->get_lazy_load_button($attr);
191 }
192 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'])))))
193 && $lazy_allowed) { // Lazy button not for WP galleries
194 $attr['load_mode'] = 'js'; // Need to set this for cases where the shortcode didn't have the setting; get_lazy_load_button fails
195 $images = $this->get_lazy_load_button($attr, 'js_load');
196 }
197 else {
198 $gallery = new Gallery($attr);
199 $images = $gallery->get_contents();
200 }
201
202 return $images;
203 }
204
205 public function get_lazy_load_button($attr = [], $button_type = 'show_gallery'): string {
206 $types = [
207 'show_gallery' => 'show_gallery',
208 'js_load' => 'load_mode'
209 ];
210 $type = $types[$button_type];
211 $button = esc_attr($attr[$type]);
212 $button_attr = [];
213
214 if (!empty($attr["{$type}_button_type"]) && 'image' === $attr["{$type}_button_type"] && !empty($attr["{$type}_button_image"])) {
215 $button_attr['type'] = 'image';
216 $button_attr['alt'] = $button;
217 $button_attr['src'] = esc_url($attr["{$type}_button_image"]);
218 }
219 else {
220 $button_attr['type'] = 'button';
221 $button_attr['value'] = $button;
222 }
223
224 $class = str_replace('_', '-', $button_type);
225 $button_attr['class'] = "photonic-{$class}-button";
226
227 unset($attr["{$type}"]);
228 unset($attr["{$type}_button_type"]);
229 unset($attr["{$type}_button_image"]);
230
231 $attr['load_mode'] = 'php'; // doesn't matter what the $button_type is.
232
233 $attr_str = http_build_query($attr);
234 $button_attr['data-photonic-shortcode'] = $attr_str;
235
236 $input_attr = [];
237 foreach ($button_attr as $name => $value) {
238 $input_attr[] = "$name='$value'";
239 }
240 $input_attr = implode(' ', $input_attr);
241
242 return "<input $input_attr/>";
243 }
244
245 /**
246 * Constructs the CSS for a "background" option
247 *
248 * @param $option
249 * @return string
250 */
251 public function get_bg_css($option): string {
252 global ${$option};
253 $option_val = ${$option};
254 if (!is_array($option_val)) {
255 $val_array = [];
256 $vals = explode(';', $option_val);
257 foreach ($vals as $val) {
258 if ('' === trim($val)) {
259 continue;
260 }
261 $pair = explode('=', $val);
262 $val_array[$pair[0]] = $pair[1];
263 }
264 $option_val = $val_array;
265 }
266 $bg_string = "";
267 $bg_rgba_string = "";
268 if (!isset($option_val['colortype']) || 'transparent' === $option_val['colortype']) {
269 $bg_string .= " transparent ";
270 }
271 else {
272 if (isset($option_val['color'])) {
273 if ('#' === substr($option_val['color'], 0, 1)) {
274 $color_string = sanitize_hex_color_no_hash(substr($option_val['color'], 1));
275 }
276 else {
277 $color_string = sanitize_hex_color($option_val['color']);
278 }
279 $rgb_str_array = [];
280 if (3 === strlen($color_string)) {
281 $rgb_str_array[] = substr($color_string, 0, 1) . substr($color_string, 0, 1);
282 $rgb_str_array[] = substr($color_string, 1, 1) . substr($color_string, 1, 1);
283 $rgb_str_array[] = substr($color_string, 2, 1) . substr($color_string, 2, 1);
284 }
285 else {
286 $rgb_str_array[] = substr($color_string, 0, 2);
287 $rgb_str_array[] = substr($color_string, 2, 2);
288 $rgb_str_array[] = substr($color_string, 4, 2);
289 }
290 $rgb_array = [];
291 $rgb_array[] = hexdec($rgb_str_array[0]);
292 $rgb_array[] = hexdec($rgb_str_array[1]);
293 $rgb_array[] = hexdec($rgb_str_array[2]);
294 $rgb_string = implode(',', $rgb_array);
295 $rgb_string = ' rgb(' . $rgb_string . ') ';
296
297 if (isset($option_val['trans'])) {
298 $bg_rgba_string = $bg_string;
299 $transparency = (int) $option_val['trans'];
300 if (0 !== $transparency) {
301 $trans_dec = $transparency / 100;
302 $rgba_string = implode(',', $rgb_array);
303 $rgba_string = ' rgba(' . $rgba_string . ',' . $trans_dec . ') ';
304 $bg_rgba_string .= $rgba_string;
305 }
306 }
307
308 $bg_string .= $rgb_string;
309 }
310 }
311 if (isset($option_val['image']) && '' !== trim($option_val['image'])) {
312 $bg_string .= " url(" . esc_url($option_val['image']) . ") ";
313 $bg_string .= $option_val['position'] . " " . $option_val['repeat'];
314
315 if ('' !== trim($bg_rgba_string)) {
316 $bg_rgba_string .= " url(" . esc_url($option_val['image']) . ") ";
317 $bg_rgba_string .= $option_val['position'] . " " . $option_val['repeat'];
318 }
319 }
320
321 if ('' !== trim($bg_string)) {
322 $bg_string = "background: " . $bg_string . " !important;\n";
323 if ('' !== trim($bg_rgba_string)) {
324 $bg_string .= "\tbackground: " . $bg_rgba_string . " !important;\n";
325 }
326 }
327 return $bg_string;
328 }
329 }
330