PluginProbe
Easy Hotel – Powerful Hotel Booking / trunk
Easy Hotel – Powerful Hotel Booking vtrunk
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / framework / fields / media / media.php

media.php in Easy Hotel – Powerful Hotel Booking trunk, at admin/includes/framework/fields/media/media.php

97 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 /**
3 *
4 * Field: media
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! class_exists( 'ESHB_Field_media' ) ) {
11 class ESHB_Field_media extends ESHB_Fields {
12
13 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
14 parent::__construct( $field, $value, $unique, $where, $parent );
15 }
16
17 public function render() {
18
19 $args = wp_parse_args( $this->field, array(
20 'url' => true,
21 'preview' => true,
22 'preview_width' => '',
23 'preview_height' => '',
24 'library' => array(),
25 'button_title' => esc_html__( 'Upload', 'easy-hotel' ),
26 'remove_title' => esc_html__( 'Remove', 'easy-hotel' ),
27 'preview_size' => 'thumbnail',
28 ) );
29
30 $default_values = array(
31 'url' => '',
32 'id' => '',
33 'width' => '',
34 'height' => '',
35 'thumbnail' => '',
36 'alt' => '',
37 'title' => '',
38 'description' => ''
39 );
40
41 // fallback
42 if ( is_numeric( $this->value ) ) {
43
44 $this->value = array(
45 'id' => $this->value,
46 'url' => wp_get_attachment_url( $this->value ),
47 'thumbnail' => wp_get_attachment_image_src( $this->value, 'thumbnail', true )[0],
48 );
49
50 }
51
52 $this->value = wp_parse_args( $this->value, $default_values );
53
54 $library = ( is_array( $args['library'] ) ) ? $args['library'] : array_filter( (array) $args['library'] );
55 $library = ( ! empty( $library ) ) ? implode(',', $library ) : '';
56 $preview_src = ( $args['preview_size'] !== 'thumbnail' ) ? $this->value['url'] : $this->value['thumbnail'];
57 $hidden_url = ( empty( $args['url'] ) ) ? ' hidden' : '';
58 $hidden_auto = ( empty( $this->value['url'] ) ) ? ' hidden' : '';
59 $placeholder = ( empty( $this->field['placeholder'] ) ) ? 'Upload' : '';
60
61 echo wp_kses_post($this->field_before());
62
63 if ( ! empty( $args['preview'] ) ) {
64
65 $preview_width = ( ! empty( $args['preview_width'] ) ) ? 'max-width:'. esc_attr( $args['preview_width'] ) .'px;' : '';
66 $preview_height = ( ! empty( $args['preview_height'] ) ) ? 'max-height:'. esc_attr( $args['preview_height'] ) .'px;' : '';
67 $preview_style = ( ! empty( $preview_width ) || ! empty( $preview_height ) ) ? ' style="'. esc_attr( $preview_width . $preview_height ) .'"': '';
68
69 echo '<div class="csf--preview'. esc_attr( $hidden_auto ) .'">';
70 echo '<div class="csf-image-preview"'. esc_attr($preview_style) .'>';
71 echo '<i class="csf--remove fas fa-times"></i><span><img src="'. esc_url( $preview_src ) .'" class="csf--src" /></span>';
72 echo '</div>';
73 echo '</div>';
74
75 }
76
77 echo '<div class="csf--placeholder">';
78 echo '<input type="text" name="'. esc_attr( $this->field_name( '[url]' ) ) .'" value="'. esc_attr( $this->value['url'] ) .'" class="csf--url'. esc_attr( $hidden_url ) .'" readonly="readonly"'. esc_attr($this->field_attributes()) .' placeholder="'. esc_attr($placeholder) .'"/>';
79 echo '<a href="#" class="button button-primary csf--button" data-library="'. esc_attr( $library ) .'" data-preview-size="'. esc_attr( $args['preview_size'] ) .'">'. esc_html($args['button_title']) .'</a>';
80 echo ( empty( $args['preview'] ) ) ? '<a href="#" class="button button-secondary csf-warning-primary csf--remove'. esc_attr( $hidden_auto ) .'">'. esc_html($args['remove_title']) .'</a>' : '';
81 echo '</div>';
82
83 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[id]' ) ) .'" value="'. esc_attr( $this->value['id'] ) .'" class="csf--id"/>';
84 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $this->value['width'] ) .'" class="csf--width"/>';
85 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $this->value['height'] ) .'" class="csf--height"/>';
86 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[thumbnail]' ) ) .'" value="'. esc_attr( $this->value['thumbnail'] ) .'" class="csf--thumbnail"/>';
87 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[alt]' ) ) .'" value="'. esc_attr( $this->value['alt'] ) .'" class="csf--alt"/>';
88 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[title]' ) ) .'" value="'. esc_attr( $this->value['title'] ) .'" class="csf--title"/>';
89 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[description]' ) ) .'" value="'. esc_attr( $this->value['description'] ) .'" class="csf--description"/>';
90
91 echo wp_kses_post($this->field_after());
92
93 }
94
95 }
96 }
97