PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.31
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.31
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 / photonic.php

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

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