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

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