balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

audio.php (7591B)


      1 <?php
      2 namespace Elementor;
      3 
      4 use Elementor\Modules\DynamicTags\Module as TagsModule;
      5 
      6 if ( ! defined( 'ABSPATH' ) ) {
      7 	exit; // Exit if accessed directly.
      8 }
      9 
     10 /**
     11  * Elementor audio widget.
     12  *
     13  * Elementor widget that displays an audio player.
     14  *
     15  * @since 1.0.0
     16  */
     17 class Widget_Audio extends Widget_Base {
     18 
     19 	/**
     20 	 * Current instance.
     21 	 *
     22 	 * @access protected
     23 	 *
     24 	 * @var array
     25 	 */
     26 	protected $_current_instance = [];
     27 
     28 	/**
     29 	 * Get widget name.
     30 	 *
     31 	 * Retrieve audio widget name.
     32 	 *
     33 	 * @since 1.0.0
     34 	 * @access public
     35 	 *
     36 	 * @return string Widget name.
     37 	 */
     38 	public function get_name() {
     39 		return 'audio';
     40 	}
     41 
     42 	/**
     43 	 * Get widget title.
     44 	 *
     45 	 * Retrieve audio widget title.
     46 	 *
     47 	 * @since 1.0.0
     48 	 * @access public
     49 	 *
     50 	 * @return string Widget title.
     51 	 */
     52 	public function get_title() {
     53 		return esc_html__( 'SoundCloud', 'elementor' );
     54 	}
     55 
     56 	/**
     57 	 * Get widget icon.
     58 	 *
     59 	 * Retrieve audio widget icon.
     60 	 *
     61 	 * @since 1.0.0
     62 	 * @access public
     63 	 *
     64 	 * @return string Widget icon.
     65 	 */
     66 	public function get_icon() {
     67 		return 'eicon-headphones';
     68 	}
     69 
     70 	/**
     71 	 * Get widget keywords.
     72 	 *
     73 	 * Retrieve the list of keywords the widget belongs to.
     74 	 *
     75 	 * @since 2.1.0
     76 	 * @access public
     77 	 *
     78 	 * @return array Widget keywords.
     79 	 */
     80 	public function get_keywords() {
     81 		return [ 'audio', 'player', 'soundcloud', 'embed' ];
     82 	}
     83 
     84 	/**
     85 	 * Register audio widget controls.
     86 	 *
     87 	 * Adds different input fields to allow the user to change and customize the widget settings.
     88 	 *
     89 	 * @since 3.1.0
     90 	 * @access protected
     91 	 */
     92 	protected function register_controls() {
     93 		$this->start_controls_section(
     94 			'section_audio',
     95 			[
     96 				'label' => esc_html__( 'SoundCloud', 'elementor' ),
     97 			]
     98 		);
     99 
    100 		$this->add_control(
    101 			'link',
    102 			[
    103 				'label' => esc_html__( 'Link', 'elementor' ),
    104 				'type' => Controls_Manager::URL,
    105 				'dynamic' => [
    106 					'active' => true,
    107 					'categories' => [
    108 						TagsModule::POST_META_CATEGORY,
    109 						TagsModule::URL_CATEGORY,
    110 					],
    111 				],
    112 				'default' => [
    113 					'url' => 'https://soundcloud.com/shchxango/john-coltrane-1963-my-favorite',
    114 				],
    115 				'options' => false,
    116 			]
    117 		);
    118 
    119 		$this->add_control(
    120 			'visual',
    121 			[
    122 				'label' => esc_html__( 'Visual Player', 'elementor' ),
    123 				'type' => Controls_Manager::SELECT,
    124 				'default' => 'no',
    125 				'options' => [
    126 					'yes' => esc_html__( 'Yes', 'elementor' ),
    127 					'no' => esc_html__( 'No', 'elementor' ),
    128 				],
    129 			]
    130 		);
    131 
    132 		$this->add_control(
    133 			'sc_options',
    134 			[
    135 				'label' => esc_html__( 'Additional Options', 'elementor' ),
    136 				'type' => Controls_Manager::HEADING,
    137 				'separator' => 'before',
    138 			]
    139 		);
    140 
    141 		$this->add_control(
    142 			'sc_auto_play',
    143 			[
    144 				'label' => esc_html__( 'Autoplay', 'elementor' ),
    145 				'type' => Controls_Manager::SWITCHER,
    146 			]
    147 		);
    148 
    149 		$this->add_control(
    150 			'sc_buying',
    151 			[
    152 				'label' => esc_html__( 'Buy Button', 'elementor' ),
    153 				'type' => Controls_Manager::SWITCHER,
    154 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    155 				'label_on' => esc_html__( 'Show', 'elementor' ),
    156 				'default' => 'yes',
    157 			]
    158 		);
    159 
    160 		$this->add_control(
    161 			'sc_liking',
    162 			[
    163 				'label' => esc_html__( 'Like Button', 'elementor' ),
    164 				'type' => Controls_Manager::SWITCHER,
    165 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    166 				'label_on' => esc_html__( 'Show', 'elementor' ),
    167 				'default' => 'yes',
    168 			]
    169 		);
    170 
    171 		$this->add_control(
    172 			'sc_download',
    173 			[
    174 				'label' => esc_html__( 'Download Button', 'elementor' ),
    175 				'type' => Controls_Manager::SWITCHER,
    176 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    177 				'label_on' => esc_html__( 'Show', 'elementor' ),
    178 				'default' => 'yes',
    179 			]
    180 		);
    181 
    182 		$this->add_control(
    183 			'sc_show_artwork',
    184 			[
    185 				'label' => esc_html__( 'Artwork', 'elementor' ),
    186 				'type' => Controls_Manager::SWITCHER,
    187 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    188 				'label_on' => esc_html__( 'Show', 'elementor' ),
    189 				'default' => 'yes',
    190 				'condition' => [
    191 					'visual' => 'no',
    192 				],
    193 			]
    194 		);
    195 
    196 		$this->add_control(
    197 			'sc_sharing',
    198 			[
    199 				'label' => esc_html__( 'Share Button', 'elementor' ),
    200 				'type' => Controls_Manager::SWITCHER,
    201 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    202 				'label_on' => esc_html__( 'Show', 'elementor' ),
    203 				'default' => 'yes',
    204 			]
    205 		);
    206 
    207 		$this->add_control(
    208 			'sc_show_comments',
    209 			[
    210 				'label' => esc_html__( 'Comments', 'elementor' ),
    211 				'type' => Controls_Manager::SWITCHER,
    212 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    213 				'label_on' => esc_html__( 'Show', 'elementor' ),
    214 				'default' => 'yes',
    215 			]
    216 		);
    217 
    218 		$this->add_control(
    219 			'sc_show_playcount',
    220 			[
    221 				'label' => esc_html__( 'Play Counts', 'elementor' ),
    222 				'type' => Controls_Manager::SWITCHER,
    223 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    224 				'label_on' => esc_html__( 'Show', 'elementor' ),
    225 				'default' => 'yes',
    226 			]
    227 		);
    228 
    229 		$this->add_control(
    230 			'sc_show_user',
    231 			[
    232 				'label' => esc_html__( 'Username', 'elementor' ),
    233 				'type' => Controls_Manager::SWITCHER,
    234 				'label_off' => esc_html__( 'Hide', 'elementor' ),
    235 				'label_on' => esc_html__( 'Show', 'elementor' ),
    236 				'default' => 'yes',
    237 			]
    238 		);
    239 
    240 		$this->add_control(
    241 			'sc_color',
    242 			[
    243 				'label' => esc_html__( 'Controls Color', 'elementor' ),
    244 				'type' => Controls_Manager::COLOR,
    245 			]
    246 		);
    247 
    248 		$this->add_control(
    249 			'view',
    250 			[
    251 				'label' => esc_html__( 'View', 'elementor' ),
    252 				'type' => Controls_Manager::HIDDEN,
    253 				'default' => 'soundcloud',
    254 			]
    255 		);
    256 
    257 		$this->end_controls_section();
    258 
    259 	}
    260 
    261 	/**
    262 	 * Render audio widget output on the frontend.
    263 	 *
    264 	 * Written in PHP and used to generate the final HTML.
    265 	 *
    266 	 * @since 1.0.0
    267 	 * @access protected
    268 	 */
    269 	protected function render() {
    270 		$settings = $this->get_settings_for_display();
    271 
    272 		if ( empty( $settings['link'] ) ) {
    273 			return;
    274 		}
    275 
    276 		$this->_current_instance = $settings;
    277 
    278 		add_filter( 'oembed_result', [ $this, 'filter_oembed_result' ], 50, 3 );
    279 		$video_html = wp_oembed_get( $settings['link']['url'], wp_embed_defaults() );
    280 		remove_filter( 'oembed_result', [ $this, 'filter_oembed_result' ], 50 );
    281 
    282 		if ( $video_html ) : ?>
    283 			<div class="elementor-soundcloud-wrapper">
    284 				<?php Utils::print_wp_kses_extended( $video_html, [ 'iframe' ] ); ?>
    285 			</div>
    286 			<?php
    287 		endif;
    288 	}
    289 
    290 	/**
    291 	 * Filter audio widget oEmbed results.
    292 	 *
    293 	 * Written in PHP and used to generate the final HTML.
    294 	 *
    295 	 * @since 1.0.0
    296 	 * @access public
    297 	 *
    298 	 * @param string $html The HTML returned by the oEmbed provider.
    299 	 *
    300 	 * @return string Filtered audio widget oEmbed HTML.
    301 	 */
    302 	public function filter_oembed_result( $html ) {
    303 		$param_keys = [
    304 			'auto_play',
    305 			'buying',
    306 			'liking',
    307 			'download',
    308 			'sharing',
    309 			'show_comments',
    310 			'show_playcount',
    311 			'show_user',
    312 			'show_artwork',
    313 		];
    314 
    315 		$params = [];
    316 
    317 		foreach ( $param_keys as $param_key ) {
    318 			$params[ $param_key ] = 'yes' === $this->_current_instance[ 'sc_' . $param_key ] ? 'true' : 'false';
    319 		}
    320 
    321 		$params['color'] = str_replace( '#', '', $this->_current_instance['sc_color'] );
    322 
    323 		preg_match( '/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $html, $matches );
    324 
    325 		$url = esc_url( add_query_arg( $params, $matches[1] ) );
    326 
    327 		$visual = 'yes' === $this->_current_instance['visual'] ? 'true' : 'false';
    328 
    329 		$html = str_replace( [ $matches[1], 'visual=true' ], [ $url, 'visual=' . $visual ], $html );
    330 
    331 		if ( 'false' === $visual ) {
    332 			$html = str_replace( 'height="400"', 'height="200"', $html );
    333 		}
    334 
    335 		return $html;
    336 	}
    337 
    338 	/**
    339 	 * Render audio widget output in the editor.
    340 	 *
    341 	 * Written as a Backbone JavaScript template and used to generate the live preview.
    342 	 *
    343 	 * @since 2.9.0
    344 	 * @access protected
    345 	 */
    346 	protected function content_template() {}
    347 }