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

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