PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.0-dev4
Elementor Website Builder – more than just a page builder v3.22.0-dev4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / audio.php

audio.php in Elementor Website Builder – more than just a page builder 3.22.0-dev4, at includes/widgets/audio.php

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