PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / admin / class-gallery-attachment-modal.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 2 months ago class-admin-notices.php 2 months ago class-admin.php 2 months ago class-attachment-fields.php 2 months ago class-columns.php 2 months ago class-demo-content.php 2 months ago class-extensions.php 2 months ago class-gallery-attachment-modal.php 2 months ago class-gallery-datasources.php 2 months ago class-gallery-editor.php 2 months ago class-gallery-metabox-fields.php 2 months ago class-gallery-metabox-items.php 2 months ago class-gallery-metabox-settings-helper.php 2 months ago class-gallery-metabox-settings.php 2 months ago class-gallery-metabox-template.php 2 months ago class-gallery-metaboxes.php 2 months ago class-menu.php 2 months ago class-pro-promotion.php 2 months ago class-settings.php 2 months ago class-silent-installer-skin.php 2 months ago class-trial-mode.php 2 months ago demo-content-galleries.php 2 months ago demo-content-images.php 2 months ago index.php 2 months ago pro-features.php 2 months ago view-features.php 2 months ago view-help-demos.php 2 months ago view-help-getting-started.php 2 months ago view-help-pro.php 2 months ago view-help.php 2 months ago view-system-info.php 2 months ago
class-gallery-attachment-modal.php
1103 lines
1 <?php
2 /*
3 * FooGallery Admin Gallery Attachment Modal class
4 */
5
6 if ( ! class_exists( 'FooGallery_Admin_Gallery_Attachment_Modal' ) ) {
7
8 class FooGallery_Admin_Gallery_Attachment_Modal {
9
10 /**
11 * Primary class constructor.
12 */
13 public function __construct() {
14 add_action( 'admin_footer', array( $this, 'foogallery_image_editor_modal' ) );
15
16 add_action( 'wp_ajax_foogallery_attachment_modal_open', array( $this, 'ajax_open_modal' ) );
17 add_action( 'wp_ajax_foogallery_attachment_modal_save', array( $this, 'ajax_save_modal' ) );
18 add_action( 'wp_ajax_foogallery_attachment_modal_taxonomy_add', array( $this, 'ajax_add_taxonomy' ) );
19 add_action( 'foogallery_attachment_modal_tabs_view', array( $this, 'display_tab_main' ), 10 );
20 add_action( 'foogallery_attachment_modal_tabs_view', array( $this, 'display_tab_taxonomies' ), 20 );
21 add_action( 'foogallery_attachment_modal_tabs_view', array( $this, 'display_tab_thumbnails' ), 30 );
22 add_action( 'foogallery_attachment_modal_tabs_view', array( $this, 'display_tab_advanced' ), 200 );
23
24 add_action( 'foogallery_attachment_modal_tab_content', array( $this, 'display_tab_content_main' ), 10, 1 );
25 add_action( 'foogallery_attachment_modal_tab_content', array( $this, 'display_tab_content_taxonomies' ), 20, 1 );
26 add_action( 'foogallery_attachment_modal_tab_content', array( $this, 'display_tab_content_thumbnails' ), 30, 1 );
27 add_action( 'foogallery_attachment_modal_tab_content', array( $this, 'display_tab_content_advanced' ), 60, 1 );
28
29 add_action( 'foogallery_attachment_modal_before_thumbnail', array( $this, 'display_attachment_info' ), 10, 1 );
30
31 add_filter( 'foogallery_attachment_modal_data', array( $this, 'foogallery_attachment_modal_data_main' ), 10, 4 );
32 add_filter( 'foogallery_attachment_modal_data', array( $this, 'foogallery_attachment_modal_data_taxonomies' ), 20, 4 );
33 add_filter( 'foogallery_attachment_modal_data', array( $this, 'foogallery_attachment_modal_data_thumbnails' ), 30, 4 );
34 add_filter( 'foogallery_attachment_modal_data', array( $this, 'foogallery_attachment_modal_data_advanced' ), 60, 4 );
35 add_filter( 'foogallery_attachment_modal_data', array( $this, 'foogallery_attachment_modal_data_info' ), 70, 4 );
36
37 add_action( 'foogallery_attachment_modal_after_tabs', array( $this, 'foogallery_img_modal_save_btn' ) );
38
39 add_action( 'foogallery_attachment_save_data', array( $this, 'foogallery_attachment_save_data_main' ), 10, 2 );
40 add_action( 'foogallery_attachment_save_data', array( $this, 'foogallery_attachment_save_data_taxonomies' ), 20, 2 );
41 add_action( 'foogallery_attachment_save_data', array( $this, 'foogallery_attachment_save_data_thumbnails' ), 30, 2 );
42 add_action( 'foogallery_attachment_save_data', array( $this, 'foogallery_attachment_save_data_advanced' ), 60, 2 );
43 }
44
45 /**
46 * Generate image edit modal on gallery creation
47 */
48 public function ajax_open_modal() {
49 if ( ! check_ajax_referer( 'foogallery_attachment_modal_open', 'nonce', false ) ) {
50 wp_send_json_error(
51 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
52 403
53 );
54 }
55
56 $img_id = isset( $_POST['img_id'] ) ? absint( wp_unslash( $_POST['img_id'] ) ) : 0;
57 $gallery_id = isset( $_POST['gallery_id'] ) ? absint( wp_unslash( $_POST['gallery_id'] ) ) : 0;
58
59 if ( ! $img_id || ! $gallery_id ) {
60 wp_send_json_error(
61 array( 'message' => __( 'Invalid attachment data.', 'foogallery' ) ),
62 400
63 );
64 }
65
66 if ( ! current_user_can( 'edit_post', $img_id ) ) {
67 wp_send_json_error(
68 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
69 403
70 );
71 }
72
73 if ( ! current_user_can( 'edit_post', $gallery_id ) ) {
74 wp_send_json_error(
75 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
76 403
77 );
78 }
79
80 $modal_data = $this->build_modal_data( $_POST );
81
82 ob_start() ?>
83
84 <div class="foogallery-image-edit-main" data-img_id="<?php echo esc_attr( $modal_data['img_id'] ); ?>" data-gallery_id="<?php echo esc_attr( $modal_data['gallery_id'] ); ?>">
85 <?php do_action( 'foogallery_attachment_modal_before_tab_container', $modal_data ); ?>
86 <div class="foogallery-image-edit-view">
87 <?php
88
89 do_action( 'foogallery_attachment_modal_before_thumbnail', $modal_data );
90
91 if ( $modal_data['image_attributes'] ) { ?>
92 <img src="<?php echo esc_url( $modal_data['image_attributes'][0] ); ?>" width="<?php echo esc_attr( $modal_data['image_attributes'][1] ); ?>" height="<?php echo esc_attr( $modal_data['image_attributes'][2] ); ?>" />
93 <?php } ?>
94 </div>
95 <div class="foogallery-image-edit-button">
96 <a target="_blank" href="<?php echo esc_url( get_admin_url().'post.php?post='.$modal_data['img_id'].'&action=edit' );?>" class="button"><?php esc_html_e('Edit Image', 'foogallery'); ?></a>
97 <a target="_blank" href="<?php echo esc_url( $modal_data['img_path'] );?>" class="button"><?php esc_html_e('Open Full Size Image', 'foogallery'); ?></a>
98 </div>
99 </div>
100
101 <div class="foogallery-image-edit-meta">
102
103 <?php do_action( 'foogallery_attachment_modal_before_tabs', $modal_data ); ?>
104
105 <div class="tabset">
106 <?php do_action( 'foogallery_attachment_modal_tabs_view', $modal_data ); ?>
107 </div>
108 <div class="tab-panels">
109 <form id="foogallery_attachment_modal_save_form" method="post" enctype="multipart/form-data">
110 <input type="hidden" name="action" value="foogallery_attachment_modal_save">
111 <input type="hidden" name="nonce" value="<?php echo esc_attr( $modal_data['nonce'] ); ?>">
112 <input type="hidden" name="img_id" value="<?php echo esc_attr( $modal_data['img_id'] ); ?>">
113 <?php do_action( 'foogallery_attachment_modal_tab_content', $modal_data ); ?>
114 </form>
115 </div>
116
117 <?php do_action( 'foogallery_attachment_modal_after_tabs', $modal_data ); ?>
118
119 </div>
120 <?php
121
122 do_action( 'foogallery_attachment_modal_after_tab_container', $modal_data );
123
124 wp_send_json( array(
125 'html' => ob_get_clean(),
126 'prev_slide' => $modal_data['prev_slide'],
127 'next_slide' => $modal_data['next_slide'],
128 'next_img_id' => $modal_data['next_img_id'],
129 'prev_img_id' => $modal_data['prev_img_id'],
130 'override_thumbnail' => $modal_data['foogallery_override_thumbnail'],
131 'current_tab' => $modal_data['current_tab']
132 ) );
133 }
134
135 /**
136 * Admin modal wrapper for gallery image edit
137 */
138 public function foogallery_image_editor_modal() {
139 global $post;
140
141 // Check if the gallery edit page is being shown.
142 $screen = get_current_screen();
143 if ( 'foogallery' !== $screen->id ) {
144 return;
145 }
146
147 if ( !is_a( $post, 'WP_Post' ) ) {
148 return;
149 }
150
151 $modal_style = foogallery_get_setting( 'advanced_attachment_modal' );
152
153 // Only show the attachment modal if the setting is turned on.
154 if ( 'on' !== $modal_style ) {
155 return;
156 }
157
158 ?>
159 <div id="foogallery-image-edit-modal" class="foogallery-modal-wrapper" style="display: none;"
160 data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_attachment_modal_open' ) ); ?>"
161 data-gallery_id="<?php echo esc_attr( $post->ID ); ?>"
162 data-modal_style="<?php echo esc_attr( $modal_style ); ?>">
163 <div class="media-modal wp-core-ui">
164 <div class="media-modal-content">
165 <div class="edit-attachment-frame mode-select hide-menu hide-router">
166 <div class="edit-media-header">
167 <button title="<?php esc_attr_e( 'Edit previous attachment in the gallery', 'foogallery' ); ?>" class="left dashicons"><span class="screen-reader-text"><?php esc_html_e( 'Edit previous attachment in the gallery', 'foogallery' ); ?></span></button>
168 <button title="<?php esc_attr_e( 'Edit next attachment in the gallery', 'foogallery' ); ?>" class="right dashicons"><span class="screen-reader-text"><?php esc_html_e( 'Edit next attachment in the gallery', 'foogallery' ); ?></span></button>
169 <button type="button" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text"><?php esc_html_e('Close dialog', 'foogallery'); ?></span></span></button>
170 </div>
171 <div class="media-frame-title foogallery-modal-title">
172 <h1><?php esc_html_e('Edit Attachment Details', 'foogallery'); ?></h1>
173 <div class="attachment-modal-autosave">
174 <input id="attachment-modal-autosave" type="checkbox" />
175 <label for="attachment-modal-autosave"><?php esc_html_e( 'Autosave', 'foogallery' ); ?></label>
176 </div>
177 </div>
178 <div class="media-frame-content foogallery-modal-container">
179 <div class="attachment-details save-ready">
180 </div>
181 </div>
182 </div>
183 </div>
184 </div>
185 </div>
186 <?php }
187
188 /**
189 * Save modal form data to database
190 */
191 public function ajax_save_modal() {
192 $foogallery = isset( $_POST['foogallery'] ) ? wp_unslash( $_POST['foogallery'] ) : array();
193
194 if ( ! is_array( $foogallery ) || empty( $foogallery ) ) {
195 wp_send_json_error(
196 array( 'message' => __( 'Invalid attachment data.', 'foogallery' ) ),
197 400
198 );
199 }
200
201 if ( ! check_ajax_referer( 'foogallery-modal-nonce', 'nonce', false ) ) {
202 wp_send_json_error(
203 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
204 403
205 );
206 }
207
208 $img_id = isset( $_POST['img_id'] ) ? absint( wp_unslash( $_POST['img_id'] ) ) : 0;
209
210 if ( ! $img_id ) {
211 wp_send_json_error(
212 array( 'message' => __( 'Invalid attachment data.', 'foogallery' ) ),
213 400
214 );
215 }
216
217 if ( ! current_user_can( 'edit_post', $img_id ) ) {
218 wp_send_json_error(
219 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
220 403
221 );
222 }
223
224 $attachment_post = get_post( $img_id );
225 if ( ! is_a( $attachment_post, 'WP_Post' ) || 'attachment' !== $attachment_post->post_type ) {
226 wp_send_json_error(
227 array( 'message' => __( 'Invalid attachment data.', 'foogallery' ) ),
228 400
229 );
230 }
231
232 do_action( 'foogallery_attachment_save_data', $img_id, $foogallery );
233 wp_send_json_success();
234 }
235
236 /**
237 * Save new taxonomy
238 */
239 public function ajax_add_taxonomy() {
240 if ( ! check_ajax_referer( 'foogallery_attachment_modal_taxonomies', 'nonce', false ) ) {
241 wp_send_json_error(
242 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
243 403
244 );
245 }
246
247 $img_id = isset( $_POST['img_id'] ) ? absint( wp_unslash( $_POST['img_id'] ) ) : 0;
248 $taxonomy = isset( $_POST['taxonomy'] ) ? sanitize_key( wp_unslash( $_POST['taxonomy'] ) ) : '';
249 $term = isset( $_POST['term'] ) ? sanitize_text_field( wp_unslash( $_POST['term'] ) ) : '';
250
251 if ( ! $img_id || '' === $taxonomy || '' === $term ) {
252 wp_send_json_error(
253 array( 'message' => __( 'Invalid data.', 'foogallery' ) ),
254 400
255 );
256 }
257
258 if ( ! taxonomy_exists( $taxonomy ) ) {
259 wp_send_json_error(
260 array( 'message' => __( 'Invalid taxonomy.', 'foogallery' ) ),
261 400
262 );
263 }
264
265 if ( ! current_user_can( 'edit_post', $img_id ) ) {
266 wp_send_json_error(
267 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
268 403
269 );
270 }
271
272 $tax = get_taxonomy( $taxonomy );
273 if ( $tax && ! empty( $tax->cap->assign_terms ) && ! current_user_can( $tax->cap->assign_terms ) ) {
274 wp_send_json_error(
275 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
276 403
277 );
278 }
279
280 $new_term = wp_insert_term( $term, $taxonomy );
281 if ( is_wp_error( $new_term ) ) {
282 wp_send_json_error(
283 array( 'message' => __( 'Could not add new taxonomy term!', 'foogallery' ) ),
284 400
285 );
286 }
287
288 if ( isset( $new_term['term_id'] ) ) {
289 $new_term_obj = get_term( $new_term['term_id'] );
290 wp_send_json_success(
291 array(
292 'id' => $new_term_obj->term_id,
293 'name' => $new_term_obj->name,
294 )
295 );
296 }
297
298 wp_send_json_error(
299 array( 'message' => __( 'Invalid data.', 'foogallery' ) ),
300 400
301 );
302 }
303
304
305 /**
306 * Save main tab data content
307 *
308 * @param $img_id int attachment id to update data
309 *
310 * @param $data array of form post data
311 *
312 */
313 public function foogallery_attachment_save_data_main( $img_id, $data ) {
314
315 if ( is_array( $data ) && !empty( $data ) ) {
316
317 $foogallery_post = array(
318 'ID' => $img_id
319 );
320
321 if ( array_key_exists( 'title', $data ) ) {
322 $foogallery_post['post_title'] = sanitize_text_field( wp_unslash( $data['title'] ) );
323 }
324
325 if ( array_key_exists( 'caption', $data ) ) {
326 $caption = is_scalar( $data['caption'] ) ? (string) $data['caption'] : '';
327 $foogallery_post['post_excerpt'] = wp_slash( wp_kses_post( $caption ) );
328 }
329
330 if ( array_key_exists( 'description', $data ) ) {
331 $foogallery_post['post_content'] = wp_kses_post( wp_unslash( $data['description'] ) );
332 }
333
334 // Update post meta values
335 if ( array_key_exists( 'alt-text', $data ) ) {
336 $alt_text = sanitize_text_field( wp_unslash( $data['alt-text'] ) );
337 if ( '' === $alt_text ) {
338 delete_post_meta( $img_id, '_wp_attachment_image_alt' );
339 } else {
340 update_post_meta( $img_id, '_wp_attachment_image_alt', $alt_text );
341 }
342 }
343
344 if ( array_key_exists( 'custom-url', $data ) ) {
345 $custom_url = foogallery_sanitize_attachment_custom_url( wp_unslash( $data['custom-url'] ) );
346 if ( '' === $custom_url ) {
347 delete_post_meta( $img_id, '_foogallery_custom_url' );
348 } else {
349 update_post_meta( $img_id, '_foogallery_custom_url', $custom_url );
350 }
351 }
352
353 if ( array_key_exists( 'custom-target', $data ) ) {
354 $custom_target = foogallery_sanitize_attachment_custom_target( wp_unslash( $data['custom-target'] ) );
355 if ( '' === $custom_target ) {
356 delete_post_meta( $img_id, '_foogallery_custom_target' );
357 } else {
358 update_post_meta( $img_id, '_foogallery_custom_target', $custom_target );
359 }
360 }
361
362 if ( array_key_exists( 'custom-rel', $data ) ) {
363 $custom_rel = foogallery_sanitize_attachment_custom_rel( wp_unslash( $data['custom-rel'] ) );
364 if ( '' === $custom_rel ) {
365 delete_post_meta( $img_id, '_foogallery_custom_rel' );
366 } else {
367 update_post_meta( $img_id, '_foogallery_custom_rel', $custom_rel );
368 }
369 }
370
371 if ( array_key_exists( 'custom-class', $data ) ) {
372 $custom_class = sanitize_text_field( wp_unslash( $data['custom-class'] ) );
373 if ( '' === $custom_class ) {
374 delete_post_meta( $img_id, '_foogallery_custom_class' );
375 } else {
376 update_post_meta( $img_id, '_foogallery_custom_class', $custom_class );
377 }
378 }
379
380 if ( is_array( $foogallery_post ) && count( $foogallery_post ) > 1 ) {
381 // Update the post into the database
382 wp_update_post( $foogallery_post );
383 }
384 }
385 }
386
387 /**
388 * Save taxonomies tab data content
389 *
390 * @param $img_id int attachment id to update data
391 *
392 * @param $data array of form post data
393 *
394 */
395
396 public function foogallery_attachment_save_data_taxonomies( $img_id, $data ) {
397
398 if ( is_array( $data ) && !empty( $data ) ) {
399
400 if ( !$this->attachments_have_taxonomies() ) {
401 return;
402 }
403
404 if ( array_key_exists( 'taxonomies', $data ) ) {
405 foreach ( $data['taxonomies'] as $taxonomy => $taxonomy_value ) {
406 $terms = explode( ',', $taxonomy_value );
407 if ( is_array( $terms ) ) {
408 $terms = array_map( 'intval', $terms );
409 wp_set_object_terms( $img_id, $terms, $taxonomy, false );
410 }
411 }
412 }
413 }
414 }
415
416 /**
417 * Save thumbnails tab data content
418 *
419 * @param $img_id int attachment id to update data
420 *
421 * @param $data array of form post data
422 *
423 */
424 public function foogallery_attachment_save_data_thumbnails( $img_id, $data ) {
425
426 if ( is_array( $data ) && !empty( $data ) ) {
427
428 if ( array_key_exists( 'crop_pos', $data ) ) {
429 update_post_meta( $img_id, 'foogallery_crop_pos', $data['crop_pos'] );
430 }
431
432 if ( array_key_exists( 'override-thumbnail-id', $data ) ) {
433 update_post_meta( $img_id, 'foogallery_override_thumbnail', $data['override-thumbnail-id'] );
434 }
435 }
436 }
437
438 /**
439 * Save advanced tab data content
440 *
441 * @param $img_id int attachment id to update data
442 *
443 * @param $data array of form post data
444 *
445 */
446 public function foogallery_attachment_save_data_advanced($img_id, $data ) {
447
448 if ( is_array( $data ) && !empty( $data ) ) {
449 if ( array_key_exists( 'data-width', $data ) ) {
450 update_post_meta( $img_id, '_data-width', $data['data-width'] );
451 }
452
453 if ( array_key_exists( 'data-height', $data ) ) {
454 update_post_meta( $img_id, '_data-height', $data['data-height'] );
455 }
456
457 if ( array_key_exists( 'panning', $data ) ) {
458 update_post_meta( $img_id, '_foobox_panning', $data['panning'] );
459 }
460
461 if ( array_key_exists( 'override_type', $data ) ) {
462 update_post_meta( $img_id, '_foogallery_override_type', $data['override_type'] );
463 }
464 }
465 }
466
467 /**
468 * Builds up the state used to populate the modal.
469 *
470 * @param $data array
471 * @return array
472 */
473 private function build_modal_data( $data = array() ) {
474
475 $modal_data = array(
476 'img_id' => 0,
477 'gallery_id' => 0,
478 );
479
480 if ( is_array ( $data ) && isset( $data['img_id'] ) && isset( $data['gallery_id'] ) ) {
481 $modal_data['img_id'] = $attachment_id = intval( sanitize_text_field( $data['img_id'] ) );
482 $modal_data['gallery_id'] = $gallery_id = intval( sanitize_text_field( $data['gallery_id'] ) );
483 $modal_data['override_attachments'] = isset( $data['override_attachments'] ) ? sanitize_text_field( $data['override_attachments'] ) : '';
484 $modal_data['current_tab'] = isset( $data['current_tab'] ) ? sanitize_text_field( $data['current_tab'] ) : '';
485 $modal_data['nonce'] = wp_create_nonce( 'foogallery-modal-nonce' );
486 $modal_data = apply_filters( 'foogallery_attachment_modal_data', $modal_data, $data, $attachment_id, $gallery_id );
487 }
488
489 return $modal_data;
490 }
491
492 /**
493 * Image modal main tab data update
494 */
495 public function foogallery_attachment_modal_data_main( $modal_data, $data, $attachment_id, $gallery_id ) {
496 if ( $attachment_id > 0 ) {
497 $attachment_post = get_post( $attachment_id );
498
499 if ( is_a( $attachment_post, 'WP_Post' ) ) {
500 $modal_data['file_url'] = wp_get_attachment_url( $attachment_id );
501 $modal_data['file_name'] = basename( $modal_data['file_url'] );
502 $modal_data['file_type'] = apply_filters( 'foogallery_attachment_modal_info_file_type', $attachment_post->post_mime_type );
503 $modal_data['author_id'] = intval( $attachment_post->post_author );
504 $modal_data['author_name'] = get_the_author_meta( 'display_name', $modal_data['author_id'] );
505 $modal_data['post_date'] = date('F d, Y', strtotime( $attachment_post->post_date ) );
506 $modal_data['img_title'] = $attachment_post->post_title;
507 $modal_data['caption'] = $attachment_post->post_excerpt;
508 $modal_data['description'] = $attachment_post->post_content;
509 $modal_data['image_alt'] = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
510 $modal_data['meta'] = wp_get_attachment_metadata( $attachment_id );
511
512 $uploaded_to_id = (int) $attachment_post->post_parent;
513 if ( $uploaded_to_id > 0 ) {
514 $uploaded_to_post = get_post( $uploaded_to_id );
515 $uploaded_to_url = get_edit_post_link( $uploaded_to_post );
516
517 if ( is_a( $uploaded_to_post, 'WP_Post' ) ) {
518 $modal_data['uploaded_to_id'] = $uploaded_to_id;
519 $modal_data['uploaded_to_title'] = get_the_title( $uploaded_to_post );
520
521 if ( ! empty( $uploaded_to_url ) ) {
522 $modal_data['uploaded_to_url'] = $uploaded_to_url;
523 }
524 }
525 }
526
527 // Get attachment file size.
528 $file_size = false;
529 if ( isset( $modal_data['meta']['filesize'] ) ) {
530 $file_size = $modal_data['meta']['filesize'];
531 } elseif ( file_exists( $modal_data['file_url'] ) ) {
532 $file_size = wp_filesize( $modal_data['file_url'] );
533 }
534 if ( ! empty( $file_size ) ) {
535 $modal_data['file_size'] = size_format( $file_size );
536 }
537
538 // Get attachment dimensions.
539 $media_dims = '';
540 if ( isset( $modal_data['meta']['width'], $modal_data['meta']['height'] ) ) {
541 $media_dims = "{$modal_data['meta']['width']}&nbsp;&times;&nbsp;{$modal_data['meta']['height']}";
542 }
543 /** This filter is documented in wp-admin/includes/media.php */
544 $modal_data['media_dims'] = apply_filters( 'media_meta', $media_dims, $attachment_post );
545
546 $modal_data['custom_url'] = get_post_meta( $attachment_id, '_foogallery_custom_url', true );
547 $modal_data['custom_target'] = get_post_meta( $attachment_id, '_foogallery_custom_target', true );
548 $modal_data['custom_rel'] = foogallery_sanitize_attachment_custom_rel( get_post_meta( $attachment_id, '_foogallery_custom_rel', true ) );
549 $modal_data['custom_class'] = get_post_meta( $attachment_id, '_foogallery_custom_class', true );
550 }
551 }
552
553 return $modal_data;
554 }
555
556 /**
557 * Image modal taxonomies & tags tab data update
558 */
559 public function foogallery_attachment_modal_data_taxonomies( $modal_data, $data, $attachment_id, $gallery_id ) {
560 if ( $attachment_id > 0 ) {
561
562 if ( !$this->attachments_have_taxonomies() ) {
563 return $modal_data;
564 }
565
566 $modal_data['taxonomies'] = array();
567
568 $taxonomies = get_object_taxonomies( 'attachment', 'objects' );
569
570 foreach ( $taxonomies as $tax_name => $taxonomy ) {
571 $modal_data['taxonomies'][$tax_name] = array(
572 'label' => $taxonomy->label,
573 'terms' => get_the_terms( $attachment_id, $tax_name )
574 );
575 }
576 }
577
578 return $modal_data;
579 }
580
581 /**
582 * Image modal thumbnails tab data update
583 */
584 public function foogallery_attachment_modal_data_thumbnails( $modal_data, $data, $attachment_id, $gallery_id ) {
585 if ( $attachment_id > 0 ) {
586
587 $modal_data['foogallery_crop_pos'] = get_post_meta( $attachment_id, 'foogallery_crop_pos', true );
588
589 $foogallery_override_thumbnail = get_post_meta( $attachment_id, '_foogallery_override_thumbnail', true );
590
591 if ( isset( $foogallery_override_thumbnail ) ) {
592
593 $modal_data['foogallery_override_thumbnail'] = $foogallery_override_thumbnail;
594 $modal_data['override_class'] = 'is-override-thumbnail';
595 $alternate_thumb_img = wp_get_attachment_image_src( $foogallery_override_thumbnail );
596
597 if ( is_array( $alternate_thumb_img ) && !empty( $alternate_thumb_img ) ) {
598 $modal_data['alternate_img_src'] = $alternate_thumb_img[0];
599 }
600 }
601 }
602
603 return $modal_data;
604 }
605
606 /**
607 * Image modal advanced tab data update
608 */
609 public function foogallery_attachment_modal_data_advanced( $modal_data, $data, $attachment_id, $gallery_id ) {
610 if ( $attachment_id > 0 ) {
611 $modal_data['data_width'] = get_post_meta( $attachment_id, '_data-width', true );
612 $modal_data['data_height'] = get_post_meta( $attachment_id, '_data-height', true );
613 $modal_data['panning'] = get_post_meta( $attachment_id, '_foobox_panning', true );
614 $modal_data['override_type'] = get_post_meta( $attachment_id, '_foogallery_override_type', true );
615 }
616 return $modal_data;
617 }
618
619 private function get_attachments_for_modal( $modal_data, $gallery_id ) {
620 if ( isset( $modal_data['override_attachments'] ) ) {
621 return explode( ',', $modal_data['override_attachments'] );
622 }
623
624 $gallery_attachments = get_post_meta( $gallery_id, FOOGALLERY_META_ATTACHMENTS, true);
625
626 if ( is_array( $gallery_attachments ) && !empty ( $gallery_attachments ) ) {
627 return $gallery_attachments;
628 }
629
630 return array();
631 }
632
633 /**
634 * Image modal info tab data update
635 */
636 public function foogallery_attachment_modal_data_info( $modal_data, $data, $attachment_id, $gallery_id ) {
637
638 if ( $attachment_id > 0 ) {
639 $modal_data['image_attributes'] = wp_get_attachment_image_src( $attachment_id, 'medium' );
640 $full_img_path = wp_get_attachment_image_src( $attachment_id, 'full' );
641 $modal_data['img_path'] = $full_img_path[0];
642
643 $gallery_attachments = $this->get_attachments_for_modal( $modal_data, $gallery_id );
644
645 if ( is_array( $gallery_attachments ) && !empty ( $gallery_attachments ) ) {
646 $modal_data['gallery_attachments'] = $gallery_attachments;
647
648 $gallery_attachment_ids = array_map( 'intval', $gallery_attachments );
649 $current_index = array_search( $attachment_id, $gallery_attachment_ids, true );
650 $attachment_count = count( $gallery_attachment_ids );
651
652 if ( false !== $current_index ) {
653 // Wrap around so first item points to last and last item points to first.
654 $has_multiple = $attachment_count > 1;
655 $prev_index = ( 0 === $current_index ) ? $attachment_count - 1 : $current_index - 1;
656 $next_index = ( $current_index === $attachment_count - 1 ) ? 0 : $current_index + 1;
657
658 $modal_data['prev_slide'] = $has_multiple;
659 $modal_data['next_slide'] = $has_multiple;
660 $modal_data['prev_img_id'] = $has_multiple ? intval( $gallery_attachment_ids[ $prev_index ] ) : 0;
661 $modal_data['next_img_id'] = $has_multiple ? intval( $gallery_attachment_ids[ $next_index ] ) : 0;
662 }
663 }
664 }
665
666 return $modal_data;
667 }
668
669 /**
670 * Image modal main tab title
671 */
672 public function display_tab_main() { ?>
673 <div class="foogallery-img-modal-tab-wrapper" data-tab_id="foogallery-panel-main">
674 <input type="radio" name="tabset" id="foogallery-tab-main" aria-controls="foogallery-panel-main" checked>
675 <label for="foogallery-tab-main"><?php esc_html_e('Main', 'foogallery'); ?></label>
676 </div>
677 <?php }
678
679 /**
680 * Image modal taxonomies & tags title
681 */
682 public function display_tab_taxonomies() {
683 if ( !$this->attachments_have_taxonomies() ) {
684 return;
685 }
686
687 ?>
688 <div class="foogallery-img-modal-tab-wrapper" data-tab_id="foogallery-panel-taxonomies">
689 <input type="radio" name="tabset" id="foogallery-tab-taxonomies" aria-controls="foogallery-panel-taxonomies">
690 <label for="foogallery-tab-taxonomies"><?php esc_html_e('Taxonomies', 'foogallery'); ?></label>
691 </div>
692 <?php }
693
694 /**
695 * Image modal thumbnails tab title
696 */
697 public function display_tab_thumbnails() { ?>
698 <div class="foogallery-img-modal-tab-wrapper" data-tab_id="foogallery-panel-thumbnails">
699 <input type="radio" name="tabset" id="foogallery-tab-thumbnails" aria-controls="foogallery-panel-thumbnails">
700 <label for="foogallery-tab-thumbnails"><?php esc_html_e('Thumbnails', 'foogallery'); ?></label>
701 </div>
702 <?php }
703
704 /**
705 * Returns true if attachments have any taxonomies registered.
706 *
707 * @return bool
708 */
709 function attachments_have_taxonomies() {
710 $taxonomies = get_object_taxonomies( 'attachment' );
711 return count( $taxonomies ) > 0;
712 }
713
714 /**
715 * Image modal advanced tab title
716 */
717 public function display_tab_advanced() { ?>
718 <div class="foogallery-img-modal-tab-wrapper" data-tab_id="foogallery-panel-advanced">
719 <input type="radio" name="tabset" id="foogallery-tab-advanced" aria-controls="foogallery-panel-advanced">
720 <label for="foogallery-tab-advanced"><?php esc_html_e('Advanced', 'foogallery'); ?></label>
721 </div>
722 <?php }
723
724 /**
725 * Image modal main tab content
726 */
727 public function display_tab_content_main( $modal_data ) {
728 if ( is_array( $modal_data ) && !empty ( $modal_data ) ) {
729 if ( $modal_data['img_id'] > 0 ) { ?>
730 <section id="foogallery-panel-main" class="tab-panel active" data-nonce="<?php echo esc_attr( $modal_data['nonce'] );?>">
731 <div class="settings">
732 <span class="setting" data-setting="title">
733 <label for="attachment-details-two-column-title" class="name"><?php esc_html_e('Title', 'foogallery'); ?></label>
734 <input type="text" id="attachment-details-two-column-title" name="foogallery[title]" value="<?php echo esc_attr( $modal_data['img_title'] );?>">
735 </span>
736 <span class="setting" data-setting="caption">
737 <label for="attachment-details-two-column-caption" class="name"><?php esc_html_e('Caption', 'foogallery'); ?></label>
738 <textarea id="attachment-details-two-column-caption" name="foogallery[caption]"><?php echo esc_textarea( $modal_data['caption'] );?></textarea>
739 </span>
740 <span class="setting" data-setting="description">
741 <label for="attachment-details-two-column-description" class="name"><?php esc_html_e('Description', 'foogallery'); ?></label>
742 <textarea id="attachment-details-two-column-description" name="foogallery[description]"><?php echo esc_html( $modal_data['description'] );?></textarea>
743 </span>
744 <span class="setting" data-setting="alt">
745 <label for="attachment-details-two-column-alt-text" class="name"><?php esc_html_e('ALT Text', 'foogallery'); ?></label>
746 <input type="text" id="attachment-details-two-column-alt-text" name="foogallery[alt-text]" value="<?php echo esc_attr( $modal_data['image_alt'] );?>" aria-describedby="alt-text-description">
747 </span>
748 <span class="setting" data-setting="custom_url">
749 <label for="attachments-foogallery-custom-url" class="name"><?php esc_html_e('Custom URL', 'foogallery'); ?></label>
750 <input type="text" id="attachments-foogallery-custom-url" name="foogallery[custom-url]" value="<?php echo esc_attr( $modal_data['custom_url'] );?>">
751 </span>
752 <span class="setting" data-setting="custom_target">
753 <label for="attachments-foogallery-custom-target" class="name"><?php esc_html_e('Custom Target', 'foogallery'); ?></label>
754 <select name="foogallery[custom-target]" id="attachments-foogallery-custom-target">
755 <?php
756 $target_options = foogallery_get_target_options();
757 foreach ( $target_options as $value => $label ) {
758 $selected = selected( $value, $modal_data['custom_target'], false );
759 echo '<option value=' . esc_attr( $value ) . ' ' . esc_attr( $selected ) . '>' . esc_html( $label ) . '</option>';
760 }
761 ?>
762 </select>
763 </span>
764 <span class="setting" data-setting="custom_rel">
765 <label for="attachments-foogallery-custom-rel" class="name"><?php esc_html_e('Custom Rel', 'foogallery'); ?></label>
766 <input type="text" id="attachments-foogallery-custom-rel" name="foogallery[custom-rel]" value="<?php echo esc_attr( $modal_data['custom_rel'] );?>">
767 </span>
768 <span class="setting has-description" data-setting="custom_class">
769 <label for="attachments-foogallery-custom-class" class="name"><?php esc_html_e('Custom Class', 'foogallery'); ?></label>
770 <input type="text" id="attachments-foogallery-custom-class" name="foogallery[custom-class]" value="<?php echo esc_attr( $modal_data['custom_class'] );?>">
771 </span>
772 <p class="description">
773 <?php esc_html_e( 'The custom class will be applied to the anchor tag of the image, which you can target with custom CSS.', 'foogallery' ); ?>
774 </p>
775 <span class="setting" data-setting="file_url">
776 <label for="attachments-foogallery-file-url" class="name"><?php esc_html_e('File URL', 'foogallery'); ?></label>
777 <div class="setting-with-buttons">
778 <input type="text" id="attachments-foogallery-file-url" value="<?php echo esc_url( $modal_data['file_url'] );?>" readonly />
779 <div>
780 <button type="button" class="button button-small copy-attachment-file-url" data-clipboard-target="#attachments-foogallery-file-url"><?php esc_html_e('Copy to clipboard', 'foogallery'); ?></button>
781 </div>
782 </div>
783 </span>
784 </div>
785 </section>
786 <?php
787 }
788 }
789 }
790
791 /**
792 * Image modal taxonomies & tags tab content
793 */
794 public function display_tab_content_taxonomies( $modal_data ) {
795 if ( !$this->attachments_have_taxonomies() ) {
796 return;
797 }
798
799 if ( is_array( $modal_data ) && array_key_exists( 'taxonomies', $modal_data ) ) {
800 if ( $modal_data['img_id'] > 0 ) {
801 $taxonomies = get_object_taxonomies( 'attachment', 'objects' );
802
803 ?>
804 <section id="foogallery-panel-taxonomies" class="tab-panel" data-nonce="<?php echo esc_attr( wp_create_nonce('foogallery_attachment_modal_taxonomies') ); ?>">
805 <div class="settings">
806 <?php
807
808 foreach ( $taxonomies as $tax_name => $taxonomy ) {
809 $terms = get_terms( array(
810 'taxonomy' => $tax_name,
811 'hide_empty' => false,
812 ) );
813
814 $selected_terms = array();
815
816 if ( array_key_exists( $tax_name, $modal_data['taxonomies'] ) ) {
817 $selected_tax_terms = $modal_data['taxonomies'][$tax_name]['terms'];
818 if ( is_array( $selected_tax_terms ) ) {
819 foreach ($selected_tax_terms as $term) {
820 $selected_terms[] = $term->term_id;
821 }
822 }
823 }
824
825 ?>
826
827 <span class="setting">
828 <label for="foogallery_attachment_taxonomy_<?php echo esc_attr( $tax_name ); ?>" class="name"><?php echo esc_html( $modal_data['taxonomies'][$tax_name]['label'] ); ?></label>
829 <div>
830 <ul data-taxonomy="<?php echo esc_attr( $tax_name ); ?>">
831 <?php
832 foreach ($terms as $term) {
833 $term_selected = in_array( $term->term_id, $selected_terms );
834 ?>
835 <li>
836 <a href="javascript:void(0);" class="button button-small<?php echo $term_selected ? ' button-primary' : ''; ?>"
837 data-term-id="<?php echo esc_attr( $term->term_id ); ?>"><?php echo esc_html( $term->name ); ?></a>
838 </li><?php
839 }
840 ?>
841 <li class="taxonomy_add">
842 <a href="javascript:void(0);" class="button button-small active foogallery_attachment_taxonomy_add" data-action="add" title="Add new">+</a>
843 <input type="text" class="foogallery_attachment_taxonomy_add" style="display: none" />
844 <a href="javascript:void(0);" class="button button-small active foogallery_attachment_taxonomy_add" style="display: none" data-action="save"><?php echo esc_html( __( 'Save','foogallery' ) ); ?></a>
845 <a href="javascript:void(0);" class="button button-small active foogallery_attachment_taxonomy_add" style="display: none" data-action="cancel"><?php echo esc_html( __( 'Cancel','foogallery' ) ); ?></a>
846 </li>
847
848 <li class="taxonomy_remove">
849 <a href="javascript:void(0);" class="button button-small active foogallery_attachment_taxonomy_remove" data-action="remove" title="Deselect all" >&ndash;</a>
850 </li>
851
852 </ul>
853 <div>
854 <a target="_blank" href="<?php echo esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax_name ) ); ?>"?><?php printf( esc_html__('Manage %s', 'foogallery' ), esc_html( $taxonomy->labels->name ) ); ?></a>
855 </div>
856 </div>
857 <input type="hidden" id="foogallery_attachment_taxonomy_<?php echo esc_attr( $tax_name ); ?>_selected" name="foogallery[taxonomies][<?php echo esc_attr( $tax_name ); ?>]" value="<?php echo esc_attr( implode( ',', $selected_terms ) ); ?>">
858
859 </span>
860
861 <?php
862 }
863
864 ?>
865 </div>
866 </section>
867 <?php
868 }
869 }
870 }
871
872 /**
873 * Image modal thumbnails tab content
874 */
875 public function display_tab_content_thumbnails( $modal_data ) {
876 if ( is_array( $modal_data ) && !empty ( $modal_data ) ) {
877 if ( $modal_data['img_id'] > 0 ) {
878
879 $crop_pos = !empty( $modal_data['foogallery_crop_pos'] ) ? $modal_data['foogallery_crop_pos'] : 'center,center';
880
881 $thumbnail_info = $this->find_thumbnail_info( $modal_data['img_id'], $modal_data['img_path'] );
882
883 $engine = foogallery_thumb_active_engine();
884
885 ?>
886 <section id="foogallery-panel-thumbnails" class="tab-panel">
887 <div class="settings">
888 <span class="setting" data-setting="crop-from-position">
889 <label for="attachments-crop-from-position" class="name"><?php esc_html_e('Crop Position', 'foogallery'); ?></label>
890 <div id="foogallery_crop_pos">
891 <input type="radio" name="foogallery[crop_pos]" value="left,top" title="<?php esc_attr_e('Left, Top', 'foogallery'); ?>" <?php checked( 'left,top', $crop_pos, true); ?>>
892 <input type="radio" name="foogallery[crop_pos]" value="center,top" title="<?php esc_attr_e('Center, Top', 'foogallery'); ?>" <?php checked( 'center,top', $crop_pos, true); ?>>
893 <input type="radio" name="foogallery[crop_pos]" value="right,top" title="<?php esc_attr_e('Right, Top', 'foogallery'); ?>" <?php checked( 'right,top', $crop_pos, true); ?>><br>
894 <input type="radio" name="foogallery[crop_pos]" value="left,center" title="<?php esc_attr_e('Left, Center', 'foogallery'); ?>" <?php checked( 'left,center', $crop_pos, true); ?>>
895 <input type="radio" name="foogallery[crop_pos]" value="center,center" title="<?php esc_attr_e('Center, Center', 'foogallery'); ?>" <?php checked( 'center,center', $crop_pos, true); ?>>
896 <input type="radio" name="foogallery[crop_pos]" value="right,center" title="<?php esc_attr_e('Right, Center', 'foogallery'); ?>" <?php checked( 'right,center', $crop_pos, true); ?>><br>
897 <input type="radio" name="foogallery[crop_pos]" value="left,bottom" title="<?php esc_attr_e('Left, Bottom', 'foogallery'); ?>" <?php checked( 'left,bottom', $crop_pos, true); ?>>
898 <input type="radio" name="foogallery[crop_pos]" value="center,bottom" title="<?php esc_attr_e('Center, Bottom', 'foogallery'); ?>" <?php checked( 'center,bottom', $crop_pos, true); ?>>
899 <input type="radio" name="foogallery[crop_pos]" value="right,bottom" title="<?php esc_attr_e('Right, Bottom', 'foogallery'); ?>" <?php checked( 'right,bottom', $crop_pos, true); ?>>
900 </div>
901 </span>
902
903 <span class="setting" data-setting="generated-thumbnails">
904 <label class="name"><?php esc_html_e( 'Thumbnail Info', 'foogallery' ); ?></label>
905 <span><?php echo $thumbnail_info; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - This is safe HTML output from find_thumbnail_info ?> </span>
906 </span>
907
908 <?php if ( $engine->has_local_cache() ) { ?>
909 <span class="setting" data-setting="clear-image-cache">
910 <label class="name"><?php esc_html_e('Clear FooGallery Thumbnails', 'foogallery'); ?></label>
911 <div>
912 <button class="button button-primary button-large" style="width: 100px"
913 id="foogallery_clear_img_thumb_cache"><?php esc_html_e( 'Clear', 'foogallery' ); ?></button>
914 <span style="position: absolute" id="foogallery_clear_img_thumb_cache_spinner" class="spinner"></span>
915 <?php wp_nonce_field( 'foogallery_clear_attachment_thumb_cache', 'foogallery_clear_attachment_thumb_cache_nonce', false ); ?>
916 </div>
917 </span>
918 <?php }
919 do_action( 'foogallery_attachment_modal_tab_content_thumbnails', $modal_data );
920 ?></div>
921 </section>
922 <?php
923 }
924 }
925 }
926
927 function find_thumbnail_info( $attachment_id, $image_url ) {
928
929 $wp_generated_count = 0;
930
931 $sizes = wp_get_registered_image_subsizes();
932
933 $thumbnail_info = esc_html__( 'Registered thumbnail sizes in WordPress : ', 'foogallery' ) . count( $sizes );
934
935 // Count thumbnails generated by WordPress
936 foreach ( $sizes as $size_key => $size ) {
937 $image = wp_get_attachment_image_src( $attachment_id, $size_key );
938
939 if ( $image ) {
940 $wp_generated_count++;
941 }
942 }
943
944 $thumbnail_info .= '<br />' . esc_html__( 'Thumbnails generated by WordPress : ', 'foogallery' ) . intval( $wp_generated_count );
945
946 $engine = foogallery_thumb_active_engine();
947
948 if ( $engine->has_local_cache() ) {
949
950 // Get FooGallery cache directory for the specific attachment
951 $foogallery_thumb_generator = new FooGallery_Thumb_Generator( $image_url );
952 $foogallery_cache_folder = $foogallery_thumb_generator->get_cache_file_directory();
953
954 // Count FooGallery thumbnails
955 $foogallery_thumbnails = $this->count_foogallery_thumbnails($foogallery_cache_folder);
956
957 $thumbnail_info .= '<br />' . esc_html__( 'Thumbnails generated by FooGallery : ', 'foogallery' ) . intval( $foogallery_thumbnails );
958 }
959
960 return $thumbnail_info;
961 }
962
963 /**
964 * Count FooGallery thumbnails in a given directory
965 *
966 * @param string $folder The directory to scan
967 * @return int The number of thumbnails
968 */
969 private function count_foogallery_thumbnails( $folder ) {
970 $wp_filesystem = foogallery_wp_filesystem();
971
972 // Initialize the WP Filesystem
973 if ( $wp_filesystem === false ) {
974 return 0;
975 }
976
977 // Check if the directory exists
978 if ( $wp_filesystem->is_dir( $folder ) ) {
979 $files = $wp_filesystem->dirlist( $folder );
980 return count( $files );
981 }
982 return 0;
983 }
984
985
986 /**
987 * Image modal advanced tab content
988 */
989 public function display_tab_content_advanced( $modal_data ) {
990 if ( is_array( $modal_data ) && !empty ( $modal_data ) ) {
991 if ( $modal_data['img_id'] > 0 ) { ?>
992 <section id="foogallery-panel-advanced" class="tab-panel">
993 <div class="settings">
994 <span class="setting has-description" data-setting="data-width">
995 <label for="attachment-details-two-column-data-width" class="name"><?php esc_html_e('Override Width', 'foogallery'); ?></label>
996 <input type="text" name="foogallery[data-width]" id="attachment-details-two-column-data-width" value="<?php echo esc_attr( $modal_data['data_width'] ); ?>">
997 </span>
998 <p class="description">
999 <?php esc_html_e( 'Specify a custom width to override the default width.', 'foogallery' ); ?>
1000 </p>
1001
1002 <span class="setting has-description" data-setting="data-height">
1003 <label for="attachment-details-two-column-data-height" class="name"><?php esc_html_e('Override Height', 'foogallery'); ?></label>
1004 <input type="text" name="foogallery[data-height]" id="attachment-details-two-column-data-height" value="<?php echo esc_attr( $modal_data['data_height'] ); ?>">
1005 </span>
1006 <p class="description">
1007 <?php esc_html_e( 'Specify a custom height to override the default height.', 'foogallery' ); ?>
1008 </p>
1009
1010 <!--To enable panning add data-overflow="true" data-proportion="false" to an item -->
1011 <span class="setting has-description" data-setting="panning">
1012 <label for="attachment-details-two-column-panning" class="name"><?php esc_html_e('Panning', 'foogallery'); ?></label>
1013 <input type="text" name="foogallery[panning]" id="attachment-details-two-column-panning" value="<?php echo esc_attr( $modal_data['panning'] ); ?>">
1014 </span>
1015 <p class="description">
1016 <?php esc_html_e( 'When using FooBox lightbox, enable panning to allow users to click and drag to navigate overflowing content.', 'foogallery' ); ?>
1017 </p>
1018 <span class="setting has-description" data-setting="override-type">
1019 <label for="attachment-details-two-column-override-type" class="name"><?php esc_html_e('Override Type', 'foogallery'); ?></label>
1020 <input type="text" name="foogallery[override_type]" id="attachment-details-two-column-override-type" value="<?php echo esc_attr( $modal_data['override_type'] ); ?>">
1021 </span>
1022 <p class="description">
1023 <?php esc_html_e( 'Override the type of the attachment used by the lightbox.', 'foogallery' ); ?>
1024 </p>
1025
1026 </div>
1027 </section>
1028 <?php
1029 }
1030 }
1031 }
1032
1033 /**
1034 * Image modal info section
1035 */
1036 public function display_attachment_info( $modal_data ) {
1037 if ( is_array( $modal_data ) && !empty ( $modal_data ) ) {
1038 if ( $modal_data['img_id'] > 0 ) { ?>
1039 <section id="foogallery-panel-info">
1040 <div class="foogallery-panel-info-inner">
1041 <div class="foogallery-modal-info-fields foogallery-modal-info-fields-full">
1042 <label class="name"><?php esc_html_e('File Name: ', 'foogallery'); ?></label>
1043 <span id="attachment-details-two-column-copy-file-name"><?php echo esc_html( $modal_data['file_name'] ); ?></span>
1044 </div>
1045 <div class="foogallery-modal-info-fields">
1046 <label class="name"><?php esc_html_e('Uploaded On: ', 'foogallery'); ?></label>
1047 <span><?php echo esc_html( $modal_data['post_date'] ); ?></span>
1048 </div>
1049 <div class="foogallery-modal-info-fields">
1050 <label class="name"><?php esc_html_e('Uploaded By: ', 'foogallery'); ?></label>
1051 <span><?php echo esc_html( $modal_data['author_name'] ); ?></span>
1052 </div>
1053 <?php if ( ! empty( $modal_data['uploaded_to_title'] ) ) : ?>
1054 <div class="foogallery-modal-info-fields">
1055 <label class="name"><?php esc_html_e('Uploaded To: ', 'foogallery'); ?></label>
1056 <span>
1057 <?php if ( ! empty( $modal_data['uploaded_to_url'] ) ) : ?>
1058 <a id="attachment-details-two-column-uploaded-to" href="<?php echo esc_url( $modal_data['uploaded_to_url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $modal_data['uploaded_to_title'] ); ?></a>
1059 <?php else : ?>
1060 <span id="attachment-details-two-column-uploaded-to"><?php echo esc_html( $modal_data['uploaded_to_title'] ); ?></span>
1061 <?php endif; ?>
1062 </span>
1063 </div>
1064 <?php endif; ?>
1065 <div class="foogallery-modal-info-fields">
1066 <label class="name"><?php esc_html_e('File Type: ', 'foogallery'); ?></label>
1067 <span><?php echo esc_html( $modal_data['file_type'] ); ?></span>
1068 </div>
1069 <div class="foogallery-modal-info-fields">
1070 <label class="name"><?php esc_html_e('File Size: ', 'foogallery'); ?></label>
1071 <span><?php echo esc_html( $modal_data['file_size'] ); ?></span>
1072 </div>
1073 <div class="foogallery-modal-info-fields">
1074 <label class="name"><?php esc_html_e('Dimensions: ', 'foogallery'); ?></label>
1075 <span><?php echo esc_html( $modal_data['media_dims'] ); ?></span>
1076 </div>
1077 </div>
1078 </section>
1079 <?php
1080 }
1081 }
1082 }
1083
1084 /**
1085 * Renders the save button and footer for the FooGallery image modal.
1086 *
1087 * This function outputs the HTML for the save button and associated footer
1088 * within the FooGallery image modal. It provides a button for saving attachment details.
1089 */
1090 public function foogallery_img_modal_save_btn() {
1091 ?>
1092 <div class="foogallery-image-edit-footer">
1093 <button id="attachments-data-save-btn" type="submit"
1094 class="button button-primary button-large"><?php esc_html_e( 'Save Attachment Details', 'foogallery' ); ?>
1095 </button>
1096 <span class="spinner"></span>
1097 </div>
1098 <?php
1099 }
1100
1101 }
1102 }
1103