# depicter/1.3.2/app/src/Document/Models/Elements/EmbedVideo.php

Depicter — Popup &amp; Slider Builder, version 1.3.2. 139 lines.

- Page: https://pluginprobe.com/plugins/depicter/1.3.2/code/app/src/Document/Models/Elements/EmbedVideo.php
- Raw: https://pluginprobe.com/plugins/depicter/1.3.2/raw/app/src/Document/Models/Elements/EmbedVideo.php
- Modified: 2022-09-21T07:01:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/depicter/1.3.2/code/app/src/Document/Models/Elements/EmbedVideo.php#L10-L20`.

```php
<?php
namespace Depicter\Document\Models\Elements;

use Averta\Core\Utility\Arr;
use Averta\Core\Utility\Embed;
use Depicter\Document\Models;
use Depicter\Html\Html;

class EmbedVideo extends Models\Element
{

	public function render() {

//		if ( empty( $this->options->source ) || false == $videoSrc = wp_get_attachment_url( $this->options->source ) ) {
//			return '';
//		}

		$videoUrl = !empty( $this->options->source ) ? $this->options->source : '';

		$elementsAttrs = [
			'data-type' => 'video'
		];

		if( isset( $this->options->autoPlay ) ){
			$elementsAttrs['data-autoplay'] = $this->options->autoPlay ? "true" : "false";
		}
		if( isset( $this->options->autoPause ) ){
			$elementsAttrs['data-auto-pause'] = $this->options->autoPause ? "true" : "false";
		}
		if( isset( $this->options->mute ) ){
			$elementsAttrs['data-muted'] = $this->options->mute ? "true" : "false";
		}

		if( isset( $this->options->goNextSection ) ){
			$elementsAttrs['data-goto-next'] = $this->options->goNextSection ? "true" : "false";
		}
		if( isset( $this->options->loop ) ){
			$elementsAttrs['data-loop'] = $this->options->loop ? "true" : "false";
		} else {
			$elementsAttrs['data-loop'] = "true";
		}

		$args = Arr::merge( $this->getDefaultAttributes(), $elementsAttrs );

		$div = Html::div( $args );

		$video = "\n" . $this->getEmbedVideo( $videoUrl ) . "\n";

		return $div->nest( $video ) . "\n";
	}


	protected function getEmbedVideo( $videoUrl ){

		$videoType = !empty( $this->options->type ) ? $this->options->type : '';

		if( $videoType == 'youtube' ){
			return $this->getYouTubeEmbed( $videoUrl );
		} elseif( $videoType == 'vimeo' ){
			return $this->getVimeoEmbed( $videoUrl );
		}

		return '';
	}

	protected function getYouTubeEmbed( $videoUrl ){
		$embed = '';

		if( $embedUrl = Embed::getYouTubeEmbedUrl( $videoUrl ) ){
			$queryParams = [];
			if( isset( $this->options->autoPlay ) ){
				$queryParams['autoplay'] = (int) $this->options->autoPlay;
			}
			if( isset( $this->options->autoPause ) ){
				$queryParams['autopause'] = (int) $this->options->autoPause;
			}
			if( isset( $this->options->controls ) ){
				$queryParams['controls'] = (int) $this->options->controls;
			}
			if( isset( $this->options->mute ) ){
				$queryParams['mute'] = (int) $this->options->mute;
			}
			if( isset( $this->options->related ) ){
				$queryParams['rel'] = $this->options->related;
			}

			$iframeAttrs = [
				'src'             =>  add_query_arg( $queryParams, $embedUrl ),
				'frameborder' 	  => '0',
				'allow'           => 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
				'allowfullscreen' => ''
			];

			$embed = Html::iframe( $iframeAttrs );
		}

		return $embed;
	}

	protected function getVimeoEmbed( $videoUrl ){
		$embed = '';

		if( $embedUrl = Embed::getVimeoEmbedUrl( $videoUrl ) ){

			$queryParams = [];

			if( isset( $this->options->autoPlay ) ){
				$queryParams['autoplay'] = (int) $this->options->autoPlay;
			}
			if( isset( $this->options->autoPause ) ){
				$queryParams['autopause'] = (int) $this->options->autoPause;
			}
			if( isset( $this->options->controls ) ){
				$queryParams['controls'] = (int) $this->options->controls;
			}
			if( isset( $this->options->mute ) ){
				$queryParams['muted'] = (int) $this->options->mute;
			}
			if( isset( $this->options->related ) ){
				$queryParams['byline'] = (int) $this->options->related;
			}

			$iframeAttrs = [
				'src'             		=>  add_query_arg( $queryParams, $embedUrl ),
				'frameborder' 	  		=> '0',
				'allowfullscreen' 		=> '',
				'webkitallowfullscreen' => '',
				'mozallowfullscreen' 	=> ''
			];

			$embed = Html::iframe( $iframeAttrs );
		}

		return $embed;
	}
}



```
