| 1 |
<?php |
| 2 |
namespace Photonic_Plugin\Core; |
| 3 |
|
| 4 |
use Photonic_Plugin\Admin\Admin_Menu; |
| 5 |
use Photonic_Plugin\Admin\Authentication; |
| 6 |
use Photonic_Plugin\Admin\Helper; |
| 7 |
use Photonic_Plugin\Options\Defaults; |
| 8 |
use Photonic_Plugin\Options\Options; |
| 9 |
use WP_Error; |
| 10 |
|
| 11 |
class Photonic { |
| 12 |
var $defaults, $localized, $provider_map, $admin_menu; |
| 13 |
|
| 14 |
function __construct() { |
| 15 |
// $start = microtime(true); |
| 16 |
global $photonic_options, $photonic_is_IE; |
| 17 |
|
| 18 |
//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. |
| 19 |
$photonic_is_IE = preg_match('/MSIE [56789]/i', $_SERVER['HTTP_USER_AGENT']); |
| 20 |
|
| 21 |
require_once(PHOTONIC_PATH."/Options/Options.php"); |
| 22 |
add_action('admin_init', [Options::get_instance(), 'prepare_options'], 20); // Setting to 20 so that CPTs can be picked up - Utilities are loaded with a priority 10 |
| 23 |
|
| 24 |
$this->localized = false; |
| 25 |
$this->provider_map = [ |
| 26 |
'flickr' => 'Flickr', |
| 27 |
'smug' => 'SmugMug', |
| 28 |
'smugmug' => 'SmugMug', |
| 29 |
'google' => 'Google', |
| 30 |
'zenfolio' => 'Zenfolio', |
| 31 |
'instagram' => 'Instagram', |
| 32 |
]; |
| 33 |
|
| 34 |
add_action('admin_menu', [&$this, 'add_admin_menu']); |
| 35 |
add_action('admin_init', [&$this, 'admin_init']); |
| 36 |
|
| 37 |
$photonic_options = get_option('photonic_options'); |
| 38 |
$set_options = isset($photonic_options) && is_array($photonic_options) ? $photonic_options : []; |
| 39 |
|
| 40 |
$defaults = Defaults::get_options(); |
| 41 |
$all_options = array_merge($defaults, $set_options); |
| 42 |
|
| 43 |
foreach ($all_options as $key => $value) { |
| 44 |
$mod_key = 'photonic_'.$key; |
| 45 |
global ${$mod_key}; |
| 46 |
${$mod_key} = $value; |
| 47 |
} |
| 48 |
|
| 49 |
define('PHOTONIC_SSL_VERIFY', empty($photonic_ssl_verify_off)); |
| 50 |
define('PHOTONIC_DEBUG', !empty($photonic_debug_on)); |
| 51 |
|
| 52 |
if (!empty($photonic_script_dev_mode)) { |
| 53 |
define('PHOTONIC_DEV_MODE', ''); |
| 54 |
} |
| 55 |
else { |
| 56 |
define('PHOTONIC_DEV_MODE', '.min'); |
| 57 |
} |
| 58 |
|
| 59 |
if (!empty($photonic_curl_timeout) && is_numeric($photonic_curl_timeout)) { |
| 60 |
define('PHOTONIC_CURL_TIMEOUT', $photonic_curl_timeout); |
| 61 |
} |
| 62 |
else { |
| 63 |
define('PHOTONIC_CURL_TIMEOUT', 10); |
| 64 |
} |
| 65 |
|
| 66 |
// Gallery |
| 67 |
if (!empty($photonic_alternative_shortcode)) { |
| 68 |
add_shortcode($photonic_alternative_shortcode, [&$this, 'modify_gallery']); |
| 69 |
add_filter('shortcode_atts_'.$photonic_alternative_shortcode, [&$this, 'native_gallery_attributes'], 10, 3); |
| 70 |
} |
| 71 |
else { |
| 72 |
add_filter('post_gallery', [&$this, 'modify_gallery'], 20, 2); |
| 73 |
add_filter('shortcode_atts_gallery', [&$this, 'native_gallery_attributes'], 10, 3); |
| 74 |
} |
| 75 |
|
| 76 |
add_shortcode('photonic_helper', [&$this, 'helper_shortcode']); |
| 77 |
|
| 78 |
add_action('wp_enqueue_scripts', [&$this, 'always_add_styles'], 20); |
| 79 |
if (!empty($photonic_always_load_scripts)) { |
| 80 |
add_action('wp_enqueue_scripts', [&$this, 'conditionally_add_scripts'], 20); |
| 81 |
} |
| 82 |
add_action('wp_head', [&$this, 'print_scripts'], 20); |
| 83 |
|
| 84 |
add_action('wp_ajax_photonic_display_level_2_contents', [&$this, 'display_level_2_contents']); |
| 85 |
add_action('wp_ajax_nopriv_photonic_display_level_2_contents', [&$this, 'display_level_2_contents']); |
| 86 |
|
| 87 |
add_action('wp_ajax_photonic_display_level_3_contents', [&$this, 'display_level_3_contents']); |
| 88 |
add_action('wp_ajax_nopriv_photonic_display_level_3_contents', [&$this, 'display_level_3_contents']); |
| 89 |
|
| 90 |
add_action('wp_ajax_photonic_load_more', [&$this, 'load_more']); |
| 91 |
add_action('wp_ajax_nopriv_photonic_load_more', [&$this, 'load_more']); |
| 92 |
|
| 93 |
add_action('wp_ajax_photonic_lazy_load', [&$this, 'lazy_load']); |
| 94 |
add_action('wp_ajax_nopriv_photonic_lazy_load', [&$this, 'lazy_load']); |
| 95 |
|
| 96 |
add_action('wp_ajax_photonic_helper_shortcode_more', [&$this, 'helper_shortcode_more']); |
| 97 |
add_action('wp_ajax_nopriv_photonic_helper_shortcode_more', [&$this, 'helper_shortcode_more']); |
| 98 |
|
| 99 |
add_action('wp_ajax_photonic_invoke_helper', [&$this, 'invoke_helper']); |
| 100 |
add_action('wp_ajax_photonic_obtain_token', [&$this, 'obtain_token']); |
| 101 |
add_action('wp_ajax_photonic_save_token', [&$this, 'save_token_in_options']); |
| 102 |
add_action('wp_ajax_photonic_delete_token', [&$this, 'delete_token_from_options']); |
| 103 |
|
| 104 |
$this->add_extensions(); |
| 105 |
$this->add_gutenberg_support(); |
| 106 |
|
| 107 |
add_action('wp_ajax_photonic_dismiss_warning', [&$this, 'dismiss_warning']); |
| 108 |
|
| 109 |
add_action('http_api_curl', [&$this, 'curl_timeout'], 100, 1); |
| 110 |
|
| 111 |
add_action('plugins_loaded', [&$this, 'enable_translations']); |
| 112 |
|
| 113 |
add_filter('body_class', [&$this, 'body_class']); |
| 114 |
|
| 115 |
// $end = microtime(true); |
| 116 |
// print_r("<!-- Photonic initialization: ".($end - $start)." -->\n"); |
| 117 |
|
| 118 |
add_action('widgets_init', [&$this, 'load_widget']); |
| 119 |
|
| 120 |
add_action('elementor/common/after_register_scripts', [&$this, 'enqueue_widget_scripts']); |
| 121 |
|
| 122 |
require_once(PHOTONIC_PATH."/Core/Template.php"); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* @param string $provider |
| 127 |
* @param array $auth_token |
| 128 |
*/ |
| 129 |
public static function save_provider_authentication($provider, $auth_token) { |
| 130 |
$photonic_authentication = get_option('photonic_authentication'); |
| 131 |
if (empty($photonic_authentication)) { |
| 132 |
$photonic_authentication = []; |
| 133 |
} |
| 134 |
if (empty($photonic_authentication[$provider])) { |
| 135 |
$photonic_authentication[$provider] = []; |
| 136 |
} |
| 137 |
$photonic_authentication[$provider] = $auth_token; |
| 138 |
update_option('photonic_authentication', $photonic_authentication); |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Adds a menu item to the "Settings" section of the admin page. |
| 143 |
* |
| 144 |
* @return void |
| 145 |
*/ |
| 146 |
function add_admin_menu() { |
| 147 |
if (current_user_can('edit_theme_options')) { |
| 148 |
$parent_slug = 'photonic-options-manager'; |
| 149 |
} |
| 150 |
else if (current_user_can('edit_posts')) { |
| 151 |
$parent_slug = 'photonic-getting-started'; |
| 152 |
} |
| 153 |
|
| 154 |
if (!empty($parent_slug)) { |
| 155 |
add_menu_page('Photonic', 'Photonic', 'edit_posts', $parent_slug, [&$this->admin_menu, 'settings'], PHOTONIC_URL.'include/images/Photonic-20-gr.png'); |
| 156 |
add_submenu_page($parent_slug, esc_html__('Settings', 'photonic'), esc_html__('Settings', 'photonic'), 'edit_theme_options', 'photonic-options-manager', [&$this->admin_menu, 'settings']); |
| 157 |
add_submenu_page($parent_slug, 'Getting Started', 'Getting Started', 'edit_posts', 'photonic-getting-started', [&$this->admin_menu, 'getting_started']); |
| 158 |
add_submenu_page($parent_slug, 'Authentication', 'Authentication', 'edit_theme_options', 'photonic-auth', [&$this->admin_menu, 'authentication']); |
| 159 |
add_submenu_page($parent_slug, esc_html__('Switch to Gutenberg', 'photonic'), esc_html__('Switch to Gutenberg', 'photonic'), 'edit_posts', 'photonic-gutenberg', [&$this->admin_menu, 'gutenberg']); |
| 160 |
add_submenu_page($parent_slug, 'Helpers', 'Helpers', 'edit_posts', 'photonic-helpers', [&$this->admin_menu, 'helpers']); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Adds all scripts and their dependencies to the end of the <body> element only on pages using Photonic. |
| 166 |
* |
| 167 |
* @param array $attr |
| 168 |
* @return void |
| 169 |
*/ |
| 170 |
function conditionally_add_scripts($attr = []) { |
| 171 |
global $photonic_slideshow_library, $photonic_custom_lightbox_js, $photonic_is_IE, $photonic_custom_lightbox, $photonic_always_load_scripts, |
| 172 |
$photonic_disable_photonic_lightbox_scripts, $photonic_disable_photonic_slider_scripts, $photonic_js_in_header, $photonic_thumbnail_style; |
| 173 |
|
| 174 |
if (isset($attr['style'])) { |
| 175 |
$layout = $attr['style']; |
| 176 |
} |
| 177 |
else if (isset($attr['layout'])) { |
| 178 |
$layout = $attr['layout']; |
| 179 |
} |
| 180 |
else if (isset($photonic_thumbnail_style)) { |
| 181 |
$layout = $photonic_thumbnail_style; |
| 182 |
} |
| 183 |
else { |
| 184 |
$layout = 'square'; |
| 185 |
} |
| 186 |
|
| 187 |
$photonic_dependencies = ['jquery']; |
| 188 |
|
| 189 |
if ($photonic_is_IE && $layout == 'masonry') { |
| 190 |
wp_enqueue_script('photonic-ie', PHOTONIC_URL.'include/scripts/front-end/src/photonic-ie.js', ['jquery-masonry', 'photonic'], $this->get_version(PHOTONIC_PATH.'/include/scripts/front-end/src/photonic-ie.js'), !($photonic_always_load_scripts && $photonic_js_in_header)); |
| 191 |
} |
| 192 |
|
| 193 |
if ($photonic_slideshow_library == 'thickbox') { |
| 194 |
wp_enqueue_script('thickbox'); |
| 195 |
$photonic_dependencies[] = 'thickbox'; |
| 196 |
} |
| 197 |
else if ($photonic_slideshow_library == 'custom') { |
| 198 |
$counter = 1; |
| 199 |
$dependencies = ['jquery']; |
| 200 |
foreach(preg_split("/((\r?\n)|(\r\n?))/", $photonic_custom_lightbox_js) as $line){ |
| 201 |
wp_enqueue_script('photonic-lightbox-'.$counter, trim($line), $dependencies, PHOTONIC_VERSION, !($photonic_always_load_scripts && $photonic_js_in_header)); |
| 202 |
$photonic_dependencies[] = 'photonic-lightbox-'.$counter; |
| 203 |
$counter++; |
| 204 |
} |
| 205 |
} |
| 206 |
else if ($photonic_slideshow_library != 'none') { |
| 207 |
if (empty($photonic_slideshow_library)) { |
| 208 |
$photonic_slideshow_library = 'swipebox'; |
| 209 |
} |
| 210 |
|
| 211 |
if (empty($photonic_disable_photonic_lightbox_scripts)) { |
| 212 |
$lb_deps = ['jquery']; |
| 213 |
if ($photonic_slideshow_library == 'fluidbox') { |
| 214 |
$lb_deps[] = 'imagesloaded'; |
| 215 |
} |
| 216 |
if ($photonic_slideshow_library == 'lightgallery') { |
| 217 |
global $photonic_enable_lg_zoom, $photonic_enable_lg_thumbnail, $photonic_enable_lg_fullscreen, $photonic_enable_lg_autoplay; |
| 218 |
$lightgallery_plugins = []; |
| 219 |
if (!empty($photonic_enable_lg_autoplay)) { $lightgallery_plugins[] = 'autoplay'; } |
| 220 |
if (!empty($photonic_enable_lg_fullscreen)) { $lightgallery_plugins[] = 'fullscreen'; } |
| 221 |
if (!empty($photonic_enable_lg_thumbnail)) { $lightgallery_plugins[] = 'thumbnail'; } |
| 222 |
if (!empty($photonic_enable_lg_zoom)) { $lightgallery_plugins[] = 'zoom'; } |
| 223 |
if (!empty($lightgallery_plugins)) { |
| 224 |
wp_enqueue_script('photonic-lightbox', PHOTONIC_URL.'include/scripts/third-party/'.$photonic_slideshow_library.'/'.$photonic_slideshow_library.PHOTONIC_DEV_MODE.'.js', $lb_deps, $this->get_version(PHOTONIC_PATH.'/include/scripts/third-party/'.$photonic_slideshow_library.'/'.$photonic_slideshow_library.PHOTONIC_DEV_MODE.'.js'), !($photonic_always_load_scripts && $photonic_js_in_header)); |
| 225 |
$photonic_dependencies[] = 'photonic-lightbox'; |
| 226 |
} |
| 227 |
if (PHOTONIC_DEV_MODE) { |
| 228 |
foreach ($lightgallery_plugins as $plugin) { |
| 229 |
wp_enqueue_script('photonic-lightbox-'.$plugin, PHOTONIC_URL.'include/scripts/third-party/'.$photonic_slideshow_library.'/lg-plugin-'.$plugin.'.min.js', ['photonic-lightbox'], $this->get_version(PHOTONIC_PATH.'/include/scripts/third-party/'.$photonic_slideshow_library.'/lg-plugin-'.$plugin.'.min.js'), !($photonic_always_load_scripts && $photonic_js_in_header)); |
| 230 |
} |
| 231 |
} |
| 232 |
else { |
| 233 |
wp_enqueue_script('photonic-lightbox-plugins', PHOTONIC_URL.'include/scripts/third-party/'.$photonic_slideshow_library.'/lightgallery-plugins.js', ['photonic-lightbox'], $this->get_version(PHOTONIC_PATH.'/include/scripts/third-party/'.$photonic_slideshow_library.'/lightgallery-plugins.js'), !($photonic_always_load_scripts && $photonic_js_in_header)); |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
$slideshow_library = $photonic_slideshow_library == 'custom' ? $photonic_custom_lightbox : $photonic_slideshow_library; |
| 240 |
$slideshow_library = empty($slideshow_library) ? 'swipebox' : $slideshow_library; |
| 241 |
|
| 242 |
if (empty($photonic_disable_photonic_lightbox_scripts) && !($slideshow_library == 'lightgallery' && !empty($lightgallery_plugins))) { |
| 243 |
$script_type = 'combo'; |
| 244 |
} |
| 245 |
else { |
| 246 |
$script_type = 'solo'; |
| 247 |
} |
| 248 |
|
| 249 |
if (empty($photonic_disable_photonic_slider_scripts)) { |
| 250 |
$script_type .= '-slider'; |
| 251 |
} |
| 252 |
|
| 253 |
wp_enqueue_script('photonic', PHOTONIC_URL."include/scripts/front-end/jq/$script_type/photonic-".$slideshow_library.PHOTONIC_DEV_MODE.'.js', $photonic_dependencies, $this->get_version(PHOTONIC_PATH."/include/scripts/front-end/jq/$script_type/photonic-".$slideshow_library.PHOTONIC_DEV_MODE.'.js'), !($photonic_always_load_scripts && $photonic_js_in_header)); |
| 254 |
|
| 255 |
$this->localize_variables_once(); |
| 256 |
|
| 257 |
if (class_exists('\FLBuilderModel') && \FLBuilderModel::is_builder_active()) { |
| 258 |
$this->enqueue_widget_scripts(); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
function localize_variables_once() { |
| 263 |
if ($this->localized) { |
| 264 |
return; |
| 265 |
} |
| 266 |
// Technically JS, but needs to happen here, otherwise the script is repeated multiple times, once for each time |
| 267 |
// <code>conditionally_add_scripts</code> is called. |
| 268 |
$js_array = $this->get_localized_js_variables(); |
| 269 |
wp_localize_script('photonic', 'Photonic_JS', $js_array); |
| 270 |
$this->localized = true; |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* Adds all styles to all pages because styles, if not added in the header can cause issues. |
| 275 |
* |
| 276 |
* @return void |
| 277 |
*/ |
| 278 |
function always_add_styles() { |
| 279 |
global $photonic_slideshow_library, $photonic_custom_lightbox_css, $photonic_disable_photonic_lightbox_scripts, $photonic_disable_photonic_slider_scripts; |
| 280 |
|
| 281 |
if ($photonic_slideshow_library == 'custom') { |
| 282 |
$counter = 1; |
| 283 |
foreach(preg_split("/((\r?\n)|(\r\n?))/", $photonic_custom_lightbox_css) as $line){ |
| 284 |
wp_enqueue_style('photonic-lightbox-'.$counter, trim($line), [], PHOTONIC_VERSION); |
| 285 |
$counter++; |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
if ($photonic_slideshow_library != 'none') { |
| 290 |
if (empty($photonic_slideshow_library)) { |
| 291 |
$photonic_slideshow_library = 'swipebox'; |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
global $photonic_custom_lightbox; |
| 296 |
$slideshow_library = !empty($photonic_disable_photonic_lightbox_scripts) ? 'none' : |
| 297 |
($photonic_slideshow_library == 'custom' ? $photonic_custom_lightbox : $photonic_slideshow_library); |
| 298 |
|
| 299 |
$this->enqueue_lightbox_styles($slideshow_library, empty($photonic_disable_photonic_slider_scripts)); |
| 300 |
|
| 301 |
global $photonic_css_in_file; |
| 302 |
$file = trailingslashit(PHOTONIC_UPLOAD_DIR).'custom-styles.css'; |
| 303 |
if (@file_exists($file) && !empty($photonic_css_in_file)) { |
| 304 |
wp_enqueue_style('photonic-custom', trailingslashit(PHOTONIC_UPLOAD_URL).'custom-styles.css', ['photonic'], $this->get_version($file)); |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
function enqueue_lightbox_styles($slideshow_library = 'swipebox', $combine_slider = true) { |
| 309 |
$template_directory = get_template_directory(); |
| 310 |
$stylesheet_directory = get_stylesheet_directory(); |
| 311 |
|
| 312 |
$folder = $combine_slider ? 'combo-slider' : 'combo'; |
| 313 |
|
| 314 |
if ($slideshow_library == 'colorbox') { |
| 315 |
global $photonic_cbox_theme; |
| 316 |
if ($photonic_cbox_theme == 'theme' && @file_exists($stylesheet_directory.'/scripts/colorbox/colorbox.css')) { |
| 317 |
wp_enqueue_style('photonic-lightbox', get_stylesheet_directory_uri().'/scripts/colorbox/colorbox.css', [], PHOTONIC_VERSION); |
| 318 |
} |
| 319 |
else if ($photonic_cbox_theme == 'theme' && @file_exists($template_directory.'/scripts/colorbox/colorbox.css')) { |
| 320 |
wp_enqueue_style('photonic-lightbox', get_template_directory_uri().'/scripts/colorbox/colorbox.css', [], PHOTONIC_VERSION); |
| 321 |
} |
| 322 |
else if ($photonic_cbox_theme == 'theme') { |
| 323 |
wp_enqueue_style('photonic-lightbox', PHOTONIC_URL.'include/scripts/third-party/colorbox/style-1/colorbox.css', [], $this->get_version(PHOTONIC_PATH.'/include/scripts/third-party/colorbox/style-1/colorbox.css')); |
| 324 |
} |
| 325 |
else { |
| 326 |
wp_enqueue_style('photonic-lightbox', PHOTONIC_URL.'include/scripts/third-party/colorbox/style-'.$photonic_cbox_theme.'/colorbox.css', [], $this->get_version(PHOTONIC_PATH.'/include/scripts/third-party/colorbox/style-'.$photonic_cbox_theme.'/colorbox.css')); |
| 327 |
} |
| 328 |
} |
| 329 |
else if ($slideshow_library == 'lightgallery') { |
| 330 |
global $photonic_enable_lg_transitions; |
| 331 |
if (!empty($photonic_enable_lg_transitions)) { |
| 332 |
wp_enqueue_style('photonic-lightbox-lg-transitions', PHOTONIC_URL.'include/scripts/third-party/lightgallery/lightgallery-transitions.min.css', [], $this->get_version(PHOTONIC_PATH.'/include/scripts/third-party/lightgallery/lightgallery-transitions.min.css')); |
| 333 |
} |
| 334 |
} |
| 335 |
else if ($slideshow_library == 'thickbox') { |
| 336 |
wp_enqueue_style('thickbox'); |
| 337 |
} |
| 338 |
|
| 339 |
wp_enqueue_style('photonic', PHOTONIC_URL."include/css/front-end/$folder/photonic-$slideshow_library.min.css", [], $this->get_version(PHOTONIC_PATH."/include/css/front-end/$folder/photonic-$slideshow_library.min.css")); |
| 340 |
} |
| 341 |
|
| 342 |
/** |
| 343 |
* Prints the custom CSS directly in the header if the option is not set to include it as a file |
| 344 |
*/ |
| 345 |
function print_scripts() { |
| 346 |
global $photonic_css_in_file; |
| 347 |
$file = trailingslashit(PHOTONIC_UPLOAD_DIR).'custom-styles.css'; |
| 348 |
if (!@file_exists($file) || empty($photonic_css_in_file)) { |
| 349 |
$this->generate_css(); |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
/** |
| 354 |
* Prints the dynamically generated CSS based on option selections. |
| 355 |
* |
| 356 |
* @param bool $header |
| 357 |
* @return string |
| 358 |
*/ |
| 359 |
function generate_css($header = true) { |
| 360 |
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; |
| 361 |
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; |
| 362 |
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; |
| 363 |
global $photonic_google_photos_constrain_by_padding; |
| 364 |
|
| 365 |
$css = ''; |
| 366 |
if ($header) { |
| 367 |
$css .= '<style type="text/css">'."\n"; |
| 368 |
} |
| 369 |
|
| 370 |
$saved_css = get_option('photonic_css'); |
| 371 |
|
| 372 |
if ($header && !empty($saved_css)) { |
| 373 |
$css .= "/* Retrieved from saved CSS */\n"; |
| 374 |
$css .= $saved_css; |
| 375 |
} |
| 376 |
else { |
| 377 |
if ($header) { |
| 378 |
$css .= "/* Dynamically generated CSS */\n"; |
| 379 |
} |
| 380 |
$css .= ".photonic-panel { ". |
| 381 |
$this->get_bg_css('photonic_flickr_gallery_panel_background'). |
| 382 |
$this->get_border_css('photonic_flickr_set_popup_thumb_border'). |
| 383 |
" }\n"; |
| 384 |
|
| 385 |
$css .= ".photonic-flickr-stream .photonic-pad-photosets { margin: {$photonic_flickr_collection_set_constrain_by_padding}px; }\n"; |
| 386 |
$css .= ".photonic-flickr-stream .photonic-pad-galleries { margin: {$photonic_flickr_galleries_constrain_by_padding}px; }\n"; |
| 387 |
$css .= ".photonic-flickr-stream .photonic-pad-photos { padding: 5px {$photonic_flickr_photos_constrain_by_padding}px; }\n"; |
| 388 |
|
| 389 |
$css .= ".photonic-google-stream .photonic-pad-photos { padding: 5px {$photonic_google_photos_constrain_by_padding}px; }\n"; |
| 390 |
|
| 391 |
$css .= ".photonic-zenfolio-stream .photonic-pad-photos { padding: 5px {$photonic_zenfolio_photos_constrain_by_padding}px; }\n"; |
| 392 |
$css .= ".photonic-zenfolio-stream .photonic-pad-photosets { margin: 5px {$photonic_zenfolio_sets_constrain_by_padding}px; }\n"; |
| 393 |
|
| 394 |
$css .= ".photonic-instagram-stream .photonic-pad-photos { padding: 5px {$photonic_instagram_photos_constrain_by_padding}px; }\n"; |
| 395 |
|
| 396 |
$css .= ".photonic-smug-stream .photonic-pad-albums { margin: {$photonic_smug_albums_album_constrain_by_padding}px; }\n"; |
| 397 |
$css .= ".photonic-smug-stream .photonic-pad-photos { padding: 5px {$photonic_smug_photos_constrain_by_padding}px; }\n"; |
| 398 |
|
| 399 |
$css .= ".photonic-flickr-panel .photonic-pad-photos { padding: 10px {$photonic_flickr_photos_pop_constrain_by_padding}px; box-sizing: border-box; }\n"; |
| 400 |
$css .= ".photonic-smug-panel .photonic-pad-photos { padding: 10px {$photonic_smug_photos_pop_constrain_by_padding}px; box-sizing: border-box; }\n"; |
| 401 |
|
| 402 |
$css .= ".photonic-random-layout .photonic-thumb { padding: {$photonic_tile_spacing}px}\n"; |
| 403 |
$css .= ".photonic-masonry-layout .photonic-thumb { padding: {$photonic_masonry_tile_spacing}px}\n"; |
| 404 |
$css .= ".photonic-mosaic-layout .photonic-thumb { padding: {$photonic_mosaic_tile_spacing}px}\n"; |
| 405 |
|
| 406 |
$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"; |
| 407 |
} |
| 408 |
|
| 409 |
if ($header) { |
| 410 |
$css .= "\n</style>\n"; |
| 411 |
echo $css; |
| 412 |
} |
| 413 |
return $css; |
| 414 |
} |
| 415 |
|
| 416 |
public static function get_version($file) { |
| 417 |
return date("Ymd-Gis", @filemtime($file)); |
| 418 |
} |
| 419 |
|
| 420 |
function admin_init() { |
| 421 |
require_once(PHOTONIC_PATH."/Admin/Admin.php"); |
| 422 |
|
| 423 |
if (!empty($_REQUEST['page']) && |
| 424 |
in_array($_REQUEST['page'], ['photonic-options-manager', 'photonic-options', 'photonic-helpers', 'photonic-getting-started', 'photonic-auth', 'photonic-gutenberg'])) { |
| 425 |
require_once(PHOTONIC_PATH."/Admin/Admin_Menu.php"); |
| 426 |
$this->admin_menu = new Admin_Menu(__FILE__, $this); |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
function add_extensions() { |
| 431 |
require_once("Gallery.php"); |
| 432 |
require_once(PHOTONIC_PATH."/Modules/Core.php"); |
| 433 |
require_once(PHOTONIC_PATH.'/Layouts/Core_Layout.php'); |
| 434 |
|
| 435 |
do_action('photonic_register_extensions'); |
| 436 |
} |
| 437 |
|
| 438 |
/** |
| 439 |
* Overrides the native gallery short code, and does a lot more. |
| 440 |
* |
| 441 |
* @param $content |
| 442 |
* @param array $attr |
| 443 |
* @return string |
| 444 |
*/ |
| 445 |
function modify_gallery($content, $attr = []) { |
| 446 |
global $photonic_alternative_shortcode; |
| 447 |
|
| 448 |
// If an alternative shortcode is used, then $content has the shortcode attributes |
| 449 |
if (!empty($photonic_alternative_shortcode)) { |
| 450 |
$attr = $content; |
| 451 |
} |
| 452 |
if ($attr == null) { |
| 453 |
$attr = []; |
| 454 |
} |
| 455 |
|
| 456 |
$this->conditionally_add_scripts($attr); |
| 457 |
$images = $this->get_gallery_images($attr); |
| 458 |
|
| 459 |
if (isset($images) && !is_array($images)) { |
| 460 |
return $images; |
| 461 |
} |
| 462 |
|
| 463 |
return $content; |
| 464 |
} |
| 465 |
|
| 466 |
/** |
| 467 |
* Adds Photonic attributes to the native WP galleries. This cannot be called in <code>Photonic_Plugin\Modules\Native</code> because |
| 468 |
* that class is not initialised until a gallery of the native type is encountered |
| 469 |
* |
| 470 |
* @param $out |
| 471 |
* @param $pairs |
| 472 |
* @param $attributes |
| 473 |
* @return mixed |
| 474 |
*/ |
| 475 |
function native_gallery_attributes($out, $pairs, $attributes) { |
| 476 |
global $photonic_wp_title_caption, $photonic_enable_popup, $photonic_thumbnail_style, $photonic_alternative_shortcode; |
| 477 |
|
| 478 |
$bypass = empty($photonic_enable_popup) || $photonic_enable_popup == 'off'; |
| 479 |
$defaults = [ |
| 480 |
'layout' => !empty($photonic_thumbnail_style) ? $photonic_thumbnail_style : 'square', |
| 481 |
'more' => '', |
| 482 |
'display' => 'in-page', |
| 483 |
'panel' => '', |
| 484 |
'filter' => '', |
| 485 |
'filter_type' => 'include', |
| 486 |
'fx' => 'slide', // LightSlider effects: fade and slide |
| 487 |
'timeout' => 4000, // Time between slides in ms |
| 488 |
'speed' => 1000, // Time for each transition |
| 489 |
'pause' => true, // Pause on hover |
| 490 |
'strip-style' => 'thumbs', |
| 491 |
'controls' => 'show', |
| 492 |
'popup' => $bypass ? 'hide' : 'show', |
| 493 |
|
| 494 |
'custom_classes' => '', |
| 495 |
'alignment' => '', |
| 496 |
|
| 497 |
'caption' => $photonic_wp_title_caption, |
| 498 |
'page' => 1, |
| 499 |
'count' => -1, |
| 500 |
'thumb_width' => 75, |
| 501 |
'thumb_height' => 75, |
| 502 |
'thumb_size' => 'thumbnail', |
| 503 |
'slide_size' => 'large', |
| 504 |
'slideshow_height' => 500, |
| 505 |
]; |
| 506 |
|
| 507 |
$attributes = array_merge($defaults, $attributes); |
| 508 |
if (empty($attributes['style']) || ($attributes['style'] == 'default' && !empty($photonic_alternative_shortcode) && $photonic_alternative_shortcode != 'gallery')) { |
| 509 |
$attributes['style'] = $attributes['layout']; |
| 510 |
} |
| 511 |
|
| 512 |
foreach ($attributes as $key => $value) { |
| 513 |
$out[$key] = $value; |
| 514 |
} |
| 515 |
return $out; |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* @param array $attr |
| 520 |
* @return string |
| 521 |
*/ |
| 522 |
function helper_shortcode($attr = []) { |
| 523 |
if ($attr == null) { |
| 524 |
$attr = []; |
| 525 |
} |
| 526 |
|
| 527 |
if (empty($attr['type']) || !in_array(strtolower($attr['type']), ['google', 'flickr', 'smugmug', 'zenfolio'])) { |
| 528 |
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>'); |
| 529 |
} |
| 530 |
|
| 531 |
$gallery = new Gallery($attr); |
| 532 |
return $gallery->get_helper_contents(); |
| 533 |
} |
| 534 |
|
| 535 |
/** |
| 536 |
* @param $attr |
| 537 |
* @return array|bool|string |
| 538 |
*/ |
| 539 |
function get_gallery_images($attr) { |
| 540 |
global $photonic_nested_shortcodes; |
| 541 |
$attr = array_merge([ |
| 542 |
// Especially for Photonic |
| 543 |
'type' => 'default', //default, flickr, smugmug, google, zenfolio, instagram |
| 544 |
'style' => 'default', //default, strip-below, strip-above, strip-right, strip-left, no-strip, launch |
| 545 |
// 'id' => $post->ID, |
| 546 |
// 'layout' => isset($photonic_thumbnail_style) ? $photonic_thumbnail_style : 'square', |
| 547 |
], $attr); |
| 548 |
|
| 549 |
if ($photonic_nested_shortcodes) { |
| 550 |
$attr = array_map('do_shortcode', $attr); |
| 551 |
} |
| 552 |
|
| 553 |
extract($attr); |
| 554 |
|
| 555 |
$type = strtolower($attr['type']); |
| 556 |
|
| 557 |
if ($type == 'picasa') { |
| 558 |
$message = esc_html__('Google has deprecated the Picasa API. Please consider switching over to Google Photos', 'photonic'); |
| 559 |
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"; |
| 560 |
} |
| 561 |
|
| 562 |
if ($type == '500px') { |
| 563 |
$message = esc_html__('The API for 500px.com is no longer available for public use.', 'photonic'); |
| 564 |
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"; |
| 565 |
} |
| 566 |
|
| 567 |
if (!empty($attr['show_gallery']) && in_array($type, ['flickr', 'smugmug', 'google', 'zenfolio', 'instagram'])) { // Lazy button not for WP galleries |
| 568 |
$images = $this->get_show_gallery_button($attr); |
| 569 |
} |
| 570 |
else { |
| 571 |
$gallery = new Gallery($attr); |
| 572 |
$images = $gallery->get_contents(); |
| 573 |
} |
| 574 |
|
| 575 |
return $images; |
| 576 |
} |
| 577 |
|
| 578 |
/** |
| 579 |
* 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. |
| 580 |
* |
| 581 |
* @return void |
| 582 |
*/ |
| 583 |
function display_level_2_contents() { |
| 584 |
$panel = esc_attr($_POST['panel_id']); |
| 585 |
$components = explode('-', $panel); |
| 586 |
|
| 587 |
if (count($components) <= 5) { |
| 588 |
die(); |
| 589 |
} |
| 590 |
$panel = implode('-', array_slice($components, 4, 10, true)); |
| 591 |
$query = sanitize_text_field($_POST['query']); |
| 592 |
$query = wp_parse_args($query); |
| 593 |
|
| 594 |
$args = [ |
| 595 |
'display' => 'popup', |
| 596 |
'layout' => 'square', |
| 597 |
'panel' => $panel, |
| 598 |
'password' => !empty($_POST['password']) ? sanitize_text_field($_POST['password']) : '', |
| 599 |
'count' => sanitize_text_field($_POST['photo_count']), |
| 600 |
'photo_more' => sanitize_text_field($_POST['photo_more']), |
| 601 |
'main_size' => $query['main_size'], |
| 602 |
'type' => $components[1] |
| 603 |
]; |
| 604 |
|
| 605 |
$provider = $components[1]; |
| 606 |
$type = $components[2]; |
| 607 |
if (in_array($provider, ['smug', 'smugmug', 'zenfolio', 'google', 'flickr'])) { |
| 608 |
if ($provider == 'smug') { |
| 609 |
$args['view'] = 'album'; |
| 610 |
$args['album_key'] = $components[4]; |
| 611 |
} |
| 612 |
else if ($provider == 'zenfolio') { |
| 613 |
$args['view'] = 'photosets'; |
| 614 |
$args['object_id'] = $components[4]; |
| 615 |
$args['thumb_size'] = sanitize_text_field($_POST['overlay_size']); |
| 616 |
$args['video_size'] = sanitize_text_field($_POST['overlay_video_size']); |
| 617 |
$args['realm_id'] = sanitize_text_field($_POST['realm_id']); |
| 618 |
} |
| 619 |
else if ($provider == 'google') { |
| 620 |
$args['view'] = 'photos'; |
| 621 |
$args['album_id'] = implode('-', array_slice($components, 4, (count($components) - 1) - 4)); |
| 622 |
$args['thumb_size'] = sanitize_text_field($_POST['overlay_size']); |
| 623 |
$args['video_size'] = sanitize_text_field($_POST['overlay_video_size']); |
| 624 |
$args['crop_thumb'] = sanitize_text_field($_POST['overlay_crop']); |
| 625 |
} |
| 626 |
else if ($provider == 'flickr') { |
| 627 |
if ($type == 'gallery') { |
| 628 |
$args['gallery_id'] = $components[4].'-'.$components[5]; |
| 629 |
$args['gallery_id_computed'] = true; |
| 630 |
} |
| 631 |
else if ($type = 'set') { |
| 632 |
$args['photoset_id'] = $components[4]; |
| 633 |
} |
| 634 |
$args['thumb_size'] = sanitize_text_field($_POST['overlay_size']); |
| 635 |
$args['video_size'] = sanitize_text_field($_POST['overlay_video_size']); |
| 636 |
} |
| 637 |
|
| 638 |
$gallery = new Gallery($args); |
| 639 |
echo $gallery->get_contents(); |
| 640 |
} |
| 641 |
die(); |
| 642 |
} |
| 643 |
|
| 644 |
function display_level_3_contents() { |
| 645 |
$node = esc_attr($_POST['node']); |
| 646 |
$components = explode('-', $node); |
| 647 |
|
| 648 |
if (count($components) <= 3) { |
| 649 |
die(); |
| 650 |
} |
| 651 |
|
| 652 |
$args = ['display' => 'in-page', 'headers' => '', 'layout' => esc_attr($_POST['layout'])]; |
| 653 |
|
| 654 |
$provider = $components[0]; |
| 655 |
if ($provider == 'flickr') { |
| 656 |
$args['collection_id'] = implode('-', array_slice($components, 2, 2, true)); |
| 657 |
$args['user_id'] = $components[4]; |
| 658 |
$args['type'] = 'flickr'; |
| 659 |
$gallery = new Gallery($args); |
| 660 |
echo $gallery->get_contents(); |
| 661 |
} |
| 662 |
die(); |
| 663 |
} |
| 664 |
|
| 665 |
/** |
| 666 |
* Constructs the CSS for a "background" option |
| 667 |
* |
| 668 |
* @param $option |
| 669 |
* @return string |
| 670 |
*/ |
| 671 |
function get_bg_css($option) { |
| 672 |
global ${$option}; |
| 673 |
$option_val = ${$option}; |
| 674 |
if (!is_array($option_val)) { |
| 675 |
$val_array = []; |
| 676 |
$vals = explode(';', $option_val); |
| 677 |
foreach ($vals as $val) { |
| 678 |
if (trim($val) == '') { continue; } |
| 679 |
$pair = explode('=', $val); |
| 680 |
$val_array[$pair[0]] = $pair[1]; |
| 681 |
} |
| 682 |
$option_val = $val_array; |
| 683 |
} |
| 684 |
$bg_string = ""; |
| 685 |
$bg_rgba_string = ""; |
| 686 |
if (!isset($option_val['colortype']) || $option_val['colortype'] == 'transparent') { |
| 687 |
$bg_string .= " transparent "; |
| 688 |
} |
| 689 |
else { |
| 690 |
if (isset($option_val['color'])) { |
| 691 |
if (substr($option_val['color'], 0, 1) == '#') { |
| 692 |
$color_string = substr($option_val['color'],1); |
| 693 |
} |
| 694 |
else { |
| 695 |
$color_string = $option_val['color']; |
| 696 |
} |
| 697 |
$rgb_str_array = []; |
| 698 |
if (strlen($color_string)==3) { |
| 699 |
$rgb_str_array[] = substr($color_string, 0, 1).substr($color_string, 0, 1); |
| 700 |
$rgb_str_array[] = substr($color_string, 1, 1).substr($color_string, 1, 1); |
| 701 |
$rgb_str_array[] = substr($color_string, 2, 1).substr($color_string, 2, 1); |
| 702 |
} |
| 703 |
else { |
| 704 |
$rgb_str_array[] = substr($color_string, 0, 2); |
| 705 |
$rgb_str_array[] = substr($color_string, 2, 2); |
| 706 |
$rgb_str_array[] = substr($color_string, 4, 2); |
| 707 |
} |
| 708 |
$rgb_array = []; |
| 709 |
$rgb_array[] = hexdec($rgb_str_array[0]); |
| 710 |
$rgb_array[] = hexdec($rgb_str_array[1]); |
| 711 |
$rgb_array[] = hexdec($rgb_str_array[2]); |
| 712 |
$rgb_string = implode(',',$rgb_array); |
| 713 |
$rgb_string = ' rgb('.$rgb_string.') '; |
| 714 |
|
| 715 |
if (isset($option_val['trans'])) { |
| 716 |
$bg_rgba_string = $bg_string; |
| 717 |
$transparency = (int)$option_val['trans']; |
| 718 |
if ($transparency != 0) { |
| 719 |
$trans_dec = $transparency/100; |
| 720 |
$rgba_string = implode(',', $rgb_array); |
| 721 |
$rgba_string = ' rgba('.$rgba_string.','.$trans_dec.') '; |
| 722 |
$bg_rgba_string .= $rgba_string; |
| 723 |
} |
| 724 |
} |
| 725 |
|
| 726 |
$bg_string .= $rgb_string; |
| 727 |
} |
| 728 |
} |
| 729 |
if (isset($option_val['image']) && trim($option_val['image']) != '') { |
| 730 |
$bg_string .= " url(".$option_val['image'].") "; |
| 731 |
$bg_string .= $option_val['position']." ".$option_val['repeat']; |
| 732 |
|
| 733 |
if (trim($bg_rgba_string) != '') { |
| 734 |
$bg_rgba_string .= " url(".$option_val['image'].") "; |
| 735 |
$bg_rgba_string .= $option_val['position']." ".$option_val['repeat']; |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
if (trim($bg_string) != '') { |
| 740 |
$bg_string = "background: ".$bg_string." !important;\n"; |
| 741 |
if (trim($bg_rgba_string) != '') { |
| 742 |
$bg_string .= "\tbackground: ".$bg_rgba_string." !important;\n"; |
| 743 |
} |
| 744 |
} |
| 745 |
return $bg_string; |
| 746 |
} |
| 747 |
|
| 748 |
/** |
| 749 |
* Generates the CSS for borders. Each border, top, right, bottom and left is generated as a separate line. |
| 750 |
* |
| 751 |
* @param $option |
| 752 |
* @return string |
| 753 |
*/ |
| 754 |
function get_border_css($option) { |
| 755 |
global ${$option}; |
| 756 |
$option_val = ${$option}; |
| 757 |
if (!is_array($option_val)) { |
| 758 |
$option_val = stripslashes($option_val); |
| 759 |
$edge_array = $this->build_edge_array($option_val); |
| 760 |
$option_val = $edge_array; |
| 761 |
} |
| 762 |
$border_string = ''; |
| 763 |
foreach ($option_val as $edge => $selections) { |
| 764 |
$border_string .= "\tborder-$edge: "; |
| 765 |
if (!isset($selections['style'])) { |
| 766 |
$selections['style'] = 'none'; |
| 767 |
} |
| 768 |
if ($selections['style'] == 'none') { |
| 769 |
$border_string .= "none"; |
| 770 |
} |
| 771 |
else { |
| 772 |
if (isset($selections['border-width'])) { |
| 773 |
$border_string .= $selections['border-width']; |
| 774 |
} |
| 775 |
if (isset($selections['border-width-type'])) { |
| 776 |
$border_string .= $selections['border-width-type']; |
| 777 |
} |
| 778 |
else { |
| 779 |
$border_string .= "px"; |
| 780 |
} |
| 781 |
$border_string .= " ".$selections['style']." "; |
| 782 |
if ($selections['colortype'] == 'transparent') { |
| 783 |
$border_string .= "transparent"; |
| 784 |
} |
| 785 |
else { |
| 786 |
if (substr($selections['color'], 0, 1) == '#') { |
| 787 |
$border_string .= $selections['color']; |
| 788 |
} |
| 789 |
else { |
| 790 |
$border_string .= '#'.$selections['color']; |
| 791 |
} |
| 792 |
} |
| 793 |
} |
| 794 |
$border_string .= ";\n"; |
| 795 |
} |
| 796 |
return "\n".$border_string; |
| 797 |
} |
| 798 |
|
| 799 |
public function build_edge_array($option_val) { |
| 800 |
$edge_array = []; |
| 801 |
$edges = explode('||', $option_val); |
| 802 |
foreach ($edges as $edge_val) { |
| 803 |
if (trim($edge_val) != '') { |
| 804 |
$edge_options = explode('::', trim($edge_val)); |
| 805 |
if (is_array($edge_options) && count($edge_options) > 1) { |
| 806 |
$val_array = []; |
| 807 |
$vals = explode(';', $edge_options[1]); |
| 808 |
foreach ($vals as $val) { |
| 809 |
$pair = explode('=', $val); |
| 810 |
if (is_array($pair) && count($pair) > 1) { |
| 811 |
$val_array[$pair[0]] = $pair[1]; |
| 812 |
} |
| 813 |
} |
| 814 |
$edge_array[$edge_options[0]] = $val_array; |
| 815 |
} |
| 816 |
} |
| 817 |
} |
| 818 |
return $edge_array; |
| 819 |
} |
| 820 |
|
| 821 |
/** |
| 822 |
* Make an HTTP request |
| 823 |
* |
| 824 |
* @static |
| 825 |
* @param $url |
| 826 |
* @param string $method GET | POST | DELETE |
| 827 |
* @param null $post_fields |
| 828 |
* @param string $user_agent |
| 829 |
* @param int $timeout |
| 830 |
* @param bool $ssl_verify_peer |
| 831 |
* @param array $headers |
| 832 |
* @param array $cookies |
| 833 |
* @return array|WP_Error |
| 834 |
*/ |
| 835 |
static function http($url, $method = 'POST', $post_fields = NULL, $user_agent = null, $timeout = 90, $ssl_verify_peer = false, $headers = [], $cookies = []) { |
| 836 |
$curl_args = [ |
| 837 |
'user-agent' => $user_agent, |
| 838 |
'timeout' => $timeout, |
| 839 |
'sslverify' => $ssl_verify_peer, |
| 840 |
'headers' => array_merge(['Expect:'], $headers), |
| 841 |
'method' => $method, |
| 842 |
'body' => $post_fields, |
| 843 |
'cookies' => $cookies, |
| 844 |
]; |
| 845 |
|
| 846 |
switch ($method) { |
| 847 |
case 'DELETE': |
| 848 |
if (!empty($post_fields)) { |
| 849 |
$url = "{$url}?{$post_fields}"; |
| 850 |
} |
| 851 |
break; |
| 852 |
} |
| 853 |
|
| 854 |
$response = wp_remote_request($url, $curl_args); |
| 855 |
return $response; |
| 856 |
} |
| 857 |
|
| 858 |
function obtain_token() { |
| 859 |
require_once(PHOTONIC_PATH."/Admin/Authentication.php"); |
| 860 |
$auth = Authentication::get_instance(); |
| 861 |
$auth->obtain_token(); |
| 862 |
die(); |
| 863 |
} |
| 864 |
|
| 865 |
/** |
| 866 |
* Invoked via AJAX in the "Authentication" page, when the user clicks on "Save Token" |
| 867 |
*/ |
| 868 |
function save_token_in_options() { |
| 869 |
$provider = strtolower(sanitize_text_field($_POST['provider'])); |
| 870 |
$token = esc_attr($_POST['token']); |
| 871 |
$secret = esc_attr($_POST['secret']); |
| 872 |
if (!empty($_POST['expires_in'])) { |
| 873 |
$expires_in = esc_attr($_POST['expires_in']); |
| 874 |
} |
| 875 |
|
| 876 |
$options = get_option('photonic_options'); |
| 877 |
if (empty($options)) { |
| 878 |
$options = []; |
| 879 |
} |
| 880 |
$option_set = false; |
| 881 |
if (in_array($provider, ['flickr', 'smug', 'zenfolio'])) { |
| 882 |
$options[$provider.'_access_token'] = $token; |
| 883 |
$options[$provider.'_token_secret'] = $secret; |
| 884 |
$option_set = true; |
| 885 |
} |
| 886 |
else if (in_array($provider, ['google'])) { |
| 887 |
$options[$provider.'_refresh_token'] = $token; |
| 888 |
$option_set = true; |
| 889 |
} |
| 890 |
else if (in_array($provider, ['instagram'])) { |
| 891 |
$client_id = esc_attr($_POST['client_id']); |
| 892 |
$user = esc_attr($_POST['user']); |
| 893 |
|
| 894 |
$options[$provider.'_access_token'] = $token; |
| 895 |
|
| 896 |
$auth_token = []; |
| 897 |
$auth_token['oauth_token'] = $token; |
| 898 |
$auth_token['oauth_token_created'] = time(); |
| 899 |
if (!empty($expires_in)) { |
| 900 |
$auth_token['oauth_token_expires'] = $expires_in; |
| 901 |
} |
| 902 |
$auth_token['client_id'] = $client_id; |
| 903 |
$auth_token['user'] = $user; |
| 904 |
|
| 905 |
self::save_provider_authentication($provider, $auth_token); |
| 906 |
|
| 907 |
$option_set = true; |
| 908 |
} |
| 909 |
|
| 910 |
if ($option_set) { |
| 911 |
update_option('photonic_options', $options); |
| 912 |
echo admin_url('admin.php?page=photonic-options-manager&tab='.$this->provider_map[$provider].'.php'); |
| 913 |
} |
| 914 |
die(); |
| 915 |
} |
| 916 |
|
| 917 |
function delete_token_from_options() { |
| 918 |
$provider = strtolower(sanitize_text_field($_POST['provider'])); |
| 919 |
$photonic_authentication = get_option('photonic_authentication'); |
| 920 |
if ($provider == 'zenfolio') { |
| 921 |
if (isset($photonic_authentication[$provider])) { |
| 922 |
unset($photonic_authentication[$provider]); |
| 923 |
} |
| 924 |
} |
| 925 |
update_option('photonic_authentication', $photonic_authentication); |
| 926 |
die(); |
| 927 |
} |
| 928 |
|
| 929 |
function invoke_helper() { |
| 930 |
require_once(PHOTONIC_PATH."/Admin/Helper.php"); |
| 931 |
$helper = new Helper(); |
| 932 |
$helper->invoke_helper(); |
| 933 |
} |
| 934 |
|
| 935 |
/** |
| 936 |
* @return array |
| 937 |
*/ |
| 938 |
public function get_localized_js_variables() { |
| 939 |
global $photonic_lightbox_no_loop, $photonic_slideshow_mode, $photonic_slideshow_interval, $photonic_slideshow_library, $photonic_custom_lightbox, |
| 940 |
$photonic_cb_transition_effect, $photonic_cb_transition_speed, |
| 941 |
$photonic_fbox_title_position, $photonic_fb3_transition_effect, $photonic_fb3_transition_speed, $photonic_fb3_show_fullscreen, $photonic_enable_fb3_fullscreen, |
| 942 |
$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, |
| 943 |
$photonic_lc_transition_effect, $photonic_lc_transition_speed_in, $photonic_lc_transition_speed_out, $photonic_lc_enable_shrink, |
| 944 |
$photonic_lg_transition_effect, $photonic_lg_transition_speed, $photonic_disable_lg_download, $photonic_lg_hide_bars_delay, |
| 945 |
$photonic_tile_spacing, $photonic_tile_min_height, $photonic_pphoto_theme, $photonic_pp_animation_speed, |
| 946 |
$photonic_enable_swipebox_mobile_bars, $photonic_sb_hide_mobile_close, $photonic_sb_hide_bars_delay, |
| 947 |
$photonic_lightbox_for_all, $photonic_lightbox_for_videos, $photonic_popup_panel_width, $photonic_deep_linking, $photonic_social_media, |
| 948 |
$photonic_slideshow_prevent_autostart, $photonic_wp_slide_adjustment, $photonic_masonry_min_width, $photonic_mosaic_trigger_width, |
| 949 |
$photonic_is_IE, $photonic_debug_on; |
| 950 |
|
| 951 |
global $photonic_js_variables; |
| 952 |
|
| 953 |
$slideshow_library = $photonic_slideshow_library == 'custom' ? $photonic_custom_lightbox : $photonic_slideshow_library; |
| 954 |
$js_array = [ |
| 955 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 956 |
'plugin_url' => PHOTONIC_URL, |
| 957 |
'is_old_IE' => $photonic_is_IE, |
| 958 |
'debug_on' => !empty($photonic_debug_on), |
| 959 |
|
| 960 |
'fbox_show_title' => $photonic_fbox_title_position == 'none' ? false : true, |
| 961 |
'fbox_title_position' => $photonic_fbox_title_position == 'none' ? 'outside' : $photonic_fbox_title_position, |
| 962 |
|
| 963 |
'slide_adjustment' => empty($photonic_wp_slide_adjustment) ? 'adapt-height-width' : $photonic_wp_slide_adjustment, |
| 964 |
|
| 965 |
'deep_linking' => isset($photonic_deep_linking) ? $photonic_deep_linking : 'none', |
| 966 |
'social_media' => isset($photonic_deep_linking) ? $photonic_deep_linking != 'none' && empty($photonic_social_media) : '', |
| 967 |
|
| 968 |
'slideshow_library' => $slideshow_library, |
| 969 |
'tile_spacing' => (empty($photonic_tile_spacing) || !absint($photonic_tile_spacing)) ? 0 : absint($photonic_tile_spacing), |
| 970 |
'tile_min_height' => (empty($photonic_tile_min_height) || !absint($photonic_tile_min_height)) ? 200 : absint($photonic_tile_min_height), |
| 971 |
'masonry_min_width' => (empty($photonic_masonry_min_width) || !absint($photonic_masonry_min_width)) ? 200 : absint($photonic_masonry_min_width), |
| 972 |
'mosaic_trigger_width' => (empty($photonic_mosaic_trigger_width) || !absint($photonic_mosaic_trigger_width)) ? 200 : absint($photonic_mosaic_trigger_width), |
| 973 |
|
| 974 |
'slideshow_mode' => (isset($photonic_slideshow_mode) && $photonic_slideshow_mode == 'on') ? true : false, |
| 975 |
'slideshow_interval' => (isset($photonic_slideshow_interval) && absint($photonic_slideshow_interval)) ? absint($photonic_slideshow_interval) : 5000, |
| 976 |
'lightbox_loop' => empty($photonic_lightbox_no_loop), |
| 977 |
|
| 978 |
'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), |
| 979 |
|
| 980 |
'cb_transition_effect' => empty($photonic_cb_transition_effect) ? 'elastic' : $photonic_cb_transition_effect, |
| 981 |
'cb_transition_speed' => (isset($photonic_cb_transition_speed) && absint($photonic_cb_transition_speed)) ? absint($photonic_cb_transition_speed) : 350, |
| 982 |
|
| 983 |
'fb3_transition_effect' => empty($photonic_fb3_transition_effect) ? 'zoom' : $photonic_fb3_transition_effect, |
| 984 |
'fb3_transition_speed' => (isset($photonic_fb3_transition_speed) && absint($photonic_fb3_transition_speed)) ? absint($photonic_fb3_transition_speed) : 366, |
| 985 |
'fb3_fullscreen_button' => !empty($photonic_fb3_show_fullscreen), |
| 986 |
'fb3_fullscreen' => isset($photonic_enable_fb3_fullscreen) && $photonic_enable_fb3_fullscreen == 'on' ? true : false, |
| 987 |
'fb3_thumbs_button' => empty($photonic_fb3_hide_thumbs), |
| 988 |
'fb3_thumbs' => isset($photonic_enable_fb3_thumbnail) && $photonic_enable_fb3_thumbnail == 'on' ? true : false, |
| 989 |
'fb3_zoom' => empty($photonic_fb3_disable_zoom), |
| 990 |
'fb3_slideshow' => empty($photonic_fb3_disable_slideshow), |
| 991 |
'fb3_download' => !empty($photonic_fb3_enable_download), |
| 992 |
'fb3_disable_right_click' => !empty($photonic_fb3_disable_right_click), |
| 993 |
|
| 994 |
'lc_transition_effect' => empty($photonic_lc_transition_effect) ? 'scrollHorizontal' : $photonic_lc_transition_effect, |
| 995 |
'lc_transition_speed_in' => (isset($photonic_lc_transition_speed_in) && absint($photonic_lc_transition_speed_in)) ? absint($photonic_lc_transition_speed_in) : 350, |
| 996 |
'lc_transition_speed_out' => (isset($photonic_lc_transition_speed_out) && absint($photonic_lc_transition_speed_out)) ? absint($photonic_lc_transition_speed_out) : 250, |
| 997 |
'lc_disable_shrink' => empty($photonic_lc_enable_shrink), |
| 998 |
|
| 999 |
'lg_transition_effect' => empty($photonic_lg_transition_effect) ? 'lg-slide' : $photonic_lg_transition_effect, |
| 1000 |
'lg_enable_download' => empty($photonic_disable_lg_download), |
| 1001 |
'lg_hide_bars_delay' => (isset($photonic_lg_hide_bars_delay) && absint($photonic_lg_hide_bars_delay)) ? absint($photonic_lg_hide_bars_delay) : 6000, |
| 1002 |
'lg_transition_speed' => (isset($photonic_lg_transition_speed) && absint($photonic_lg_transition_speed)) ? absint($photonic_lg_transition_speed) : 600, |
| 1003 |
|
| 1004 |
'pphoto_theme' => isset($photonic_pphoto_theme) ? $photonic_pphoto_theme : 'pp_default', |
| 1005 |
'pphoto_animation_speed' => empty($photonic_pp_animation_speed) ? 'fast' : $photonic_pp_animation_speed, |
| 1006 |
|
| 1007 |
'enable_swipebox_mobile_bars' => !empty($photonic_enable_swipebox_mobile_bars), |
| 1008 |
'sb_hide_mobile_close' => !empty($photonic_sb_hide_mobile_close), |
| 1009 |
'sb_hide_bars_delay' => (isset($photonic_sb_hide_bars_delay) && absint($photonic_sb_hide_bars_delay)) ? absint($photonic_sb_hide_bars_delay) : 0, |
| 1010 |
|
| 1011 |
'lightbox_for_all' => !empty($photonic_lightbox_for_all), |
| 1012 |
'lightbox_for_videos' => !empty($photonic_lightbox_for_videos), |
| 1013 |
|
| 1014 |
'slideshow_autostart' => !(isset($photonic_slideshow_prevent_autostart) && $photonic_slideshow_prevent_autostart == 'on'), |
| 1015 |
|
| 1016 |
'password_failed' => esc_attr__('This album is password-protected. Please provide a valid password.', 'photonic'), |
| 1017 |
'incorrect_password' => esc_attr__('Incorrect password.', 'photonic'), |
| 1018 |
'maximize_panel' => esc_attr__('Show', 'photonic'), |
| 1019 |
'minimize_panel' => esc_attr__('Hide', 'photonic'), |
| 1020 |
]; |
| 1021 |
$photonic_js_variables = $js_array; |
| 1022 |
return $js_array; |
| 1023 |
} |
| 1024 |
|
| 1025 |
function enable_translations() { |
| 1026 |
load_plugin_textdomain('photonic', FALSE, FALSE); |
| 1027 |
} |
| 1028 |
|
| 1029 |
function load_more() { |
| 1030 |
$provider = esc_attr($_POST['provider']); |
| 1031 |
$query = sanitize_text_field($_POST['query']); |
| 1032 |
$attr = wp_parse_args($query); |
| 1033 |
|
| 1034 |
$attr['type'] = $provider; |
| 1035 |
if ($provider == 'flickr') { |
| 1036 |
$attr['page'] = isset($attr['page']) ? $attr['page'] + 1 : 0; |
| 1037 |
} |
| 1038 |
else if ($provider == 'google') { |
| 1039 |
} |
| 1040 |
else if ($provider == 'smug') { |
| 1041 |
$attr['start'] = $attr['start'] + $attr['count']; |
| 1042 |
} |
| 1043 |
else if ($provider == 'zenfolio') { |
| 1044 |
$attr['offset'] = $attr['offset'] + $attr['limit']; |
| 1045 |
} |
| 1046 |
else if ($provider == 'instagram') { |
| 1047 |
} |
| 1048 |
else if ($provider == 'wp') { |
| 1049 |
$attr['page'] = $attr['page'] + 1; |
| 1050 |
} |
| 1051 |
else { |
| 1052 |
unset($attr['type']); |
| 1053 |
} |
| 1054 |
|
| 1055 |
if (!empty($attr['type'])) { |
| 1056 |
$gallery = new Gallery($attr); |
| 1057 |
echo $gallery->get_contents(); |
| 1058 |
} |
| 1059 |
die(); |
| 1060 |
} |
| 1061 |
|
| 1062 |
function helper_shortcode_more() { |
| 1063 |
if (!empty($_POST['provider'])) { |
| 1064 |
$provider = sanitize_text_field($_POST['provider']); |
| 1065 |
if (in_array($provider, ['google'])) { |
| 1066 |
$attr = ['type' => $provider]; |
| 1067 |
if ($provider == 'google') { |
| 1068 |
$attr['nextPageToken'] = sanitize_text_field($_POST['nextPageToken']); |
| 1069 |
$gallery = new Gallery($attr); |
| 1070 |
echo $gallery->get_helper_contents(); |
| 1071 |
} |
| 1072 |
} |
| 1073 |
} |
| 1074 |
die(); |
| 1075 |
} |
| 1076 |
|
| 1077 |
/** |
| 1078 |
* @param string|array $classes |
| 1079 |
* @return array |
| 1080 |
*/ |
| 1081 |
function body_class($classes = []) { |
| 1082 |
if (!is_array($classes)) { |
| 1083 |
$classes = explode(' ', $classes); |
| 1084 |
} |
| 1085 |
|
| 1086 |
global $photonic_is_IE; |
| 1087 |
if ($photonic_is_IE) { |
| 1088 |
$classes[] = 'photonic-ie'; |
| 1089 |
} |
| 1090 |
|
| 1091 |
return $classes; |
| 1092 |
} |
| 1093 |
|
| 1094 |
/** |
| 1095 |
* Used for handling the front-end for Gutenberg blocks |
| 1096 |
* |
| 1097 |
* @param $attributes |
| 1098 |
* @return array|bool|string |
| 1099 |
*/ |
| 1100 |
function render_block($attributes) { |
| 1101 |
if (!empty($attributes['shortcode'])) { |
| 1102 |
$shortcode = (array)(json_decode($attributes['shortcode'])); |
| 1103 |
|
| 1104 |
if (!empty($attributes['align'])) { |
| 1105 |
$shortcode['alignment'] = $attributes['align']; |
| 1106 |
} |
| 1107 |
if (!empty($attributes['className'])) { |
| 1108 |
$shortcode['custom_classes'] = $attributes['className']; |
| 1109 |
} |
| 1110 |
|
| 1111 |
$this->conditionally_add_scripts($shortcode); |
| 1112 |
return $this->get_gallery_images($shortcode); |
| 1113 |
} |
| 1114 |
return ''; |
| 1115 |
} |
| 1116 |
|
| 1117 |
private function add_gutenberg_support() { |
| 1118 |
if (function_exists('register_block_type')) { |
| 1119 |
register_block_type('photonic/gallery', |
| 1120 |
[ |
| 1121 |
'attributes' => [ |
| 1122 |
'shortcode' => [ |
| 1123 |
'type' => 'string', |
| 1124 |
], |
| 1125 |
], |
| 1126 |
'render_callback' => [&$this, 'render_block'], |
| 1127 |
] |
| 1128 |
); |
| 1129 |
} |
| 1130 |
} |
| 1131 |
|
| 1132 |
function dismiss_warning() { |
| 1133 |
$user_id = get_current_user_id(); |
| 1134 |
$response = []; |
| 1135 |
if (!empty($_POST['dismissible'])) { |
| 1136 |
add_user_meta( $user_id, "photonic_".esc_sql($_POST['dismissible']), 'true', true ); |
| 1137 |
$response[$_POST['dismissible']] = 'true'; |
| 1138 |
} |
| 1139 |
echo json_encode($response); |
| 1140 |
die(); |
| 1141 |
} |
| 1142 |
|
| 1143 |
function curl_timeout($handle) { |
| 1144 |
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, PHOTONIC_CURL_TIMEOUT); |
| 1145 |
curl_setopt($handle, CURLOPT_TIMEOUT, PHOTONIC_CURL_TIMEOUT); |
| 1146 |
} |
| 1147 |
|
| 1148 |
static function log($element) { |
| 1149 |
if (PHOTONIC_DEBUG) { |
| 1150 |
print_r($element); |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
static function doc_link($link) { |
| 1155 |
return ' '.sprintf(esc_html__('See %1$shere%2$s for documentation.', 'photonic'), "<a href='$link'>", '</a>'); |
| 1156 |
} |
| 1157 |
|
| 1158 |
function get_show_gallery_button($attr = []) { |
| 1159 |
$button = esc_attr($attr['show_gallery']); |
| 1160 |
$button_attr = []; |
| 1161 |
|
| 1162 |
if (!empty($attr['show_gallery_button_type']) && $attr['show_gallery_button_type'] == 'image' && !empty($attr['show_gallery_button_image'])) { |
| 1163 |
$button_attr['type'] = 'image'; |
| 1164 |
$button_attr['alt'] = $button; |
| 1165 |
$button_attr['src'] = esc_url($attr['show_gallery_button_image']); |
| 1166 |
} |
| 1167 |
else { |
| 1168 |
$button_attr['type'] = 'button'; |
| 1169 |
$button_attr['value'] = $button; |
| 1170 |
} |
| 1171 |
$button_attr['class'] = 'photonic-show-gallery-button'; |
| 1172 |
|
| 1173 |
unset($attr['show_gallery']); |
| 1174 |
unset($attr['show_gallery_button_type']); |
| 1175 |
unset($attr['show_gallery_button_image']); |
| 1176 |
|
| 1177 |
$attr_str = http_build_query($attr); |
| 1178 |
$button_attr['data-photonic-shortcode'] = $attr_str; |
| 1179 |
|
| 1180 |
$input_attr = []; |
| 1181 |
foreach ($button_attr as $name => $value) { |
| 1182 |
$input_attr[] = "$name='$value'"; |
| 1183 |
} |
| 1184 |
$input_attr = implode(' ', $input_attr); |
| 1185 |
|
| 1186 |
return "<input $input_attr/>"; |
| 1187 |
} |
| 1188 |
|
| 1189 |
function lazy_load() { |
| 1190 |
$shortcode = $_POST['shortcode']; |
| 1191 |
parse_str($shortcode, $attr); |
| 1192 |
$images = $this->get_gallery_images($attr); |
| 1193 |
echo $images; |
| 1194 |
die(); |
| 1195 |
} |
| 1196 |
|
| 1197 |
function load_widget() { |
| 1198 |
require_once(PHOTONIC_PATH. '/Add_Ons/WP/Widget.php'); |
| 1199 |
register_widget("Photonic_Plugin\Add_Ons\WP\Widget"); |
| 1200 |
} |
| 1201 |
|
| 1202 |
static function enqueue_widget_scripts() { |
| 1203 |
global $photonic_alternative_shortcode; |
| 1204 |
$js_array = [ |
| 1205 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 1206 |
'shortcode' => empty($photonic_alternative_shortcode) ? 'gallery' : $photonic_alternative_shortcode, |
| 1207 |
'current_shortcode' => esc_html__('Current shortcode', 'photonic'), |
| 1208 |
'edit_message' => esc_html__('Click on the icon to edit your gallery.', 'photonic'), |
| 1209 |
]; |
| 1210 |
wp_enqueue_script('photonic-widget', PHOTONIC_URL.'include/scripts/admin/widget.js', ['jquery'], Photonic::get_version(PHOTONIC_PATH.'/include/scripts/admin/widget.js')); |
| 1211 |
wp_localize_script('photonic-widget', 'Photonic_Widget_JS', $js_array); |
| 1212 |
wp_enqueue_style('photonic-widget', PHOTONIC_URL.'include/css/admin/widget.css', [], Photonic::get_version(PHOTONIC_PATH.'/include/css/admin/widget.css')); |
| 1213 |
} |
| 1214 |
} |
| 1215 |
|