<?php
namespace Website\Widgets\VideoPlayer; use Moto; class Widget extends Moto\System\Widgets\AbstractWidget { protected $_name = 'video_player'; protected static $_defaultProperties = array( 'preset' => 'default', 'tracks' => array(), 'settings' => array( 'autoplay' => false, 'muted' => false, ), 'autoplaySettings' => array( 'forced' => false, 'onlyWhenVisible' => false, ), 'spacing' => array( 'top' => 'auto', 'right' => 'auto', 'bottom' => 'auto', 'left' => 'auto', ), 'buttons' => array( 'download' => false ) ); protected $_templateType = 'templates'; protected $_widgetId = true; public function init() { if (!isset($this->properties['version'])) { $this->properties['version'] = 1; } if ($this->properties['version'] === 1) { $this->_migrateToVersion2(); } parent::init(); } protected function _migrateToVersion2() { $track = Moto\Util::getValue($this->properties, 'tracks.0'); if (is_array($track)) { $track = array( 'webm' => array( 'id' => null, 'name' => null, 'path' => null, 'filesize' => null, 'length' => null, ), 'mp4' => $track, ); $this->properties['tracks'][0] = $track; } $this->properties['version'] = 2; } public function getTrackTitle($track) { $value = Moto\Util::getValue($track, 'webm.name'); if (empty($value)) { $value = Moto\Util::getValue($track, 'mp4.name'); } return $value; } public function getTrackDuration($track) { $value = Moto\Util::getValue($track, 'webm.length'); if (empty($value)) { $value = Moto\Util::getValue($track, 'mp4.length'); } return $value; } public function exportButtons() { return json_encode($this->properties['buttons']); } } 