| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Elements; |
| 3 |
|
| 4 |
use Averta\Core\Utility\Arr; |
| 5 |
use Depicter; |
| 6 |
use Depicter\Document\Models; |
| 7 |
use Depicter\Html\Html; |
| 8 |
|
| 9 |
class Video extends Models\Element |
| 10 |
{ |
| 11 |
|
| 12 |
public function render() { |
| 13 |
|
| 14 |
if ( empty( $this->options->source ) ) { |
| 15 |
return ''; |
| 16 |
} |
| 17 |
|
| 18 |
$elementsAttrs = []; |
| 19 |
|
| 20 |
if( isset( $this->options->autoPlay ) ){ |
| 21 |
$elementsAttrs['data-autoplay'] = $this->options->autoPlay ? "true" : "false"; |
| 22 |
} |
| 23 |
if( isset( $this->options->autoPause ) ){ |
| 24 |
$elementsAttrs['data-auto-pause'] = $this->options->autoPause ? "true" : "false"; |
| 25 |
} |
| 26 |
|
| 27 |
if( isset( $this->options->goNextSection ) ){ |
| 28 |
$elementsAttrs['data-goto-next'] = $this->options->goNextSection ? "true" : "false"; |
| 29 |
} |
| 30 |
if( isset( $this->options->loop ) ){ |
| 31 |
$elementsAttrs['data-loop'] = $this->options->loop ? "true" : "false"; |
| 32 |
} else { |
| 33 |
$elementsAttrs['data-loop'] = "false"; |
| 34 |
} |
| 35 |
|
| 36 |
$playerType = [ 'native', 'youtube', 'vimeo' ]; |
| 37 |
$elementsAttrs['data-player-type'] = isset( $this->options->type ) && in_array( $this->options->type, $playerType ) ? $this->options->type : "native"; |
| 38 |
|
| 39 |
if( !empty( $this->options->muted ) ){ |
| 40 |
$elementsAttrs['data-muted'] = $this->options->muted ? "true" : "false"; |
| 41 |
} else if( !empty( $this->options->mute ) ){ |
| 42 |
$elementsAttrs['data-muted'] = $this->options->mute ? "true" : "false"; |
| 43 |
} |
| 44 |
|
| 45 |
if( !empty( $this->options->related ) ){ |
| 46 |
$elementsAttrs['data-limit-related'] = $this->options->related ? "true" : "false"; |
| 47 |
} |
| 48 |
|
| 49 |
if( !empty( $this->options->startingTime ) ){ |
| 50 |
$elementsAttrs['data-starting-time'] = $this->options->startingTime ?? "0"; |
| 51 |
} |
| 52 |
|
| 53 |
if( !empty( $this->options->endingTime ) ){ |
| 54 |
$elementsAttrs['data-ending-time'] = $this->options->endingTime ?? "null"; |
| 55 |
} |
| 56 |
|
| 57 |
$elementsAttrs['data-controls'] = esc_attr( $this->options->controls ) ?? "true"; |
| 58 |
|
| 59 |
$elementsAttrs['data-video-src'] = Depicter::media()->getSourceUrl( $this->options->source ); |
| 60 |
|
| 61 |
$elementsAttrs = Arr::merge( $this->getDefaultAttributes(), $elementsAttrs ); |
| 62 |
if ( isset( $elementsAttrs['data-height'] ) ) { |
| 63 |
$elementsAttrs['data-height'] = 'auto,,'; |
| 64 |
} |
| 65 |
|
| 66 |
$div = Html::div( $elementsAttrs ); |
| 67 |
|
| 68 |
if ( false !== $a = $this->getLinkTag() ) { |
| 69 |
return $a->nest( $div ); |
| 70 |
} |
| 71 |
|
| 72 |
return $div . "\n"; |
| 73 |
} |
| 74 |
} |
| 75 |
|