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

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