PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0-dev2
Elementor Website Builder – more than just a page builder v3.1.0-dev2
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.0-dev2, at includes/widgets/video.php

1,145 lines 25.9 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 1.0.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 'rel',
388 [
389 'label' => __( 'Suggested Videos', 'elementor' ),
390 'type' => Controls_Manager::SELECT,
391 'options' => [
392 '' => __( 'Current Video Channel', 'elementor' ),
393 'yes' => __( 'Any Video', 'elementor' ),
394 ],
395 'condition' => [
396 'video_type' => 'youtube',
397 ],
398 ]
399 );
400
401 // Vimeo.
402 $this->add_control(
403 'vimeo_title',
404 [
405 'label' => __( 'Intro Title', 'elementor' ),
406 'type' => Controls_Manager::SWITCHER,
407 'label_off' => __( 'Hide', 'elementor' ),
408 'label_on' => __( 'Show', 'elementor' ),
409 'default' => 'yes',
410 'condition' => [
411 'video_type' => 'vimeo',
412 ],
413 ]
414 );
415
416 $this->add_control(
417 'vimeo_portrait',
418 [
419 'label' => __( 'Intro Portrait', 'elementor' ),
420 'type' => Controls_Manager::SWITCHER,
421 'label_off' => __( 'Hide', 'elementor' ),
422 'label_on' => __( 'Show', 'elementor' ),
423 'default' => 'yes',
424 'condition' => [
425 'video_type' => 'vimeo',
426 ],
427 ]
428 );
429
430 $this->add_control(
431 'vimeo_byline',
432 [
433 'label' => __( 'Intro Byline', 'elementor' ),
434 'type' => Controls_Manager::SWITCHER,
435 'label_off' => __( 'Hide', 'elementor' ),
436 'label_on' => __( 'Show', 'elementor' ),
437 'default' => 'yes',
438 'condition' => [
439 'video_type' => 'vimeo',
440 ],
441 ]
442 );
443
444 $this->add_control(
445 'color',
446 [
447 'label' => __( 'Controls Color', 'elementor' ),
448 'type' => Controls_Manager::COLOR,
449 'default' => '',
450 'condition' => [
451 'video_type' => [ 'vimeo', 'dailymotion' ],
452 ],
453 ]
454 );
455
456 $this->add_control(
457 'download_button',
458 [
459 'label' => __( 'Download Button', 'elementor' ),
460 'type' => Controls_Manager::SWITCHER,
461 'label_off' => __( 'Hide', 'elementor' ),
462 'label_on' => __( 'Show', 'elementor' ),
463 'condition' => [
464 'video_type' => 'hosted',
465 ],
466 ]
467 );
468
469 $this->add_control(
470 'poster',
471 [
472 'label' => __( 'Poster', 'elementor' ),
473 'type' => Controls_Manager::MEDIA,
474 'dynamic' => [
475 'active' => true,
476 ],
477 'condition' => [
478 'video_type' => 'hosted',
479 ],
480 ]
481 );
482
483 $this->add_control(
484 'view',
485 [
486 'label' => __( 'View', 'elementor' ),
487 'type' => Controls_Manager::HIDDEN,
488 'default' => 'youtube',
489 ]
490 );
491
492 $this->end_controls_section();
493
494 $this->start_controls_section(
495 'section_image_overlay',
496 [
497 'label' => __( 'Image Overlay', 'elementor' ),
498 ]
499 );
500
501 $this->add_control(
502 'show_image_overlay',
503 [
504 'label' => __( 'Image Overlay', 'elementor' ),
505 'type' => Controls_Manager::SWITCHER,
506 'label_off' => __( 'Hide', 'elementor' ),
507 'label_on' => __( 'Show', 'elementor' ),
508 'frontend_available' => true,
509 ]
510 );
511
512 $this->add_control(
513 'image_overlay',
514 [
515 'label' => __( 'Choose Image', 'elementor' ),
516 'type' => Controls_Manager::MEDIA,
517 'default' => [
518 'url' => Utils::get_placeholder_image_src(),
519 ],
520 'dynamic' => [
521 'active' => true,
522 ],
523 'condition' => [
524 'show_image_overlay' => 'yes',
525 ],
526 'frontend_available' => true,
527 ]
528 );
529
530 $this->add_control(
531 'lazy_load',
532 [
533 'label' => __( 'Lazy Load', 'elementor' ),
534 'type' => Controls_Manager::SWITCHER,
535 'condition' => [
536 'show_image_overlay' => 'yes',
537 'video_type!' => 'hosted',
538 ],
539 ]
540 );
541
542 $this->add_group_control(
543 Group_Control_Image_Size::get_type(),
544 [
545 'name' => 'image_overlay', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `image_overlay_size` and `image_overlay_custom_dimension`.
546 'default' => 'full',
547 'separator' => 'none',
548 'condition' => [
549 'show_image_overlay' => 'yes',
550 ],
551 ]
552 );
553
554 $this->add_control(
555 'show_play_icon',
556 [
557 'label' => __( 'Play Icon', 'elementor' ),
558 'type' => Controls_Manager::SWITCHER,
559 'default' => 'yes',
560 'condition' => [
561 'show_image_overlay' => 'yes',
562 'image_overlay[url]!' => '',
563 ],
564 ]
565 );
566
567 $this->add_control(
568 'lightbox',
569 [
570 'label' => __( 'Lightbox', 'elementor' ),
571 'type' => Controls_Manager::SWITCHER,
572 'frontend_available' => true,
573 'label_off' => __( 'Off', 'elementor' ),
574 'label_on' => __( 'On', 'elementor' ),
575 'condition' => [
576 'show_image_overlay' => 'yes',
577 'image_overlay[url]!' => '',
578 ],
579 'separator' => 'before',
580 ]
581 );
582
583 $this->end_controls_section();
584
585 $this->start_controls_section(
586 'section_video_style',
587 [
588 'label' => __( 'Video', 'elementor' ),
589 'tab' => Controls_Manager::TAB_STYLE,
590 ]
591 );
592
593 $this->add_control(
594 'aspect_ratio',
595 [
596 'label' => __( 'Aspect Ratio', 'elementor' ),
597 'type' => Controls_Manager::SELECT,
598 'options' => [
599 '169' => '16:9',
600 '219' => '21:9',
601 '43' => '4:3',
602 '32' => '3:2',
603 '11' => '1:1',
604 '916' => '9:16',
605 ],
606 'default' => '169',
607 'prefix_class' => 'elementor-aspect-ratio-',
608 'frontend_available' => true,
609 ]
610 );
611
612 $this->add_group_control(
613 Group_Control_Css_Filter::get_type(),
614 [
615 'name' => 'css_filters',
616 'selector' => '{{WRAPPER}} .elementor-wrapper',
617 ]
618 );
619
620 $this->add_control(
621 'play_icon_title',
622 [
623 'label' => __( 'Play Icon', 'elementor' ),
624 'type' => Controls_Manager::HEADING,
625 'condition' => [
626 'show_image_overlay' => 'yes',
627 'show_play_icon' => 'yes',
628 ],
629 'separator' => 'before',
630 ]
631 );
632
633 $this->add_control(
634 'play_icon_color',
635 [
636 'label' => __( 'Color', 'elementor' ),
637 'type' => Controls_Manager::COLOR,
638 'selectors' => [
639 '{{WRAPPER}} .elementor-custom-embed-play i' => 'color: {{VALUE}}',
640 ],
641 'condition' => [
642 'show_image_overlay' => 'yes',
643 'show_play_icon' => 'yes',
644 ],
645 ]
646 );
647
648 $this->add_responsive_control(
649 'play_icon_size',
650 [
651 'label' => __( 'Size', 'elementor' ),
652 'type' => Controls_Manager::SLIDER,
653 'range' => [
654 'px' => [
655 'min' => 10,
656 'max' => 300,
657 ],
658 ],
659 'selectors' => [
660 '{{WRAPPER}} .elementor-custom-embed-play i' => 'font-size: {{SIZE}}{{UNIT}}',
661 ],
662 'condition' => [
663 'show_image_overlay' => 'yes',
664 'show_play_icon' => 'yes',
665 ],
666 ]
667 );
668
669 $this->add_group_control(
670 Group_Control_Text_Shadow::get_type(),
671 [
672 'name' => 'play_icon_text_shadow',
673 'selector' => '{{WRAPPER}} .elementor-custom-embed-play i',
674 'fields_options' => [
675 'text_shadow_type' => [
676 'label' => _x( 'Shadow', 'Text Shadow Control', 'elementor' ),
677 ],
678 ],
679 'condition' => [
680 'show_image_overlay' => 'yes',
681 'show_play_icon' => 'yes',
682 ],
683 ]
684 );
685
686 $this->end_controls_section();
687
688 $this->start_controls_section(
689 'section_lightbox_style',
690 [
691 'label' => __( 'Lightbox', 'elementor' ),
692 'tab' => Controls_Manager::TAB_STYLE,
693 'condition' => [
694 'show_image_overlay' => 'yes',
695 'image_overlay[url]!' => '',
696 'lightbox' => 'yes',
697 ],
698 ]
699 );
700
701 $this->add_control(
702 'lightbox_color',
703 [
704 'label' => __( 'Background Color', 'elementor' ),
705 'type' => Controls_Manager::COLOR,
706 'selectors' => [
707 '#elementor-lightbox-{{ID}}' => 'background-color: {{VALUE}};',
708 ],
709 ]
710 );
711
712 $this->add_control(
713 'lightbox_ui_color',
714 [
715 'label' => __( 'UI Color', 'elementor' ),
716 'type' => Controls_Manager::COLOR,
717 'selectors' => [
718 '#elementor-lightbox-{{ID}} .dialog-lightbox-close-button' => 'color: {{VALUE}}',
719 ],
720 ]
721 );
722
723 $this->add_control(
724 'lightbox_ui_color_hover',
725 [
726 'label' => __( 'UI Hover Color', 'elementor' ),
727 'type' => Controls_Manager::COLOR,
728 'selectors' => [
729 '#elementor-lightbox-{{ID}} .dialog-lightbox-close-button:hover' => 'color: {{VALUE}}',
730 ],
731 'separator' => 'after',
732 ]
733 );
734
735 $this->add_control(
736 'lightbox_video_width',
737 [
738 'label' => __( 'Content Width', 'elementor' ),
739 'type' => Controls_Manager::SLIDER,
740 'default' => [
741 'unit' => '%',
742 ],
743 'range' => [
744 '%' => [
745 'min' => 30,
746 ],
747 ],
748 'selectors' => [
749 '(desktop+)#elementor-lightbox-{{ID}} .elementor-video-container' => 'width: {{SIZE}}{{UNIT}};',
750 ],
751 ]
752 );
753
754 $this->add_control(
755 'lightbox_content_position',
756 [
757 'label' => __( 'Content Position', 'elementor' ),
758 'type' => Controls_Manager::SELECT,
759 'frontend_available' => true,
760 'options' => [
761 '' => __( 'Center', 'elementor' ),
762 'top' => __( 'Top', 'elementor' ),
763 ],
764 'selectors' => [
765 '#elementor-lightbox-{{ID}} .elementor-video-container' => '{{VALUE}}; transform: translateX(-50%);',
766 ],
767 'selectors_dictionary' => [
768 'top' => 'top: 60px',
769 ],
770 ]
771 );
772
773 $this->add_responsive_control(
774 'lightbox_content_animation',
775 [
776 'label' => __( 'Entrance Animation', 'elementor' ),
777 'type' => Controls_Manager::ANIMATION,
778 'frontend_available' => true,
779 ]
780 );
781
782 $this->end_controls_section();
783 }
784
785 /**
786 * Render video widget output on the frontend.
787 *
788 * Written in PHP and used to generate the final HTML.
789 *
790 * @since 1.0.0
791 * @access protected
792 */
793 protected function render() {
794 $settings = $this->get_settings_for_display();
795
796 $video_url = $settings[ $settings['video_type'] . '_url' ];
797
798 if ( 'hosted' === $settings['video_type'] ) {
799 $video_url = $this->get_hosted_video_url();
800 } else {
801 $embed_params = $this->get_embed_params();
802 $embed_options = $this->get_embed_options();
803 }
804
805 if ( empty( $video_url ) ) {
806 return;
807 }
808
809 if ( 'youtube' === $settings['video_type'] ) {
810 $video_html = '<div class="elementor-video"></div>';
811 } else {
812 if ( 'hosted' === $settings['video_type'] ) {
813 $this->add_render_attribute( 'video-wrapper', 'class', 'e-hosted-video' );
814
815 ob_start();
816
817 $this->render_hosted_video();
818
819 $video_html = ob_get_clean();
820 } else {
821 $is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode();
822 $post_id = get_queried_object_id();
823
824 if ( $is_static_render_mode ) {
825 $video_html = Embed::get_embed_thumbnail_html( $video_url, $post_id );
826 } else {
827 $video_html = Embed::get_embed_html( $video_url, $embed_params, $embed_options );
828 }
829 }
830
831 if ( empty( $video_html ) ) {
832 echo esc_url( $video_url );
833
834 return;
835 }
836 }
837
838 $this->add_render_attribute( 'video-wrapper', 'class', 'elementor-wrapper' );
839
840 if ( ! $settings['lightbox'] ) {
841 $this->add_render_attribute( 'video-wrapper', 'class', 'elementor-fit-aspect-ratio' );
842 }
843
844 $this->add_render_attribute( 'video-wrapper', 'class', 'elementor-open-' . ( $settings['lightbox'] ? 'lightbox' : 'inline' ) );
845 ?>
846 <div <?php echo $this->get_render_attribute_string( 'video-wrapper' ); ?>>
847 <?php
848 if ( ! $settings['lightbox'] ) {
849 echo $video_html; // XSS ok.
850 }
851
852 if ( $this->has_image_overlay() ) {
853 $this->add_render_attribute( 'image-overlay', 'class', 'elementor-custom-embed-image-overlay' );
854
855 if ( $settings['lightbox'] ) {
856 if ( 'hosted' === $settings['video_type'] ) {
857 $lightbox_url = $video_url;
858 } else {
859 $lightbox_url = Embed::get_embed_url( $video_url, $embed_params, $embed_options );
860 }
861
862 $lightbox_options = [
863 'type' => 'video',
864 'videoType' => $settings['video_type'],
865 'url' => $lightbox_url,
866 'modalOptions' => [
867 'id' => 'elementor-lightbox-' . $this->get_id(),
868 'entranceAnimation' => $settings['lightbox_content_animation'],
869 'entranceAnimation_tablet' => $settings['lightbox_content_animation_tablet'],
870 'entranceAnimation_mobile' => $settings['lightbox_content_animation_mobile'],
871 'videoAspectRatio' => $settings['aspect_ratio'],
872 ],
873 ];
874
875 if ( 'hosted' === $settings['video_type'] ) {
876 $lightbox_options['videoParams'] = $this->get_hosted_params();
877 }
878
879 $this->add_render_attribute( 'image-overlay', [
880 'data-elementor-open-lightbox' => 'yes',
881 'data-elementor-lightbox' => wp_json_encode( $lightbox_options ),
882 ] );
883
884 if ( Plugin::$instance->editor->is_edit_mode() ) {
885 $this->add_render_attribute( 'image-overlay', [
886 'class' => 'elementor-clickable',
887 ] );
888 }
889 } else {
890 // When there is an image URL but no ID, it means the overlay image is the placeholder. In this case, get the placeholder URL.
891 if ( empty( $settings['image_overlay']['id'] && ! empty( $settings['image_overlay']['url'] ) ) ) {
892 $image_url = Utils::get_placeholder_image_src();
893 } else {
894 $image_url = Group_Control_Image_Size::get_attachment_image_src( $settings['image_overlay']['id'], 'image_overlay', $settings );
895 }
896
897 $this->add_render_attribute( 'image-overlay', 'style', 'background-image: url(' . $image_url . ');' );
898 }
899 ?>
900 <div <?php echo $this->get_render_attribute_string( 'image-overlay' ); ?>>
901 <?php if ( $settings['lightbox'] ) : ?>
902 <?php echo Group_Control_Image_Size::get_attachment_image_html( $settings, 'image_overlay' ); ?>
903 <?php endif; ?>
904 <?php if ( 'yes' === $settings['show_play_icon'] ) : ?>
905 <div class="elementor-custom-embed-play" role="button">
906 <i class="eicon-play" aria-hidden="true"></i>
907 <span class="elementor-screen-only"><?php echo __( 'Play Video', 'elementor' ); ?></span>
908 </div>
909 <?php endif; ?>
910 </div>
911 <?php } ?>
912 </div>
913 <?php
914 }
915
916 /**
917 * Render video widget as plain content.
918 *
919 * Override the default behavior, by printing the video URL insted of rendering it.
920 *
921 * @since 1.4.5
922 * @access public
923 */
924 public function render_plain_content() {
925 $settings = $this->get_settings_for_display();
926
927 if ( 'hosted' !== $settings['video_type'] ) {
928 $url = $settings[ $settings['video_type'] . '_url' ];
929 } else {
930 $url = $this->get_hosted_video_url();
931 }
932
933 echo esc_url( $url );
934 }
935
936 /**
937 * Get embed params.
938 *
939 * Retrieve video widget embed parameters.
940 *
941 * @since 1.5.0
942 * @access public
943 *
944 * @return array Video embed parameters.
945 */
946 public function get_embed_params() {
947 $settings = $this->get_settings_for_display();
948
949 $params = [];
950
951 if ( $settings['autoplay'] && ! $this->has_image_overlay() ) {
952 $params['autoplay'] = '1';
953
954 if ( $settings['play_on_mobile'] ) {
955 $params['playsinline'] = '1';
956 }
957 }
958
959 $params_dictionary = [];
960
961 if ( 'youtube' === $settings['video_type'] ) {
962 $params_dictionary = [
963 'loop',
964 'controls',
965 'mute',
966 'rel',
967 'modestbranding',
968 ];
969
970 if ( $settings['loop'] ) {
971 $video_properties = Embed::get_video_properties( $settings['youtube_url'] );
972
973 $params['playlist'] = $video_properties['video_id'];
974 }
975
976 $params['start'] = $settings['start'];
977
978 $params['end'] = $settings['end'];
979
980 $params['wmode'] = 'opaque';
981 } elseif ( 'vimeo' === $settings['video_type'] ) {
982 $params_dictionary = [
983 'loop',
984 'mute' => 'muted',
985 'vimeo_title' => 'title',
986 'vimeo_portrait' => 'portrait',
987 'vimeo_byline' => 'byline',
988 ];
989
990 $params['color'] = str_replace( '#', '', $settings['color'] );
991
992 $params['autopause'] = '0';
993 } elseif ( 'dailymotion' === $settings['video_type'] ) {
994 $params_dictionary = [
995 'controls',
996 'mute',
997 'showinfo' => 'ui-start-screen-info',
998 'logo' => 'ui-logo',
999 ];
1000
1001 $params['ui-highlight'] = str_replace( '#', '', $settings['color'] );
1002
1003 $params['start'] = $settings['start'];
1004
1005 $params['endscreen-enable'] = '0';
1006 }
1007
1008 foreach ( $params_dictionary as $key => $param_name ) {
1009 $setting_name = $param_name;
1010
1011 if ( is_string( $key ) ) {
1012 $setting_name = $key;
1013 }
1014
1015 $setting_value = $settings[ $setting_name ] ? '1' : '0';
1016
1017 $params[ $param_name ] = $setting_value;
1018 }
1019
1020 return $params;
1021 }
1022
1023 /**
1024 * Whether the video widget has an overlay image or not.
1025 *
1026 * Used to determine whether an overlay image was set for the video.
1027 *
1028 * @since 1.0.0
1029 * @access protected
1030 *
1031 * @return bool Whether an image overlay was set for the video.
1032 */
1033 protected function has_image_overlay() {
1034 $settings = $this->get_settings_for_display();
1035
1036 return ! empty( $settings['image_overlay']['url'] ) && 'yes' === $settings['show_image_overlay'];
1037 }
1038
1039 /**
1040 * @since 2.1.0
1041 * @access private
1042 */
1043 private function get_embed_options() {
1044 $settings = $this->get_settings_for_display();
1045
1046 $embed_options = [];
1047
1048 if ( 'youtube' === $settings['video_type'] ) {
1049 $embed_options['privacy'] = $settings['yt_privacy'];
1050 } elseif ( 'vimeo' === $settings['video_type'] ) {
1051 $embed_options['start'] = $settings['start'];
1052 }
1053
1054 $embed_options['lazy_load'] = ! empty( $settings['lazy_load'] );
1055
1056 return $embed_options;
1057 }
1058
1059 /**
1060 * @since 2.1.0
1061 * @access private
1062 */
1063 private function get_hosted_params() {
1064 $settings = $this->get_settings_for_display();
1065
1066 $video_params = [];
1067
1068 foreach ( [ 'autoplay', 'loop', 'controls' ] as $option_name ) {
1069 if ( $settings[ $option_name ] ) {
1070 $video_params[ $option_name ] = '';
1071 }
1072 }
1073
1074 if ( $settings['mute'] ) {
1075 $video_params['muted'] = 'muted';
1076 }
1077
1078 if ( $settings['play_on_mobile'] ) {
1079 $video_params['playsinline'] = '';
1080 }
1081
1082 if ( ! $settings['download_button'] ) {
1083 $video_params['controlsList'] = 'nodownload';
1084 }
1085
1086 if ( $settings['poster']['url'] ) {
1087 $video_params['poster'] = $settings['poster']['url'];
1088 }
1089
1090 return $video_params;
1091 }
1092
1093 /**
1094 * @param bool $from_media
1095 *
1096 * @return string
1097 * @since 2.1.0
1098 * @access private
1099 */
1100 private function get_hosted_video_url() {
1101 $settings = $this->get_settings_for_display();
1102
1103 if ( ! empty( $settings['insert_url'] ) ) {
1104 $video_url = $settings['external_url']['url'];
1105 } else {
1106 $video_url = $settings['hosted_url']['url'];
1107 }
1108
1109 if ( empty( $video_url ) ) {
1110 return '';
1111 }
1112
1113 if ( $settings['start'] || $settings['end'] ) {
1114 $video_url .= '#t=';
1115 }
1116
1117 if ( $settings['start'] ) {
1118 $video_url .= $settings['start'];
1119 }
1120
1121 if ( $settings['end'] ) {
1122 $video_url .= ',' . $settings['end'];
1123 }
1124
1125 return $video_url;
1126 }
1127
1128 /**
1129 *
1130 * @since 2.1.0
1131 * @access private
1132 */
1133 private function render_hosted_video() {
1134 $video_url = $this->get_hosted_video_url();
1135 if ( empty( $video_url ) ) {
1136 return;
1137 }
1138
1139 $video_params = $this->get_hosted_params();
1140 ?>
1141 <video class="elementor-video" src="<?php echo esc_url( $video_url ); ?>" <?php echo Utils::render_html_attributes( $video_params ); ?>></video>
1142 <?php
1143 }
1144 }
1145