| 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( !empty( $this->options->muted ) ){ |
| 26 |
$elementsAttrs['data-muted'] = $this->options->muted ? "true" : "false"; |
| 27 |
} else if( !empty( $this->options->mute ) ){ |
| 28 |
$elementsAttrs['data-muted'] = $this->options->mute ? "true" : "false"; |
| 29 |
} |
| 30 |
|
| 31 |
$playerType = [ 'native', 'youtube', 'vimeo' ]; |
| 32 |
$elementsAttrs['data-player-type'] = isset( $this->options->type ) && in_array( $this->options->type, $playerType ) ? $this->options->type : "native"; |
| 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'] = "false"; |
| 41 |
} |
| 42 |
|
| 43 |
if( !empty( $this->options->related ) ){ |
| 44 |
$elementsAttrs['data-limit-related'] = $this->options->related ? "true" : "false"; |
| 45 |
} |
| 46 |
|
| 47 |
if( !empty( $this->options->startingTime ) ){ |
| 48 |
$elementsAttrs['data-starting-time'] = $this->options->startingTime ?? "0"; |
| 49 |
} |
| 50 |
|
| 51 |
if( !empty( $this->options->endingTime ) ){ |
| 52 |
$elementsAttrs['data-ending-time'] = $this->options->endingTime ?? "null"; |
| 53 |
} |
| 54 |
|
| 55 |
$elementsAttrs['data-controls'] = isset( $this->options->controls ) ? esc_attr( $this->options->controls ) : "true"; |
| 56 |
|
| 57 |
$elementsAttrs['data-video-src'] = $videoUrl; |
| 58 |
if ( $elementsAttrs['data-player-type'] == 'youtube' && !empty( $videoUrl ) ) { |
| 59 |
$elementsAttrs['data-video-poster'] = Embed::getYouTubePosterUrl( $videoUrl ); |
| 60 |
} |
| 61 |
|
| 62 |
$args = Arr::merge( $this->getDefaultAttributes(), $elementsAttrs ); |
| 63 |
|
| 64 |
return Html::div( $args ); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|