PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Models / Elements / EmbedVideo.php

EmbedVideo.php in Depicter — Popup & Slider Builder 1.9.2, at app/src/Document/Models/Elements/EmbedVideo.php

134 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document\Models\Elements;
3
4 use Averta\Core\Utility\Arr;
5 use Averta\Core\Utility\Embed;
6 use Depicter\Document\Models;
7 use Depicter\Html\Html;
8
9 class EmbedVideo extends Models\Element{
10
11 public function render() {
12
13 $videoUrl = !empty( $this->options->source ) ? $this->options->source : '';
14
15 $elementsAttrs = [
16 'data-type' => 'video'
17 ];
18
19 if( isset( $this->options->autoPlay ) ){
20 $elementsAttrs['data-autoplay'] = $this->options->autoPlay ? "true" : "false";
21 }
22 if( isset( $this->options->autoPause ) ){
23 $elementsAttrs['data-auto-pause'] = $this->options->autoPause ? "true" : "false";
24 }
25 if( isset( $this->options->mute ) ){
26 $elementsAttrs['data-muted'] = $this->options->mute ? "true" : "false";
27 }
28
29 if( isset( $this->options->goNextSection ) ){
30 $elementsAttrs['data-goto-next'] = $this->options->goNextSection ? "true" : "false";
31 }
32 if( isset( $this->options->loop ) ){
33 $elementsAttrs['data-loop'] = $this->options->loop ? "true" : "false";
34 } else {
35 $elementsAttrs['data-loop'] = "true";
36 }
37
38 $args = Arr::merge( $this->getDefaultAttributes(), $elementsAttrs );
39
40 $div = Html::div( $args );
41
42 $video = "\n" . $this->getEmbedVideo( $videoUrl ) . "\n";
43
44 return $div->nest( $video ) . "\n";
45 }
46
47
48 protected function getEmbedVideo( $videoUrl ){
49
50 $videoType = !empty( $this->options->type ) ? $this->options->type : '';
51
52 if( $videoType == 'youtube' ){
53 return $this->getYouTubeEmbed( $videoUrl );
54 } elseif( $videoType == 'vimeo' ){
55 return $this->getVimeoEmbed( $videoUrl );
56 }
57
58 return '';
59 }
60
61 protected function getYouTubeEmbed( $videoUrl ){
62 $embed = '';
63
64 if( $embedUrl = Embed::getYouTubeVimeoEmbedUrl( $videoUrl ) ){
65 $queryParams = [];
66 if( isset( $this->options->autoPlay ) ){
67 $queryParams['autoplay'] = (int) $this->options->autoPlay;
68 }
69 if( isset( $this->options->autoPause ) ){
70 $queryParams['autopause'] = (int) $this->options->autoPause;
71 }
72 if( isset( $this->options->controls ) ){
73 $queryParams['controls'] = (int) $this->options->controls;
74 }
75 if( isset( $this->options->mute ) ){
76 $queryParams['mute'] = (int) $this->options->mute;
77 }
78 if( isset( $this->options->related ) ){
79 $queryParams['rel'] = $this->options->related;
80 }
81
82 $iframeAttrs = [
83 'src' => add_query_arg( $queryParams, $embedUrl ),
84 'frameborder' => '0',
85 'allow' => 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
86 'allowfullscreen' => ''
87 ];
88
89 $embed = Html::iframe( $iframeAttrs );
90 }
91
92 return $embed;
93 }
94
95 protected function getVimeoEmbed( $videoUrl ){
96 $embed = '';
97
98 if( $embedUrl = Embed::getYouTubeVimeoEmbedUrl( $videoUrl ) ){
99
100 $queryParams = [];
101
102 if( isset( $this->options->autoPlay ) ){
103 $queryParams['autoplay'] = (int) $this->options->autoPlay;
104 }
105 if( isset( $this->options->autoPause ) ){
106 $queryParams['autopause'] = (int) $this->options->autoPause;
107 }
108 if( isset( $this->options->controls ) ){
109 $queryParams['controls'] = (int) $this->options->controls;
110 }
111 if( isset( $this->options->mute ) ){
112 $queryParams['muted'] = (int) $this->options->mute;
113 }
114 if( isset( $this->options->related ) ){
115 $queryParams['byline'] = (int) $this->options->related;
116 }
117
118 $iframeAttrs = [
119 'src' => add_query_arg( $queryParams, $embedUrl ),
120 'frameborder' => '0',
121 'allowfullscreen' => '',
122 'webkitallowfullscreen' => '',
123 'mozallowfullscreen' => ''
124 ];
125
126 $embed = Html::iframe( $iframeAttrs );
127 }
128
129 return $embed;
130 }
131 }
132
133
134