PluginProbe ʕ •ᴥ•ʔ
Presto Player / 2.2.3-beta1
Presto Player v2.2.3-beta1
4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / inc / Integrations / Elementor / VideoWidget.php
presto-player / inc / Integrations / Elementor Last commit date
Elementor.php 2 years ago ReusableVideoWidget.php 3 years ago VideoWidget.php 5 years ago
VideoWidget.php
503 lines
1 <?php
2
3 namespace PrestoPlayer\Integrations\Elementor;
4
5 use Elementor\Utils;
6 use Elementor\Widget_Base;
7 use Elementor\Controls_Manager;
8 use PrestoPlayer\Models\Preset;
9 use PrestoPlayer\Blocks\VimeoBlock;
10 use PrestoPlayer\Blocks\YouTubeBlock;
11 use PrestoPlayer\Blocks\SelfHostedBlock;
12 use Elementor\Modules\DynamicTags\Module as TagsModule;
13
14 if (!defined('ABSPATH')) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * presto-player video widget.
20 *
21 * presto-player widget that displays a video player.
22 *
23 * @since 1.0.0
24 */
25 class VideoWidget extends Widget_Base
26 {
27 private $is_premium = false;
28 private $version = '';
29
30 public function setPremium($pro)
31 {
32 $this->is_premium = $pro;
33 }
34
35 public function setVersion($version)
36 {
37 $this->version = $version;
38 }
39
40 /**
41 * Get widget name.
42 *
43 * Retrieve video widget name.
44 *
45 * @since 1.0.0
46 * @access public
47 *
48 * @return string Widget name.
49 */
50 public function get_name()
51 {
52 return 'presto_video';
53 }
54
55 /**
56 * Get widget title.
57 *
58 * Retrieve video widget title.
59 *
60 * @since 1.0.0
61 * @access public
62 *
63 * @return string Widget title.
64 */
65 public function get_title()
66 {
67 return __('Presto Video', 'presto-player');
68 }
69
70 /**
71 * Get widget icon.
72 *
73 * Retrieve video widget icon.
74 *
75 * @since 1.0.0
76 * @access public
77 *
78 * @return string Widget icon.
79 */
80 public function get_icon()
81 {
82 return 'eicon-youtube';
83 }
84
85 /**
86 * Get widget categories.
87 *
88 * Retrieve the list of categories the video widget belongs to.
89 *
90 * Used to determine where to display the widget in the editor.
91 *
92 * @since 2.0.0
93 * @access public
94 *
95 * @return array Widget categories.
96 */
97 public function get_categories()
98 {
99 return ['basic'];
100 }
101
102 /**
103 * Get widget keywords.
104 *
105 * Retrieve the list of keywords the widget belongs to.
106 *
107 * @since 2.1.0
108 * @access public
109 *
110 * @return array Widget keywords.
111 */
112 public function get_keywords()
113 {
114 return ['video', 'player', 'embed', 'youtube', 'vimeo'];
115 }
116
117 public function fake_toggle_html($label = '')
118 {
119 return '<div class="elementor-control-muted_preview elementor-control-type-switcher elementor-label-inline elementor-control-separator-default">
120 <div class="elementor-control-content">
121 <div class="elementor-control-field">
122 <label for="elementor-control-default-c513" class="elementor-control-title">' . esc_html($label) . ' <i class="eicon-pro-icon"></i></label>
123 <div class="elementor-control-input-wrapper">
124 <label class="elementor-switch elementor-control-unit-2">
125 <input id="elementor-control-default-c513" type="checkbox" data-setting="muted_preview" class="elementor-switch-input" value="yes" disabled>
126 <span class="elementor-switch-label" data-on="Yes" data-off="No"></span>
127 <span class="elementor-switch-handle"></span>
128 </label>
129 </div>
130 </div>
131 </div>
132 </div>';
133 }
134
135 /**
136 * Register video widget controls.
137 *
138 * Adds different input fields to allow the user to change and customize the widget settings.
139 *
140 * @since 1.0.0
141 * @access protected
142 */
143 protected function _register_controls()
144 {
145 $this->start_controls_section(
146 'section_video',
147 [
148 'label' => __('Video', 'presto-player'),
149 ]
150 );
151
152 $this->add_control(
153 'video_type',
154 [
155 'label' => __('Source', 'presto-player'),
156 'type' => Controls_Manager::SELECT,
157 'default' => 'youtube',
158 'options' => [
159 'youtube' => __('YouTube', 'presto-player'),
160 'vimeo' => __('Vimeo', 'presto-player'),
161 'hosted' => __('Self Hosted', 'presto-player'),
162 ],
163 ]
164 );
165
166 $this->add_control(
167 'youtube_url',
168 [
169 'label' => __('Link', 'presto-player'),
170 'type' => Controls_Manager::TEXT,
171 'dynamic' => [
172 'active' => true,
173 'categories' => [
174 TagsModule::POST_META_CATEGORY,
175 TagsModule::URL_CATEGORY,
176 ],
177 ],
178 'placeholder' => __('Enter your URL', 'presto-player') . ' (YouTube)',
179 'default' => 'https://www.youtube.com/watch?v=XHOmBV4js_E',
180 'label_block' => true,
181 'condition' => [
182 'video_type' => 'youtube',
183 ],
184 ]
185 );
186
187 $this->add_control(
188 'vimeo_url',
189 [
190 'label' => __('Link', 'presto-player'),
191 'type' => Controls_Manager::TEXT,
192 'dynamic' => [
193 'active' => true,
194 'categories' => [
195 TagsModule::POST_META_CATEGORY,
196 TagsModule::URL_CATEGORY,
197 ],
198 ],
199 'placeholder' => __('Enter your URL', 'presto-player') . ' (Vimeo)',
200 'default' => 'https://vimeo.com/235215203',
201 'label_block' => true,
202 'condition' => [
203 'video_type' => 'vimeo',
204 ],
205 ]
206 );
207
208 $this->add_control(
209 'hosted_url',
210 [
211 'label' => __('Add/Select Video', 'presto-player'),
212 'type' => Controls_Manager::MEDIA,
213 'dynamic' => [
214 'active' => true,
215 'categories' => [
216 TagsModule::MEDIA_CATEGORY,
217 ],
218 ],
219 'media_type' => 'video',
220 'condition' => [
221 'video_type' => 'hosted',
222 ],
223 ]
224 );
225
226 $this->add_control(
227 'external_url',
228 [
229 'label' => __('URL', 'presto-player'),
230 'type' => Controls_Manager::URL,
231 'autocomplete' => false,
232 'options' => false,
233 'label_block' => true,
234 'show_label' => false,
235 'dynamic' => [
236 'active' => true,
237 'categories' => [
238 TagsModule::POST_META_CATEGORY,
239 TagsModule::URL_CATEGORY,
240 ],
241 ],
242 'media_type' => 'video',
243 'placeholder' => __('Enter your URL', 'presto-player'),
244 'condition' => [
245 'video_type' => 'hosted',
246 'insert_url' => 'yes',
247 ],
248 ]
249 );
250
251 $this->add_control(
252 'video_options',
253 [
254 'label' => __('Video Options', 'presto-player'),
255 'type' => Controls_Manager::HEADING,
256 'separator' => 'before',
257 ]
258 );
259
260 if (!$this->is_premium) {
261 $this->add_control(
262 'important_note',
263 [
264 'type' => \Elementor\Controls_Manager::RAW_HTML,
265 'raw' => $this->fake_toggle_html(__('Muted Preview', 'presto-player')),
266 'condition' => [
267 'autoplay' => '',
268 ],
269 ]
270 );
271 } else {
272 $this->add_control(
273 'muted_preview',
274 [
275 'label' => __('Muted Preview', 'presto-player'),
276 'type' => Controls_Manager::SWITCHER,
277 'condition' => [
278 'autoplay' => '',
279 ],
280 ]
281 );
282 }
283
284
285 $this->add_control(
286 'autoplay',
287 [
288 'label' => __('Autoplay', 'presto-player'),
289 'type' => Controls_Manager::SWITCHER,
290 'condition' => [
291 'muted_preview' => '',
292 ],
293 ]
294 );
295
296 $this->add_control(
297 'play-inline',
298 [
299 'label' => __('Play inline', 'presto-player'),
300 'type' => Controls_Manager::SWITCHER,
301 ]
302 );
303
304 $this->add_control(
305 'poster',
306 [
307 'label' => __('Poster', 'presto-player'),
308 'type' => Controls_Manager::MEDIA,
309
310 ]
311 );
312
313 $this->end_controls_section();
314
315 $this->start_controls_section(
316 'section_video_style',
317 [
318 'label' => __('Video Preset', 'presto-player'),
319 'tab' => Controls_Manager::TAB_STYLE,
320 ]
321 );
322
323 $options = $this->get_preset_options();
324
325 $this->add_control(
326 'preset',
327 [
328 'label' => __('Select A Preset', 'presto-player'),
329 'type' => Controls_Manager::SELECT,
330 'options' => $options['options'],
331 'default' => $options['default_id'],
332 'frontend_available' => true,
333 ]
334 );
335
336 $this->end_controls_section();
337 }
338
339 protected function get_preset_options()
340 {
341 $presets = new Preset();
342 $presets = $presets->all();
343
344 $preset_options = [];
345 $default_id = 0;
346 if (!empty($presets)) {
347 foreach ($presets as $preset) {
348 if ($preset->slug === 'default') {
349 $default_id = $preset->id;
350 }
351 $preset_options[$preset->id] = $preset->name;
352 }
353 }
354
355 return [
356 'options' => $preset_options,
357 'default_id' => $default_id
358 ];
359 }
360
361 /**
362 * Render video widget output on the frontend.
363 *
364 * Written in PHP and used to generate the final HTML.
365 *
366 * @since 1.0.0
367 * @access protected
368 */
369 protected function render()
370 {
371 $settings = $this->get_settings_for_display();
372
373 switch ($settings['video_type']) {
374 case 'hosted':
375 $hosted = new SelfHostedBlock($this->is_premium, $this->version);
376 echo $hosted->html([
377 'id' => $settings['hosted_url']['id'],
378 'src' => $settings['hosted_url']['url'],
379 'preset' => $settings['preset'],
380 'autoplay' => $settings['autoplay'],
381 'playsInline' => $settings['play-inline'],
382 'poster' => !empty($settings['poster']['url']) ? $settings['poster']['url'] : '',
383 'chapters' => []
384 ], '');
385 break;
386 case 'youtube':
387 $youtube = new YouTubeBlock($this->is_premium, $this->version);
388 echo $youtube->html([
389 'src' => $settings['youtube_url'],
390 'preset' => $settings['preset'],
391 'autoplay' => $settings['autoplay'],
392 'playsInline' => $settings['play-inline'],
393 'poster' => !empty($settings['poster']['url']) ? $settings['poster']['url'] : '',
394 'chapters' => []
395 ], '');
396 break;
397 case 'vimeo':
398 $vimeo = new VimeoBlock($this->is_premium, $this->version);
399 echo $vimeo->html([
400 'src' => $settings['vimeo_url'],
401 'preset' => $settings['preset'],
402 'autoplay' => $settings['autoplay'],
403 'playsInline' => $settings['play-inline'],
404 'poster' => !empty($settings['poster']['url']) ? $settings['poster']['url'] : '',
405 'chapters' => []
406 ], '');
407 break;
408 }
409
410 // print_r($settings);
411 }
412
413
414 /**
415 * @since 2.1.0
416 * @access private
417 */
418 private function get_hosted_params()
419 {
420 $settings = $this->get_settings_for_display();
421
422 $video_params = [];
423
424 foreach (['autoplay', 'loop', 'controls'] as $option_name) {
425 if ($settings[$option_name]) {
426 $video_params[$option_name] = '';
427 }
428 }
429
430 if ($settings['mute']) {
431 $video_params['muted'] = 'muted';
432 }
433
434 if ($settings['play_on_mobile']) {
435 $video_params['playsinline'] = '';
436 }
437
438 if (!$settings['download_button']) {
439 $video_params['controlsList'] = 'nodownload';
440 }
441
442 if ($settings['poster']['url']) {
443 $video_params['poster'] = $settings['poster']['url'];
444 }
445
446 return $video_params;
447 }
448
449 /**
450 * @param bool $from_media
451 *
452 * @return string
453 * @since 2.1.0
454 * @access private
455 */
456 private function get_hosted_video_url()
457 {
458 $settings = $this->get_settings_for_display();
459
460 if (!empty($settings['insert_url'])) {
461 $video_url = $settings['external_url']['url'];
462 } else {
463 $video_url = $settings['hosted_url']['url'];
464 }
465
466 if (empty($video_url)) {
467 return '';
468 }
469
470 if ($settings['start'] || $settings['end']) {
471 $video_url .= '#t=';
472 }
473
474 if ($settings['start']) {
475 $video_url .= $settings['start'];
476 }
477
478 if ($settings['end']) {
479 $video_url .= ',' . $settings['end'];
480 }
481
482 return $video_url;
483 }
484
485 /**
486 *
487 * @since 2.1.0
488 * @access private
489 */
490 private function render_hosted_video()
491 {
492 $video_url = $this->get_hosted_video_url();
493 if (empty($video_url)) {
494 return;
495 }
496
497 $video_params = $this->get_hosted_params();
498 ?>
499 <video class="presto-player-video" src="<?php echo esc_url($video_url); ?>" <?php echo Utils::render_html_attributes($video_params); ?>></video>
500 <?php
501 }
502 }
503