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