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