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