PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.4.4
StreamCast – bring live radio to your site with a sleek player v2.4.4
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / vendor / codestar-framework / fields / media / media.php

media.php in StreamCast – bring live radio to your site with a sleek player 2.4.4, at vendor/codestar-framework/fields/media/media.php

97 lines 5.1 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( 'STREAMCAST_STREAMCAST_CSF_Field_media' ) ) {
11 class STREAMCAST_STREAMCAST_CSF_Field_media extends STREAMCAST_STREAMCAST_CSF_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', 'streamcast' ),
26 'remove_title' => esc_html__( 'Remove', 'streamcast' ),
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'] ) ) ? ' placeholder="'. esc_html__( 'Not selected', 'streamcast' ) .'"' : '';
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="streamcast-csf--preview'. esc_attr( $hidden_auto ) .'">';
70 echo '<div class="streamcast-csf-image-preview"'. $preview_style .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
71 echo '<i class="streamcast-csf--remove fas fa-times"></i><span><img src="'. esc_url( $preview_src ) .'" class="streamcast-csf--src" /></span>';
72 echo '</div>';
73 echo '</div>';
74
75 }
76
77 echo '<div class="streamcast-csf--placeholder">';
78 echo '<input type="text" name="'. esc_attr( $this->field_name( '[url]' ) ) .'" value="'. esc_attr( $this->value['url'] ) .'" class="streamcast-csf--url'. esc_attr( $hidden_url ) .'" readonly="readonly"'. $this->field_attributes() . $placeholder .' />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
79 echo '<a href="#" class="button button-primary streamcast-csf--button" data-library="'. esc_attr( $library ) .'" data-preview-size="'. esc_attr( $args['preview_size'] ) .'">'. wp_kses_post( $args['button_title'] ) .'</a>';
80 echo ( empty( $args['preview'] ) ) ? '<a href="#" class="button button-secondary streamcast-csf-warning-primary streamcast-csf--remove'. esc_attr( $hidden_auto ) .'">'. wp_kses_post( $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="streamcast-csf--id"/>';
84 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $this->value['width'] ) .'" class="streamcast-csf--width"/>';
85 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $this->value['height'] ) .'" class="streamcast-csf--height"/>';
86 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[thumbnail]' ) ) .'" value="'. esc_attr( $this->value['thumbnail'] ) .'" class="streamcast-csf--thumbnail"/>';
87 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[alt]' ) ) .'" value="'. esc_attr( $this->value['alt'] ) .'" class="streamcast-csf--alt"/>';
88 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[title]' ) ) .'" value="'. esc_attr( $this->value['title'] ) .'" class="streamcast-csf--title"/>';
89 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[description]' ) ) .'" value="'. esc_attr( $this->value['description'] ) .'" class="streamcast-csf--description"/>';
90
91 echo wp_kses_post( $this->field_after() );
92
93 }
94
95 }
96 }
97