aboutsummaryrefslogtreecommitdiff
path: root/lib/Videolist/Platform/Youtube.php
diff options
context:
space:
mode:
authorSteve Clay <steve@mrclay.org>2012-04-10 09:51:45 -0400
committerSteve Clay <steve@mrclay.org>2012-04-10 09:51:45 -0400
commit595f87c960f0d0b01ebd386686d522f25fa56b91 (patch)
treef463996bf325d472a1df6b43a7f4c8d943c22f5c /lib/Videolist/Platform/Youtube.php
parent6d4ac854d8f0a4480ffe16f2bd2a7861707074ee (diff)
downloadelgg-595f87c960f0d0b01ebd386686d522f25fa56b91.tar.gz
elgg-595f87c960f0d0b01ebd386686d522f25fa56b91.tar.bz2
Handle shortened Youtube URLs
Diffstat (limited to 'lib/Videolist/Platform/Youtube.php')
-rw-r--r--lib/Videolist/Platform/Youtube.php30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/Videolist/Platform/Youtube.php b/lib/Videolist/Platform/Youtube.php
index 41c7d1252..648ac282c 100644
--- a/lib/Videolist/Platform/Youtube.php
+++ b/lib/Videolist/Platform/Youtube.php
@@ -10,16 +10,28 @@ class Videolist_Platform_Youtube implements Videolist_PlatformInterface
public function parseUrl($url)
{
$parsed = parse_url($url);
- parse_str($parsed['query'], $query);
-
- if ($parsed['host'] != 'www.youtube.com' || $parsed['path'] != '/watch' || !isset($query['v'])) {
- return false;
+ $id = '';
+ if (! empty($parsed['host'])) {
+ if ($parsed['host'] === 'youtu.be') {
+ // short URLs
+ $id = substr($parsed['path'], 1);
+ } elseif ($parsed['host'] === 'www.youtube.com'
+ && $parsed['path'] === '/watch'
+ && ! empty($parsed['query'])) {
+ // long URLs
+ parse_str($parsed['query'], $query);
+ if (! empty($query['v'])) {
+ $id = $query['v'];
+ }
+ }
}
-
- return array(
- 'videotype' => 'youtube',
- 'video_id' => $query['v'],
- );
+ if ($id) {
+ return array(
+ 'videotype' => 'youtube',
+ 'video_id' => $id,
+ );
+ }
+ return false;
}
public function getData($parsed)