Commit 02e403ed authored by Francois Marier's avatar Francois Marier Committed by Gerrit Code Review
Browse files

Merge "Reworking vimeo media source for externalvideo"

parents 15316d63 230a9879
......@@ -8,30 +8,18 @@ class Media_vimeo implements MediaBase {
private static $default_width = 400;
private static $default_height = 225;
private static $embed_sources = array(
private static $iframe_sources = array(
array(
'match' => '#http://vimeo\.com/([0-9]+)#',
'url' => 'http://vimeo.com/moogaloop.swf?clip_id=$1&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1&autoplay=0&loop=0'
'match' => '#.*http://vimeo\.com/moogaloop\.swf\?clip_id=([0-9]+).*#',
'url' => 'http://player.vimeo.com/video/$1'
),
array(
'match' => '#<iframe src="http://player\.vimeo\.com/video/(.+)" width="([0-9]+)" height="([0-9]+)" frameborder="([0-9]+)"></iframe>#',
'url' => 'http://player.vimeo.com/video/$1'
),
array(
'match' => '#<embed src="http://(.+)" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="([0-9]+)" height="([0-9]+)"></embed>#',
'url' => 'http://$1'
'match' => '#.*http://player\.vimeo\.com/video/([0-9]+).*#',
'url' => 'http://player.vimeo.com/video/$1'
),
array(
'match' => '#http://vimeo\.com/moogaloop\.swf\?(.+)#',
'url' => 'http://vimeo.com/moogaloop.swf?$1'
),
array(
'match' => '#http://player\.vimeo\.com/video/([0-9]+)#',
'url' => 'http://player.vimeo.com/video/$1'
'match' => '#https?://(www\.|secure\.)?vimeo\.com/([0-9]+)#',
'url' => 'http://player.vimeo.com/video/$2'
),
);
......@@ -39,22 +27,18 @@ class Media_vimeo implements MediaBase {
public function process_url($input, $width=0, $height=0) {
$width = $width ? (int)$width : self::$default_width;
$height = $height ? (int)$height : self::$default_height;
$input = self::clean_input($input);
foreach (self::$embed_sources as $source) {
foreach (self::$iframe_sources as $source) {
if (preg_match($source['match'], $input)) {
$output = preg_replace($source['match'], $source['url'], $input);
$result = array(
'videoid' => $output,
'type' => 'embed',
'type' => 'iframe',
'width' => $width,
'height' => $height,
);
if (preg_match(self::$embed_sources[4]['match'], $output)) {
$result['type'] = 'iframe';
}
return $result;
}
}
......@@ -62,7 +46,7 @@ class Media_vimeo implements MediaBase {
}
public function validate_url($input) {
foreach (self::$embed_sources as $source) {
foreach (self::$iframe_sources as $source) {
if (preg_match($source['match'], $input)) {
return true;
}
......@@ -73,17 +57,4 @@ class Media_vimeo implements MediaBase {
public function get_base_url() {
return self::$base_url;
}
private function clean_input($input) {
//Strip out unnecessary tags.
$replace = array(
'#<p>(.+)</p>#',
'#<object width="([0-9]+)" height="([0-9]+)">#',
'#<param name="(.+)" value="(.+)" />#',
'#</object>#',
);
$input = preg_replace($replace, '', $input);
return $input;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment