PluginProbe
Depicter — Popup & Slider Builder / 1.6.2
Depicter — Popup & Slider Builder v1.6.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.6.2, at app/src/Document/Models/Elements/EmbedVideo.php

139 lines 3.6 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
12 public function render() {
13
14 // if ( empty( $this->options->source ) || false == $videoSrc = wp_get_attachment_url( $this->options->source ) ) {
15 // return '';
16 // }
17
18 $videoUrl = !empty( $this->options->source ) ? $this->options->source : '';
19
20 $elementsAttrs = [
21 'data-type' => 'video'
22 ];
23
24 if( isset( $this->options->autoPlay ) ){
25 $elementsAttrs['data-autoplay'] = $this->options->autoPlay ? "true" : "false";
26 }
27 if( isset( $this->options->autoPause ) ){
28 $elementsAttrs['data-auto-pause'] = $this->options->autoPause ? "true" : "false";
29 }
30 if( isset( $this->options->mute ) ){
31 $elementsAttrs['data-muted'] = $this->options->mute ? "true" : "false";
32 }
33
34 if( isset( $this->options->goNextSection ) ){
35 $elementsAttrs['data-goto-next'] = $this->options->goNextSection ? "true" : "false";
36 }
37 if( isset( $this->options->loop ) ){
38 $elementsAttrs['data-loop'] = $this->options->loop ? "true" : "false";
39 } else {
40 $elementsAttrs['data-loop'] = "true";
41 }
42
43 $args = Arr::merge( $this->getDefaultAttributes(), $elementsAttrs );
44
45 $div = Html::div( $args );
46
47 $video = "\n" . $this->getEmbedVideo( $videoUrl ) . "\n";
48
49 return $div->nest( $video ) . "\n";
50 }
51
52
53 protected function getEmbedVideo( $videoUrl ){
54
55 $videoType = !empty( $this->options->type ) ? $this->options->type : '';
56
57 if( $videoType == 'youtube' ){
58 return $this->getYouTubeEmbed( $videoUrl );
59 } elseif( $videoType == 'vimeo' ){
60 return $this->getVimeoEmbed( $videoUrl );
61 }
62
63 return '';
64 }
65
66 protected function getYouTubeEmbed( $videoUrl ){
67 $embed = '';
68
69 if( $embedUrl = Embed::getYouTubeEmbedUrl( $videoUrl ) ){
70 $queryParams = [];
71 if( isset( $this->options->autoPlay ) ){
72 $queryParams['autoplay'] = (int) $this->options->autoPlay;
73 }
74 if( isset( $this->options->autoPause ) ){
75 $queryParams['autopause'] = (int) $this->options->autoPause;
76 }
77 if( isset( $this->options->controls ) ){
78 $queryParams['controls'] = (int) $this->options->controls;
79 }
80 if( isset( $this->options->mute ) ){
81 $queryParams['mute'] = (int) $this->options->mute;
82 }
83 if( isset( $this->options->related ) ){
84 $queryParams['rel'] = $this->options->related;
85 }
86
87 $iframeAttrs = [
88 'src' => add_query_arg( $queryParams, $embedUrl ),
89 'frameborder' => '0',
90 'allow' => 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
91 'allowfullscreen' => ''
92 ];
93
94 $embed = Html::iframe( $iframeAttrs );
95 }
96
97 return $embed;
98 }
99
100 protected function getVimeoEmbed( $videoUrl ){
101 $embed = '';
102
103 if( $embedUrl = Embed::getVimeoEmbedUrl( $videoUrl ) ){
104
105 $queryParams = [];
106
107 if( isset( $this->options->autoPlay ) ){
108 $queryParams['autoplay'] = (int) $this->options->autoPlay;
109 }
110 if( isset( $this->options->autoPause ) ){
111 $queryParams['autopause'] = (int) $this->options->autoPause;
112 }
113 if( isset( $this->options->controls ) ){
114 $queryParams['controls'] = (int) $this->options->controls;
115 }
116 if( isset( $this->options->mute ) ){
117 $queryParams['muted'] = (int) $this->options->mute;
118 }
119 if( isset( $this->options->related ) ){
120 $queryParams['byline'] = (int) $this->options->related;
121 }
122
123 $iframeAttrs = [
124 'src' => add_query_arg( $queryParams, $embedUrl ),
125 'frameborder' => '0',
126 'allowfullscreen' => '',
127 'webkitallowfullscreen' => '',
128 'mozallowfullscreen' => ''
129 ];
130
131 $embed = Html::iframe( $iframeAttrs );
132 }
133
134 return $embed;
135 }
136 }
137
138
139