PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.32
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.32
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 2.45 All 140 releases
photonic / photonic.php

photonic.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.32, at photonic.php

2,077 lines 81.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Photonic Gallery & Lightbox for Flickr, SmugMug, Google Photos & Others
4 * Plugin URI: https://aquoid.com/plugins/photonic/
5 * Description: Extends the native gallery to support Flickr, SmugMug, Google Photos, Zenfolio and Instagram. JS libraries like Swipebox, Fancybox, PhotoSwipe, Magnific, Colorbox, PrettyPhoto, Image Lightbox, Featherlight, Lightcase and Lightgallery are supported. Photos are displayed in grids of square or circular thumbnails, or slideshows, or justified or masonry or random mosaic layouts. The plugin also extends all layout options to a regular WP gallery.
6 * Version: 2.32
7 * Author: Sayontan Sinha
8 * Author URI: https://mynethome.net/
9 * License: GNU General Public License (GPL), v3 (or newer)
10 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
11 * Text Domain: photonic
12 *
13 * Copyright (c) 2011 - 2020 Sayontan Sinha. All rights reserved.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19 class Photonic {
20 var $version, $registered_extensions, $defaults, $plugin_name, $options_page_name, $settings_page, $helper_page, $getting_started_page, $authentication_page, $gutenberg_page, $localized;
21 function __construct() {
22 // $start = microtime(true);
23 global $photonic_options, $photonic_setup_options, $photonic_is_IE, $photonic_default_options;
24 if (!defined('PHOTONIC_VERSION')) {
25 define('PHOTONIC_VERSION', '2.32');
26 }
27
28 if (!defined('PHOTONIC_PATH')) {
29 define('PHOTONIC_PATH', plugin_dir_path(__FILE__));
30 }
31
32 if (!defined('PHOTONIC_URL')) {
33 define('PHOTONIC_URL', plugin_dir_url(__FILE__));
34 }
35
36 $upload_dir = wp_upload_dir();
37 if (!defined('PHOTONIC_UPLOAD_DIR')) {
38 define('PHOTONIC_UPLOAD_DIR', trailingslashit($upload_dir['basedir']).'photonic');
39 }
40
41 if (!defined('PHOTONIC_UPLOAD_URL')) {
42 define('PHOTONIC_UPLOAD_URL', trailingslashit($upload_dir['baseurl']).'photonic');
43 }
44
45 //WP provides a global $is_IE, but we specifically need to find IE6x (or, heaven forbid, IE5x). Note that older versions of Opera used to identify themselves as IE6, so we exclude Opera.
46 $photonic_is_IE = preg_match('/MSIE [56789]/i', $_SERVER['HTTP_USER_AGENT']);
47
48 require_once(plugin_dir_path(__FILE__)."/options/photonic-options.php");
49 require_once(plugin_dir_path(__FILE__)."/options/defaults.php");
50
51 $this->plugin_name = plugin_basename(__FILE__);
52 $this->localized = false;
53
54 add_action('admin_menu', [&$this, 'add_admin_menu']);
55 add_action('admin_enqueue_scripts', [&$this, 'add_admin_scripts']);
56 add_action('admin_init', [&$this, 'admin_init']);
57 add_action('admin_notices', [&$this, 'admin_notices']);
58
59 $photonic_options = get_option('photonic_options');
60 $set_options = isset($photonic_options) && is_array($photonic_options) ? $photonic_options : [];
61
62 $all_options = array_merge($photonic_default_options, $set_options);
63
64 foreach ($all_options as $key => $value) {
65 $mod_key = 'photonic_'.$key;
66 global ${$mod_key};
67 ${$mod_key} = $value;
68 }
69
70 if (is_admin()) {
71 foreach ($photonic_setup_options as $default_option) {
72 if (isset($default_option['id'])) {
73 $default_option['std'] = $photonic_default_options[$default_option['id']];
74 }
75 }
76 }
77
78 if (!empty($photonic_ssl_verify_off)) {
79 define('PHOTONIC_SSL_VERIFY', false);
80 }
81 else {
82 define('PHOTONIC_SSL_VERIFY', true);
83 }
84
85 if (!empty($photonic_script_dev_mode)) {
86 define('PHOTONIC_DEV_MODE', '');
87 }
88 else {
89 define('PHOTONIC_DEV_MODE', '.min');
90 }
91
92 if (!empty($photonic_curl_timeout) && is_numeric($photonic_curl_timeout)) {
93 define('PHOTONIC_CURL_TIMEOUT', $photonic_curl_timeout);
94 }
95 else {
96 define('PHOTONIC_CURL_TIMEOUT', 10);
97 }
98
99 if (!empty($photonic_debug_on)) {
100 define('PHOTONIC_DEBUG', true);
101 }
102 else {
103 define('PHOTONIC_DEBUG', false);
104 }
105
106 add_action('admin_head', [$this, 'admin_head']);
107
108 // Gallery
109 if (!empty($photonic_alternative_shortcode)) {
110 add_shortcode($photonic_alternative_shortcode, [&$this, 'modify_gallery']);
111 }
112 else {
113 add_filter('post_gallery', [&$this, 'modify_gallery'], 20, 2);
114 }
115 add_filter('shortcode_atts_gallery', [&$this, 'native_gallery_attributes'], 10, 3);
116
117 add_shortcode('photonic_helper', [&$this, 'helper_shortcode']);
118
119 add_action('wp_enqueue_scripts', [&$this, 'always_add_styles'], 20);
120 if (!empty($photonic_always_load_scripts)) {
121 add_action('wp_enqueue_scripts', [&$this, 'conditionally_add_scripts'], 20);
122 }
123 add_action('wp_head', [&$this, 'print_scripts'], 20);
124
125 global $photonic_flickr_allow_oauth, $photonic_smug_allow_oauth;
126 if ($photonic_flickr_allow_oauth || $photonic_smug_allow_oauth) {
127 add_action('wp_loaded', [&$this, 'check_authentication'], 20);
128 }
129
130 add_action('wp_ajax_photonic_display_level_2_contents', [&$this, 'display_level_2_contents']);
131 add_action('wp_ajax_nopriv_photonic_display_level_2_contents', [&$this, 'display_level_2_contents']);
132
133 add_action('wp_ajax_photonic_display_level_3_contents', [&$this, 'display_level_3_contents']);
134 add_action('wp_ajax_nopriv_photonic_display_level_3_contents', [&$this, 'display_level_3_contents']);
135
136 add_action('wp_ajax_photonic_load_more', [&$this, 'load_more']);
137 add_action('wp_ajax_nopriv_photonic_load_more', [&$this, 'load_more']);
138
139 add_action('wp_ajax_photonic_lazy_load', [&$this, 'lazy_load']);
140 add_action('wp_ajax_nopriv_photonic_lazy_load', [&$this, 'lazy_load']);
141
142 add_action('wp_ajax_photonic_helper_shortcode_more', [&$this, 'helper_shortcode_more']);
143 add_action('wp_ajax_nopriv_photonic_helper_shortcode_more', [&$this, 'helper_shortcode_more']);
144
145 add_filter('media_upload_tabs', [&$this, 'media_upload_tabs']);
146 add_action('media_upload_photonic', [&$this, 'media_upload_photonic']);
147
148 add_action('print_media_templates', [&$this, 'edit_gallery']);
149
150 add_action('wp_ajax_photonic_invoke_helper', [&$this, 'invoke_helper']);
151 add_action('wp_ajax_photonic_obtain_token', [&$this, 'obtain_token']);
152 add_action('wp_ajax_photonic_save_token', [&$this, 'save_token_in_options']);
153 add_action('wp_ajax_photonic_delete_token', [&$this, 'delete_token_from_options']);
154
155 $this->registered_extensions = [];
156 $this->add_extensions();
157
158 add_action('wp_ajax_photonic_authenticate', [&$this, 'authenticate']);
159 add_action('wp_ajax_nopriv_photonic_authenticate', [&$this, 'authenticate']);
160
161 add_action('wp_ajax_photonic_dismiss_warning', [&$this, 'dismiss_warning']);
162 add_action('wp_ajax_nopriv_photonic_dismiss_warning', [&$this, 'dismiss_warning']);
163
164 add_action('http_api_curl', [&$this, 'curl_timeout'], 100, 1);
165
166 if (empty($photonic_disable_flow_editor_global)) {
167 add_action('media_buttons', [&$this, 'add_photonic_button']);
168 add_action('admin_action_photonic_flow', [&$this, 'gallery_builder']);
169 add_action('wp_ajax_photonic_flow_next_screen', [&$this, 'flow_next_screen']);
170 add_action('wp_ajax_nopriv_photonic_flow_next_screen', [&$this, 'flow_next_screen']);
171 add_action('wp_ajax_photonic_flow_more', [&$this, 'flow_more']);
172 add_action('wp_ajax_nopriv_photonic_flow_more', [&$this, 'flow_more']);
173 }
174
175 $this->add_gutenberg_support();
176 add_action('enqueue_block_editor_assets', [&$this, 'enqueue_gutenberg_assets']);
177
178 add_action('plugins_loaded', [&$this, 'enable_translations']);
179
180 add_filter('body_class', [&$this, 'body_class'], 10, 2);
181 // $end = microtime(true);
182 // print_r("<!-- Photonic initialization: ".($end - $start)." -->\n");
183
184 // require_once(plugin_dir_path(__FILE__)."/Photonic_Template.php");
185 }
186
187 /**
188 * @param $show_full
189 * @param bool $return_formatted
190 * @return array
191 */
192 public static function get_wp_image_sizes($show_full, $return_formatted = false) {
193 global $_wp_additional_image_sizes;
194 $image_sizes = [];
195 $standard_sizes = ['thumbnail', 'medium', 'large'];
196 if ($show_full) {
197 $standard_sizes[] = 'full';
198 }
199 foreach ($standard_sizes as $standard_size) {
200 if ($standard_size != 'full') {
201 $image_sizes[$standard_size] = ['width' => get_option($standard_size . '_size_w'), 'height' => get_option($standard_size . '_size_h')];
202 }
203 else {
204 $image_sizes[$standard_size] = ['width' => esc_html__('Original width', 'photonic'), 'height' => esc_html__('Original height', 'photonic')];
205 }
206 }
207 if (is_array($_wp_additional_image_sizes)) {
208 $image_sizes = array_merge($image_sizes, $_wp_additional_image_sizes);
209 }
210
211 if ($return_formatted) {
212 $formatted = [];
213 foreach ($image_sizes as $size_name => $size_attrs) {
214 $formatted[$size_name] = "$size_name ({$size_attrs['width']} &times; {$size_attrs['height']})";
215 }
216 return $formatted;
217 }
218 return $image_sizes;
219 }
220
221 /**
222 * @param string $provider
223 * @param array $auth_token
224 */
225 public static function save_provider_authentication(string $provider, array $auth_token) {
226 $photonic_authentication = get_option('photonic_authentication');
227 if (empty($photonic_authentication)) {
228 $photonic_authentication = [];
229 }
230 if (empty($photonic_authentication[$provider])) {
231 $photonic_authentication[$provider] = [];
232 }
233 $photonic_authentication[$provider] = $auth_token;
234 update_option('photonic_authentication', $photonic_authentication);
235 }
236
237 /**
238 * Adds a menu item to the "Settings" section of the admin page.
239 *
240 * @return void
241 */
242 function add_admin_menu() {
243 global $photonic_options_manager;
244 if (current_user_can('edit_theme_options')) {
245 $parent_slug = 'photonic-options-manager';
246 }
247 else if (current_user_can('edit_posts')) {
248 $parent_slug = 'photonic-getting-started';
249 }
250
251 if (!empty($parent_slug)) {
252 $this->options_page_name = add_menu_page('Photonic', 'Photonic', 'edit_posts', $parent_slug, [&$photonic_options_manager, 'render_settings_page'], plugins_url('include/images/Photonic-20-gr.png', __FILE__));
253 $this->settings_page = add_submenu_page($parent_slug, esc_html__('Settings', 'photonic'), esc_html__('Settings', 'photonic'), 'edit_theme_options', 'photonic-options-manager', [&$photonic_options_manager, 'render_settings_page']);
254 $this->getting_started_page = add_submenu_page($parent_slug, 'Getting Started', 'Getting Started', 'edit_posts', 'photonic-getting-started', [&$photonic_options_manager, 'render_getting_started']);
255 $this->authentication_page = add_submenu_page($parent_slug, 'Authentication', 'Authentication', 'edit_theme_options', 'photonic-auth', [&$photonic_options_manager, 'render_authentication']);
256 $this->gutenberg_page = add_submenu_page($parent_slug, esc_html__('Prepare for Gutenberg', 'photonic'), '<div style="color: #c66">'.esc_html__('Prepare for Gutenberg', 'photonic').'</div>', 'edit_posts', 'photonic-gutenberg', [&$photonic_options_manager, 'render_gutenberg']);
257 $this->helper_page = add_submenu_page($parent_slug, 'Helpers', 'Helpers', 'edit_posts', 'photonic-helpers', [&$photonic_options_manager, 'render_helpers']);
258 }
259 }
260
261 /**
262 * Adds all scripts and their dependencies to the <head> of the Photonic administration page. This takes care to not add scripts on other admin pages.
263 *
264 * @param $hook
265 * @return void
266 */
267 function add_admin_scripts($hook) {
268 if ($this->options_page_name == $hook) {
269 wp_enqueue_style('photonic-admin-css', plugins_url('include/css/admin.css', __FILE__), ['wp-color-picker'], $this->get_version(plugin_dir_path(__FILE__).'include/css/admin.css'));
270 global $photonic_options;
271 $js_array = [
272 'category' => isset($photonic_options) && isset($photonic_options['last-set-section']) ? $photonic_options['last-set-section'] : 'generic-settings',
273 ];
274 wp_enqueue_script('photonic-options-js', plugins_url('include/scripts/admin/options-manager.js', __FILE__), ['jquery', 'wp-color-picker'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/admin/options-manager.js'));
275 wp_localize_script('photonic-options-js', 'Photonic_Options_JS', $js_array);
276 }
277 else if ($this->helper_page == $hook || $this->authentication_page == $hook || $this->gutenberg_page == $hook) {
278 wp_enqueue_script('photonic-admin-js', plugins_url('include/scripts/admin/helpers.js', __FILE__), ['jquery'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/admin/helpers.js'));
279 wp_enqueue_style('photonic-admin-css', plugins_url('include/css/admin.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/css/admin.css'));
280
281 $js_array = [
282 'obtain_token' => esc_attr__('Step 2: Obtain Token', 'photonic')
283 ];
284 wp_localize_script('photonic-admin-js', 'Photonic_Admin_JS', $js_array);
285 }
286 else if ($this->getting_started_page == $hook) {
287 wp_enqueue_style('photonic-admin-css', plugins_url('include/css/admin.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/css/admin.css'));
288 }
289 else if ('media-upload-popup' == $hook) {
290 wp_enqueue_script('jquery');
291 wp_enqueue_style('photonic-upload', plugins_url('include/css/admin-form.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/css/admin-form.css'));
292 }
293 else if ('post-new.php' == $hook || 'post.php' == $hook) {
294 global $photonic_disable_editor, $photonic_disable_editor_post_type;
295 $disabled_types = explode(',', $photonic_disable_editor_post_type);
296 $post_type = empty($_REQUEST['post_type']) ? 'post' : $_REQUEST['post_type'];
297 wp_enqueue_style('photonic-upload', plugins_url('include/css/admin-form.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/css/admin-form.css'));
298 if (empty($photonic_disable_editor) && !in_array($post_type, $disabled_types)) {
299 $this->prepare_mce_data();
300
301 add_editor_style(plugins_url('include/css/admin-editor.css?'.$this->get_version(plugin_dir_path(__FILE__).'include/css/admin-editor.css'), __FILE__));
302 }
303 }
304 }
305
306 /**
307 * Adds all scripts and their dependencies to the end of the <body> element only on pages using Photonic.
308 *
309 * @param array $attr
310 * @return void
311 */
312 function conditionally_add_scripts($attr = []) {
313 global $photonic_slideshow_library, $photonic_custom_lightbox_js, $photonic_is_IE, $photonic_custom_lightbox, $photonic_always_load_scripts,
314 $photonic_disable_photonic_lightbox_scripts, $photonic_disable_photonic_slider_scripts, $photonic_js_in_header, $photonic_thumbnail_style;
315
316 if (isset($attr['style'])) {
317 $layout = $attr['style'];
318 }
319 else if (isset($attr['layout'])) {
320 $layout = $attr['layout'];
321 }
322 else if (isset($photonic_thumbnail_style)) {
323 $layout = $photonic_thumbnail_style;
324 }
325 else {
326 $layout = 'square';
327 }
328
329 $photonic_dependencies = ['jquery'];
330
331 if ($photonic_is_IE && $layout == 'masonry') {
332 wp_enqueue_script('photonic-ie', plugins_url('include/scripts/front-end/src/photonic-ie.js', __FILE__), ['jquery-masonry', 'photonic'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/front-end/src/photonic-ie.js'), !($photonic_always_load_scripts && $photonic_js_in_header));
333 }
334
335 if ($photonic_slideshow_library == 'thickbox') {
336 wp_enqueue_script('thickbox');
337 $photonic_dependencies[] = 'thickbox';
338 }
339 else if ($photonic_slideshow_library == 'custom') {
340 $counter = 1;
341 $dependencies = ['jquery'];
342 foreach(preg_split("/((\r?\n)|(\r\n?))/", $photonic_custom_lightbox_js) as $line){
343 wp_enqueue_script('photonic-lightbox-'.$counter, trim($line), $dependencies, PHOTONIC_VERSION, !($photonic_always_load_scripts && $photonic_js_in_header));
344 $photonic_dependencies[] = 'photonic-lightbox-'.$counter;
345 $counter++;
346 }
347 }
348 else if ($photonic_slideshow_library != 'none') {
349 if (empty($photonic_slideshow_library)) {
350 $photonic_slideshow_library = 'swipebox';
351 }
352
353 if (empty($photonic_disable_photonic_lightbox_scripts)) {
354 $lb_deps = ['jquery'];
355 if ($photonic_slideshow_library == 'fluidbox') {
356 $lb_deps[] = 'imagesloaded';
357 }
358 if ($photonic_slideshow_library == 'lightgallery') {
359 global $photonic_enable_lg_zoom, $photonic_enable_lg_thumbnail, $photonic_enable_lg_fullscreen, $photonic_enable_lg_autoplay;
360 $lightgallery_plugins = [];
361 if (!empty($photonic_enable_lg_autoplay)) { $lightgallery_plugins[] = 'autoplay'; }
362 if (!empty($photonic_enable_lg_fullscreen)) { $lightgallery_plugins[] = 'fullscreen'; }
363 if (!empty($photonic_enable_lg_thumbnail)) { $lightgallery_plugins[] = 'thumbnail'; }
364 if (!empty($photonic_enable_lg_zoom)) { $lightgallery_plugins[] = 'zoom'; }
365 if (!empty($lightgallery_plugins)) {
366 wp_enqueue_script('photonic-lightbox', plugins_url('include/scripts/third-party/'.$photonic_slideshow_library.'/'.$photonic_slideshow_library.PHOTONIC_DEV_MODE.'.js', __FILE__), $lb_deps, $this->get_version(plugin_dir_path(__FILE__).'include/scripts/third-party/'.$photonic_slideshow_library.'/'.$photonic_slideshow_library.PHOTONIC_DEV_MODE.'.js'), !($photonic_always_load_scripts && $photonic_js_in_header));
367 $photonic_dependencies[] = 'photonic-lightbox';
368 }
369 if (PHOTONIC_DEV_MODE) {
370 foreach ($lightgallery_plugins as $plugin) {
371 wp_enqueue_script('photonic-lightbox-'.$plugin, plugins_url('include/scripts/third-party/'.$photonic_slideshow_library.'/lg-plugin-'.$plugin.'.min.js', __FILE__), ['photonic-lightbox'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/third-party/'.$photonic_slideshow_library.'/lg-plugin-'.$plugin.'.min.js'), !($photonic_always_load_scripts && $photonic_js_in_header));
372 }
373 }
374 else {
375 wp_enqueue_script('photonic-lightbox-plugins', plugins_url('include/scripts/third-party/'.$photonic_slideshow_library.'/lightgallery-plugins.js', __FILE__), ['photonic-lightbox'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/third-party/'.$photonic_slideshow_library.'/lightgallery-plugins.js'), !($photonic_always_load_scripts && $photonic_js_in_header));
376 }
377 }
378 else if ($photonic_slideshow_library == 'galleria') {
379 wp_enqueue_script('photonic-lightbox-theme', plugins_url('include/scripts/third-party/galleria/themes/classic/galleria.classic.min.js', __FILE__), ['photonic-lightbox'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/third-party/galleria/themes/classic/galleria.classic.min.js'), !($photonic_always_load_scripts && $photonic_js_in_header));
380 }
381 }
382 }
383
384 $slideshow_library = $photonic_slideshow_library == 'custom' ? $photonic_custom_lightbox : $photonic_slideshow_library;
385 $slideshow_library = empty($slideshow_library) ? 'swipebox' : $slideshow_library;
386
387 if (empty($photonic_disable_photonic_lightbox_scripts) && !($slideshow_library == 'lightgallery' && !empty($lightgallery_plugins))) {
388 $script_type = 'combo';
389 }
390 else {
391 $script_type = 'solo';
392 }
393
394 if (empty($photonic_disable_photonic_slider_scripts)) {
395 $script_type .= '-slider';
396 }
397
398 wp_enqueue_script('photonic', plugins_url("include/scripts/front-end/jq/$script_type/photonic-".$slideshow_library.PHOTONIC_DEV_MODE.'.js', __FILE__), $photonic_dependencies, $this->get_version(plugin_dir_path(__FILE__)."include/scripts/front-end/jq/$script_type/photonic-".$slideshow_library.PHOTONIC_DEV_MODE.'.js'), !($photonic_always_load_scripts && $photonic_js_in_header));
399
400 $this->localize_variables_once();
401 }
402
403 function localize_variables_once() {
404 if ($this->localized) {
405 return;
406 }
407 // Technicall JS, but needs to happen here, otherwise the script is repeated multiple times, once for each time
408 // <code>conditionally_add_scripts</code> is called.
409 $js_array = $this->get_localized_js_variables();
410 wp_localize_script('photonic', 'Photonic_JS', $js_array);
411 $this->localized = true;
412 }
413
414 /**
415 * Adds all styles to all pages because styles, if not added in the header can cause issues.
416 *
417 * @return void
418 */
419 function always_add_styles() {
420 global $photonic_slideshow_library, $photonic_custom_lightbox_css, $photonic_disable_photonic_lightbox_scripts, $photonic_disable_photonic_slider_scripts;
421
422 if ($photonic_slideshow_library == 'custom') {
423 $counter = 1;
424 foreach(preg_split("/((\r?\n)|(\r\n?))/", $photonic_custom_lightbox_css) as $line){
425 wp_enqueue_style('photonic-lightbox-'.$counter, trim($line), [], PHOTONIC_VERSION);
426 $counter++;
427 }
428 }
429
430 if ($photonic_slideshow_library != 'none') {
431 if (empty($photonic_slideshow_library)) {
432 $photonic_slideshow_library = 'swipebox';
433 }
434 }
435
436 global $photonic_custom_lightbox;
437 $slideshow_library = !empty($photonic_disable_photonic_lightbox_scripts) ? 'none' :
438 ($photonic_slideshow_library == 'custom' ? $photonic_custom_lightbox : $photonic_slideshow_library);
439
440 $this->enqueue_lightbox_styles($slideshow_library, empty($photonic_disable_photonic_slider_scripts));
441
442 global $photonic_css_in_file;
443 $file = trailingslashit(PHOTONIC_UPLOAD_DIR).'custom-styles.css';
444 if (@file_exists($file) && !empty($photonic_css_in_file)) {
445 wp_enqueue_style('photonic-custom', trailingslashit(PHOTONIC_UPLOAD_URL).'custom-styles.css', ['photonic'], $this->get_version($file));
446 }
447 }
448
449 function enqueue_lightbox_styles($slideshow_library = 'swipebox', $combine_slider = true) {
450 $template_directory = get_template_directory();
451 $stylesheet_directory = get_stylesheet_directory();
452
453 $folder = $combine_slider ? 'combo-slider' : 'combo';
454
455 if ($slideshow_library == 'colorbox') {
456 global $photonic_cbox_theme;
457 if ($photonic_cbox_theme == 'theme' && @file_exists($stylesheet_directory.'/scripts/colorbox/colorbox.css')) {
458 wp_enqueue_style('photonic-lightbox', get_stylesheet_directory_uri().'/scripts/colorbox/colorbox.css', [], PHOTONIC_VERSION);
459 }
460 else if ($photonic_cbox_theme == 'theme' && @file_exists($template_directory.'/scripts/colorbox/colorbox.css')) {
461 wp_enqueue_style('photonic-lightbox', get_template_directory_uri().'/scripts/colorbox/colorbox.css', [], PHOTONIC_VERSION);
462 }
463 else if ($photonic_cbox_theme == 'theme') {
464 wp_enqueue_style('photonic-lightbox', plugins_url('include/scripts/third-party/colorbox/style-1/colorbox.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/third-party/colorbox/style-1/colorbox.css'));
465 }
466 else {
467 wp_enqueue_style('photonic-lightbox', plugins_url('include/scripts/third-party/colorbox/style-'.$photonic_cbox_theme.'/colorbox.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/third-party/colorbox/style-'.$photonic_cbox_theme.'/colorbox.css'));
468 }
469 }
470 else if ($slideshow_library == 'lightgallery') {
471 global $photonic_enable_lg_transitions;
472 if (!empty($photonic_enable_lg_transitions)) {
473 wp_enqueue_style('photonic-lightbox-lg-transitions', plugins_url('include/scripts/third-party/lightgallery/lightgallery-transitions.min.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/third-party/lightgallery/lightgallery-transitions.min.css'));
474 }
475 }
476 else if ($slideshow_library == 'thickbox') {
477 wp_enqueue_style('thickbox');
478 }
479
480 wp_enqueue_style('photonic', plugins_url("include/css/front-end/$folder/photonic-$slideshow_library.min.css", __FILE__), [], $this->get_version(plugin_dir_path(__FILE__)."include/css/front-end/$folder/photonic-$slideshow_library.min.css"));
481 }
482
483 /**
484 * Prints the custom CSS directly in the header if the option is not set to include it as a file
485 */
486 function print_scripts() {
487 global $photonic_css_in_file;
488 $file = trailingslashit(PHOTONIC_UPLOAD_DIR).'custom-styles.css';
489 if (!@file_exists($file) || empty($photonic_css_in_file)) {
490 $this->generate_css();
491 }
492 }
493
494 /**
495 * Prints the dynamically generated CSS based on option selections.
496 *
497 * @param bool $header
498 * @return string
499 */
500 function generate_css($header = true) {
501 global $photonic_flickr_collection_set_constrain_by_padding, $photonic_flickr_photos_constrain_by_padding, $photonic_flickr_photos_pop_constrain_by_padding, $photonic_flickr_galleries_constrain_by_padding;
502 global $photonic_smug_photos_constrain_by_padding, $photonic_smug_photos_pop_constrain_by_padding, $photonic_smug_albums_album_constrain_by_padding, $photonic_instagram_photos_constrain_by_padding;
503 global $photonic_zenfolio_photos_constrain_by_padding, $photonic_zenfolio_sets_constrain_by_padding, $photonic_tile_spacing, $photonic_masonry_tile_spacing, $photonic_mosaic_tile_spacing, $photonic_masonry_min_width;
504 global $photonic_google_photos_constrain_by_padding;
505
506 $css = '';
507 if ($header) {
508 $css .= '<style type="text/css">'."\n";
509 }
510
511 $saved_css = get_option('photonic_css');
512
513 if ($header && !empty($saved_css)) {
514 $css .= "/* Retrieved from saved CSS */\n";
515 $css .= $saved_css;
516 }
517 else {
518 if ($header) {
519 $css .= "/* Dynamically generated CSS */\n";
520 }
521 $css .= ".photonic-panel { ".
522 $this->get_bg_css('photonic_flickr_gallery_panel_background').
523 $this->get_border_css('photonic_flickr_set_popup_thumb_border').
524 " }\n";
525
526 $css .= ".photonic-flickr-stream .photonic-pad-photosets { margin: {$photonic_flickr_collection_set_constrain_by_padding}px; }\n";
527 $css .= ".photonic-flickr-stream .photonic-pad-galleries { margin: {$photonic_flickr_galleries_constrain_by_padding}px; }\n";
528 $css .= ".photonic-flickr-stream .photonic-pad-photos { padding: 5px {$photonic_flickr_photos_constrain_by_padding}px; }\n";
529
530 $css .= ".photonic-google-stream .photonic-pad-photos { padding: 5px {$photonic_google_photos_constrain_by_padding}px; }\n";
531
532 $css .= ".photonic-zenfolio-stream .photonic-pad-photos { padding: 5px {$photonic_zenfolio_photos_constrain_by_padding}px; }\n";
533 $css .= ".photonic-zenfolio-stream .photonic-pad-photosets { margin: 5px {$photonic_zenfolio_sets_constrain_by_padding}px; }\n";
534
535 $css .= ".photonic-instagram-stream .photonic-pad-photos { padding: 5px {$photonic_instagram_photos_constrain_by_padding}px; }\n";
536
537 $css .= ".photonic-smug-stream .photonic-pad-albums { margin: {$photonic_smug_albums_album_constrain_by_padding}px; }\n";
538 $css .= ".photonic-smug-stream .photonic-pad-photos { padding: 5px {$photonic_smug_photos_constrain_by_padding}px; }\n";
539
540 $css .= ".photonic-flickr-panel .photonic-pad-photos { padding: 10px {$photonic_flickr_photos_pop_constrain_by_padding}px; box-sizing: border-box; }\n";
541 $css .= ".photonic-smug-panel .photonic-pad-photos { padding: 10px {$photonic_smug_photos_pop_constrain_by_padding}px; box-sizing: border-box; }\n";
542
543 $css .= ".photonic-random-layout .photonic-thumb { padding: {$photonic_tile_spacing}px}\n";
544 $css .= ".photonic-masonry-layout .photonic-thumb { padding: {$photonic_masonry_tile_spacing}px}\n";
545 $css .= ".photonic-mosaic-layout .photonic-thumb { padding: {$photonic_mosaic_tile_spacing}px}\n";
546
547 $css .= ".photonic-ie .photonic-masonry-layout .photonic-level-1, .photonic-ie .photonic-masonry-layout .photonic-level-2 { width: ".(absint($photonic_masonry_min_width) ? absint($photonic_masonry_min_width) : 200)."px; }\n";
548 }
549
550 if ($header) {
551 $css .= "\n</style>\n";
552 echo $css;
553 }
554 return $css;
555 }
556
557 function get_version($file) {
558 return date("Ymd-Gis", @filemtime($file));
559 }
560
561 function admin_init() {
562 if (!empty($_REQUEST['page']) &&
563 in_array($_REQUEST['page'], ['photonic-options-manager', 'photonic-options', 'photonic-helpers', 'photonic-getting-started', 'photonic-auth', 'photonic-gutenberg'])) {
564 global $photonic_options_manager;
565 require_once(plugin_dir_path(__FILE__)."/photonic-options-manager.php");
566 $photonic_options_manager = new Photonic_Options_Manager(__FILE__, $this);
567 $photonic_options_manager->init();
568 }
569 }
570
571 function add_extensions() {
572 require_once(plugin_dir_path(__FILE__)."/extensions/Photonic_Processor.php");
573 require_once(plugin_dir_path(__FILE__)."/extensions/Photonic_OAuth1_Processor.php");
574 require_once(plugin_dir_path(__FILE__)."/extensions/Photonic_OAuth2_Processor.php");
575 $this->register_extension('Photonic_Flickr_Processor', plugin_dir_path(__FILE__)."/extensions/Photonic_Flickr_Processor.php");
576 $this->register_extension('Photonic_Google_Photos_Processor', plugin_dir_path(__FILE__)."/extensions/Photonic_Google_Photos_Processor.php");
577 $this->register_extension('Photonic_Native_Processor', plugin_dir_path(__FILE__)."/extensions/Photonic_Native_Processor.php");
578 $this->register_extension('Photonic_SmugMug_Processor', plugin_dir_path(__FILE__)."/extensions/Photonic_SmugMug_Processor.php");
579 $this->register_extension('Photonic_Instagram_Processor', plugin_dir_path(__FILE__)."/extensions/Photonic_Instagram_Processor.php");
580 $this->register_extension('Photonic_Zenfolio_Processor', plugin_dir_path(__FILE__)."/extensions/Photonic_Zenfolio_Processor.php");
581
582 require_once(plugin_dir_path(__FILE__).'/layouts/Layout_Default.php');
583 require_once(plugin_dir_path(__FILE__).'/layouts/Layout_Slideshow.php');
584
585 do_action('photonic_register_extensions');
586 }
587
588 public function register_extension($extension, $path) {
589 if (@!file_exists($path)) {
590 return;
591 }
592 require_once($path);
593 if (!class_exists($extension) || is_subclass_of($extension, 'Photonic_Processor')) {
594 return;
595 }
596 $this->registered_extensions[] = $extension;
597 }
598
599 /**
600 * Overrides the native gallery short code, and does a lot more.
601 *
602 * @param $content
603 * @param array $attr
604 * @return string
605 */
606 function modify_gallery($content, $attr = []) {
607 global $photonic_alternative_shortcode;
608
609 // If an alternative shortcode is used, then $content has the shortcode attributes
610 if (!empty($photonic_alternative_shortcode)) {
611 $attr = $content;
612 }
613 if ($attr == null) {
614 $attr = [];
615 }
616
617 $this->conditionally_add_scripts($attr);
618 $images = $this->get_gallery_images($attr);
619
620 if (isset($images) && !is_array($images)) {
621 return $images;
622 }
623
624 return $content;
625 }
626
627 /**
628 * Adds Photonic attributes to the native WP galleries. This cannot be called in <code>Photonic_Native_Processor</code> because
629 * that class is not initialised until a gallery of the native type is encountered
630 *
631 * @param $out
632 * @param $pairs
633 * @param $attributes
634 * @return mixed
635 */
636 function native_gallery_attributes($out, $pairs, $attributes) {
637 global $photonic_wp_title_caption, $photonic_enable_popup, $photonic_thumbnail_style, $photonic_alternative_shortcode;
638 if (!empty($photonic_alternative_shortcode) && $photonic_alternative_shortcode != 'gallery') {
639 return $out;
640 }
641
642 $bypass = !isset($photonic_enable_popup) || $photonic_enable_popup === false || $photonic_enable_popup == '' || $photonic_enable_popup == 'off';
643 $defaults = [
644 'layout' => !empty($photonic_thumbnail_style) ? $photonic_thumbnail_style : 'square',
645 'more' => '',
646 'display' => 'in-page',
647 'panel' => '',
648 'filter' => '',
649 'filter_type' => 'include',
650 'fx' => 'slide', // LightSlider effects: fade and slide
651 'timeout' => 4000, // Time between slides in ms
652 'speed' => 1000, // Time for each transition
653 'pause' => true, // Pause on hover
654 'strip-style' => 'thumbs',
655 'controls' => 'show',
656 'popup' => $bypass ? 'hide' : 'show',
657
658 'custom_classes' => '',
659 'alignment' => '',
660
661 'caption' => $photonic_wp_title_caption,
662 'page' => 1,
663 'count' => -1,
664 'thumb_width' => 75,
665 'thumb_height' => 75,
666 'thumb_size' => 'thumbnail',
667 'slide_size' => 'large',
668 'slideshow_height' => 500,
669 ];
670
671 $attributes = array_merge($defaults, $attributes);
672 if (empty($attributes['style']) || ($attributes['style'] == 'default' && !empty($photonic_alternative_shortcode) && $photonic_alternative_shortcode != 'gallery')) {
673 $attributes['style'] = $attributes['layout'];
674 }
675
676 foreach ($attributes as $key => $value) {
677 $out[$key] = $value;
678 }
679 return $out;
680 }
681
682 /**
683 * @param array $attr
684 * @return string
685 */
686 function helper_shortcode($attr = []) {
687 if ($attr == null) {
688 $attr = [];
689 }
690
691 if (empty($attr['type']) || !in_array(strtolower($attr['type']), ['google', 'flickr', 'smugmug', 'zenfolio'])) {
692 return sprintf(esc_html__('Please specify a value for %1%s. Accepted values are %2$s, %3$s, %4$s, %5$s', 'photonic'), '<code>type</code>', '<code>google</code>', '<code>flickr</code>', '<code>smugmug</code>', '<code>zenfolio</code>');
693 }
694 $gallery = $this->initialize_extension($attr['type']);
695 return $gallery->execute_helper($attr);
696 }
697
698 /**
699 * @param $attr
700 * @return array|bool|string
701 */
702 private function get_gallery_images($attr) {
703 global $photonic_nested_shortcodes;
704 $attr = array_merge([
705 // Especially for Photonic
706 'type' => 'default', //default, flickr, smugmug, google, zenfolio, instagram
707 'style' => 'default', //default, strip-below, strip-above, strip-right, strip-left, no-strip, launch
708 // 'id' => $post->ID,
709 // 'layout' => isset($photonic_thumbnail_style) ? $photonic_thumbnail_style : 'square',
710 ], $attr);
711
712 if ($photonic_nested_shortcodes) {
713 $attr = array_map('do_shortcode', $attr);
714 }
715
716 extract($attr);
717
718 $type = strtolower($attr['type']);
719
720 if ($type == 'picasa') {
721 $message = esc_html__('Google has deprecated the Picasa API. Please consider switching over to Google Photos', 'photonic');
722 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";
723 }
724
725 if ($type == '500px') {
726 $message = esc_html__('The API for 500px.com is no longer available for public use.', 'photonic');
727 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";
728 }
729
730 if (!empty($attr['show_gallery']) && in_array($type, ['flickr', 'smugmug', 'google', 'zenfolio', 'instagram'])) { // Lazy button not for WP galleries
731 $images = $this->get_show_gallery_button($attr);
732 }
733 else {
734 if (!in_array($type, ['flickr', 'smugmug', 'google', 'zenfolio', 'instagram'])) {
735 $gallery = $this->initialize_extension('native');
736 }
737 else {
738 $gallery = $this->initialize_extension($type);
739 }
740
741 if (!is_null($gallery)) {
742 $images = $gallery->get_gallery_images($attr);
743 }
744 }
745
746 return $images;
747 }
748
749 /**
750 * @param $provider
751 * @return Photonic_Processor|Photonic_Flickr_Processor|Photonic_Instagram_Processor|Photonic_Native_Processor|Photonic_Google_Photos_Processor|Photonic_SmugMug_Processor|Photonic_Zenfolio_Processor
752 */
753 function initialize_extension($provider) {
754 global $photonic_flickr_gallery, $photonic_google_gallery, $photonic_smugmug_gallery, $photonic_instagram_gallery,
755 $photonic_zenfolio_gallery, $photonic_fb_gallery, $photonic_native_gallery;
756 if ($provider == 'flickr') {
757 if (!isset($photonic_flickr_gallery)) $photonic_flickr_gallery = new Photonic_Flickr_Processor();
758 return $photonic_flickr_gallery;
759 }
760 else if ($provider == 'google') {
761 if (!isset($photonic_google_gallery)) $photonic_google_gallery = new Photonic_Google_Photos_Processor();
762 return $photonic_google_gallery;
763 }
764 else if ($provider == 'smugmug' || $provider == 'smug') {
765 if (!isset($photonic_smugmug_gallery)) $photonic_smugmug_gallery = new Photonic_SmugMug_Processor();
766 return $photonic_smugmug_gallery;
767 }
768 else if ($provider == 'zenfolio') {
769 if (!isset($photonic_zenfolio_gallery)) $photonic_zenfolio_gallery = new Photonic_Zenfolio_Processor();
770 return $photonic_zenfolio_gallery;
771 }
772 else if ($provider == 'instagram') {
773 if (!isset($photonic_instagram_gallery)) $photonic_instagram_gallery = new Photonic_Instagram_Processor();
774 return $photonic_instagram_gallery;
775 }
776 else {
777 if (!isset($photonic_native_gallery)) $photonic_native_gallery = new Photonic_Native_Processor();
778 return $photonic_native_gallery;
779 }
780 }
781
782 /**
783 * Clicking on a level 2 object (i.e. an Album / Set / Gallery) triggers this. This will fetch the contents of the level 2 object and generate the markup for it.
784 *
785 * @return void
786 */
787 function display_level_2_contents() {
788 $panel = esc_attr($_POST['panel_id']);
789 $components = explode('-', $panel);
790
791 if (count($components) <= 5) {
792 die();
793 }
794 $panel = implode('-', array_slice($components, 4, 10, true));
795 $query = sanitize_text_field($_POST['query']);
796 $query = wp_parse_args($query);
797
798 $args = [
799 'display' => 'popup',
800 'layout' => 'square',
801 'panel' => $panel,
802 'password' => !empty($_POST['password']) ? sanitize_text_field($_POST['password']) : '',
803 'count' => sanitize_text_field($_POST['photo_count']),
804 'photo_more' => sanitize_text_field($_POST['photo_more']),
805 'main_size' => $query['main_size'],
806 ];
807
808 $provider = $components[1];
809 $type = $components[2];
810 if ($provider == 'smug') {
811 $this->check_authentication_smug();
812 $args['view'] = 'album';
813 $args['album_key'] = $components[4];
814 $gallery = $this->initialize_extension('smugmug');
815 }
816 else if ($provider == 'zenfolio') {
817 $args['view'] = 'photosets';
818 $args['object_id'] = $components[4];
819 $args['thumb_size'] = sanitize_text_field($_POST['overlay_size']);
820 $args['video_size'] = sanitize_text_field($_POST['overlay_video_size']);
821 $args['realm_id'] = sanitize_text_field($_POST['realm_id']);
822 $gallery = $this->initialize_extension('zenfolio');
823 }
824 else if ($provider == 'google') {
825 $args['view'] = 'photos';
826 $args['album_id'] = implode('-', array_slice($components, 4, (count($components) - 1) - 4));
827 $args['thumb_size'] = sanitize_text_field($_POST['overlay_size']);
828 $args['video_size'] = sanitize_text_field($_POST['overlay_video_size']);
829 $args['crop_thumb'] = sanitize_text_field($_POST['overlay_crop']);
830 $gallery = $this->initialize_extension('google');
831 }
832 else if ($provider == 'flickr') {
833 if ($type == 'gallery') {
834 $args['gallery_id'] = $components[4].'-'.$components[5];
835 $args['gallery_id_computed'] = true;
836 }
837 else if ($type = 'set') {
838 $args['photoset_id'] = $components[4];
839 }
840 $args['thumb_size'] = sanitize_text_field($_POST['overlay_size']);
841 $args['video_size'] = sanitize_text_field($_POST['overlay_video_size']);
842 $gallery = $this->initialize_extension('flickr');
843 }
844
845 echo $gallery->get_gallery_images($args);
846 die();
847 }
848
849 function display_level_3_contents() {
850 $node = esc_attr($_POST['node']);
851 $components = explode('-', $node);
852
853 if (count($components) <= 3) {
854 die();
855 }
856
857 $args = ['display' => 'in-page', 'headers' => '', 'layout' => esc_attr($_POST['layout'])];
858
859 $provider = $components[0];
860 if ($provider == 'flickr') {
861 $args['collection_id'] = implode('-', array_slice($components, 2, 2, true));
862 $args['user_id'] = $components[4];
863 $gallery = $this->initialize_extension('flickr');
864 }
865
866 echo $gallery->get_gallery_images($args);
867 die();
868 }
869
870 /**
871 * Checks if a text being passed to it is an integer or not.
872 *
873 * @param $val
874 * @return bool
875 */
876 static function check_integer($val) {
877 if (substr($val, 0, 1) == '-') {
878 $val = substr($val, 1);
879 }
880 return (preg_match('/^\d*$/', $val) == 1);
881 }
882
883 /**
884 * Converts a string to a boolean variable, if possible.
885 *
886 * @param $value
887 * @return bool
888 */
889 static function string_to_bool($value) {
890 if ($value == true || $value == 'true' || $value == 'TRUE' || $value == '1') {
891 return true;
892 }
893 else if ($value == false || $value == 'false' || $value == 'FALSE' || $value == '0') {
894 return false;
895 }
896 else {
897 return $value;
898 }
899 }
900
901 /**
902 * Constructs the CSS for a "background" option
903 *
904 * @param $option
905 * @return string
906 */
907 function get_bg_css($option) {
908 global ${$option};
909 $option_val = ${$option};
910 if (!is_array($option_val)) {
911 $val_array = [];
912 $vals = explode(';', $option_val);
913 foreach ($vals as $val) {
914 if (trim($val) == '') { continue; }
915 $pair = explode('=', $val);
916 $val_array[$pair[0]] = $pair[1];
917 }
918 $option_val = $val_array;
919 }
920 $bg_string = "";
921 $bg_rgba_string = "";
922 if (!isset($option_val['colortype']) || $option_val['colortype'] == 'transparent') {
923 $bg_string .= " transparent ";
924 }
925 else {
926 if (isset($option_val['color'])) {
927 if (substr($option_val['color'], 0, 1) == '#') {
928 $color_string = substr($option_val['color'],1);
929 }
930 else {
931 $color_string = $option_val['color'];
932 }
933 $rgb_str_array = [];
934 if (strlen($color_string)==3) {
935 $rgb_str_array[] = substr($color_string, 0, 1).substr($color_string, 0, 1);
936 $rgb_str_array[] = substr($color_string, 1, 1).substr($color_string, 1, 1);
937 $rgb_str_array[] = substr($color_string, 2, 1).substr($color_string, 2, 1);
938 }
939 else {
940 $rgb_str_array[] = substr($color_string, 0, 2);
941 $rgb_str_array[] = substr($color_string, 2, 2);
942 $rgb_str_array[] = substr($color_string, 4, 2);
943 }
944 $rgb_array = [];
945 $rgb_array[] = hexdec($rgb_str_array[0]);
946 $rgb_array[] = hexdec($rgb_str_array[1]);
947 $rgb_array[] = hexdec($rgb_str_array[2]);
948 $rgb_string = implode(',',$rgb_array);
949 $rgb_string = ' rgb('.$rgb_string.') ';
950
951 if (isset($option_val['trans'])) {
952 $bg_rgba_string = $bg_string;
953 $transparency = (int)$option_val['trans'];
954 if ($transparency != 0) {
955 $trans_dec = $transparency/100;
956 $rgba_string = implode(',', $rgb_array);
957 $rgba_string = ' rgba('.$rgba_string.','.$trans_dec.') ';
958 $bg_rgba_string .= $rgba_string;
959 }
960 }
961
962 $bg_string .= $rgb_string;
963 }
964 }
965 if (isset($option_val['image']) && trim($option_val['image']) != '') {
966 $bg_string .= " url(".$option_val['image'].") ";
967 $bg_string .= $option_val['position']." ".$option_val['repeat'];
968
969 if (trim($bg_rgba_string) != '') {
970 $bg_rgba_string .= " url(".$option_val['image'].") ";
971 $bg_rgba_string .= $option_val['position']." ".$option_val['repeat'];
972 }
973 }
974
975 if (trim($bg_string) != '') {
976 $bg_string = "background: ".$bg_string." !important;\n";
977 if (trim($bg_rgba_string) != '') {
978 $bg_string .= "\tbackground: ".$bg_rgba_string." !important;\n";
979 }
980 }
981 return $bg_string;
982 }
983
984 /**
985 * Generates the CSS for borders. Each border, top, right, bottom and left is generated as a separate line.
986 *
987 * @param $option
988 * @return string
989 */
990 function get_border_css($option) {
991 global ${$option};
992 $option_val = ${$option};
993 if (!is_array($option_val)) {
994 $option_val = stripslashes($option_val);
995 $edge_array = $this->build_edge_array($option_val);
996 $option_val = $edge_array;
997 }
998 $border_string = '';
999 foreach ($option_val as $edge => $selections) {
1000 $border_string .= "\tborder-$edge: ";
1001 if (!isset($selections['style'])) {
1002 $selections['style'] = 'none';
1003 }
1004 if ($selections['style'] == 'none') {
1005 $border_string .= "none";
1006 }
1007 else {
1008 if (isset($selections['border-width'])) {
1009 $border_string .= $selections['border-width'];
1010 }
1011 if (isset($selections['border-width-type'])) {
1012 $border_string .= $selections['border-width-type'];
1013 }
1014 else {
1015 $border_string .= "px";
1016 }
1017 $border_string .= " ".$selections['style']." ";
1018 if ($selections['colortype'] == 'transparent') {
1019 $border_string .= "transparent";
1020 }
1021 else {
1022 if (substr($selections['color'], 0, 1) == '#') {
1023 $border_string .= $selections['color'];
1024 }
1025 else {
1026 $border_string .= '#'.$selections['color'];
1027 }
1028 }
1029 }
1030 $border_string .= ";\n";
1031 }
1032 return "\n".$border_string;
1033 }
1034
1035 /**
1036 * Generates the CSS for use in padding. This generates individual padding strings for each side, top, right, bottom and left.
1037 *
1038 * @param $option
1039 * @return string
1040 */
1041 function get_padding_css($option) {
1042 global ${$option};
1043 $option_val = ${$option};
1044 if (!is_array($option_val)) {
1045 $option_val = stripslashes($option_val);
1046 $edge_array = $this->build_edge_array($option_val);
1047 $option_val = $edge_array;
1048 }
1049
1050 $edges = [];
1051 foreach ($option_val as $edge => $selections) {
1052 $padding = '';
1053 if (isset($selections['padding'])) {
1054 $padding .= $selections['padding'];
1055 }
1056 else {
1057 $padding .= 0;
1058 }
1059
1060 if ($padding != '0' && isset($selections['padding-type'])) {
1061 $padding .= $selections['padding-type'];
1062 }
1063 else if ($padding != '0') {
1064 $padding .= "px";
1065 }
1066 $edges[$edge] = $padding;
1067 }
1068
1069 $edge_master = ['top', 'right', 'bottom', 'left'];
1070 $consolidated = '';
1071 foreach ($edge_master as $edge) {
1072 $consolidated .= empty($edges[$edge]) ? '0 ' : $edges[$edge].' ';
1073 }
1074 $padding_string = "\tpadding: $consolidated;\n";
1075
1076 return $padding_string;
1077 }
1078
1079 public function build_edge_array($option_val) {
1080 $edge_array = [];
1081 $edges = explode('||', $option_val);
1082 foreach ($edges as $edge_val) {
1083 if (trim($edge_val) != '') {
1084 $edge_options = explode('::', trim($edge_val));
1085 if (is_array($edge_options) && count($edge_options) > 1) {
1086 $val_array = [];
1087 $vals = explode(';', $edge_options[1]);
1088 foreach ($vals as $val) {
1089 $pair = explode('=', $val);
1090 if (is_array($pair) && count($pair) > 1) {
1091 $val_array[$pair[0]] = $pair[1];
1092 }
1093 }
1094 $edge_array[$edge_options[0]] = $val_array;
1095 }
1096 }
1097 }
1098 return $edge_array;
1099 }
1100
1101 /**
1102 * Adds a "Photonic" tab to the "Add Media" panel.
1103 *
1104 * @param $tabs
1105 * @return array
1106 */
1107 function media_upload_tabs($tabs) {
1108 if (!function_exists('is_gutenberg_page') || (function_exists('is_gutenberg_page') && !is_gutenberg_page())) {
1109 $tabs['photonic'] = 'Photonic';
1110 }
1111 return $tabs;
1112 }
1113
1114 /**
1115 * Invokes the form to display the photonic insertion screen in the "Add Media" panel. The call to wp_iframe ensures that the right CSS and JS are called.
1116 *
1117 * @return void
1118 */
1119 function media_upload_photonic() {
1120 wp_iframe([&$this, 'media_upload_photonic_form']);
1121 }
1122
1123 /**
1124 * First prints the standard buttons for media upload, then shows the UI for Photonic.
1125 *
1126 * @return void
1127 */
1128 function media_upload_photonic_form() {
1129 media_upload_header();
1130 require_once(plugin_dir_path(__FILE__)."/admin/add-gallery.php");
1131 }
1132
1133 function edit_gallery() {
1134 global $photonic_disable_editor, $photonic_disable_editor_post_type;
1135 $disabled_types = explode(',', $photonic_disable_editor_post_type);
1136 $post_type = empty($_REQUEST['post_type']) ? 'post' : $_REQUEST['post_type'];
1137 // check if WYSIWYG is enabled
1138 if ('true' == get_user_option('rich_editing') && empty($photonic_disable_editor) && !in_array($post_type, $disabled_types)) {
1139 require_once(plugin_dir_path(__FILE__)."/admin/edit-gallery-templates.php");
1140 }
1141 }
1142
1143 static function get_image_sizes_selection($element_name, $show_full = false) {
1144 $image_sizes = self::get_wp_image_sizes($show_full);
1145 $ret = "<select name='$element_name'>";
1146 foreach ($image_sizes as $size_name => $size_attrs) {
1147 $ret .= "<option value='$size_name'>$size_name ({$size_attrs['width']} &times; {$size_attrs['height']})</option>";
1148 }
1149 $ret .= '</select>';
1150 return $ret;
1151 }
1152
1153 /**
1154 * Make an HTTP request
1155 *
1156 * @static
1157 * @param $url
1158 * @param string $method GET | POST | DELETE
1159 * @param null $post_fields
1160 * @param string $user_agent
1161 * @param int $timeout
1162 * @param bool $ssl_verify_peer
1163 * @param array $headers
1164 * @param array $cookies
1165 * @return array|WP_Error
1166 */
1167 static function http($url, $method = 'POST', $post_fields = NULL, $user_agent = null, $timeout = 90, $ssl_verify_peer = false, $headers = [], $cookies = []) {
1168 $curl_args = [
1169 'user-agent' => $user_agent,
1170 'timeout' => $timeout,
1171 'sslverify' => $ssl_verify_peer,
1172 'headers' => array_merge(['Expect:'], $headers),
1173 'method' => $method,
1174 'body' => $post_fields,
1175 'cookies' => $cookies,
1176 ];
1177
1178 switch ($method) {
1179 case 'DELETE':
1180 if (!empty($post_fields)) {
1181 $url = "{$url}?{$post_fields}";
1182 }
1183 break;
1184 }
1185
1186 $response = wp_remote_request($url, $curl_args);
1187 return $response;
1188 }
1189
1190 /**
1191 * Returns the page where the OAuth API is being invoked. The invocation happens through admin-ajax.php, but we don't want
1192 * the validated user to land up there. Instead we want the users to reach the page where they clicked the "Login" button.
1193 *
1194 * @static
1195 * @return string
1196 */
1197 static function get_callback_url() {
1198 global $photonic_callback_url;
1199 if (isset($photonic_callback_url)) {
1200 return $photonic_callback_url;
1201 }
1202
1203 $page_URL = 'http';
1204 if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
1205 $page_URL .= "s";
1206 }
1207 $page_URL .= "://";
1208 if (isset($_SERVER["SERVER_PORT"])) {
1209 $page_URL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
1210 }
1211 else if (!isset($_SERVER["SERVER_PORT"]) && $page_URL == 'http://') {
1212 $page_URL .= $_SERVER["SERVER_NAME"].":80".$_SERVER["REQUEST_URI"];
1213 }
1214 else if (!isset($_SERVER["SERVER_PORT"]) && $page_URL == 'https://') {
1215 $page_URL .= $_SERVER["SERVER_NAME"].":443".$_SERVER["REQUEST_URI"];
1216 }
1217 else {
1218 $page_URL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
1219 }
1220 return $page_URL;
1221 }
1222
1223 /**
1224 * Checks if a user has authenticated a particular provider's services. When this is invoked we don't know if the page has
1225 * a Flickr / SmugMug gallery, so we just invoke it and set some global variables.
1226 *
1227 * @return void
1228 */
1229 function check_authentication() {
1230 if (is_admin()) {
1231 return;
1232 }
1233 global $photonic_flickr_allow_oauth, $photonic_smug_allow_oauth;
1234 if (!$photonic_flickr_allow_oauth && !$photonic_smug_allow_oauth) {
1235 return;
1236 }
1237
1238 global $photonic_flickr_oauth_done, $photonic_smug_oauth_done;
1239 $photonic_flickr_oauth_done = $photonic_smug_oauth_done = false;
1240
1241 $cookie = Photonic::parse_cookie();
1242 global $photonic_flickr_gallery;
1243
1244 $this->check_provider_authentication($photonic_flickr_allow_oauth, 'flickr', $photonic_flickr_gallery, $photonic_flickr_oauth_done);
1245
1246 $this->check_authentication_smug($cookie);
1247 }
1248
1249 /**
1250 * Searches for specific cookies in the user's browser. It then builds an array with the available cookies. The keys of the array
1251 * are the individual providers ('flickr', 'smug' etc) and the values are arrays of key-value mappings.
1252 *
1253 * @static
1254 * @return array
1255 */
1256 public static function parse_cookie() {
1257 $cookie = [
1258 'flickr' => [],
1259 'smug' => [],
1260 ];
1261 $auth_types = [
1262 'flickr' => 'oauth1',
1263 'smug' => 'oauth1',
1264 ];
1265 $cookie_keys = ['oauth_token', 'oauth_token_secret', 'oauth_token_type', 'access_token', 'access_token_type', 'oauth_token_created', 'oauth_token_expires', 'oauth_refresh_token'];
1266 foreach ($cookie as $provider => $cookies) {
1267 $orig_secret = $auth_types[$provider] == 'oauth1' ? 'photonic_'.$provider.'_api_secret' : 'photonic_'.$provider.'_client_secret';
1268 global ${$orig_secret};
1269 if (isset(${$orig_secret})) {
1270 $secret = md5(${$orig_secret}, false);
1271 foreach ($cookie_keys as $cookie_key) {
1272 $key = '-'.str_replace('_', '-', $cookie_key);
1273 if (isset($_COOKIE['photonic-'.$secret.$key])) {
1274 $cookie[$provider][$cookie_key] = $_COOKIE['photonic-'.$secret.$key];
1275 }
1276 }
1277 }
1278 }
1279 return $cookie;
1280 }
1281
1282 /**
1283 * The initiation process for the authentication. When a user clicks on this button, a request token is obtained and the authorization
1284 * is performed. Then the user is redirected to an authorization site, where the user can authorize this site.
1285 */
1286 function authenticate() {
1287 if (isset($_POST['provider'])) {
1288 $provider = sanitize_text_field($_POST['provider']);
1289 $callback_id = sanitize_text_field($_POST['callback_id']);
1290 $post_id = substr($callback_id, 19);
1291 global $photonic_callback_url;
1292 $photonic_callback_url = get_permalink($post_id);
1293
1294 $gallery = $this->initialize_extension($provider);
1295 switch ($provider) {
1296 case 'flickr':
1297 $request_token = $gallery->get_request_token();
1298 $authorize_url = $gallery->get_authorize_URL($request_token);
1299 echo $authorize_url.'&perms=read';
1300 die;
1301
1302 case 'smug':
1303 $request_token = $gallery->get_request_token();
1304 $authorize_url = $gallery->get_authorize_URL($request_token);
1305 echo $authorize_url.'&Access=Full&Permissions=Read';
1306 die;
1307 }
1308 }
1309 }
1310
1311 function obtain_token() {
1312 global $photonic_google_gallery, $photonic_flickr_gallery, $photonic_smugmug_gallery, $photonic_zenfolio_gallery;
1313 $provider = sanitize_text_field($_POST['provider']);
1314 if ($provider == 'google') {
1315 $code = esc_attr($_POST['code']);
1316 $photonic_google_gallery = $this->initialize_extension('google');
1317 global $photonic_google_use_own_keys, $photonic_google_client_id, $photonic_google_client_secret;
1318 // if (!empty($photonic_google_use_own_keys) || (!empty($photonic_google_client_id) && !empty($photonic_google_client_secret))) {
1319 $response = Photonic::http($photonic_google_gallery->access_token_URL(), 'POST', [
1320 'code' => $code,
1321 'grant_type' => 'authorization_code',
1322 'client_id' => $photonic_google_gallery->client_id,
1323 'client_secret' => $photonic_google_gallery->client_secret,
1324 'redirect_uri' => admin_url('admin.php?page=photonic-auth&source=google'),
1325 ]);
1326 /* }
1327 else {
1328 $response = Photonic::http($photonic_google_gallery->access_token_URL(), 'POST', [
1329 'code' => $code,
1330 'grant_type' => 'authorization_code',
1331 'client_id' => $photonic_google_gallery->client_id,
1332 'client_secret' => $photonic_google_gallery->client_secret,
1333 'redirect_uri' => 'https://aquoid.com/photonic-router/google.php',
1334 'state' => admin_url('admin.php?page=photonic-auth&source=google'),
1335 ]);
1336 }*/
1337
1338 if (!is_wp_error($response) && is_array($response)) {
1339 echo($response['body']);
1340 }
1341 else {
1342 }
1343 }
1344 else if ($provider == 'flickr') {
1345 $photonic_flickr_gallery = $this->initialize_extension('flickr');
1346 if (empty($_POST['oauth_token']) && empty($_POST['oauth_verifier'])) {
1347 $request_token = $photonic_flickr_gallery->get_request_token(admin_url('admin.php?page=photonic-auth&provider=flickr'), false);
1348 $authorize_url = $photonic_flickr_gallery->get_authorize_URL($request_token);
1349 $authorize_url .= '&perms=read';
1350 $photonic_flickr_gallery->save_token($request_token);
1351 echo $authorize_url;
1352 }
1353 }
1354 else if ($provider == 'smug') {
1355 $photonic_smugmug_gallery = $this->initialize_extension('smugmug');
1356 if (empty($_POST['oauth_token']) && empty($_POST['oauth_verifier'])) {
1357 $request_token = $photonic_smugmug_gallery->get_request_token(admin_url('admin.php?page=photonic-auth&provider=smug'), false);
1358 $authorize_url = $photonic_smugmug_gallery->get_authorize_URL($request_token);
1359 $authorize_url .= '&Access=Full&Permissions=Read';
1360 $photonic_smugmug_gallery->save_token($request_token);
1361 echo $authorize_url;
1362 }
1363 }
1364 else if ($provider == 'zenfolio') {
1365 $photonic_zenfolio_gallery = $this->initialize_extension('zenfolio');
1366 if (!empty($_POST['password'])) {
1367 $response = $photonic_zenfolio_gallery->authenticate($_POST['password']);
1368 if (!empty($response['error'])) {
1369 echo $response['error'];
1370 }
1371 else if (!empty($response['success'])) {
1372 esc_html_e('Authentication successful! All your galleries will be displayed with Authentication in place.', 'photonic');
1373 }
1374 }
1375 }
1376 die();
1377 }
1378
1379 /**
1380 * Invoked via AJAX in the "Authentication" page, when the user clicks on "Save Token"
1381 */
1382 function save_token_in_options() {
1383 $provider = strtolower(sanitize_text_field($_POST['provider']));
1384 $token = esc_attr($_POST['token']);
1385 $secret = esc_attr($_POST['secret']);
1386 $expires_in = esc_attr($_POST['expires_in']);
1387
1388 $options = get_option('photonic_options');
1389 if (empty($options)) {
1390 $options = [];
1391 }
1392 $option_set = false;
1393 if (in_array($provider, ['flickr', 'smug', 'zenfolio'])) {
1394 $options[$provider.'_access_token'] = $token;
1395 $options[$provider.'_token_secret'] = $secret;
1396 $option_set = true;
1397 }
1398 else if (in_array($provider, ['google'])) {
1399 $options[$provider.'_refresh_token'] = $token;
1400 $option_set = true;
1401 }
1402 else if (in_array($provider, ['instagram'])) {
1403 $client_id = esc_attr($_POST['client_id']);
1404 $user = esc_attr($_POST['user']);
1405
1406 $options[$provider.'_access_token'] = $token;
1407
1408 $auth_token = [];
1409 $auth_token['oauth_token'] = $token;
1410 $auth_token['oauth_token_created'] = time();
1411 $auth_token['oauth_token_expires'] = $expires_in;
1412 $auth_token['client_id'] = $client_id;
1413 $auth_token['user'] = $user;
1414
1415 self::save_provider_authentication($provider, $auth_token);
1416
1417 $option_set = true;
1418 }
1419
1420 if ($option_set) {
1421 update_option('photonic_options', $options);
1422 echo admin_url('admin.php?page=photonic-options-manager&tab='.($provider == 'smug' ? 'smugmug' : $provider).'-options.php');
1423 }
1424 die();
1425 }
1426
1427 function delete_token_from_options() {
1428 $provider = strtolower(sanitize_text_field($_POST['provider']));
1429 $photonic_authentication = get_option('photonic_authentication');
1430 if ($provider == 'zenfolio') {
1431 if (isset($photonic_authentication[$provider])) {
1432 unset($photonic_authentication[$provider]);
1433 }
1434 }
1435 update_option('photonic_authentication', $photonic_authentication);
1436 die();
1437 }
1438
1439 function invoke_helper() {
1440 global $photonic_options_manager;
1441 require_once(plugin_dir_path(__FILE__)."/photonic-options-manager.php");
1442 $photonic_options_manager = new Photonic_Options_Manager(__FILE__, $this);
1443 $photonic_options_manager->init();
1444 $photonic_options_manager->invoke_helper();
1445 }
1446
1447 /**
1448 * @return array
1449 */
1450 public function get_localized_js_variables() {
1451 global $photonic_lightbox_no_loop, $photonic_slideshow_mode, $photonic_slideshow_interval, $photonic_slideshow_library, $photonic_custom_lightbox,
1452 $photonic_cb_transition_effect, $photonic_cb_transition_speed,
1453 $photonic_fbox_title_position, $photonic_fb3_transition_effect, $photonic_fb3_transition_speed, $photonic_fb3_show_fullscreen, $photonic_enable_fb3_fullscreen,
1454 $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,
1455 $photonic_lc_transition_effect, $photonic_lc_transition_speed_in, $photonic_lc_transition_speed_out, $photonic_lc_enable_shrink,
1456 $photonic_lg_transition_effect, $photonic_lg_transition_speed, $photonic_disable_lg_download, $photonic_lg_hide_bars_delay,
1457 $photonic_tile_spacing, $photonic_tile_min_height, $photonic_pphoto_theme, $photonic_pp_animation_speed,
1458 $photonic_enable_swipebox_mobile_bars, $photonic_sb_hide_mobile_close, $photonic_sb_hide_bars_delay,
1459 $photonic_lightbox_for_all, $photonic_lightbox_for_videos, $photonic_popup_panel_width, $photonic_deep_linking, $photonic_social_media,
1460 $photonic_slideshow_prevent_autostart, $photonic_wp_slide_adjustment, $photonic_masonry_min_width, $photonic_mosaic_trigger_width,
1461 $photonic_is_IE, $photonic_debug_on;
1462
1463 global $photonic_js_variables;
1464
1465 $slideshow_library = $photonic_slideshow_library == 'custom' ? $photonic_custom_lightbox : $photonic_slideshow_library;
1466 $js_array = [
1467 'ajaxurl' => admin_url('admin-ajax.php'),
1468 'plugin_url' => PHOTONIC_URL,
1469 'is_old_IE' => $photonic_is_IE,
1470 'debug_on' => !empty($photonic_debug_on),
1471
1472 'fbox_show_title' => $photonic_fbox_title_position == 'none' ? false : true,
1473 'fbox_title_position' => $photonic_fbox_title_position == 'none' ? 'outside' : $photonic_fbox_title_position,
1474
1475 'slide_adjustment' => empty($photonic_wp_slide_adjustment) ? 'adapt-height-width' : $photonic_wp_slide_adjustment,
1476
1477 'deep_linking' => isset($photonic_deep_linking) ? $photonic_deep_linking : 'none',
1478 'social_media' => isset($photonic_deep_linking) ? $photonic_deep_linking != 'none' && empty($photonic_social_media) : '',
1479
1480 'slideshow_library' => $slideshow_library,
1481 'tile_spacing' => (empty($photonic_tile_spacing) || !absint($photonic_tile_spacing)) ? 0 : absint($photonic_tile_spacing),
1482 'tile_min_height' => (empty($photonic_tile_min_height) || !absint($photonic_tile_min_height)) ? 200 : absint($photonic_tile_min_height),
1483 'masonry_min_width' => (empty($photonic_masonry_min_width) || !absint($photonic_masonry_min_width)) ? 200 : absint($photonic_masonry_min_width),
1484 'mosaic_trigger_width' => (empty($photonic_mosaic_trigger_width) || !absint($photonic_mosaic_trigger_width)) ? 200 : absint($photonic_mosaic_trigger_width),
1485
1486 'slideshow_mode' => (isset($photonic_slideshow_mode) && $photonic_slideshow_mode == 'on') ? true : false,
1487 'slideshow_interval' => (isset($photonic_slideshow_interval) && absint($photonic_slideshow_interval)) ? absint($photonic_slideshow_interval) : 5000,
1488 'lightbox_loop' => empty($photonic_lightbox_no_loop),
1489
1490 '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),
1491
1492 'cb_transition_effect' => empty($photonic_cb_transition_effect) ? 'elastic' : $photonic_cb_transition_effect,
1493 'cb_transition_speed' => (isset($photonic_cb_transition_speed) && absint($photonic_cb_transition_speed)) ? absint($photonic_cb_transition_speed) : 350,
1494
1495 'fb3_transition_effect' => empty($photonic_fb3_transition_effect) ? 'zoom' : $photonic_fb3_transition_effect,
1496 'fb3_transition_speed' => (isset($photonic_fb3_transition_speed) && absint($photonic_fb3_transition_speed)) ? absint($photonic_fb3_transition_speed) : 366,
1497 'fb3_fullscreen_button' => !empty($photonic_fb3_show_fullscreen),
1498 'fb3_fullscreen' => isset($photonic_enable_fb3_fullscreen) && $photonic_enable_fb3_fullscreen == 'on' ? true : false,
1499 'fb3_thumbs_button' => empty($photonic_fb3_hide_thumbs),
1500 'fb3_thumbs' => isset($photonic_enable_fb3_thumbnail) && $photonic_enable_fb3_thumbnail == 'on' ? true : false,
1501 'fb3_zoom' => empty($photonic_fb3_disable_zoom),
1502 'fb3_slideshow' => empty($photonic_fb3_disable_slideshow),
1503 'fb3_download' => !empty($photonic_fb3_enable_download),
1504 'fb3_disable_right_click' => !empty($photonic_fb3_disable_right_click),
1505
1506 'lc_transition_effect' => empty($photonic_lc_transition_effect) ? 'scrollHorizontal' : $photonic_lc_transition_effect,
1507 'lc_transition_speed_in' => (isset($photonic_lc_transition_speed_in) && absint($photonic_lc_transition_speed_in)) ? absint($photonic_lc_transition_speed_in) : 350,
1508 'lc_transition_speed_out' => (isset($photonic_lc_transition_speed_out) && absint($photonic_lc_transition_speed_out)) ? absint($photonic_lc_transition_speed_out) : 250,
1509 'lc_disable_shrink' => empty($photonic_lc_enable_shrink),
1510
1511 'lg_transition_effect' => empty($photonic_lg_transition_effect) ? 'lg-slide' : $photonic_lg_transition_effect,
1512 'lg_enable_download' => empty($photonic_disable_lg_download),
1513 'lg_hide_bars_delay' => (isset($photonic_lg_hide_bars_delay) && absint($photonic_lg_hide_bars_delay)) ? absint($photonic_lg_hide_bars_delay) : 6000,
1514 'lg_transition_speed' => (isset($photonic_lg_transition_speed) && absint($photonic_lg_transition_speed)) ? absint($photonic_lg_transition_speed) : 600,
1515
1516 'pphoto_theme' => isset($photonic_pphoto_theme) ? $photonic_pphoto_theme : 'pp_default',
1517 'pphoto_animation_speed' => empty($photonic_pp_animation_speed) ? 'fast' : $photonic_pp_animation_speed,
1518
1519 'enable_swipebox_mobile_bars' => !empty($photonic_enable_swipebox_mobile_bars),
1520 'sb_hide_mobile_close' => !empty($photonic_sb_hide_mobile_close),
1521 'sb_hide_bars_delay' => (isset($photonic_sb_hide_bars_delay) && absint($photonic_sb_hide_bars_delay)) ? absint($photonic_sb_hide_bars_delay) : 0,
1522
1523 'lightbox_for_all' => !empty($photonic_lightbox_for_all),
1524 'lightbox_for_videos' => !empty($photonic_lightbox_for_videos),
1525
1526 'slideshow_autostart' => !(isset($photonic_slideshow_prevent_autostart) && $photonic_slideshow_prevent_autostart == 'on'),
1527
1528 'password_failed' => esc_attr__('This album is password-protected. Please provide a valid password.', 'photonic'),
1529 'incorrect_password' => esc_attr__('Incorrect password.', 'photonic'),
1530 'maximize_panel' => esc_attr__('Show', 'photonic'),
1531 'minimize_panel' => esc_attr__('Hide', 'photonic'),
1532 ];
1533 $photonic_js_variables = $js_array;
1534 return $js_array;
1535 }
1536
1537 function enable_translations() {
1538 load_plugin_textdomain('photonic', FALSE, FALSE);
1539 }
1540
1541 /**
1542 * Checks authentication status for a provider, by verifying both, server-side and client-side authentication.
1543 *
1544 * @param $allow_auth
1545 * @param $provider
1546 * @param $gallery Photonic_OAuth1_Processor|Photonic_OAuth2_Processor
1547 * @param $oauth_done
1548 */
1549 function check_provider_authentication($allow_auth, $provider, &$gallery, &$oauth_done) {
1550 $this->initialize_extension($provider);
1551 $cookie = Photonic::parse_cookie();
1552 if ($allow_auth && isset($cookie[$provider]) && isset($cookie[$provider]['oauth_token']) && isset($cookie[$provider]['oauth_token_secret'])) {
1553 $current_token = [
1554 'oauth_token' => $cookie[$provider]['oauth_token'],
1555 'oauth_token_secret' => $cookie[$provider]['oauth_token_secret'],
1556 ];
1557 if (isset($_REQUEST['oauth_verifier']) && isset($_REQUEST['oauth_token'])) {
1558 $current_token['oauth_token'] = $_REQUEST['oauth_token'];
1559 $current_token['oauth_verifier'] = $_REQUEST['oauth_verifier'];
1560 $new_token = $gallery->get_access_token($current_token);
1561 if (isset($new_token['oauth_token']) && isset($new_token['oauth_token_secret'])) {
1562 // Strip out the token and the verifier from the callback URL and send the user to the callback URL.
1563 $oauth_done = true;
1564 $redirect = remove_query_arg(['oauth_token', 'oauth_verifier']);
1565 wp_redirect($redirect);
1566 exit;
1567 }
1568 }
1569 else if (isset($cookie[$provider]['oauth_token_type']) && $cookie[$provider]['oauth_token_type'] == 'access') {
1570 $access_token_response = $gallery->check_access_token($current_token);
1571 if (is_wp_error($access_token_response)) {
1572 $gallery->is_server_down = true;
1573 }
1574 $oauth_done = $gallery->is_access_token_valid($access_token_response);
1575 }
1576 }
1577 else if (!empty($gallery->token) && !empty($gallery->token_secret)) {
1578 $token = ['oauth_token' => $gallery->token, 'oauth_token_secret' => $gallery->token_secret];
1579 $access_token_response = $gallery->check_access_token($token);
1580 if (is_wp_error($access_token_response)) {
1581 $gallery->is_server_down = true;
1582 }
1583 $oauth_done = $gallery->is_access_token_valid($access_token_response);
1584 }
1585 }
1586
1587 /**
1588 * @param $cookie
1589 * @return void
1590 */
1591 public function check_authentication_smug($cookie = null) {
1592 if ($cookie == null) {
1593 $cookie = Photonic::parse_cookie();
1594 }
1595
1596 global $photonic_smugmug_gallery, $photonic_smug_allow_oauth, $photonic_smug_oauth_done;
1597 $photonic_smugmug_gallery = $this->initialize_extension('smugmug');
1598 if ($photonic_smug_allow_oauth && isset($cookie['smug']) && isset($cookie['smug']['oauth_token']) && isset($cookie['smug']['oauth_token_secret'])) {
1599 $current_token = [
1600 'oauth_token' => $cookie['smug']['oauth_token'],
1601 'oauth_token_secret' => $cookie['smug']['oauth_token_secret']
1602 ];
1603
1604 if (!$photonic_smug_oauth_done &&
1605 ((isset($cookie['smug']['oauth_token_type']) && $cookie['smug']['oauth_token_type'] == 'request') || !isset($cookie['smug']['oauth_token_type']))) {
1606 $current_token['oauth_verifier'] = $_REQUEST['oauth_verifier'];
1607 $new_token = $photonic_smugmug_gallery->get_access_token($current_token);
1608 if (isset($new_token['oauth_token']) && isset($new_token['oauth_token_secret'])) {
1609 $access_token_response = $photonic_smugmug_gallery->check_access_token($new_token);
1610 if (is_wp_error($access_token_response)) {
1611 $photonic_smugmug_gallery->is_server_down = true;
1612 }
1613 $photonic_smug_oauth_done = $photonic_smugmug_gallery->is_access_token_valid($access_token_response);
1614 }
1615 }
1616 else if (isset($cookie['smug']['oauth_token_type']) && $cookie['smug']['oauth_token_type'] == 'access') {
1617 $access_token_response = $photonic_smugmug_gallery->check_access_token($current_token);
1618 if (is_wp_error($access_token_response)) {
1619 $photonic_smugmug_gallery->is_server_down = true;
1620 }
1621 $photonic_smug_oauth_done = $photonic_smugmug_gallery->is_access_token_valid($access_token_response);
1622 }
1623 }
1624 else if (!empty($photonic_smugmug_gallery->token) && !empty($photonic_smugmug_gallery->token_secret)) {
1625 $token = ['oauth_token' => $photonic_smugmug_gallery->token, 'oauth_token_secret' => $photonic_smugmug_gallery->token_secret];
1626 $access_token_response = $photonic_smugmug_gallery->check_access_token($token);
1627 if (is_wp_error($access_token_response)) {
1628 $photonic_smugmug_gallery->is_server_down = true;
1629 }
1630 $photonic_smug_oauth_done = $photonic_smugmug_gallery->is_access_token_valid($access_token_response);
1631 }
1632 }
1633
1634 function load_more() {
1635 $provider = esc_attr($_POST['provider']);
1636 $query = sanitize_text_field($_POST['query']);
1637 $attr = wp_parse_args($query);
1638
1639 $gallery = $this->initialize_extension($provider);
1640 if ($provider == 'flickr') {
1641 $attr['page'] = isset($attr['page']) ? $attr['page'] + 1 : 0;
1642 }
1643 else if ($provider == 'google') {
1644 }
1645 else if ($provider == 'smug') {
1646 $attr['start'] = $attr['start'] + $attr['count'];
1647 }
1648 else if ($provider == 'zenfolio') {
1649 $attr['offset'] = $attr['offset'] + $attr['limit'];
1650 }
1651 else if ($provider == 'instagram') {
1652 }
1653 else if ($provider == 'wp') {
1654 $attr['page'] = $attr['page'] + 1;
1655 }
1656
1657 if (!is_null($gallery)) {
1658 echo $gallery->get_gallery_images($attr);
1659 }
1660 die();
1661 }
1662
1663 function helper_shortcode_more() {
1664 if (!empty($_POST['provider'])) {
1665 $provider = sanitize_text_field($_POST['provider']);
1666 if (in_array($provider, ['google'])) {
1667 $gallery = $this->initialize_extension($provider);
1668 if ($provider == 'google') {
1669 echo $gallery->execute_helper(['nextPageToken' => sanitize_text_field($_POST['nextPageToken'])]);
1670 }
1671 }
1672 }
1673 die();
1674 }
1675
1676 static function title_caption_options($blank = false, $selection = false) {
1677 $ret = [
1678 '' => esc_html__('Default from settings', 'photonic'),
1679 'none' => esc_html__('No title / caption / description', 'photonic'),
1680 'title' => esc_html__('Always use the photo title, even if blank', 'photonic'),
1681 'desc' => esc_html__('Always use the photo description / caption, even if blank', 'photonic'),
1682 'desc-title' => esc_html__('Use the photo description / caption. If blank use the title', 'photonic'),
1683 'title-desc' => esc_html__('Use the photo title. If blank use the description / caption', 'photonic'),
1684 ];
1685
1686 if (!$blank) {
1687 unset($ret['']);
1688 }
1689 else if (!empty($ret[$selection])) {
1690 $ret[''] .= ' - '.$ret[$selection];
1691 }
1692
1693 return $ret;
1694 }
1695
1696 static function layout_options($show_blank = false) {
1697 $ret = [];
1698 if ($show_blank) {
1699 $ret[''] = '';
1700 }
1701 return array_merge($ret, [
1702 'strip-below' => esc_html__('Thumbnail strip below slideshow', 'photonic'),
1703 'strip-above' => esc_html__('Thumbnail strip above slideshow', 'photonic'),
1704 'strip-right' => esc_html__('Thumbnail strip to the right of the slideshow', 'photonic'),
1705 'no-strip' => esc_html__('Slideshow without thumbnails', 'photonic'),
1706 'square' => esc_html__('Square thumbnail grid, lightbox', 'photonic'),
1707 'circle' => esc_html__('Circular thumbnail grid, lightbox', 'photonic'),
1708 'random' => esc_html__('Random justified gallery, lightbox', 'photonic'),
1709 'masonry' => esc_html__('Masonry layout, lightbox', 'photonic'),
1710 'mosaic' => esc_html__('Mosaic layout, lightbox', 'photonic'),
1711 ]);
1712 }
1713
1714 static function media_options($blank = false, $selection = false) {
1715 $options = [
1716 '' => esc_html__('Default from settings', 'photonic'),
1717 'photos' => esc_html__('Photos only', 'photonic'),
1718 'videos' => esc_html__('Videos only', 'photonic'),
1719 'all' => esc_html__('Both photos and videos', 'photonic'),
1720 ];
1721
1722 if (!$blank) {
1723 unset($options['']);
1724 }
1725 else if (!empty($options[$selection])) {
1726 $options[''] .= ' - '.$options[$selection];
1727 }
1728
1729 return $options;
1730 }
1731
1732 function admin_head() {
1733 // check user permissions
1734 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
1735 return;
1736 }
1737
1738 global $photonic_disable_editor, $photonic_disable_editor_post_type;
1739 $disabled_types = explode(',', $photonic_disable_editor_post_type);
1740 $screen = get_current_screen();
1741 $post_type = empty($_REQUEST['post_type']) ? 'post' : $_REQUEST['post_type'];
1742 // check if WYSIWYG is enabled
1743 if ('true' == get_user_option('rich_editing') && empty($photonic_disable_editor) && !in_array($post_type, $disabled_types) && $screen->base == 'post') {
1744 $this->prepare_mce_data();
1745 add_filter('mce_external_plugins', [$this ,'mce_photonic'], 5);
1746 add_filter('mce_buttons', [$this ,'mce_flow_button'], 5);
1747 }
1748 }
1749
1750 function prepare_mce_data() {
1751 global $photonic_alternative_shortcode, $photonic_disable_flow_editor;
1752 $url = add_query_arg( [
1753 'action' => 'photonic_flow',
1754 'class' => 'photonic-flow',
1755 'post_id' => empty($_REQUEST['post']) ? '' : $_REQUEST['post'],
1756 'width' => '1000',
1757 'height' => '600',
1758 'TB_iframe' => 'true',
1759 ], admin_url( 'admin.php' ) );
1760 $js_array = [
1761 'flow_url' => $url,
1762 'ajaxurl' => admin_url('admin-ajax.php'),
1763 'shortcode' => empty($photonic_alternative_shortcode) ? 'gallery' : $photonic_alternative_shortcode,
1764 'disable_flow' => !empty($photonic_disable_flow_editor),
1765 'default_gallery_type' => 'default',
1766 'plugin_dir' => plugin_dir_url(__FILE__),
1767 ];
1768 wp_enqueue_script('photonic-admin-js', plugins_url('include/scripts/admin/gallery-settings.js', __FILE__), ['jquery', 'media-views', 'media-upload'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/admin/gallery-settings.js'));
1769 wp_localize_script('photonic-admin-js', 'Photonic_Admin_JS', $js_array);
1770 }
1771
1772 function mce_photonic($plugin_array) {
1773 $plugin_array['photonic'] = plugins_url('include/scripts/admin/mce.js?'.$this->get_version(plugin_dir_path(__FILE__).'include/scripts/admin/mce.js') , __FILE__);
1774 return $plugin_array;
1775 }
1776
1777 function mce_flow_button($buttons) {
1778 array_push($buttons, 'photonic_flow');
1779 return $buttons;
1780 }
1781
1782 /**
1783 * @param string|array $classes
1784 * @param string $class
1785 * @return array
1786 */
1787 function body_class($classes = [], $class = '') {
1788 if (!is_array($classes)) {
1789 $classes = explode(' ', $classes);
1790 }
1791 global $photonic_is_IE;
1792 if ($photonic_is_IE) {
1793 $classes[] = 'photonic-ie';
1794 }
1795
1796 return $classes;
1797 }
1798
1799 function add_photonic_button() {
1800 add_thickbox();
1801 $url = add_query_arg([
1802 'action' => 'photonic_flow',
1803 'class' => 'photonic-flow',
1804 'post_id' => empty($_REQUEST['post']) ? '' : $_REQUEST['post'],
1805 'width' => '1000',
1806 'height' => '600',
1807 'TB_iframe' => 'true',
1808 ], admin_url( 'admin.php' ) );
1809
1810 printf('<a href="%s" class="button photonic-button thickbox" id="photonic-add-gallery" title="Photonic Gallery"><img class="wp-media-buttons-icon" src="'.plugins_url('include/images/Photonic-20.png', __FILE__).'"/> %s</a>',
1811 $url, esc_html__( 'Add / Edit Photonic Gallery', 'photonic'));
1812 }
1813
1814 function gallery_builder() {
1815 define( 'IFRAME_REQUEST', true );
1816 $this->enqueue_flow_scripts();
1817 iframe_header(esc_html__('Add / Edit Photonic Gallery', 'photonic'));
1818 require_once(plugin_dir_path(__FILE__).'/admin/flow/Flow.php');
1819 iframe_footer();
1820 exit;
1821 }
1822
1823 function enqueue_flow_scripts() {
1824 global $photonic_alternative_shortcode;
1825 $flow_js = [
1826 'ajaxurl' => admin_url('admin-ajax.php'),
1827 'shortcode' => empty($photonic_alternative_shortcode) ? 'gallery' : $photonic_alternative_shortcode,
1828 'insert_gallery' => esc_html__('Insert Gallery', 'photonic'),
1829 'update_gallery' => esc_html__('Update Gallery', 'photonic'),
1830 'error_mandatory' => esc_html__('Please fill the mandatory fields. Mandatory fields are marked with a red "*".', 'photonic'),
1831 'media_library_title' => esc_html__('Select from WordPress Media Library', 'photonic'),
1832 'media_library_button' => esc_html__('Select', 'photonic'),
1833 'info_editor_not_shortcode' => esc_html__('The text selected in the editor is not a Photonic shortcode. Creating a new shortcode.', 'photonic'),
1834 'info_editor_block_select' => sprintf(esc_html__('%1$sHint:%2$s To edit an existing Photonic block simply click on the block.', 'photonic'), '<strong>', '</strong>'),
1835 ];
1836 if (!empty($_REQUEST['shortcode'])) {
1837 $flow_js['shortcode'] = $_REQUEST['shortcode'];
1838 }
1839 wp_enqueue_style('photonic-flow', plugins_url('include/css/admin-flow.css', __FILE__), [], $this->get_version(plugin_dir_path(__FILE__).'include/css/admin-flow.css'));
1840 wp_enqueue_script('photonic-flow-js', plugins_url('include/scripts/admin/flow.js', __FILE__), ['jquery'], $this->get_version(plugin_dir_path(__FILE__).'include/scripts/admin/flow.js'));
1841 wp_localize_script('photonic-flow-js', 'Photonic_Flow_JS', $flow_js);
1842 }
1843
1844 function flow_next_screen() {
1845 require_once(plugin_dir_path(__FILE__)."/admin/flow/Photonic_Flow_Manager.php");
1846 if (isset($_POST['provider'])) {
1847 $flow_manager = new Photonic_Flow_Manager();
1848 echo $flow_manager->get_screen();
1849 }
1850 die();
1851 }
1852
1853 function flow_more() {
1854 require_once(plugin_dir_path(__FILE__)."/admin/flow/Photonic_Flow_Manager.php");
1855 if (isset($_POST['url']) && isset($_POST['provider']) && isset($_POST['display_type'])) {
1856 $url = base64_decode(sanitize_text_field($_POST['url']));
1857
1858 $provider = sanitize_text_field($_POST['provider']);
1859 $display_type = sanitize_text_field($_POST['display_type']);
1860 $args = ['sslverify' => PHOTONIC_SSL_VERIFY];
1861 if ($provider == 'smugmug') {
1862 global $photonic_smugmug_gallery;
1863 if (!isset($photonic_smugmug_gallery)) {
1864 $photonic_smugmug_gallery = $this->initialize_extension($provider);
1865 }
1866
1867 $body = [
1868 'APIKey' => $photonic_smugmug_gallery->api_key,
1869 '_accept' => 'application/json',
1870 '_expandmethod' => 'inline',
1871 '_verbosity' => '1',
1872 ];
1873
1874 if ($display_type == 'album-photo' || $display_type == 'multi-album') {
1875 $body['_expand'] = 'HighlightImage.ImageSizes';
1876 }
1877
1878 $args['body'] = $body;
1879 }
1880
1881 // $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
1882 $response = wp_remote_request($url, $args);
1883 $flow_manager = new Photonic_Flow_Manager();
1884 $objects = $flow_manager->process_response($response, $provider, $display_type, [], [], $url, true);
1885
1886 if (!empty($objects['success'])) {
1887 echo $objects['success'];
1888 }
1889 else if (!empty($objects['error'])) {
1890 echo $objects['error'];
1891 }
1892 }
1893 die();
1894 }
1895
1896 public static function get_formatted_post_type_array() {
1897 global $photonic_post_type_array;
1898 $ret = [];
1899
1900 $post_types = get_post_types(['show_ui' => 1], 'objects');
1901 if (!empty($post_types)) {
1902 foreach ($post_types as $name => $post_type) {
1903 $ret[$name] = ["title" => $post_type->label." (Post type: $name)", "depth" => 0];
1904 }
1905 }
1906
1907 $photonic_post_type_array = $ret;
1908 return $ret;
1909 }
1910
1911 /**
1912 * Used for handling the front-end for Gutenberg blocks
1913 *
1914 * @param $attributes
1915 * @return array|bool|string
1916 */
1917 function render_block($attributes) {
1918 if (!empty($attributes['shortcode'])) {
1919 $shortcode = (array)(json_decode($attributes['shortcode']));
1920
1921 if (!empty($attributes['align'])) {
1922 $shortcode['alignment'] = $attributes['align'];
1923 }
1924 if (!empty($attributes['className'])) {
1925 $shortcode['custom_classes'] = $attributes['className'];
1926 }
1927
1928 $this->conditionally_add_scripts($shortcode);
1929 return $this->get_gallery_images($shortcode);
1930 }
1931 return '';
1932 }
1933
1934 function enqueue_gutenberg_assets() {
1935 if (function_exists('register_block_type')) {
1936 wp_enqueue_script('photonic-gutenberg',
1937 plugins_url('include/scripts/admin/block.js', __FILE__),
1938 ['jquery', 'wp-blocks', 'wp-i18n', 'wp-element', 'shortcode', 'thickbox'],
1939 $this->get_version(plugin_dir_path(__FILE__).'include/scripts/admin/block.js')
1940 );
1941
1942 if (function_exists( 'gutenberg_get_jed_locale_data')) {
1943 $locale = gutenberg_get_jed_locale_data('photonic');
1944 $content = 'wp.i18n.setLocaleData('.json_encode($locale).', "photonic");';
1945 wp_script_add_data( 'photonic-gutenberg', 'data', $content );
1946 }
1947
1948 global $photonic_alternative_shortcode;
1949 $url = add_query_arg( [
1950 'action' => 'photonic_flow',
1951 'class' => 'photonic-flow',
1952 'post_id' => empty($_REQUEST['post']) ? '' : $_REQUEST['post'],
1953 'width' => '1000',
1954 'height' => '600',
1955 'TB_iframe' => 'true',
1956 ], admin_url( 'admin.php' ) );
1957
1958 $js_array = [
1959 'flow_url' => $url,
1960 'ajaxurl' => admin_url('admin-ajax.php'),
1961 'shortcode' => empty($photonic_alternative_shortcode) ? 'gallery' : $photonic_alternative_shortcode,
1962 'default_gallery_type' => 'default',
1963 'plugin_dir' => plugin_dir_url(__FILE__),
1964 ];
1965 wp_localize_script('photonic-gutenberg', 'Photonic_Gutenberg_JS', $js_array);
1966
1967 wp_enqueue_style('photonic-gutenberg',
1968 plugins_url('include/css/admin-block.css', __FILE__),
1969 ['thickbox'],
1970 $this->get_version(plugin_dir_path(__FILE__).'include/css/admin-block.css')
1971 );
1972 }
1973 }
1974
1975 private function add_gutenberg_support() {
1976 if (function_exists('register_block_type')) {
1977 register_block_type('photonic/gallery',
1978 [
1979 'attributes' => [
1980 'shortcode' => [
1981 'type' => 'string',
1982 ],
1983 ],
1984 'render_callback' => [&$this, 'render_block'],
1985 ]
1986 );
1987 }
1988 }
1989
1990 function admin_notices() {
1991 if (!empty($_REQUEST['page']) && in_array($_REQUEST['page'], ['photonic-options-manager', 'photonic-getting-started', 'photonic-auth', 'photonic-helpers'])){
1992 if (function_exists('register_block_type')) {
1993 $dismissed = get_user_meta(get_current_user_id(), 'photonic_gutenberg');
1994 if (!$dismissed) {
1995 echo "<div class='notice notice-warning'>\n<p>\n";
1996 echo sprintf(esc_html__('It looks like you are using the Gutenberg editor. Please ensure that you have followed the instructions under %s.', 'photonic'), '<em><a href="'.admin_url('admin.php?page=photonic-gutenberg').'">Photonic &rarr; Prepare for Gutenberg</a></em>');
1997 echo "</p>\n";
1998 echo "<button type='button' data-photonic-dismissible='gutenberg' class='photonic-notice-dismiss'><span class='screen-reader-text'>Dismiss this notice.</span></button>";
1999 echo "</div>\n";
2000 }
2001 }
2002 }
2003 }
2004
2005 function dismiss_warning() {
2006 $user_id = get_current_user_id();
2007 $response = [];
2008 if (!empty($_POST['dismissible'])) {
2009 add_user_meta( $user_id, "photonic_".esc_sql($_POST['dismissible']), 'true', true );
2010 $response[$_POST['dismissible']] = 'true';
2011 }
2012 echo json_encode($response);
2013 die();
2014 }
2015
2016 function curl_timeout($handle) {
2017 curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, PHOTONIC_CURL_TIMEOUT);
2018 curl_setopt($handle, CURLOPT_TIMEOUT, PHOTONIC_CURL_TIMEOUT);
2019 }
2020
2021 static function log($element) {
2022 if (PHOTONIC_DEBUG) {
2023 print_r($element);
2024 }
2025 }
2026
2027 static function doc_link($link) {
2028 return ' '.sprintf(esc_html__('See %1$shere%2$s for documentation.', 'photonic'), "<a href='$link'>", '</a>');
2029 }
2030
2031 function get_show_gallery_button($attr = []) {
2032 $button = esc_attr($attr['show_gallery']);
2033 $button_attr = [];
2034
2035 if (!empty($attr['show_gallery_button_type']) && $attr['show_gallery_button_type'] == 'image' && !empty($attr['show_gallery_button_image'])) {
2036 $button_attr['type'] = 'image';
2037 $button_attr['alt'] = $button;
2038 $button_attr['src'] = esc_url($attr['show_gallery_button_image']);
2039 }
2040 else {
2041 $button_attr['type'] = 'button';
2042 $button_attr['value'] = $button;
2043 }
2044 $button_attr['class'] = 'photonic-show-gallery-button';
2045
2046 unset($attr['show_gallery']);
2047 unset($attr['show_gallery_button_type']);
2048 unset($attr['show_gallery_button_image']);
2049
2050 $attr_str = http_build_query($attr);
2051 $button_attr['data-photonic-shortcode'] = $attr_str;
2052
2053 $input_attr = [];
2054 foreach ($button_attr as $name => $value) {
2055 $input_attr[] = "$name='$value'";
2056 }
2057 $input_attr = implode(' ', $input_attr);
2058
2059 return "<input $input_attr/>";
2060 }
2061
2062 function lazy_load() {
2063 $shortcode = $_POST['shortcode'];
2064 parse_str($shortcode, $attr);
2065 $images = $this->get_gallery_images($attr);
2066 echo $images;
2067 die();
2068 }
2069 }
2070
2071 add_action('init', 'photonic_init', 100); // Delaying the start from 10 to 100 so that CPTs can be picked up
2072
2073 function photonic_init() {
2074 global $photonic;
2075 $photonic = new Photonic();
2076 }
2077