Commit 230a9879 authored by Brett Wilkins's avatar Brett Wilkins
Browse files

Reworking vimeo media source for externalvideo



This is related to Bug #802338, removing the vague expression entirely.

I have also taken the liberty of modifying this to always use iframes,
as to better support devices without flash support.

Change-Id: I180cf1b76a25d6a0d237a315025c2c1c732f8ca6
Signed-off-by: default avatarBrett Wilkins <brett@catalyst.net.nz>
parent 781e3f8e
......@@ -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&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;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