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 | Admin/Admin.php +259 -145 2.43 → 3.37 View file →
@@ -1,13 +1,14 @@
1 1 <?php
2 +
2 3 namespace Photonic_Plugin\Admin;
3 4
4 5 use Photonic_Plugin\Admin\Wizard\Wizard;
5 6 use Photonic_Plugin\Core\Photonic;
6 -use Photonic_Plugin\Modules\SmugMug;
7 +use Photonic_Plugin\Platforms\SmugMug;
7 8
8 9 class Admin {
9 - function __construct() {
10 + public function __construct() {
10 11 global $photonic_disable_flow_editor_global;
11 12
12 13 // General
13 14 add_action('admin_head', [$this, 'admin_head']);
@@ -19,22 +20,20 @@
19 20
20 21 add_action('print_media_templates', [&$this, 'edit_gallery']);
21 22
22 23 // Gutenberg
23 - add_action('admin_notices', [&$this, 'admin_notices']);
24 24 add_action('enqueue_block_editor_assets', [&$this, 'enqueue_gutenberg_assets']);
25 + add_action('enqueue_block_assets', [&$this, 'enqueue_fse_assets']); // Site Editor; without this, the block doesn't work on the FSE Site Editor
25 26
26 27 if (empty($photonic_disable_flow_editor_global)) {
27 28 add_action('media_buttons', [&$this, 'add_photonic_button']);
28 29 add_action('admin_action_photonic_wizard', [&$this, 'open_wizard']);
29 30 add_action('wp_ajax_photonic_wizard_next_screen', [&$this, 'wizard_next_screen']);
30 - add_action('wp_ajax_nopriv_photonic_wizard_next_screen', [&$this, 'wizard_next_screen']);
31 31 add_action('wp_ajax_photonic_wizard_more', [&$this, 'flow_more']);
32 - add_action('wp_ajax_nopriv_photonic_wizard_more', [&$this, 'flow_more']);
33 32 }
34 33 }
35 34
36 - function admin_head() {
35 + public function admin_head() {
37 36 // check user permissions
38 37 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
39 38 return;
40 39 }
@@ -39,102 +38,208 @@
39 38 return;
40 39 }
41 40
42 41 global $photonic_disable_editor, $photonic_disable_editor_post_type;
43 - $disabled_types = explode(',', $photonic_disable_editor_post_type);
42 + $disabled_types = explode(',', esc_attr($photonic_disable_editor_post_type));
44 43 $screen = get_current_screen();
45 - $post_type = empty($_REQUEST['post_type']) ? 'post' : $_REQUEST['post_type'];
44 +
46 45 // check if WYSIWYG is enabled
47 - if ('true' == get_user_option('rich_editing') && empty($photonic_disable_editor) && !in_array($post_type, $disabled_types) && $screen->base == 'post') {
46 + if (user_can_richedit() && empty($photonic_disable_editor) && !in_array($_REQUEST['post_type'] ?? 'post', $disabled_types, true) && 'post' === $screen->base) { // phpcs:ignore WordPress.Security.NonceVerification
48 47 $this->prepare_mce_data();
49 - add_filter('mce_external_plugins', [$this ,'mce_photonic'], 5);
50 - add_filter('mce_buttons', [$this ,'mce_flow_button'], 5);
48 + add_filter('mce_external_plugins', [$this, 'mce_photonic'], 5);
49 + add_filter('mce_buttons', [$this, 'mce_flow_button'], 5);
51 50 }
52 51 }
53 52
54 - function add_photonic_button() {
53 + public function add_photonic_button() {
55 54 add_thickbox();
56 55 $url = $this->get_wizard_modal_url();
57 56
58 - printf('<a href="%1$s" class="button photonic-button thickbox" id="photonic-add-gallery" title="Photonic Gallery"><img class="wp-media-buttons-icon" src="'.PHOTONIC_URL.'include/images/Photonic-20.png'.'" alt="%2$s" /> %2$s</a>',
59 - $url, esc_html__( 'Add / Edit Photonic Gallery', 'photonic'));
57 + printf(
58 + '<a href="%1$s" class="button photonic-button thickbox" id="photonic-add-gallery" title="Photonic Gallery"><img class="wp-media-buttons-icon" src="' . esc_url(PHOTONIC_URL) . 'include/images/Photonic-20.png" alt="%2$s" /> %2$s</a>',
59 + esc_url($url),
60 + esc_html__('Add / Edit Photonic Gallery', 'photonic')
61 + );
60 62 }
61 63
62 - function open_wizard() {
63 - define( 'IFRAME_REQUEST', true );
64 + public function open_wizard() {
65 + define('IFRAME_REQUEST', true); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
64 66 $this->enqueue_wizard_scripts();
65 67 iframe_header(esc_html__('Add / Edit Photonic Gallery', 'photonic'));
66 - require_once(PHOTONIC_PATH.'/Admin/Wizard/Screen_Flow.php');
68 + require_once PHOTONIC_PATH . '/Admin/Wizard/Screen_Flow.php';
67 69 iframe_footer();
68 70 exit;
69 71 }
70 72
71 - function enqueue_wizard_scripts() {
72 - global $photonic_alternative_shortcode;
73 - $wizard_js = [
74 - 'ajaxurl' => admin_url('admin-ajax.php'),
75 - 'shortcode' => empty($photonic_alternative_shortcode) ? 'gallery' : $photonic_alternative_shortcode,
76 - 'insert_gallery' => esc_html__('Insert Gallery', 'photonic'),
77 - 'update_gallery' => esc_html__('Update Gallery', 'photonic'),
78 - 'error_mandatory' => esc_html__('Please fill the mandatory fields. Mandatory fields are marked with a red "*".', 'photonic'),
79 - 'media_library_title' => esc_html__('Select from WordPress Media Library', 'photonic'),
80 - 'media_library_button' => esc_html__('Select', 'photonic'),
81 - 'info_editor_not_shortcode' => esc_html__('The text selected in the editor is not a Photonic shortcode. Creating a new shortcode.', 'photonic'),
82 - 'info_editor_block_select' => sprintf(esc_html__('%1$sHint:%2$s To edit an existing Photonic block simply click on the block.', 'photonic'), '<strong>', '</strong>'),
83 - ];
84 - if (!empty($_REQUEST['shortcode'])) {
85 - $wizard_js['shortcode'] = $_REQUEST['shortcode'];
73 + public function enqueue_wizard_scripts() {
74 + if (current_user_can('edit_posts') && isset($_REQUEST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['nonce'])), 'photonic-wizard-' . get_current_user_id())) {
75 + global $photonic_alternative_shortcode, $photonic_debug_on;
76 + $safe_origin = '';
77 + $url_parts = wp_parse_url(home_url());
78 + $safe_origin_scheme = $url_parts['scheme'] ?? '';
79 + $safe_origin_separator = empty($safe_origin_scheme) ? '' : '://';
80 + $safe_origin_port = empty($url_parts['port']) ? '' : ':' . $url_parts['port'];
81 + $safe_origin .= $safe_origin_scheme . $safe_origin_separator . $url_parts['host'] . $safe_origin_port;
82 + $wizard_js = [
83 + 'ajaxurl' => admin_url('admin-ajax.php'),
84 + 'shortcode' => sanitize_text_field($photonic_alternative_shortcode ?: 'gallery'),
85 + 'insert_gallery' => esc_html__('Insert Gallery', 'photonic'),
86 + 'update_gallery' => esc_html__('Update Gallery', 'photonic'),
87 + 'error_mandatory' => esc_html__('Please fill the mandatory fields. Mandatory fields are marked with a red "*".', 'photonic'),
88 + 'media_library_title' => esc_html__('Select from WordPress Media Library', 'photonic'),
89 + 'media_library_button' => esc_html__('Select', 'photonic'),
90 + 'info_editor_not_shortcode' => esc_html__('The text selected in the editor is not a Photonic shortcode. Creating a new shortcode.', 'photonic'),
91 + 'info_editor_google_shortcode' => esc_html__('The text selected in the editor is Photonic shortcode for Google Photos. With effect from April 2025, Google Photos is no longer supported. Creating a new shortcode.', 'photonic'),
92 + /* Translators: 1: Open HTML tag 2: Close HTML tag */
93 + 'info_editor_block_select' => sprintf(esc_html__('%1$sHint:%2$s To edit an existing Photonic block simply click on the block.', 'photonic'), '<strong>', '</strong>'),
94 + 'safe_origin' => $safe_origin,
95 + 'debug_on' => !empty($photonic_debug_on),
96 + ];
97 + if (!empty($_REQUEST['shortcode'])) {
98 + $wizard_js['shortcode'] = sanitize_text_field($_REQUEST['shortcode']);
99 + }
100 + wp_enqueue_style('photonic-flow', PHOTONIC_URL . 'include/css/admin/admin-flow.css', [], Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin-flow.css'));
101 + wp_enqueue_script('photonic-flow-js', PHOTONIC_URL . 'include/js/admin/wizard.js', ['jquery'], Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/wizard.js'), false);
102 + wp_localize_script('photonic-flow-js', 'Photonic_Wizard_JS', $wizard_js);
86 103 }
87 - wp_enqueue_style('photonic-flow', PHOTONIC_URL.'include/css/admin/admin-flow.css', [], Photonic::get_version(PHOTONIC_PATH.'/include/css/admin/admin-flow.css'));
88 - wp_enqueue_script('photonic-flow-js', PHOTONIC_URL.'include/scripts/admin/flow.js', ['jquery'], Photonic::get_version(PHOTONIC_PATH.'/include/scripts/admin/flow.js'));
89 - wp_localize_script('photonic-flow-js', 'Photonic_Wizard_JS', $wizard_js);
90 104 }
91 105
92 - function wizard_next_screen() {
93 - require_once(PHOTONIC_PATH."/Admin/Wizard/Wizard.php");
94 - if (isset($_POST['provider'])) {
95 - $wizard = new Wizard();
96 - echo $wizard->get_screen();
106 + public function wizard_next_screen() {
107 + if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) {
108 + require_once PHOTONIC_PATH . '/Admin/Wizard/Wizard.php';
109 + if (isset($_POST['provider'])) {
110 + $safe_tags = array_merge_recursive(
111 + [
112 + 'form' => [
113 + 'id' => true,
114 + 'class' => true,
115 + 'name' => true,
116 + 'data-photonic-submission' => true,
117 + 'data-photonic-submission-pending' => true,
118 + ],
119 +
120 + 'input' => [
121 + 'type' => true,
122 + 'id' => true,
123 + 'name' => true,
124 + 'value' => true,
125 + 'checked' => true,
126 + 'class' => true,
127 + 'data-photonic-option-condition' => true,
128 + ],
129 +
130 + 'label' => [
131 + 'class' => true,
132 + 'for' => true,
133 + ],
134 +
135 + 'select' => [
136 + 'name' => true,
137 + 'id' => true,
138 + 'class' => true,
139 + 'aria-describedby' => true,
140 + ],
141 +
142 + 'option' => [
143 + 'value' => true,
144 + 'selected' => true,
145 + 'data-photonic-option-condition' => true,
146 + ],
147 +
148 + // Custom data attributes
149 + 'div' => [
150 + 'data-current-screen' => true,
151 +
152 + 'data-photonic-flow-selector-for' => true,
153 + 'data-photonic-flow-selector-mode' => true,
154 +
155 + 'data-photonic-condition' => true,
156 + 'data-photonic-flow-sequence' => true,
157 + 'data-photonic-flow-sequence-group' => true,
158 +
159 + 'data-photonic-flow-selection-id' => true,
160 + 'data-photonic-selection-alt-id' => true,
161 + 'data-photonic-selection-alt-id-2' => true,
162 + ],
163 +
164 + 'span' => [
165 + 'data-photonic-selection-id' => true,
166 + ],
167 +
168 + 'ol' => [
169 + 'data-photonic-date-filter' => true,
170 + 'data-photonic-filter-count' => true,
171 + 'data-photonic-date-range-filter' => true,
172 + ],
173 +
174 + 'a' => [
175 + 'data-photonic-add-date' => true,
176 + 'data-photonic-mark-for' => true,
177 + 'data-photonic-more-link' => true,
178 + 'data-photonic-display-type' => true,
179 + 'data-photonic-provider' => true,
180 + 'data-photonic-nonce' => true,
181 + ]
182 + ],
183 + wp_kses_allowed_html('post')
184 + );
185 +
186 + $wizard = new Wizard();
187 + // echo $wizard->get_screen(); // Cannot escape ... has form and JS markup; individual parts are escaped as appropriate.
188 + echo wp_kses($wizard->get_screen(), $safe_tags); // Cannot escape ... has form and JS markup; individual parts are escaped as appropriate.
189 + }
97 190 }
98 191 die();
99 192 }
100 193
101 - function flow_more() {
102 - require_once(PHOTONIC_PATH."/Admin/Wizard/Wizard.php");
103 - if (isset($_POST['url']) && isset($_POST['provider']) && isset($_POST['display_type'])) {
104 - $url = base64_decode(sanitize_text_field($_POST['url']));
194 + public function flow_more() {
195 + if (check_ajax_referer('photonic-wizard-more-' . get_current_user_id())) {
196 + require_once PHOTONIC_PATH . '/Admin/Wizard/Wizard.php';
197 + if (isset($_POST['url']) && isset($_POST['provider']) && isset($_POST['display_type'])) {
198 + $url = base64_decode(sanitize_text_field($_POST['url'])); // The `url` for fetching additional results is base64-encoded in the wizard in wizard.js using `btoa`
105 199
106 - $provider = sanitize_text_field($_POST['provider']);
107 - $display_type = sanitize_text_field($_POST['display_type']);
108 - $args = ['sslverify' => PHOTONIC_SSL_VERIFY];
109 - if ($provider == 'smugmug') {
110 - require_once(PHOTONIC_PATH."/Modules/SmugMug.php");
111 - $gallery = SmugMug::get_instance();
200 + $provider = sanitize_text_field($_POST['provider']);
201 + $display_type = sanitize_text_field($_POST['display_type']);
202 + $existing = [];
203 + if (!empty($_POST['filter'])) {
204 + $existing['selected_data'] = sanitize_text_field($_POST['filter']);
205 + }
206 + $args = ['sslverify' => PHOTONIC_SSL_VERIFY];
207 + if ('smugmug' === $provider) {
208 + require_once PHOTONIC_PATH . '/Platforms/SmugMug.php';
209 + $gallery = SmugMug::get_instance();
112 210
113 - $body = [
114 - 'APIKey' => $gallery->api_key,
115 - '_accept' => 'application/json',
116 - '_expandmethod' => 'inline',
117 - '_verbosity' => '1',
118 - ];
211 + $body = [
212 + 'APIKey' => $gallery->api_key,
213 + '_accept' => 'application/json',
214 + '_expandmethod' => 'inline',
215 + '_verbosity' => '1',
216 + ];
119 217
120 - if ($display_type == 'album-photo' || $display_type == 'multi-album') {
121 - $body['_expand'] = 'HighlightImage.ImageSizes';
218 + if ('album-photo' === $display_type || 'multi-album' === $display_type) {
219 + $body['_expand'] = 'HighlightImage.ImageSizes';
220 + }
221 +
222 + $args['body'] = $body;
122 223 }
123 224
124 - $args['body'] = $body;
125 - }
225 + // URL has come via base64, so we will check that it is directing to a whitelist of hosts...
226 + $url_parts = wp_parse_url($url);
227 + if (in_array($url_parts['host'], Wizard::base_apis(), true)) {
228 + $response = wp_remote_request($url, $args);
229 + $wizard = new Wizard();
230 + $objects = $wizard->process_response($response, $provider, $display_type, [], $existing, $url, true);
126 231
127 - $response = wp_remote_request($url, $args);
128 - $wizard = new Wizard();
129 - $objects = $wizard->process_response($response, $provider, $display_type, [], [], $url, true);
130 -
131 - if (!empty($objects['success'])) {
132 - echo $objects['success'];
232 + if (!empty($objects['success'])) {
233 + echo wp_kses_post($objects['success']);
234 + }
235 + elseif (!empty($objects['error'])) {
236 + if ($objects['error'] !== $wizard->error_no_data_returned) { // Typically happens if there is a "next token" without corresponding data
237 + echo wp_kses_post($objects['error']);
238 + }
239 + }
240 + }
133 241 }
134 - else if (!empty($objects['error'])) {
135 - echo $objects['error'];
136 - }
137 242 }
138 243 die();
139 244 }
140 245
@@ -143,69 +248,84 @@
143 248 *
144 249 * @param $hook
145 250 * @return void
146 251 */
147 - function add_admin_scripts($hook) {
148 - if ('media-upload-popup' == $hook) {
252 + public function add_admin_scripts($hook) {
253 + if ('media-upload-popup' === $hook) {
149 254 wp_enqueue_script('jquery');
150 - wp_enqueue_style('photonic-upload', PHOTONIC_URL.'include/css/admin/admin-form.css', [], Photonic::get_version(PHOTONIC_PATH.'/include/css/admin/admin-form.css'));
255 + wp_enqueue_style('photonic-upload', PHOTONIC_URL . 'include/css/admin/admin-form.css', [], Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin-form.css'));
151 256 }
152 - else if ('post-new.php' == $hook || 'post.php' == $hook) {
153 - global $photonic_disable_editor, $photonic_disable_editor_post_type;
257 + elseif ('post-new.php' === $hook || 'post.php' === $hook) {
258 + global $photonic_disable_editor, $photonic_disable_editor_post_type, $photonic_alternative_shortcode;
154 259 $disabled_types = explode(',', $photonic_disable_editor_post_type);
155 - $post_type = empty($_REQUEST['post_type']) ? 'post' : $_REQUEST['post_type'];
156 - wp_enqueue_style('photonic-upload', PHOTONIC_URL.'include/css/admin/admin-form.css', [], Photonic::get_version(PHOTONIC_PATH.'/include/css/admin/admin-form.css'));
157 - if (empty($photonic_disable_editor) && !in_array($post_type, $disabled_types)) {
260 + wp_enqueue_style('photonic-upload', PHOTONIC_URL . 'include/css/admin/admin-form.css', [], Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin-form.css'));
261 + wp_enqueue_script('photonic-native-ui', PHOTONIC_URL . 'include/js/admin/native-ui.js', ['shortcode', 'thickbox'], Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/native-ui.js'), false);
262 + wp_enqueue_script('photonic-editor', PHOTONIC_URL . 'include/js/admin/editor.js', ['photonic-native-ui'], Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/editor.js'), false);
263 + $editor_js = [
264 + 'shortcode' => sanitize_text_field($photonic_alternative_shortcode ?: 'gallery'),
265 + ];
266 + wp_localize_script('photonic-editor', 'Photonic_Editor_JS', $editor_js);
267 +
268 + if (empty($photonic_disable_editor) && !in_array($_REQUEST['post_type'] ?? 'post', $disabled_types, true)) { // phpcs:ignore WordPress.Security.NonceVerification
158 269 $this->prepare_mce_data();
159 270
160 - add_editor_style(PHOTONIC_URL.'include/css/admin/admin-editor.css?'.Photonic::get_version(PHOTONIC_PATH.'/include/css/admin/admin-editor.css'));
271 + add_editor_style(PHOTONIC_URL . 'include/css/admin/admin-editor.css?' . Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin-editor.css'));
161 272 }
162 273 }
163 - else if ('widgets.php' == $hook) {
274 + elseif ('widgets.php' === $hook) {
164 275 Photonic::enqueue_widget_scripts();
165 276 }
166 277 }
167 278
168 - function prepare_mce_data() {
279 + public function prepare_mce_data() {
169 280 $url = $this->get_wizard_modal_url();
170 281 $js_array = $this->get_wizard_js_parameters($url);
171 282
172 - wp_enqueue_script('photonic-admin-js', PHOTONIC_URL.'include/scripts/admin/gallery-settings.js', ['jquery', 'media-views', 'media-upload'], Photonic::get_version(PHOTONIC_PATH.'/include/scripts/admin/gallery-settings.js'));
283 + wp_enqueue_script('photonic-admin-js', PHOTONIC_URL . 'include/js/admin/gallery-settings.js', ['jquery', 'media-views', 'media-upload'], Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/gallery-settings.js'), false);
173 284 wp_localize_script('photonic-admin-js', 'Photonic_Admin_JS', $js_array);
174 285 }
175 286
176 - function mce_photonic($plugin_array) {
177 - $plugin_array['photonic'] = PHOTONIC_URL.'include/scripts/admin/mce.js?'.Photonic::get_version(PHOTONIC_PATH.'/include/scripts/admin/mce.js');
287 + public function mce_photonic($plugin_array) {
288 + $plugin_array['photonic'] = PHOTONIC_URL . 'include/js/admin/mce.js?' . Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/mce.js');
178 289 return $plugin_array;
179 290 }
180 291
181 - function mce_flow_button($buttons) {
292 + public function mce_flow_button($buttons) {
182 293 array_push($buttons, 'photonic_wizard');
183 294 return $buttons;
184 295 }
185 296
186 - function enqueue_gutenberg_assets() {
187 - if (function_exists('register_block_type')) {
188 - wp_enqueue_script('photonic-gutenberg',
189 - PHOTONIC_URL.'include/scripts/admin/block.js',
190 - ['jquery', 'wp-blocks', 'wp-i18n', 'wp-element', 'shortcode', 'thickbox'],
191 - Photonic::get_version(PHOTONIC_PATH.'/include/scripts/admin/block.js')
192 - );
297 + public function enqueue_gutenberg_assets() {
298 + wp_enqueue_script('photonic-native-ui', PHOTONIC_URL . 'include/js/admin/native-ui.js', ['shortcode', 'thickbox'], Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/native-ui.js'), false);
299 + wp_enqueue_script(
300 + 'photonic-gutenberg',
301 + PHOTONIC_URL . 'include/js/admin/block.js',
302 + ['wp-blocks', 'wp-i18n', 'wp-element', 'shortcode', 'thickbox', 'photonic-native-ui'],
303 + Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/block.js'),
304 + false
305 + );
193 306
194 - if (function_exists( 'gutenberg_get_jed_locale_data')) {
195 - $locale = gutenberg_get_jed_locale_data('photonic');
196 - $content = 'wp.i18n.setLocaleData('.json_encode($locale).', "photonic");';
197 - wp_script_add_data( 'photonic-gutenberg', 'data', $content );
198 - }
307 + wp_set_script_translations('photonic-gutenberg', 'photonic');
199 308
200 - $url = $this->get_wizard_modal_url();
201 - $js_array = $this->get_wizard_js_parameters($url);
202 - wp_localize_script('photonic-gutenberg', 'Photonic_Gutenberg_JS', $js_array);
309 + $url = $this->get_wizard_modal_url();
310 + $js_array = $this->get_wizard_js_parameters($url);
311 + wp_localize_script('photonic-gutenberg', 'Photonic_Gutenberg_JS', $js_array);
203 312
204 - wp_enqueue_style('photonic-gutenberg',
205 - PHOTONIC_URL.'include/css/admin/admin-block.css',
313 + wp_enqueue_style(
314 + 'photonic-gutenberg',
315 + PHOTONIC_URL . 'include/css/admin/admin-block.css',
316 + ['thickbox'],
317 + Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin-block.css')
318 + );
319 + }
320 +
321 + public function enqueue_fse_assets() {
322 + if (is_admin()) {
323 + wp_enqueue_style(
324 + 'photonic-gutenberg',
325 + PHOTONIC_URL . 'include/css/admin/admin-block.css',
206 326 ['thickbox'],
207 - Photonic::get_version(PHOTONIC_PATH.'/include/css/admin/admin-block.css')
327 + Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin-block.css')
208 328 );
209 329 }
210 330 }
211 331
@@ -214,10 +334,11 @@
214 334 *
215 335 * @param $tabs
216 336 * @return array
217 337 */
218 - function media_upload_tabs($tabs) {
219 - if (!function_exists('is_gutenberg_page') || (function_exists('is_gutenberg_page') && !is_gutenberg_page())) {
338 + public function media_upload_tabs($tabs): array {
339 + $current_screen = get_current_screen();
340 + if (!empty($current_screen) && $current_screen->is_block_editor()) {
220 341 $tabs['photonic'] = 'Photonic';
221 342 }
222 343 return $tabs;
223 344 }
@@ -226,9 +347,9 @@
226 347 * Invokes the form to display the photonic insertion screen in the "Add Media" panel. The call to wp_iframe ensures that the right CSS and JS are called.
227 348 *
228 349 * @return void
229 350 */
230 - function media_upload_photonic() {
351 + public function media_upload_photonic() {
231 352 wp_iframe([&$this, 'media_upload_photonic_form']);
232 353 }
233 354
234 355 /**
@@ -235,20 +356,19 @@
235 356 * First prints the standard buttons for media upload, then shows the UI for Photonic.
236 357 *
237 358 * @return void
238 359 */
239 - function media_upload_photonic_form() {
360 + public function media_upload_photonic_form() {
240 361 media_upload_header();
241 - require_once(PHOTONIC_PATH."/Admin/Forms/Add_Gallery.php");
362 + require_once PHOTONIC_PATH . '/Admin/Forms/Add_Gallery.php';
242 363 }
243 364
244 - function edit_gallery() {
365 + public function edit_gallery() {
245 366 global $photonic_disable_editor, $photonic_disable_editor_post_type;
246 367 $disabled_types = explode(',', $photonic_disable_editor_post_type);
247 - $post_type = empty($_REQUEST['post_type']) ? 'post' : $_REQUEST['post_type'];
248 368 // check if WYSIWYG is enabled
249 - if ('true' == get_user_option('rich_editing') && empty($photonic_disable_editor) && !in_array($post_type, $disabled_types)) {
250 - require_once(PHOTONIC_PATH."/Admin/Forms/Edit_Gallery_Templates.php");
369 + if (user_can_richedit() && empty($photonic_disable_editor) && !in_array($_REQUEST['post_type'] ?? 'post', $disabled_types, true)) { // phpcs:ignore WordPress.Security.NonceVerification
370 + require_once PHOTONIC_PATH . '/Admin/Forms/Edit_Gallery_Templates.php';
251 371 }
252 372 }
253 373
254 374 /**
@@ -253,18 +373,28 @@
253 373
254 374 /**
255 375 * @return string
256 376 */
257 - private function get_wizard_modal_url() {
258 - $url = add_query_arg([
259 - 'action' => 'photonic_wizard',
260 - 'class' => 'photonic-flow',
261 - 'post_id' => empty($_REQUEST['post']) ? '' : $_REQUEST['post'],
262 - 'width' => '1000',
263 - 'height' => '600',
264 - 'TB_iframe' => 'true',
265 - ], admin_url('admin.php'));
266 - return $url;
377 + private function get_wizard_modal_url(): string {
378 + $user = get_current_user_id();
379 + if (0 === $user) {
380 + $user = wp_rand(1);
381 + }
382 +
383 + $post = empty($_REQUEST['post']) ? '' : sanitize_text_field($_REQUEST['post']); // phpcs:ignore WordPress.Security.NonceVerification
384 +
385 + return add_query_arg(
386 + [
387 + 'action' => 'photonic_wizard',
388 + 'class' => 'photonic-flow',
389 + 'post_id' => $post,
390 + 'nonce' => wp_create_nonce('photonic-wizard-' . $user),
391 + 'width' => '1000',
392 + 'height' => '600',
393 + 'TB_iframe' => 'true',
394 + ],
395 + admin_url('admin.php')
396 + );
267 397 }
268 398
269 399 /**
270 400 * @param string $url
@@ -269,34 +399,18 @@
269 399 /**
270 400 * @param string $url
271 401 * @return array
272 402 */
273 - private function get_wizard_js_parameters($url) {
403 + private function get_wizard_js_parameters($url): array {
274 404 global $photonic_alternative_shortcode, $photonic_disable_flow_editor, $photonic_disable_flow_editor_global;
275 - $js_array = [
276 - 'flow_url' => $url,
277 - 'ajaxurl' => admin_url('admin-ajax.php'),
278 - 'shortcode' => empty($photonic_alternative_shortcode) ? 'gallery' : $photonic_alternative_shortcode,
279 - 'disable_flow' => !empty($photonic_disable_flow_editor) || !empty($photonic_disable_flow_editor_global),
405 + return [
406 + 'flow_url' => $url,
407 + 'ajaxurl' => admin_url('admin-ajax.php'),
408 + 'shortcode' => sanitize_text_field($photonic_alternative_shortcode ?: 'gallery'),
409 + 'disable_flow' => !empty($photonic_disable_flow_editor) || !empty($photonic_disable_flow_editor_global),
280 410 'default_gallery_type' => 'default',
281 - 'plugin_dir' => plugin_dir_url(__FILE__),
411 + 'plugin_dir' => plugin_dir_url(__FILE__),
282 412 ];
283 - return $js_array;
284 413 }
285 -
286 - function admin_notices() {
287 - if (!empty($_REQUEST['page']) && in_array($_REQUEST['page'], ['photonic-options-manager', 'photonic-getting-started', 'photonic-auth', 'photonic-helpers'])){
288 - if (function_exists('register_block_type')) {
289 - $dismissed = get_user_meta(get_current_user_id(), 'photonic_gutenberg');
290 - if (!$dismissed) {
291 - echo "<div class='notice notice-warning'>\n<p>\n";
292 - echo sprintf(esc_html__('It looks like you are using the Gutenberg editor. Please ensure that you have followed the instructions under %s.', 'photonic'), '<em><a href="'.admin_url('admin.php?page=photonic-gutenberg').'">Photonic &rarr; Switch to Gutenberg</a></em>');
293 - echo "</p>\n";
294 - echo "<button type='button' data-photonic-dismissible='gutenberg' class='photonic-notice-dismiss'><span class='screen-reader-text'>Dismiss this notice.</span></button>";
295 - echo "</div>\n";
296 - }
297 - }
298 - }
299 - }
300 414 }
301 415
302 -new Admin();
416 +new Admin();