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

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