aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2011-11-09 20:24:56 +0100
committerSem <sembrestels@riseup.net>2011-11-09 20:24:56 +0100
commitf2280654f8aaa33964e62c27a9cab6c96372ba57 (patch)
treef4a8ee2d358d6f8d55ec9875fcce49550d16ba2f /lib
parentb0f15fbebe3781626ba6b086d63ed364f6822209 (diff)
downloadelgg-f2280654f8aaa33964e62c27a9cab6c96372ba57.tar.gz
elgg-f2280654f8aaa33964e62c27a9cab6c96372ba57.tar.bz2
No regexp when parsing urls. Blip.tv support added. Style added. Fixed edit action.
Diffstat (limited to 'lib')
-rw-r--r--lib/videolist.php104
1 files changed, 57 insertions, 47 deletions
diff --git a/lib/videolist.php b/lib/videolist.php
index 9e29f3061..c62109b77 100644
--- a/lib/videolist.php
+++ b/lib/videolist.php
@@ -1,81 +1,77 @@
<?php
-define('YOUTUBE', 1);
-define('VIMEO', 2);
-define('METACAFE', 3);
-
function videolist_parseurl_youtube($url) {
- if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(youtube\.com\/)(.*)/', $url, $matches)) {
- return false;
- }
-
- $domain = $matches[2] . $matches[3];
- $path = $matches[4];
-
- if (!preg_match('/^(watch\?v=)([a-zA-Z0-9_-]*)(&.*)?$/',$path, $matches)) {
- return false;
+ $parsed = parse_url($url);
+ parse_str($parsed['query'], $query);
+
+ if ($parsed['host'] != 'www.youtube.com' || $parsed['path'] != '/watch' || !isset($query['v'])) {
+ return false;
}
-
- $hash = $matches[2];
return array(
- 'domain' => $domain,
- 'video_id' => $hash,
+ 'videotype' => 'youtube',
+ 'video_id' => $query['v'],
);
}
function videolist_parseurl_vimeo($url) {
- if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)*(vimeo\.com\/)(.*)/', $url, $matches)) {
+ $parsed = parse_url($url);
+ $path = explode('/', $parsed['path']);
+
+ if ($parsed['host'] != 'vimeo.com' || !(int) $path[1]) {
return false;
}
- $domain = $matches[2] . $matches[3];
- $hash = $matches[4];
-
return array(
- 'domain' => $domain,
- 'video_id' => $hash,
+ 'videotype' => 'vimeo',
+ 'video_id' => $path[1],
);
}
function videolist_parseurl_metacafe($url) {
- if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(metacafe\.com\/)(.*)/', $url, $matches)) {
+ $parsed = parse_url($url);
+ $path = explode('/', $parsed['path']);
+
+ if ($parsed['host'] != 'www.metacafe.com' || $path[1] != 'watch' || !(int) $path[2]) {
return false;
}
+
+ return array(
+ 'videotype' => 'metacafe',
+ 'video_id' => $path[2],
+ );
+}
- $domain = $matches[2] . $matches[3];
- $path = $matches[4];
-
- $hash = $matches[2];
+function videolist_parseurl_bliptv($url) {
+ $parsed = parse_url($url);
+ $path = explode('/', $parsed['path']);
+ if ($parsed['host'] != 'blip.tv' || count($path) < 3) {
+ return false;
+ }
+
return array(
- 'domain' => $domain,
- 'video_id' => $hash,
+ 'videotype' => 'bliptv',
+ 'video_id' => $parsed['path'],
);
}
function videolist_parseurl($url){
- if ($parsed = videolist_parseurl_youtube($url)){
- $parsed['site'] = YOUTUBE;
- return $parsed;
- } elseif ($parsed = videolist_parseurl_vimeo($url)) {
- $parsed['site'] = VIMEO;
- return $parsed;
- } elseif ($parsed = videolist_parseurl_metacafe($url)) {
- $parsed['site'] = METACAFE;
- return $parsed;
- } else {
- return array();
- }
+ if ($parsed = videolist_parseurl_youtube($url)) return $parsed;
+ elseif ($parsed = videolist_parseurl_vimeo($url)) return $parsed;
+ elseif ($parsed = videolist_parseurl_metacafe($url)) return $parsed;
+ elseif ($parsed = videolist_parseurl_bliptv($url)) return $parsed;
+ else return array();
}
function videolist_get_data($video_parsed_url) {
- $site = $video_parsed_url['site'];
+ $videotype = $video_parsed_url['videotype'];
$video_id = $video_parsed_url['video_id'];
- switch($site){
- case YOUTUBE: return videolist_get_data_youtube($video_id);
- case VIMEO: return videolist_get_data_vimeo($video_id);
- case METACAFE: return videolist_get_data_metacafe($video_id);
+ switch($videotype){
+ case 'youtube': return videolist_get_data_youtube($video_id);
+ case 'vimeo': return videolist_get_data_vimeo($video_id);
+ case 'metacafe': return videolist_get_data_metacafe($video_id);
+ case 'bliptv': return videolist_get_data_bliptv($video_id);
default: return array();
}
}
@@ -127,3 +123,17 @@ function videolist_get_data_metacafe($video_id){ //FIXME
'videotype' => 'metacafe',
);
}
+
+function videolist_get_data_bliptv($video_id){
+ $buffer = file_get_contents('http://blip.tv'.$video_id.'?skin=rss');
+ $xml = new SimpleXMLElement($buffer);
+
+ return array(
+ 'title' => current($xml->xpath('/rss/channel/item/title')),
+ 'description' => current($xml->xpath('/rss/channel/item/description')),
+ 'thumbnail' => current($xml->xpath('/rss/channel/item/media:thumbnail/@url')),
+ 'embedurl' => current($xml->xpath('/rss/channel/item/blip:embedUrl')),
+ 'video_id' => $video_id,
+ 'videotype' => 'bliptv',
+ );
+}