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