PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.20
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.20
3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 2.45 All 140 releases
photonic / photonic.php

photonic.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.20, at photonic.php

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