PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.4
Elementor Website Builder – more than just a page builder v3.20.4
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.20.4, at includes/widgets/audio.php

339 lines 7.2 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 /**
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->end_controls_section();
249
250 }
251
252 /**
253 * Render audio widget output on the frontend.
254 *
255 * Written in PHP and used to generate the final HTML.
256 *
257 * @since 1.0.0
258 * @access protected
259 */
260 protected function render() {
261 $settings = $this->get_settings_for_display();
262
263 if ( empty( $settings['link'] ) ) {
264 return;
265 }
266
267 $this->_current_instance = $settings;
268
269 add_filter( 'oembed_result', [ $this, 'filter_oembed_result' ], 50, 3 );
270 $video_html = wp_oembed_get( $settings['link']['url'], wp_embed_defaults() );
271 remove_filter( 'oembed_result', [ $this, 'filter_oembed_result' ], 50 );
272
273 if ( $video_html ) : ?>
274 <div class="elementor-soundcloud-wrapper">
275 <?php Utils::print_wp_kses_extended( $video_html, [ 'iframe' ] ); ?>
276 </div>
277 <?php
278 endif;
279 }
280
281 /**
282 * Filter audio widget oEmbed results.
283 *
284 * Written in PHP and used to generate the final HTML.
285 *
286 * @since 1.0.0
287 * @access public
288 *
289 * @param string $html The HTML returned by the oEmbed provider.
290 *
291 * @return string Filtered audio widget oEmbed HTML.
292 */
293 public function filter_oembed_result( $html ) {
294 $param_keys = [
295 'auto_play',
296 'buying',
297 'liking',
298 'download',
299 'sharing',
300 'show_comments',
301 'show_playcount',
302 'show_user',
303 'show_artwork',
304 ];
305
306 $params = [];
307
308 foreach ( $param_keys as $param_key ) {
309 $params[ $param_key ] = 'yes' === $this->_current_instance[ 'sc_' . $param_key ] ? 'true' : 'false';
310 }
311
312 $params['color'] = str_replace( '#', '', $this->_current_instance['sc_color'] );
313
314 preg_match( '/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $html, $matches );
315
316 $url = esc_url( add_query_arg( $params, $matches[1] ) );
317
318 $visual = 'yes' === $this->_current_instance['visual'] ? 'true' : 'false';
319
320 $html = str_replace( [ $matches[1], 'visual=true' ], [ $url, 'visual=' . $visual ], $html );
321
322 if ( 'false' === $visual ) {
323 $html = str_replace( 'height="400"', 'height="200"', $html );
324 }
325
326 return $html;
327 }
328
329 /**
330 * Render audio widget output in the editor.
331 *
332 * Written as a Backbone JavaScript template and used to generate the live preview.
333 *
334 * @since 2.9.0
335 * @access protected
336 */
337 protected function content_template() {}
338 }
339