- fix layout Meta Blog: - added Vimeo video - fix YouTube, Vimeo preview image - fix URL rulemaster
@ -0,0 +1,86 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* Created by Error202 |
||||||
|
* Date: 06.07.2018 |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace core\helpers; |
||||||
|
|
||||||
|
|
||||||
|
class VideoHelper |
||||||
|
{ |
||||||
|
public static function identityProvider($url) |
||||||
|
{ |
||||||
|
if (preg_match('%youtube|youtu\.be%i', $url)) { |
||||||
|
return 'youtube'; |
||||||
|
} |
||||||
|
elseif (preg_match('%vimeo%i', $url)) { |
||||||
|
return 'vimeo'; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static function getThumb($url) |
||||||
|
{ |
||||||
|
$src = ''; |
||||||
|
switch (self::identityProvider($url)) { |
||||||
|
case 'youtube': |
||||||
|
$id = VideoHelper::parseYoutubeUrl($url); |
||||||
|
$src = 'https://i.ytimg.com/vi/' . $id . '/maxresdefault.jpg'; |
||||||
|
break; |
||||||
|
case 'vimeo': |
||||||
|
$id = VideoHelper::parseVimeoUrl($url); |
||||||
|
$data = file_get_contents("http://vimeo.com/api/v2/video/$id.json"); |
||||||
|
$data = json_decode($data); |
||||||
|
$src = $data[0]->thumbnail_large; |
||||||
|
break; |
||||||
|
} |
||||||
|
return $src; |
||||||
|
} |
||||||
|
|
||||||
|
public static function parseVimeoUrl($url) |
||||||
|
{ |
||||||
|
$urls = parse_url($url); |
||||||
|
// https://vimeo.com/274720181 |
||||||
|
if($urls['host'] == 'vimeo.com'){ |
||||||
|
$id = ltrim($urls['path'],'/'); |
||||||
|
} |
||||||
|
// https://player.vimeo.com/video/274720181 |
||||||
|
else { |
||||||
|
$parts = explode('/',$urls['path']); |
||||||
|
$id = end($parts); |
||||||
|
} |
||||||
|
|
||||||
|
return $id; |
||||||
|
} |
||||||
|
|
||||||
|
public static function parseYoutubeUrl($url) |
||||||
|
{ |
||||||
|
$urls = parse_url($url); |
||||||
|
//url is http://youtu.be/xxxx |
||||||
|
if($urls['host'] == 'youtu.be'){ |
||||||
|
$id = ltrim($urls['path'],'/'); |
||||||
|
} |
||||||
|
//url is http://www.youtube.com/embed/xxxx |
||||||
|
else if(strpos($urls['path'],'embed') == 1){ |
||||||
|
$parts = explode('/',$urls['path']); |
||||||
|
$id = end($parts); |
||||||
|
} |
||||||
|
//url is xxxx only |
||||||
|
else if(strpos($url,'/')===false){ |
||||||
|
$id = $url; |
||||||
|
} |
||||||
|
//http://www.youtube.com/watch?feature=player_embedded&v=m-t4pcO99gI |
||||||
|
//url is http://www.youtube.com/watch?v=xxxx |
||||||
|
else{ |
||||||
|
parse_str($urls['query']); |
||||||
|
/* @var $v */ |
||||||
|
$id = $v; |
||||||
|
if(!empty($feature)){ |
||||||
|
$id = end(explode('v=',$urls['query'])); |
||||||
|
} |
||||||
|
} |
||||||
|
return $id; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* Created by Error202 |
||||||
|
* Date: 06.07.2018 |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace core\widgets; |
||||||
|
|
||||||
|
|
||||||
|
use yii\base\Widget; |
||||||
|
use core\helpers\VideoHelper; |
||||||
|
|
||||||
|
class VideoWidget extends Widget |
||||||
|
{ |
||||||
|
public $src; |
||||||
|
|
||||||
|
public $width = 640; |
||||||
|
public $height = 360; |
||||||
|
public $style = "width: 100%"; |
||||||
|
|
||||||
|
public function run() { |
||||||
|
$player = ''; |
||||||
|
switch (VideoHelper::identityProvider($this->src)) { |
||||||
|
case 'youtube': |
||||||
|
$id = VideoHelper::parseYoutubeUrl($this->src); |
||||||
|
$player = '<iframe style="'.$this->style.'" width="'.$this->width.'" height="'.$this->height.'" src="https://www.youtube.com/embed/'.$id.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'; |
||||||
|
break; |
||||||
|
case 'vimeo': |
||||||
|
$id = VideoHelper::parseVimeoUrl($this->src); |
||||||
|
$player = '<iframe style="'.$this->style.'" src="https://player.vimeo.com/video/'.$id.'" width="'.$this->width.'" height="'.$this->height.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; |
||||||
|
break; |
||||||
|
} |
||||||
|
return $player; |
||||||
|
} |
||||||
|
} |
Before Width: | Height: | Size: 167 KiB |
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 98 KiB |
Before Width: | Height: | Size: 220 KiB |
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 166 KiB |
Before Width: | Height: | Size: 135 KiB |
Before Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 164 KiB |
Before Width: | Height: | Size: 186 KiB |
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 110 KiB |
Before Width: | Height: | Size: 254 KiB |
Before Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 148 KiB |
Before Width: | Height: | Size: 183 KiB |
Before Width: | Height: | Size: 154 KiB |
Before Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 133 KiB |
Before Width: | Height: | Size: 189 KiB |
Before Width: | Height: | Size: 351 KiB |
Before Width: | Height: | Size: 187 KiB After Width: | Height: | Size: 213 KiB |
Before Width: | Height: | Size: 286 KiB |
Before Width: | Height: | Size: 389 KiB |
Before Width: | Height: | Size: 301 KiB |
Before Width: | Height: | Size: 231 KiB |
Before Width: | Height: | Size: 270 KiB |
Before Width: | Height: | Size: 386 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 191 KiB |
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 264 KiB |
Before Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 150 KiB |
Before Width: | Height: | Size: 188 KiB |
Before Width: | Height: | Size: 160 KiB |
Before Width: | Height: | Size: 117 KiB |
Before Width: | Height: | Size: 138 KiB |
Before Width: | Height: | Size: 194 KiB |
Before Width: | Height: | Size: 69 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 342 KiB |
Before Width: | Height: | Size: 556 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 267 KiB After Width: | Height: | Size: 192 KiB |
Before Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 630 KiB |
Before Width: | Height: | Size: 364 KiB |
Before Width: | Height: | Size: 849 KiB |
Before Width: | Height: | Size: 695 KiB |
Before Width: | Height: | Size: 350 KiB |
Before Width: | Height: | Size: 364 KiB |
Before Width: | Height: | Size: 560 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 28 KiB |