PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.3
Elementor Website Builder – more than just a page builder v3.1.3
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 / video.php

video.php in Elementor Website Builder – more than just a page builder 3.1.3, at includes/widgets/video.php

1,168 lines 26.4 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 video widget.
12 *
13 * Elementor widget that displays a video player.
14 *
15 * @since 1.0.0
16 */
17 class Widget_Video extends Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve video widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 *
27 * @return string Widget name.
28 */
29 public function get_name() {
30 return 'video';
31 }
32
33 /**
34 * Get widget title.
35 *
36 * Retrieve video widget title.
37 *
38 * @since 1.0.0
39 * @access public
40 *
41 * @return string Widget title.
42 */
43 public function get_title() {
44 return __( 'Video', 'elementor' );
45 }
46
47 /**
48 * Get widget icon.
49 *
50 * Retrieve video widget icon.
51 *
52 * @since 1.0.0
53 * @access public
54 *
55 * @return string Widget icon.
56 */
57 public function get_icon() {
58 return 'eicon-youtube';
59 }
60
61 /**
62 * Get widget categories.
63 *
64 * Retrieve the list of categories the video widget belongs to.
65 *
66 * Used to determine where to display the widget in the editor.
67 *
68 * @since 2.0.0
69 * @access public
70 *
71 * @return array Widget categories.
72 */
73 public function get_categories() {
74 return [ 'basic' ];
75 }
76
77 /**
78 * Get widget keywords.
79 *
80 * Retrieve the list of keywords the widget belongs to.
81 *
82 * @since 2.1.0
83 * @access public
84 *
85 * @return array Widget keywords.
86 */
87 public function get_keywords() {
88 return [ 'video', 'player', 'embed', 'youtube', 'vimeo', 'dailymotion' ];
89 }
90
91 /**
92 * Register video widget controls.
93 *
94 * Adds different input fields to allow the user to change and customize the widget settings.
95 *
96 * @since 3.1.0
97 * @access protected
98 */
99 protected function register_controls() {
100 $this->start_controls_section(
101 'section_video',
102 [
103 'label' => __( 'Video', 'elementor' ),
104 ]
105 );
106
107 $this->add_control(
108 'video_type',
109 [
110 'label' => __( 'Source', 'elementor' ),
111 'type' => Controls_Manager::SELECT,
112 'default' => 'youtube',
113 'options' => [
114 'youtube' => __( 'YouTube', 'elementor' ),
115 'vimeo' => __( 'Vimeo', 'elementor' ),
116 'dailymotion' => __( 'Dailymotion', 'elementor' ),
117 'hosted' => __( 'Self Hosted', 'elementor' ),
118 ],
119 'frontend_available' => true,
120 ]
121 );
122
123 $this->add_control(
124 'youtube_url',
125 [
126 'label' => __( 'Link', 'elementor' ),
127 'type' => Controls_Manager::TEXT,
128 'dynamic' => [
129 'active' => true,
130 'categories' => [
131 TagsModule::POST_META_CATEGORY,
132 TagsModule::URL_CATEGORY,
133 ],
134 ],
135 'placeholder' => __( 'Enter your URL', 'elementor' ) . ' (YouTube)',
136 'default' => 'https://www.youtube.com/watch?v=XHOmBV4js_E',
137 'label_block' => true,
138 'condition' => [
139 'video_type' => 'youtube',
140 ],
141 'frontend_available' => true,
142 ]
143 );
144
145 $this->add_control(
146 'vimeo_url',
147 [
148 'label' => __( 'Link', 'elementor' ),
149 'type' => Controls_Manager::TEXT,
150 'dynamic' => [
151 'active' => true,
152 'categories' => [
153 TagsModule::POST_META_CATEGORY,
154 TagsModule::URL_CATEGORY,
155 ],
156 ],
157 'placeholder' => __( 'Enter your URL', 'elementor' ) . ' (Vimeo)',
158 'default' => 'https://vimeo.com/235215203',
159 'label_block' => true,
160 'condition' => [
161 'video_type' => 'vimeo',
162 ],
163 ]
164 );
165
166 $this->add_control(
167 'dailymotion_url',
168 [
169 'label' => __( 'Link', 'elementor' ),
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', 'elementor' ) . ' (Dailymotion)',
179 'default' => 'https://www.dailymotion.com/video/x6tqhqb',
180 'label_block' => true,
181 'condition' => [
182 'video_type' => 'dailymotion',
183 ],
184 ]
185 );
186
187 $this->add_control(
188 'insert_url',
189 [
190 'label' => __( 'External URL', 'elementor' ),
191 'type' => Controls_Manager::SWITCHER,
192 'condition' => [
193 'video_type' => 'hosted',
194 ],
195 ]
196 );
197
198 $this->add_control(
199 'hosted_url',
200 [
201 'label' => __( 'Choose File', 'elementor' ),
202 'type' => Controls_Manager::MEDIA,
203 'dynamic' => [
204 'active' => true,
205 'categories' => [
206 TagsModule::MEDIA_CATEGORY,
207 ],
208 ],
209 'media_type' => 'video',
210 'condition' => [
211 'video_type' => 'hosted',
212 'insert_url' => '',
213 ],
214 ]
215 );
216
217 $this->add_control(
218 'external_url',
219 [
220 'label' => __( 'URL', 'elementor' ),
221 'type' => Controls_Manager::URL,
222 'autocomplete' => false,
223 'options' => false,
224 'label_block' => true,
225 'show_label' => false,
226 'dynamic' => [
227 'active' => true,
228 'categories' => [
229 TagsModule::POST_META_CATEGORY,
230 TagsModule::URL_CATEGORY,
231 ],
232 ],
233 'media_type' => 'video',
234 'placeholder' => __( 'Enter your URL', 'elementor' ),
235 'condition' => [
236 'video_type' => 'hosted',
237 'insert_url' => 'yes',
238 ],
239 ]
240 );
241
242 $this->add_control(
243 'start',
244 [
245 'label' => __( 'Start Time', 'elementor' ),
246 'type' => Controls_Manager::NUMBER,
247 'description' => __( 'Specify a start time (in seconds)', 'elementor' ),
248 'frontend_available' => true,
249 ]
250 );
251
252 $this->add_control(
253 'end',
254 [
255 'label' => __( 'End Time', 'elementor' ),
256 'type' => Controls_Manager::NUMBER,
257 'description' => __( 'Specify an end time (in seconds)', 'elementor' ),
258 'condition' => [
259 'video_type' => [ 'youtube', 'hosted' ],
260 ],
261 'frontend_available' => true,
262 ]
263 );
264
265 $this->add_control(
266 'video_options',
267 [
268 'label' => __( 'Video Options', 'elementor' ),
269 'type' => Controls_Manager::HEADING,
270 'separator' => 'before',
271 ]
272 );
273
274 $this->add_control(
275 'autoplay',
276 [
277 'label' => __( 'Autoplay', 'elementor' ),
278 'type' => Controls_Manager::SWITCHER,
279 'frontend_available' => true,
280 ]
281 );
282
283 $this->add_control(
284 'play_on_mobile',
285 [
286 'label' => __( 'Play On Mobile', 'elementor' ),
287 'type' => Controls_Manager::SWITCHER,
288 'condition' => [
289 'autoplay' => 'yes',
290 ],
291 'frontend_available' => true,
292 ]
293 );
294
295 $this->add_control(
296 'mute',
297 [
298 'label' => __( 'Mute', 'elementor' ),
299 'type' => Controls_Manager::SWITCHER,
300 'frontend_available' => true,
301 ]
302 );
303
304 $this->add_control(
305 'loop',
306 [
307 'label' => __( 'Loop', 'elementor' ),
308 'type' => Controls_Manager::SWITCHER,
309 'condition' => [
310 'video_type!' => 'dailymotion',
311 ],
312 'frontend_available' => true,
313 ]
314 );
315
316 $this->add_control(
317 'controls',
318 [
319 'label' => __( 'Player Controls', 'elementor' ),
320 'type' => Controls_Manager::SWITCHER,
321 'label_off' => __( 'Hide', 'elementor' ),
322 'label_on' => __( 'Show', 'elementor' ),
323 'default' => 'yes',
324 'condition' => [
325 'video_type!' => 'vimeo',
326 ],
327 'frontend_available' => true,
328 ]
329 );
330
331 $this->add_control(
332 'showinfo',
333 [
334 'label' => __( 'Video Info', 'elementor' ),
335 'type' => Controls_Manager::SWITCHER,
336 'label_off' => __( 'Hide', 'elementor' ),
337 'label_on' => __( 'Show', 'elementor' ),
338 'default' => 'yes',
339 'condition' => [
340 'video_type' => [ 'dailymotion' ],
341 ],
342 ]
343 );
344
345 $this->add_control(
346 'modestbranding',
347 [
348 'label' => __( 'Modest Branding', 'elementor' ),
349 'type' => Controls_Manager::SWITCHER,
350 'condition' => [
351 'video_type' => [ 'youtube' ],
352 'controls' => 'yes',
353 ],
354 'frontend_available' => true,
355 ]
356 );
357
358 $this->add_control(
359 'logo',
360 [
361 'label' => __( 'Logo', 'elementor' ),
362 'type' => Controls_Manager::SWITCHER,
363 'label_off' => __( 'Hide', 'elementor' ),
364 'label_on' => __( 'Show', 'elementor' ),
365 'default' => 'yes',
366 'condition' => [
367 'video_type' => [ 'dailymotion' ],
368 ],
369 ]
370 );
371
372 // YouTube.
373 $this->add_control(
374 'yt_privacy',
375 [
376 'label' => __( 'Privacy Mode', 'elementor' ),
377 'type' => Controls_Manager::SWITCHER,
378 'description' => __( 'When you turn on privacy mode, YouTube won\'t store information about visitors on your website unless they play the video.', 'elementor' ),
379 'condition' => [
380 'video_type' => 'youtube',
381 ],
382 'frontend_available' => true,
383 ]
384 );
385
386 $this->add_control(
387 'lazy_load',
388 [
389 'label' => __( 'Lazy Load', 'elementor' ),
390 'type' => Controls_Manager::SWITCHER,
391 'conditions' => [
392 'relation' => 'or',
393 'terms' => [
394 [
395 'name' => 'video_type',
396 'operator' => '===',
397 'value' => 'youtube',
398 ],
399 [
400 'relation' => 'and',
401 'terms' => [
402 [
403 'name' => 'show_image_overlay',
404 'operator' => '===',
405 'value' => 'yes',
406 ],
407 [
408 'name' => 'video_type',
409 'operator' => '!==',
410 'value' => 'hosted',
411 ],
412 ],
413 ],
414 ],
415 ],
416 'frontend_available' => true,
417 ]
418 );
419
420 $this->add_control(
421 'rel',
422 [
423 'label' => __( 'Suggested Videos', 'elementor' ),
424 'type' => Controls_Manager::SELECT,
425 'options' => [
426 '' => __( 'Current Video Channel', 'elementor' ),
427 'yes' => __( 'Any Video', 'elementor' ),
428 ],
429 'condition' => [
430 'video_type' => 'youtube',
431 ],
432 ]
433 );
434
435 // Vimeo.
436 $this->add_control(
437 'vimeo_title',
438 [
439 'label' => __( 'Intro Title', 'elementor' ),
440 'type' => Controls_Manager::SWITCHER,
441 'label_off' => __( 'Hide', 'elementor' ),
442 'label_on' => __( 'Show', 'elementor' ),
443 'default' => 'yes',
444 'condition' => [
445 'video_type' => 'vimeo',
446 ],
447 ]
448 );
449
450 $this->add_control(
451 'vimeo_portrait',
452 [
453 'label' => __( 'Intro Portrait', 'elementor' ),
454 'type' => Controls_Manager::SWITCHER,
455 'label_off' => __( 'Hide', 'elementor' ),
456 'label_on' => __( 'Show', 'elementor' ),
457 'default' => 'yes',
458 'condition' => [
459 'video_type' => 'vimeo',
460 ],
461 ]
462 );
463
464 $this->add_control(
465 'vimeo_byline',
466 [
467 'label' => __( 'Intro Byline', 'elementor' ),
468 'type' => Controls_Manager::SWITCHER,
469 'label_off' => __( 'Hide', 'elementor' ),
470 'label_on' => __( 'Show', 'elementor' ),
471 'default' => 'yes',
472 'condition' => [
473 'video_type' => 'vimeo',
474 ],
475 ]
476 );
477
478 $this->add_control(
479 'color',
480 [
481 'label' => __( 'Controls Color', 'elementor' ),
482 'type' => Controls_Manager::COLOR,
483 'default' => '',
484 'condition' => [
485 'video_type' => [ 'vimeo', 'dailymotion' ],
486 ],
487 ]
488 );
489
490 $this->add_control(
491 'download_button',
492 [
493 'label' => __( 'Download Button', 'elementor' ),
494 'type' => Controls_Manager::SWITCHER,
495 'label_off' => __( 'Hide', 'elementor' ),
496 'label_on' => __( 'Show', 'elementor' ),
497 'condition' => [
498 'video_type' => 'hosted',
499 ],
500 ]
501 );
502
503 $this->add_control(
504 'poster',
505 [
506 'label' => __( 'Poster', 'elementor' ),
507 'type' => Controls_Manager::MEDIA,
508 'dynamic' => [
509 'active' => true,
510 ],
511 'condition' => [
512 'video_type' => 'hosted',
513 ],
514 ]
515 );
516
517 $this->add_control(
518 'view',
519 [
520 'label' => __( 'View', 'elementor' ),
521 'type' => Controls_Manager::HIDDEN,
522 'default' => 'youtube',
523 ]
524 );
525
526 $this->end_controls_section();
527
528 $this->start_controls_section(
529 'section_image_overlay',
530 [
531 'label' => __( 'Image Overlay', 'elementor' ),
532 ]
533 );
534
535 $this->add_control(
536 'show_image_overlay',
537 [
538 'label' => __( 'Image Overlay', 'elementor' ),
539 'type' => Controls_Manager::SWITCHER,
540 'label_off' => __( 'Hide', 'elementor' ),
541 'label_on' => __( 'Show', 'elementor' ),
542 'frontend_available' => true,
543 ]
544 );
545
546 $this->add_control(
547 'image_overlay',
548 [
549 'label' => __( 'Choose Image', 'elementor' ),
550 'type' => Controls_Manager::MEDIA,
551 'default' => [
552 'url' => Utils::get_placeholder_image_src(),
553 ],
554 'dynamic' => [
555 'active' => true,
556 ],
557 'condition' => [
558 'show_image_overlay' => 'yes',
559 ],
560 'frontend_available' => true,
561 ]
562 );
563
564 $this->add_group_control(
565 Group_Control_Image_Size::get_type(),
566 [
567 'name' => 'image_overlay', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `image_overlay_size` and `image_overlay_custom_dimension`.
568 'default' => 'full',
569 'separator' => 'none',
570 'condition' => [
571 'show_image_overlay' => 'yes',
572 ],
573 ]
574 );
575
576 $this->add_control(
577 'show_play_icon',
578 [
579 'label' => __( 'Play Icon', 'elementor' ),
580 'type' => Controls_Manager::SWITCHER,
581 'default' => 'yes',
582 'condition' => [
583 'show_image_overlay' => 'yes',
584 'image_overlay[url]!' => '',
585 ],
586 ]
587 );
588
589 $this->add_control(
590 'lightbox',
591 [
592 'label' => __( 'Lightbox', 'elementor' ),
593 'type' => Controls_Manager::SWITCHER,
594 'frontend_available' => true,
595 'label_off' => __( 'Off', 'elementor' ),
596 'label_on' => __( 'On', 'elementor' ),
597 'condition' => [
598 'show_image_overlay' => 'yes',
599 'image_overlay[url]!' => '',
600 ],
601 'separator' => 'before',
602 ]
603 );
604
605 $this->end_controls_section();
606
607 $this->start_controls_section(
608 'section_video_style',
609 [
610 'label' => __( 'Video', 'elementor' ),
611 'tab' => Controls_Manager::TAB_STYLE,
612 ]
613 );
614
615 $this->add_control(
616 'aspect_ratio',
617 [
618 'label' => __( 'Aspect Ratio', 'elementor' ),
619 'type' => Controls_Manager::SELECT,
620 'options' => [
621 '169' => '16:9',
622 '219' => '21:9',
623 '43' => '4:3',
624 '32' => '3:2',
625 '11' => '1:1',
626 '916' => '9:16',
627 ],
628 'default' => '169',
629 'prefix_class' => 'elementor-aspect-ratio-',
630 'frontend_available' => true,
631 ]
632 );
633
634 $this->add_group_control(
635 Group_Control_Css_Filter::get_type(),
636 [
637 'name' => 'css_filters',
638 'selector' => '{{WRAPPER}} .elementor-wrapper',
639 ]
640 );
641
642 $this->add_control(
643 'play_icon_title',
644 [
645 'label' => __( 'Play Icon', 'elementor' ),
646 'type' => Controls_Manager::HEADING,
647 'condition' => [
648 'show_image_overlay' => 'yes',
649 'show_play_icon' => 'yes',
650 ],
651 'separator' => 'before',
652 ]
653 );
654
655 $this->add_control(
656 'play_icon_color',
657 [
658 'label' => __( 'Color', 'elementor' ),
659 'type' => Controls_Manager::COLOR,
660 'selectors' => [
661 '{{WRAPPER}} .elementor-custom-embed-play i' => 'color: {{VALUE}}',
662 ],
663 'condition' => [
664 'show_image_overlay' => 'yes',
665 'show_play_icon' => 'yes',
666 ],
667 ]
668 );
669
670 $this->add_responsive_control(
671 'play_icon_size',
672 [
673 'label' => __( 'Size', 'elementor' ),
674 'type' => Controls_Manager::SLIDER,
675 'range' => [
676 'px' => [
677 'min' => 10,
678 'max' => 300,
679 ],
680 ],
681 'selectors' => [
682 '{{WRAPPER}} .elementor-custom-embed-play i' => 'font-size: {{SIZE}}{{UNIT}}',
683 ],
684 'condition' => [
685 'show_image_overlay' => 'yes',
686 'show_play_icon' => 'yes',
687 ],
688 ]
689 );
690
691 $this->add_group_control(
692 Group_Control_Text_Shadow::get_type(),
693 [
694 'name' => 'play_icon_text_shadow',
695 'selector' => '{{WRAPPER}} .elementor-custom-embed-play i',
696 'fields_options' => [
697 'text_shadow_type' => [
698 'label' => _x( 'Shadow', 'Text Shadow Control', 'elementor' ),
699 ],
700 ],
701 'condition' => [
702 'show_image_overlay' => 'yes',
703 'show_play_icon' => 'yes',
704 ],
705 ]
706 );
707
708 $this->end_controls_section();
709
710 $this->start_controls_section(
711 'section_lightbox_style',
712 [
713 'label' => __( 'Lightbox', 'elementor' ),
714 'tab' => Controls_Manager::TAB_STYLE,
715 'condition' => [
716 'show_image_overlay' => 'yes',
717 'image_overlay[url]!' => '',
718 'lightbox' => 'yes',
719 ],
720 ]
721 );
722
723 $this->add_control(
724 'lightbox_color',
725 [
726 'label' => __( 'Background Color', 'elementor' ),
727 'type' => Controls_Manager::COLOR,
728 'selectors' => [
729 '#elementor-lightbox-{{ID}}' => 'background-color: {{VALUE}};',
730 ],
731 ]
732 );
733
734 $this->add_control(
735 'lightbox_ui_color',
736 [
737 'label' => __( 'UI Color', 'elementor' ),
738 'type' => Controls_Manager::COLOR,
739 'selectors' => [
740 '#elementor-lightbox-{{ID}} .dialog-lightbox-close-button' => 'color: {{VALUE}}',
741 ],
742 ]
743 );
744
745 $this->add_control(
746 'lightbox_ui_color_hover',
747 [
748 'label' => __( 'UI Hover Color', 'elementor' ),
749 'type' => Controls_Manager::COLOR,
750 'selectors' => [
751 '#elementor-lightbox-{{ID}} .dialog-lightbox-close-button:hover' => 'color: {{VALUE}}',
752 ],
753 'separator' => 'after',
754 ]
755 );
756
757 $this->add_control(
758 'lightbox_video_width',
759 [
760 'label' => __( 'Content Width', 'elementor' ),
761 'type' => Controls_Manager::SLIDER,
762 'default' => [
763 'unit' => '%',
764 ],
765 'range' => [
766 '%' => [
767 'min' => 30,
768 ],
769 ],
770 'selectors' => [
771 '(desktop+)#elementor-lightbox-{{ID}} .elementor-video-container' => 'width: {{SIZE}}{{UNIT}};',
772 ],
773 ]
774 );
775
776 $this->add_control(
777 'lightbox_content_position',
778 [
779 'label' => __( 'Content Position', 'elementor' ),
780 'type' => Controls_Manager::SELECT,
781 'frontend_available' => true,
782 'options' => [
783 '' => __( 'Center', 'elementor' ),
784 'top' => __( 'Top', 'elementor' ),
785 ],
786 'selectors' => [
787 '#elementor-lightbox-{{ID}} .elementor-video-container' => '{{VALUE}}; transform: translateX(-50%);',
788 ],
789 'selectors_dictionary' => [
790 'top' => 'top: 60px',
791 ],
792 ]
793 );
794
795 $this->add_responsive_control(
796 'lightbox_content_animation',
797 [
798 'label' => __( 'Entrance Animation', 'elementor' ),
799 'type' => Controls_Manager::ANIMATION,
800 'frontend_available' => true,
801 ]
802 );
803
804 $this->end_controls_section();
805 }
806
807 /**
808 * Render video widget output on the frontend.
809 *
810 * Written in PHP and used to generate the final HTML.
811 *
812 * @since 1.0.0
813 * @access protected
814 */
815 protected function render() {
816 $settings = $this->get_settings_for_display();
817
818 $video_url = $settings[ $settings['video_type'] . '_url' ];
819
820 if ( 'hosted' === $settings['video_type'] ) {
821 $video_url = $this->get_hosted_video_url();
822 } else {
823 $embed_params = $this->get_embed_params();
824 $embed_options = $this->get_embed_options();
825 }
826
827 if ( empty( $video_url ) ) {
828 return;
829 }
830
831 if ( 'youtube' === $settings['video_type'] ) {
832 $video_html = '<div class="elementor-video"></div>';
833 }
834
835 if ( 'hosted' === $settings['video_type'] ) {
836 $this->add_render_attribute( 'video-wrapper', 'class', 'e-hosted-video' );
837
838 ob_start();
839
840 $this->render_hosted_video();
841
842 $video_html = ob_get_clean();
843 } else {
844 $is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode();
845 $post_id = get_queried_object_id();
846
847 if ( $is_static_render_mode ) {
848 $video_html = Embed::get_embed_thumbnail_html( $video_url, $post_id );
849 // YouTube API requires a different markup which was set above.
850 } else if ( 'youtube' !== $settings['video_type'] ) {
851 $video_html = Embed::get_embed_html( $video_url, $embed_params, $embed_options );
852 }
853 }
854
855 if ( empty( $video_html ) ) {
856 echo esc_url( $video_url );
857
858 return;
859 }
860
861 $this->add_render_attribute( 'video-wrapper', 'class', 'elementor-wrapper' );
862
863 if ( ! $settings['lightbox'] ) {
864 $this->add_render_attribute( 'video-wrapper', 'class', 'elementor-fit-aspect-ratio' );
865 }
866
867 $this->add_render_attribute( 'video-wrapper', 'class', 'elementor-open-' . ( $settings['lightbox'] ? 'lightbox' : 'inline' ) );
868 ?>
869 <div <?php echo $this->get_render_attribute_string( 'video-wrapper' ); ?>>
870 <?php
871 if ( ! $settings['lightbox'] ) {
872 echo $video_html; // XSS ok.
873 }
874
875 if ( $this->has_image_overlay() ) {
876 $this->add_render_attribute( 'image-overlay', 'class', 'elementor-custom-embed-image-overlay' );
877
878 if ( $settings['lightbox'] ) {
879 if ( 'hosted' === $settings['video_type'] ) {
880 $lightbox_url = $video_url;
881 } else {
882 $lightbox_url = Embed::get_embed_url( $video_url, $embed_params, $embed_options );
883 }
884
885 $lightbox_options = [
886 'type' => 'video',
887 'videoType' => $settings['video_type'],
888 'url' => $lightbox_url,
889 'modalOptions' => [
890 'id' => 'elementor-lightbox-' . $this->get_id(),
891 'entranceAnimation' => $settings['lightbox_content_animation'],
892 'entranceAnimation_tablet' => $settings['lightbox_content_animation_tablet'],
893 'entranceAnimation_mobile' => $settings['lightbox_content_animation_mobile'],
894 'videoAspectRatio' => $settings['aspect_ratio'],
895 ],
896 ];
897
898 if ( 'hosted' === $settings['video_type'] ) {
899 $lightbox_options['videoParams'] = $this->get_hosted_params();
900 }
901
902 $this->add_render_attribute( 'image-overlay', [
903 'data-elementor-open-lightbox' => 'yes',
904 'data-elementor-lightbox' => wp_json_encode( $lightbox_options ),
905 ] );
906
907 if ( Plugin::$instance->editor->is_edit_mode() ) {
908 $this->add_render_attribute( 'image-overlay', [
909 'class' => 'elementor-clickable',
910 ] );
911 }
912 } else {
913 // When there is an image URL but no ID, it means the overlay image is the placeholder. In this case, get the placeholder URL.
914 if ( empty( $settings['image_overlay']['id'] && ! empty( $settings['image_overlay']['url'] ) ) ) {
915 $image_url = $settings['image_overlay']['url'];
916 } else {
917 $image_url = Group_Control_Image_Size::get_attachment_image_src( $settings['image_overlay']['id'], 'image_overlay', $settings );
918 }
919
920 $this->add_render_attribute( 'image-overlay', 'style', 'background-image: url(' . $image_url . ');' );
921 }
922 ?>
923 <div <?php echo $this->get_render_attribute_string( 'image-overlay' ); ?>>
924 <?php if ( $settings['lightbox'] ) : ?>
925 <?php echo Group_Control_Image_Size::get_attachment_image_html( $settings, 'image_overlay' ); ?>
926 <?php endif; ?>
927 <?php if ( 'yes' === $settings['show_play_icon'] ) : ?>
928 <div class="elementor-custom-embed-play" role="button">
929 <i class="eicon-play" aria-hidden="true"></i>
930 <span class="elementor-screen-only"><?php echo __( 'Play Video', 'elementor' ); ?></span>
931 </div>
932 <?php endif; ?>
933 </div>
934 <?php } ?>
935 </div>
936 <?php
937 }
938
939 /**
940 * Render video widget as plain content.
941 *
942 * Override the default behavior, by printing the video URL insted of rendering it.
943 *
944 * @since 1.4.5
945 * @access public
946 */
947 public function render_plain_content() {
948 $settings = $this->get_settings_for_display();
949
950 if ( 'hosted' !== $settings['video_type'] ) {
951 $url = $settings[ $settings['video_type'] . '_url' ];
952 } else {
953 $url = $this->get_hosted_video_url();
954 }
955
956 echo esc_url( $url );
957 }
958
959 /**
960 * Get embed params.
961 *
962 * Retrieve video widget embed parameters.
963 *
964 * @since 1.5.0
965 * @access public
966 *
967 * @return array Video embed parameters.
968 */
969 public function get_embed_params() {
970 $settings = $this->get_settings_for_display();
971
972 $params = [];
973
974 if ( $settings['autoplay'] && ! $this->has_image_overlay() ) {
975 $params['autoplay'] = '1';
976
977 if ( $settings['play_on_mobile'] ) {
978 $params['playsinline'] = '1';
979 }
980 }
981
982 $params_dictionary = [];
983
984 if ( 'youtube' === $settings['video_type'] ) {
985 $params_dictionary = [
986 'loop',
987 'controls',
988 'mute',
989 'rel',
990 'modestbranding',
991 ];
992
993 if ( $settings['loop'] ) {
994 $video_properties = Embed::get_video_properties( $settings['youtube_url'] );
995
996 $params['playlist'] = $video_properties['video_id'];
997 }
998
999 $params['start'] = $settings['start'];
1000
1001 $params['end'] = $settings['end'];
1002
1003 $params['wmode'] = 'opaque';
1004 } elseif ( 'vimeo' === $settings['video_type'] ) {
1005 $params_dictionary = [
1006 'loop',
1007 'mute' => 'muted',
1008 'vimeo_title' => 'title',
1009 'vimeo_portrait' => 'portrait',
1010 'vimeo_byline' => 'byline',
1011 ];
1012
1013 $params['color'] = str_replace( '#', '', $settings['color'] );
1014
1015 $params['autopause'] = '0';
1016 } elseif ( 'dailymotion' === $settings['video_type'] ) {
1017 $params_dictionary = [
1018 'controls',
1019 'mute',
1020 'showinfo' => 'ui-start-screen-info',
1021 'logo' => 'ui-logo',
1022 ];
1023
1024 $params['ui-highlight'] = str_replace( '#', '', $settings['color'] );
1025
1026 $params['start'] = $settings['start'];
1027
1028 $params['endscreen-enable'] = '0';
1029 }
1030
1031 foreach ( $params_dictionary as $key => $param_name ) {
1032 $setting_name = $param_name;
1033
1034 if ( is_string( $key ) ) {
1035 $setting_name = $key;
1036 }
1037
1038 $setting_value = $settings[ $setting_name ] ? '1' : '0';
1039
1040 $params[ $param_name ] = $setting_value;
1041 }
1042
1043 return $params;
1044 }
1045
1046 /**
1047 * Whether the video widget has an overlay image or not.
1048 *
1049 * Used to determine whether an overlay image was set for the video.
1050 *
1051 * @since 1.0.0
1052 * @access protected
1053 *
1054 * @return bool Whether an image overlay was set for the video.
1055 */
1056 protected function has_image_overlay() {
1057 $settings = $this->get_settings_for_display();
1058
1059 return ! empty( $settings['image_overlay']['url'] ) && 'yes' === $settings['show_image_overlay'];
1060 }
1061
1062 /**
1063 * @since 2.1.0
1064 * @access private
1065 */
1066 private function get_embed_options() {
1067 $settings = $this->get_settings_for_display();
1068
1069 $embed_options = [];
1070
1071 if ( 'youtube' === $settings['video_type'] ) {
1072 $embed_options['privacy'] = $settings['yt_privacy'];
1073 } elseif ( 'vimeo' === $settings['video_type'] ) {
1074 $embed_options['start'] = $settings['start'];
1075 }
1076
1077 $embed_options['lazy_load'] = ! empty( $settings['lazy_load'] );
1078
1079 return $embed_options;
1080 }
1081
1082 /**
1083 * @since 2.1.0
1084 * @access private
1085 */
1086 private function get_hosted_params() {
1087 $settings = $this->get_settings_for_display();
1088
1089 $video_params = [];
1090
1091 foreach ( [ 'autoplay', 'loop', 'controls' ] as $option_name ) {
1092 if ( $settings[ $option_name ] ) {
1093 $video_params[ $option_name ] = '';
1094 }
1095 }
1096
1097 if ( $settings['mute'] ) {
1098 $video_params['muted'] = 'muted';
1099 }
1100
1101 if ( $settings['play_on_mobile'] ) {
1102 $video_params['playsinline'] = '';
1103 }
1104
1105 if ( ! $settings['download_button'] ) {
1106 $video_params['controlsList'] = 'nodownload';
1107 }
1108
1109 if ( $settings['poster']['url'] ) {
1110 $video_params['poster'] = $settings['poster']['url'];
1111 }
1112
1113 return $video_params;
1114 }
1115
1116 /**
1117 * @param bool $from_media
1118 *
1119 * @return string
1120 * @since 2.1.0
1121 * @access private
1122 */
1123 private function get_hosted_video_url() {
1124 $settings = $this->get_settings_for_display();
1125
1126 if ( ! empty( $settings['insert_url'] ) ) {
1127 $video_url = $settings['external_url']['url'];
1128 } else {
1129 $video_url = $settings['hosted_url']['url'];
1130 }
1131
1132 if ( empty( $video_url ) ) {
1133 return '';
1134 }
1135
1136 if ( $settings['start'] || $settings['end'] ) {
1137 $video_url .= '#t=';
1138 }
1139
1140 if ( $settings['start'] ) {
1141 $video_url .= $settings['start'];
1142 }
1143
1144 if ( $settings['end'] ) {
1145 $video_url .= ',' . $settings['end'];
1146 }
1147
1148 return $video_url;
1149 }
1150
1151 /**
1152 *
1153 * @since 2.1.0
1154 * @access private
1155 */
1156 private function render_hosted_video() {
1157 $video_url = $this->get_hosted_video_url();
1158 if ( empty( $video_url ) ) {
1159 return;
1160 }
1161
1162 $video_params = $this->get_hosted_params();
1163 ?>
1164 <video class="elementor-video" src="<?php echo esc_url( $video_url ); ?>" <?php echo Utils::render_html_attributes( $video_params ); ?>></video>
1165 <?php
1166 }
1167 }
1168