traits
5 months ago
accordion.php
9 months ago
alert.php
9 months ago
audio.php
1 year ago
button.php
9 months ago
common-base.php
8 months ago
common-optimized.php
1 year ago
common.php
1 year ago
counter.php
5 months ago
divider.php
7 months ago
google-maps.php
1 year ago
heading.php
4 months ago
html.php
1 year ago
icon-box.php
5 months ago
icon-list.php
5 months ago
icon.php
5 months ago
image-box.php
5 months ago
image-carousel.php
5 months ago
image-gallery.php
5 months ago
image.php
5 months ago
inner-section.php
2 years ago
menu-anchor.php
1 year ago
progress.php
11 months ago
rating.php
9 months ago
read-more.php
1 year ago
shortcode.php
1 year ago
sidebar.php
1 year ago
social-icons.php
2 months ago
spacer.php
1 year ago
star-rating.php
5 months ago
tabs.php
5 months ago
testimonial.php
5 months ago
text-editor.php
5 months ago
toggle.php
9 months ago
video.php
7 months ago
wordpress.php
1 year ago
audio.php
346 lines
| 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 | protected function is_dynamic_content(): bool { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | public function has_widget_inner_wrapper(): bool { |
| 89 | return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Register audio widget controls. |
| 94 | * |
| 95 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 96 | * |
| 97 | * @since 3.1.0 |
| 98 | * @access protected |
| 99 | */ |
| 100 | protected function register_controls() { |
| 101 | $this->start_controls_section( |
| 102 | 'section_audio', |
| 103 | [ |
| 104 | 'label' => esc_html__( 'SoundCloud', 'elementor' ), |
| 105 | ] |
| 106 | ); |
| 107 | |
| 108 | $this->add_control( |
| 109 | 'link', |
| 110 | [ |
| 111 | 'label' => esc_html__( 'Link', 'elementor' ), |
| 112 | 'type' => Controls_Manager::URL, |
| 113 | 'dynamic' => [ |
| 114 | 'active' => true, |
| 115 | 'categories' => [ |
| 116 | TagsModule::POST_META_CATEGORY, |
| 117 | TagsModule::URL_CATEGORY, |
| 118 | ], |
| 119 | ], |
| 120 | 'default' => [ |
| 121 | 'url' => 'https://soundcloud.com/shchxango/john-coltrane-1963-my-favorite', |
| 122 | ], |
| 123 | 'options' => false, |
| 124 | ] |
| 125 | ); |
| 126 | |
| 127 | $this->add_control( |
| 128 | 'visual', |
| 129 | [ |
| 130 | 'label' => esc_html__( 'Visual Player', 'elementor' ), |
| 131 | 'type' => Controls_Manager::SELECT, |
| 132 | 'default' => 'no', |
| 133 | 'options' => [ |
| 134 | 'yes' => esc_html__( 'Yes', 'elementor' ), |
| 135 | 'no' => esc_html__( 'No', 'elementor' ), |
| 136 | ], |
| 137 | ] |
| 138 | ); |
| 139 | |
| 140 | $this->add_control( |
| 141 | 'sc_options', |
| 142 | [ |
| 143 | 'label' => esc_html__( 'Additional Options', 'elementor' ), |
| 144 | 'type' => Controls_Manager::HEADING, |
| 145 | 'separator' => 'before', |
| 146 | ] |
| 147 | ); |
| 148 | |
| 149 | $this->add_control( |
| 150 | 'sc_auto_play', |
| 151 | [ |
| 152 | 'label' => esc_html__( 'Autoplay', 'elementor' ), |
| 153 | 'type' => Controls_Manager::SWITCHER, |
| 154 | ] |
| 155 | ); |
| 156 | |
| 157 | $this->add_control( |
| 158 | 'sc_buying', |
| 159 | [ |
| 160 | 'label' => esc_html__( 'Buy Button', 'elementor' ), |
| 161 | 'type' => Controls_Manager::SWITCHER, |
| 162 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 163 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 164 | 'default' => 'yes', |
| 165 | ] |
| 166 | ); |
| 167 | |
| 168 | $this->add_control( |
| 169 | 'sc_liking', |
| 170 | [ |
| 171 | 'label' => esc_html__( 'Like Button', 'elementor' ), |
| 172 | 'type' => Controls_Manager::SWITCHER, |
| 173 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 174 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 175 | 'default' => 'yes', |
| 176 | ] |
| 177 | ); |
| 178 | |
| 179 | $this->add_control( |
| 180 | 'sc_download', |
| 181 | [ |
| 182 | 'label' => esc_html__( 'Download Button', 'elementor' ), |
| 183 | 'type' => Controls_Manager::SWITCHER, |
| 184 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 185 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 186 | 'default' => 'yes', |
| 187 | ] |
| 188 | ); |
| 189 | |
| 190 | $this->add_control( |
| 191 | 'sc_show_artwork', |
| 192 | [ |
| 193 | 'label' => esc_html__( 'Artwork', 'elementor' ), |
| 194 | 'type' => Controls_Manager::SWITCHER, |
| 195 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 196 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 197 | 'default' => 'yes', |
| 198 | 'condition' => [ |
| 199 | 'visual' => 'no', |
| 200 | ], |
| 201 | ] |
| 202 | ); |
| 203 | |
| 204 | $this->add_control( |
| 205 | 'sc_sharing', |
| 206 | [ |
| 207 | 'label' => esc_html__( 'Share Button', 'elementor' ), |
| 208 | 'type' => Controls_Manager::SWITCHER, |
| 209 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 210 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 211 | 'default' => 'yes', |
| 212 | ] |
| 213 | ); |
| 214 | |
| 215 | $this->add_control( |
| 216 | 'sc_show_comments', |
| 217 | [ |
| 218 | 'label' => esc_html__( 'Comments', 'elementor' ), |
| 219 | 'type' => Controls_Manager::SWITCHER, |
| 220 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 221 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 222 | 'default' => 'yes', |
| 223 | ] |
| 224 | ); |
| 225 | |
| 226 | $this->add_control( |
| 227 | 'sc_show_playcount', |
| 228 | [ |
| 229 | 'label' => esc_html__( 'Play Counts', 'elementor' ), |
| 230 | 'type' => Controls_Manager::SWITCHER, |
| 231 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 232 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 233 | 'default' => 'yes', |
| 234 | ] |
| 235 | ); |
| 236 | |
| 237 | $this->add_control( |
| 238 | 'sc_show_user', |
| 239 | [ |
| 240 | 'label' => esc_html__( 'Username', 'elementor' ), |
| 241 | 'type' => Controls_Manager::SWITCHER, |
| 242 | 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 243 | 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 244 | 'default' => 'yes', |
| 245 | ] |
| 246 | ); |
| 247 | |
| 248 | $this->add_control( |
| 249 | 'sc_color', |
| 250 | [ |
| 251 | 'label' => esc_html__( 'Controls Color', 'elementor' ), |
| 252 | 'type' => Controls_Manager::COLOR, |
| 253 | ] |
| 254 | ); |
| 255 | |
| 256 | $this->end_controls_section(); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Render audio widget output on the frontend. |
| 261 | * |
| 262 | * Written in PHP and used to generate the final HTML. |
| 263 | * |
| 264 | * @since 1.0.0 |
| 265 | * @access protected |
| 266 | */ |
| 267 | protected function render() { |
| 268 | $settings = $this->get_settings_for_display(); |
| 269 | |
| 270 | if ( empty( $settings['link'] ) ) { |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | $this->_current_instance = $settings; |
| 275 | |
| 276 | add_filter( 'oembed_result', [ $this, 'filter_oembed_result' ], 50, 3 ); |
| 277 | $video_html = wp_oembed_get( $settings['link']['url'], wp_embed_defaults() ); |
| 278 | remove_filter( 'oembed_result', [ $this, 'filter_oembed_result' ], 50 ); |
| 279 | |
| 280 | if ( $video_html ) : ?> |
| 281 | <div class="elementor-soundcloud-wrapper"> |
| 282 | <?php Utils::print_wp_kses_extended( $video_html, [ 'iframe' ] ); ?> |
| 283 | </div> |
| 284 | <?php |
| 285 | endif; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Filter audio widget oEmbed results. |
| 290 | * |
| 291 | * Written in PHP and used to generate the final HTML. |
| 292 | * |
| 293 | * @since 1.0.0 |
| 294 | * @access public |
| 295 | * |
| 296 | * @param string $html The HTML returned by the oEmbed provider. |
| 297 | * |
| 298 | * @return string Filtered audio widget oEmbed HTML. |
| 299 | */ |
| 300 | public function filter_oembed_result( $html ) { |
| 301 | $param_keys = [ |
| 302 | 'auto_play', |
| 303 | 'buying', |
| 304 | 'liking', |
| 305 | 'download', |
| 306 | 'sharing', |
| 307 | 'show_comments', |
| 308 | 'show_playcount', |
| 309 | 'show_user', |
| 310 | 'show_artwork', |
| 311 | ]; |
| 312 | |
| 313 | $params = []; |
| 314 | |
| 315 | foreach ( $param_keys as $param_key ) { |
| 316 | $params[ $param_key ] = 'yes' === $this->_current_instance[ 'sc_' . $param_key ] ? 'true' : 'false'; |
| 317 | } |
| 318 | |
| 319 | $params['color'] = str_replace( '#', '', $this->_current_instance['sc_color'] ); |
| 320 | |
| 321 | preg_match( '/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $html, $matches ); |
| 322 | |
| 323 | $url = esc_url( add_query_arg( $params, $matches[1] ) ); |
| 324 | |
| 325 | $visual = 'yes' === $this->_current_instance['visual'] ? 'true' : 'false'; |
| 326 | |
| 327 | $html = str_replace( [ $matches[1], 'visual=true' ], [ $url, 'visual=' . $visual ], $html ); |
| 328 | |
| 329 | if ( 'false' === $visual ) { |
| 330 | $html = str_replace( 'height="400"', 'height="200"', $html ); |
| 331 | } |
| 332 | |
| 333 | return $html; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Render audio widget output in the editor. |
| 338 | * |
| 339 | * Written as a Backbone JavaScript template and used to generate the live preview. |
| 340 | * |
| 341 | * @since 2.9.0 |
| 342 | * @access protected |
| 343 | */ |
| 344 | protected function content_template() {} |
| 345 | } |
| 346 |