]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
No regexp when parsing urls. Blip.tv support added. Style added. Fixed edit action.
authorSem <sembrestels@riseup.net>
Wed, 9 Nov 2011 19:24:56 +0000 (20:24 +0100)
committerSem <sembrestels@riseup.net>
Wed, 9 Nov 2011 19:24:56 +0000 (20:24 +0100)
actions/videolist/edit.php
lib/videolist.php
views/default/object/videolist_item.php
views/default/videolist/css.php
views/default/videolist/watch/bliptv.php [new file with mode: 0644]
views/default/videolist/watch/vimeo.php
views/default/videolist/watch/youtube.php

index 2ca99c1c44553edf91ed90978e71a66641588752..f9db7b6a28800cc0fd76e36bc63b3d4399b08580 100644 (file)
@@ -32,8 +32,9 @@ if (!$input['video_url']) {
 \r
 $parsed_url = videolist_parseurl($input['video_url']);\r
 \r
-if(!$parsed) {\r
+if(!$parsed_url) {\r
        register_error(elgg_echo('videolist:error:invalid_url'));\r
+       forward(REFERER);\r
 }\r
 \r
 if ($video_guid) {\r
index 9e29f3061517d0c39972c8803be0b89e3c11eb47..c62109b77336fd986e8d197532c5dcfb491d56cf 100644 (file)
@@ -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',
+       );
+}
index bda333a2d15c09677b13401efce5eb1f522b1708..6ed284a43aa9760b5316573b22fff44533a55217 100644 (file)
@@ -60,11 +60,12 @@ if (elgg_in_context('widgets')) {
 
 if ($full && !elgg_in_context('gallery')) {
        
-       $content= elgg_view("videolist/watch/{$entity->videotype}", array(
-               'video_id' => $entity->video_id,
+       $content = elgg_view("videolist/watch/{$entity->videotype}", array(
+               'entity' => $entity,
                'width' => 600,
                'height' => 400,
        ));
+       $content = "<div class=\"videolist-watch\">$content</div>";
 
        $params = array(
                'entity' => $entity,
index 93069181a7b9efdb69181f193e65bde611e40edc..6f2bf397dd122d90df10745299910afa7bbb688f 100644 (file)
  */
 ?>
 
+.videolist-watch {
+       margin-top: 40px;
+       margin-left: 20px;
+}
+
 .videolist_error{
        color:red;
        font-weight:bold;
diff --git a/views/default/videolist/watch/bliptv.php b/views/default/videolist/watch/bliptv.php
new file mode 100644 (file)
index 0000000..b7f72de
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+$embedurl = $vars['entity']->embedurl;
+$width = $vars['width'];
+$height = $vars['height'];
+
+echo "<iframe src=\"$embedurl\" width=\"$width\" height=\"$height\" frameborder=\"0\" allowfullscreen></iframe>";
index caf34c1f47d2331bf79714470e83e229f9840ee8..97b5e8d887fe0f9e6bf51d182909ece920a7cb6d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
-$video_id = $vars['video_id'];
+$video_id = $vars['entity']->video_id;
 $width = $vars['width'];
 $height = $vars['height'];
 
-echo "<iframe src=\"http://player.vimeo.com/video/$video_id?byline=0&amp;color=e11531&amp;autoplay=1\" width=\"$width\" height=\"$height\" frameborder=\"0\" webkitAllowFullScreen allowFullScreen></iframe>";
+echo "<iframe src=\"http://player.vimeo.com/video/$video_id?byline=0\" width=\"$width\" height=\"$height\" frameborder=\"0\" webkitAllowFullScreen allowFullScreen></iframe>";
index 4b62aabbc5406aca37ea111b7adde5f9aeffe4b1..e0b2ece066d65fc9a2f69a07fc028ef136b5d5e5 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-$video_id = $vars['video_id'];
+$video_id = $vars['entity']->video_id;
 $width = $vars['width'];
 $height = $vars['height'];