-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoYouTube.php
72 lines (60 loc) · 1.76 KB
/
VideoYouTube.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
*
* VideoYoutube Class
*
* El Widget permite mostrar un video de YouTube
*
* @copyright
*
* Copyright (c) 2012 Jose Oscar Vogel
*
* Se permite el uso, modificacion y distribucion del contenido del mismo
*
* Ejemplo de uso:
* $this->widget('ext.video.VideoYouTube',
* array('htmlOptions'=>array(
* 'width'=>640,
* 'height'=>480,
* 'src'=>'http://www.youtube.com/watch?v=yePBXsH7LhI',
* )));
*/
class VideoYouTube extends CWidget{
public $htmlOptions = array();
public $defaultHtmlOptions = array();
public function init(){
if (!isset($this->htmlOptions['src']))
throw new CException('Debe setear el atributo "src" en "htmlOptions".');
$this->defaultHtmlOptions = array('width' => '600', 'height' => '500');
$this->htmlOptions = CMap::mergeArray($this->defaultHtmlOptions, $this->htmlOptions);
}
public function run(){
$this->RenderContent();
}
protected function renderContent()
{
echo CHtml::openTag('iframe',array(
'src'=>'http://www.youtube.com/embed/'. $this->getYouTubeCode($this->htmlOptions['src']) . '?rel=' .
(isset($this->htmlOptions['rel']) ? $this->htmlOptions['rel'] : '1') . '&border=' .
(isset($this->htmlOptions['border']) ? $this->htmlOptions['border'] : '0'),
'type'=>'application/x-shockwave-flash',
'width'=>$this->htmlOptions['width'],
'height'=>$this->htmlOptions['height'],
));
echo CHtml::closeTag('iframe');
}
/**
* Obtiene el codigo de YouTube de un link de YouTube
* @param string link
* @return string YouTube codigo
*/
protected function getYouTubeCode($link)
{
$pos = strrpos ($link, '/');
if($pos !== false)
return substr($link, $pos);
else
return '';
}
}
?>