resources
4 years ago
ajax-customers.php
4 years ago
ajax-orders.php
3 years ago
ajax-posts.php
4 years ago
ajax-products.php
4 years ago
ajax-terms.php
4 years ago
buttons.php
5 years ago
checkbox-array.php
4 years ago
checkbox.php
4 years ago
colorpicker.php
4 years ago
copy-to-clipboard.php
4 years ago
country-select.php
4 years ago
custom.php
5 years ago
customtabs.php
5 years ago
date-format.php
4 years ago
datepicker.php
4 years ago
dimensions.php
4 years ago
email.php
4 years ago
file.php
3 years ago
hidden.php
4 years ago
html.php
5 years ago
icons.php
4 years ago
image-dimensions.php
4 years ago
image-gallery.php
2 years ago
inline-fields.php
4 years ago
list-table.php
4 years ago
media.php
1 year ago
multi-colorpicker.php
5 years ago
multi-select.php
3 years ago
number.php
4 years ago
onoff.php
3 years ago
password.php
4 years ago
preview.php
4 years ago
radio.php
2 years ago
select-buttons.php
4 years ago
select-images.php
3 years ago
select-mailchimp.php
4 years ago
select.php
4 years ago
sep.php
5 years ago
sidebarlist.php
4 years ago
sidebars.php
5 years ago
simple-text.php
4 years ago
slider.php
4 years ago
text-array.php
3 years ago
text-button.php
4 years ago
text.php
4 years ago
textarea-codemirror.php
4 years ago
textarea-editor.php
4 years ago
textarea.php
4 years ago
title.php
4 years ago
toggle-element-fixed.php
1 year ago
toggle-element.php
2 years ago
upload.php
4 years ago
media.php
101 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Template for displaying the Media field |
| 4 | * |
| 5 | * @var array $field The field. |
| 6 | * @package YITH\PluginFramework\Templates\Fields |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 10 | |
| 11 | list ( $field_id, $class, $name, $value, $store_as, $allow_custom_url, $default, $custom_attributes, $data ) = yith_plugin_fw_extract( $field, 'id', 'class', 'name', 'value', 'store_as', 'allow_custom_url', 'default', 'custom_attributes', 'data' ); |
| 12 | |
| 13 | $allowed_store_as = array( 'url', 'id' ); |
| 14 | $store_as = $store_as ?? 'url'; |
| 15 | $store_as = in_array( $store_as, $allowed_store_as, true ) ? $store_as : 'url'; |
| 16 | $allow_custom_url = $allow_custom_url ?? true; |
| 17 | $allow_custom_url = $allow_custom_url && 'url' === $store_as; |
| 18 | |
| 19 | $url = $value; |
| 20 | if ( 'id' === $store_as ) { |
| 21 | $url = wp_get_attachment_url( $value ); |
| 22 | } |
| 23 | |
| 24 | $is_image = $url && preg_match( '/(jpg|jpeg|png|gif|ico|svg|jpe|webp)$/', $url ); |
| 25 | $file_name = $url ? basename( wp_parse_url( $url, PHP_URL_PATH ) ?? '' ) : ''; |
| 26 | |
| 27 | $classes = array( |
| 28 | 'yith-plugin-fw-media', |
| 29 | $allow_custom_url ? 'yith-plugin-fw-media--has-tabs' : '', |
| 30 | $class, |
| 31 | ); |
| 32 | |
| 33 | $classes = implode( ' ', array_filter( $classes ) ); |
| 34 | |
| 35 | $preview_type = $is_image ? 'image' : ( $file_name ? 'file' : 'upload' ); |
| 36 | |
| 37 | wp_enqueue_media(); // Late enqueue media scripts. |
| 38 | wp_enqueue_script( 'wp-media-utils' ); |
| 39 | ?> |
| 40 | <div class="<?php echo esc_attr( $classes ); ?>"> |
| 41 | <?php if ( $allow_custom_url ) : ?> |
| 42 | <div class="yith-plugin-fw-media__tabs"> |
| 43 | <div class="yith-plugin-fw-media__tab yith-plugin-fw-media__upload-tab yith-plugin-fw-media__tab--active" data-tab-selector=".yith-plugin-fw-media__preview"> |
| 44 | <svg class="yith-plugin-fw-media__tab__icon" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> |
| 45 | <path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5"></path> |
| 46 | </svg> |
| 47 | <span class="yith-plugin-fw-media__tab__title"><?php echo esc_html__( 'Upload file', 'yith-plugin-fw' ); ?></span> |
| 48 | </div> |
| 49 | <div class="yith-plugin-fw-media__tab yith-plugin-fw-media__url-tab" data-tab-selector=".yith-plugin-fw-media__value-container"> |
| 50 | <svg class="yith-plugin-fw-media__tab__icon" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> |
| 51 | <path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244"></path> |
| 52 | </svg> |
| 53 | <span class="yith-plugin-fw-media__tab__title"><?php echo esc_html__( 'Enter URL', 'yith-plugin-fw' ); ?></span> |
| 54 | </div> |
| 55 | </div> |
| 56 | <?php endif; ?> |
| 57 | |
| 58 | <div class="yith-plugin-fw-media__content"> |
| 59 | <div class="yith-plugin-fw-media__preview" data-type="<?php echo esc_attr( $preview_type ); ?>"> |
| 60 | <img class="yith-plugin-fw-media__preview__image" src="<?php echo esc_url( $url ); ?>"/> |
| 61 | <div class="yith-plugin-fw-media__preview__file"> |
| 62 | <svg class="yith-plugin-fw-media__preview__file__icon" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> |
| 63 | <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"></path> |
| 64 | </svg> |
| 65 | <span class="yith-plugin-fw-media__preview__file__name"><?php echo esc_html( $file_name ); ?></span> |
| 66 | </div> |
| 67 | <div class="yith-plugin-fw-media__preview__upload"> |
| 68 | <?php |
| 69 | echo sprintf( |
| 70 | // translators: %s is the alternative action "Upload a file". |
| 71 | esc_html__( 'Drag or %s', 'yith-plugin-fw' ), |
| 72 | '<a href="#" class="yith-plugin-fw-media__preview__upload__link">' . esc_html__( 'Upload a file', 'yith-plugin-fw' ) . '</a>' |
| 73 | ) |
| 74 | ?> |
| 75 | </div> |
| 76 | |
| 77 | <div class="yith-plugin-fw-media__preview__actions"> |
| 78 | <i class="yith-plugin-fw-media__preview__action yith-plugin-fw-media__preview__action--edit yith-icon yith-icon-edit"></i> |
| 79 | <i class="yith-plugin-fw-media__preview__action yith-plugin-fw-media__preview__action--delete yith-icon yith-icon-trash"></i> |
| 80 | </div> |
| 81 | |
| 82 | <div class="yith-plugin-fw-media__preview__dropzone"></div> |
| 83 | </div> |
| 84 | <div class="yith-plugin-fw-media__value-container" style="display: none"> |
| 85 | <input type="<?php echo 'url' === $store_as ? 'text' : 'hidden'; ?>" |
| 86 | id="<?php echo esc_attr( $field_id ); ?>" |
| 87 | name="<?php echo esc_attr( $name ); ?>" |
| 88 | class="yith-plugin-fw-media__value <?php echo 'url' === $store_as ? 'yith-plugin-fw-media__url-value' : 'yith-plugin-fw-media__id-value'; ?>" |
| 89 | value="<?php echo esc_attr( $value ); ?>" |
| 90 | |
| 91 | <?php if ( isset( $default ) ) : ?> |
| 92 | data-std="<?php echo esc_attr( $default ); ?>" |
| 93 | <?php endif; ?> |
| 94 | |
| 95 | <?php yith_plugin_fw_html_attributes_to_string( $custom_attributes, true ); ?> |
| 96 | <?php yith_plugin_fw_html_data_to_string( $data, true ); ?> |
| 97 | /> |
| 98 | </div> |
| 99 | </div> |
| 100 | </div> |
| 101 |