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