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