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