forked from heartshare/yii2-video-embed-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoEmbed.php
54 lines (41 loc) · 1.64 KB
/
VideoEmbed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @copyright Copyright © CICSolutions, CICSolutions.com, 2014
* @package yii2-video-embed-widget
* @version 1.0.0
*/
namespace cics\widgets;
use yii\helpers\Html;
class VideoEmbed extends \yii\base\Widget
{
public $url = null;
public $show_errors = false;
public $responsive = true;
public $container_id = '';
public $container_class = '';
public function run()
{
// make sure a source url was provided
if (is_null($this->url) || empty($this->url))
return $this->show_errors ? 'Please pass a URL parameter to scan for a video to embed.' : false;
// include embed class
include_once(__DIR__ . '/../../../vendor/embed/embed/src/autoloader.php');
// look up data for the supplied url
$data = \Embed\Embed::create($this->url);
// make sure we received a video embed code from the lookup
if (!is_object($data) || is_null($data->code))
return $this->show_errors ? "Embed code could not be generated for this URL ({$this->url})" : false;
// build the video container with custom id and class if desired
$custom_container = !empty($this->container_id) || !empty($this->container_class);
$video_embed = $custom_container ? '<div id="' . $this->container_id . '" class="' . $this->container_class . '">' : '';
// also set responsiveness class (video-container) if desired
$video_embed .= $this->responsive ? '<div class="video-container">' : '';
// insert the embed code
$video_embed .= $data->code;
// close the containers
$video_embed .= $this->responsive ? '</div>' : '';
$video_embed .= $custom_container ? '</div>' : '';
// return the video embed code
return $video_embed;
}
}