PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / fields / media / media.php

media.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/fields/media/media.php

101 lines 4.9 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 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
3 /**
4 *
5 * Field: media
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 *
10 */
11 if ( ! class_exists( 'CSF_Field_media' ) ) {
12 class CSF_Field_media extends CSF_Fields {
13
14 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
15 parent::__construct( $field, $value, $unique, $where, $parent );
16 }
17
18 public function render() {
19
20 $args = wp_parse_args( $this->field, array(
21 'url' => true,
22 'preview' => true,
23 'preview_width' => '',
24 'preview_height' => '',
25 'library' => array(),
26 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
27 'button_title' => esc_html__( 'Upload', 'csf' ),
28 'remove_title' => esc_html__( 'Remove', 'csf' ),
29 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
30 'preview_size' => 'thumbnail',
31 ) );
32
33 $default_values = array(
34 'url' => '',
35 'id' => '',
36 'width' => '',
37 'height' => '',
38 'thumbnail' => '',
39 'alt' => '',
40 'title' => '',
41 'description' => ''
42 );
43
44 // fallback
45 if ( is_numeric( $this->value ) ) {
46
47 $this->value = array(
48 'id' => $this->value,
49 'url' => wp_get_attachment_url( $this->value ),
50 'thumbnail' => wp_get_attachment_image_src( $this->value, 'thumbnail', true )[0],
51 );
52
53 }
54
55 $this->value = wp_parse_args( $this->value, $default_values );
56
57 $library = ( is_array( $args['library'] ) ) ? $args['library'] : array_filter( (array) $args['library'] );
58 $library = ( ! empty( $library ) ) ? implode(',', $library ) : '';
59 $preview_src = ( $args['preview_size'] !== 'thumbnail' ) ? $this->value['url'] : $this->value['thumbnail'];
60 $hidden_url = ( empty( $args['url'] ) ) ? ' hidden' : '';
61 $hidden_auto = ( empty( $this->value['url'] ) ) ? ' hidden' : '';
62 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
63 $placeholder = ( empty( $this->field['placeholder'] ) ) ? ' placeholder="'. esc_html__( 'Not selected', 'csf' ) .'"' : '';
64
65 echo $this->field_before();
66
67 if ( ! empty( $args['preview'] ) ) {
68
69 $preview_width = ( ! empty( $args['preview_width'] ) ) ? 'max-width:'. esc_attr( $args['preview_width'] ) .'px;' : '';
70 $preview_height = ( ! empty( $args['preview_height'] ) ) ? 'max-height:'. esc_attr( $args['preview_height'] ) .'px;' : '';
71 $preview_style = ( ! empty( $preview_width ) || ! empty( $preview_height ) ) ? ' style="'. esc_attr( $preview_width . $preview_height ) .'"': '';
72
73 echo '<div class="csf--preview'. esc_attr( $hidden_auto ) .'">';
74 echo '<div class="csf-image-preview"'. $preview_style .'>';
75 echo '<i class="csf--remove fas fa-times"></i><span><img src="'. esc_url( $preview_src ) .'" class="csf--src" /></span>';
76 echo '</div>';
77 echo '</div>';
78
79 }
80
81 echo '<div class="csf--placeholder">';
82 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"'. $this->field_attributes() . $placeholder .' />';
83 echo '<a href="#" class="button button-primary csf--button" data-library="'. esc_attr( $library ) .'" data-preview-size="'. esc_attr( $args['preview_size'] ) .'">'. $args['button_title'] .'</a>';
84 echo ( empty( $args['preview'] ) ) ? '<a href="#" class="button button-secondary csf-warning-primary csf--remove'. esc_attr( $hidden_auto ) .'">'. $args['remove_title'] .'</a>' : '';
85 echo '</div>';
86
87 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[id]' ) ) .'" value="'. esc_attr( $this->value['id'] ) .'" class="csf--id"/>';
88 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $this->value['width'] ) .'" class="csf--width"/>';
89 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $this->value['height'] ) .'" class="csf--height"/>';
90 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[thumbnail]' ) ) .'" value="'. esc_attr( $this->value['thumbnail'] ) .'" class="csf--thumbnail"/>';
91 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[alt]' ) ) .'" value="'. esc_attr( $this->value['alt'] ) .'" class="csf--alt"/>';
92 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[title]' ) ) .'" value="'. esc_attr( $this->value['title'] ) .'" class="csf--title"/>';
93 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[description]' ) ) .'" value="'. esc_attr( $this->value['description'] ) .'" class="csf--description"/>';
94
95 echo $this->field_after();
96
97 }
98
99 }
100 }
101