}
function embed_media($text) {
+ global $_base_path;
+
if (preg_match("/\[media(\|[0-9]+\|[0-9]+)?\]*/", $text)==0){
return $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&callback=ATutor.course.showYouTubeOnBlackberry&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);
--- /dev/null
+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('');
+ }
+
+})();