http://atutor.ca/atutor/mantis/view.php?id=4635
authorcindy li <cli@ocad.ca>
Fri, 17 Dec 2010 17:48:06 +0000 (17:48 -0000)
committercindy li <cli@ocad.ca>
Fri, 17 Dec 2010 17:48:06 +0000 (17:48 -0000)
Handle youTube video on blackberry. Still needs improvement at handling more complex youTube url like "?v=gtCIS3PyLwk&feature=related"

docs/include/lib/output.inc.php
docs/jscripts/ATutorYouTubeOnBlackberry.js [new file with mode: 0644]

index dbce985..e65c27e 100644 (file)
@@ -666,6 +666,8 @@ function convert_youtube_watchURL_to_playURL($youtube_watchURL) {
 }
 
 function embed_media($text) {
+       global $_base_path;
+       
        if (preg_match("/\[media(\|[0-9]+\|[0-9]+)?\]*/", $text)==0){
                return $text;
        }
@@ -682,8 +684,18 @@ function embed_media($text) {
        // Lastly, we loop through all $media_matches / $media_replaces. (We choose $media_replace as index because $media_matches is multi-dimensioned.) It is important that for each $media_matches there is a $media_replace with the same index. For each media match we check the width/height, or we use the default value of 425x350. We then replace the height/width/media1/media2 parameter placeholders in $media_replace with the correct ones, before running a str_replace on $text, replacing the given media with its correct replacement.
 
        // youtube videos
-       preg_match_all("#\[media[0-9a-z\|]*\]http://([a-z0-9\.]*)?youtube.com/watch\?v=(.*)\[/media\]#iU",$text,$media_matches[],PREG_SET_ORDER);
-       $media_replace[] = '<object width="##WIDTH##" height="##HEIGHT##"><param name="movie" value="http://##MEDIA1##youtube.com/v/##MEDIA2##"></param><embed src="http://##MEDIA1##youtube.com/v/##MEDIA2##" type="application/x-shockwave-flash" width="##WIDTH##" height="##HEIGHT##"></embed></object>';
+       if (is_mobile_device() && get_mobile_device_type() == BLACKBERRY_DEVICE) {
+               preg_match_all("#\[media[0-9a-z\|]*\]http://([a-z0-9\.]*)?youtube.com/watch\?v=(.*)\[/media\]#iU",$text,$media_matches[],PREG_SET_ORDER);
+               $media_replace[] = '<script type="text/javascript" src="'.$_base_path.'jscripts/ATutorYouTubeOnBlackberry.js"></script>'."\n".
+                       '<p id="blackberry_##MEDIA2##">'."\n".
+                       '<script'."\n".
+                       '  src="http://gdata.youtube.com/feeds/mobile/videos/##MEDIA2##?alt=json-in-script&amp;callback=ATutor.course.showYouTubeOnBlackberry&amp;format=6" [^]'."\n".
+                       '  type="text/javascript">'."\n".
+                       '</script>';
+       } else {
+               preg_match_all("#\[media[0-9a-z\|]*\]http://([a-z0-9\.]*)?youtube.com/watch\?v=(.*)\[/media\]#iU",$text,$media_matches[],PREG_SET_ORDER);
+               $media_replace[] = '<object width="##WIDTH##" height="##HEIGHT##"><param name="movie" value="http://##MEDIA1##youtube.com/v/##MEDIA2##"></param><embed src="http://##MEDIA1##youtube.com/v/##MEDIA2##" type="application/x-shockwave-flash" width="##WIDTH##" height="##HEIGHT##"></embed></object>';
+       }
        
        // .mpg
        preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).mpg\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
diff --git a/docs/jscripts/ATutorYouTubeOnBlackberry.js b/docs/jscripts/ATutorYouTubeOnBlackberry.js
new file mode 100644 (file)
index 0000000..c7b4a9c
--- /dev/null
@@ -0,0 +1,46 @@
+var ATutor = ATutor || {};
+ATutor.course = ATutor.course || {};
+
+(function() {
+       ATutor.course.showYouTubeOnBlackberry = function (data) {
+         var html = [''];
+         var entry = data.entry;
+         
+         // var to hold the rtsp link
+         var rtspUrl = '';
+         
+         // vars to hold the thumbnail info
+         var thumbnailUrl = '';
+         var thumbnailH = '10';
+         var thumbnailW = '10';
+         var idUrl = entry.id.$t;
+         var videoID = '';
+       
+         /* http://gdata.youtube.com/feeds/mobile/videos/O7BXgT413i4 */
+         if (idUrl.length > 45) {
+               videoID = idUrl.substring(45, idUrl.length);
+         }
+       
+         // get the array with the rtsp links
+         var mediacontents = entry.media$group.media$content || [];
+         if (mediacontents.length > 1) {
+               rtspUrl = mediacontents[1].url;
+         }
+         else if (mediacontents.length > 0) {
+               rtspUrl = mediacontents[0].url;
+         }
+         
+         // get array with the thumbnail links and grab the first one
+         var thumbnails = entry.media$group.media$thumbnail || [];
+         if (thumbnails.length > 0) {
+               thumbnailUrl = thumbnails[0].url;
+               thumbnailH = (thumbnails[0].height * 2);
+               thumbnailW = (thumbnails[0].width *2);
+         }
+       
+         html.push('<a href="', rtspUrl ,'"><img alt="Thumbnail picture of YouTube video (link around the picture)" src="', thumbnailUrl ,'" width="', thumbnailW ,'" height="', thumbnailH ,'" /></a>');
+         
+         document.getElementById('blackberry_' + videoID).innerHTML = html.join('');
+       }
+
+})();