From bacdeaa7d3dca73e1346cd67aedc6ae13d4ef615 Mon Sep 17 00:00:00 2001 From: Heshan Wanigasooriya Date: Mon, 27 Apr 2009 09:48:39 +0000 Subject: adding includes files --- includes/apiclient.inc | 134 ++++++++++++++++ includes/common.inc | 423 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 557 insertions(+) create mode 100644 includes/apiclient.inc create mode 100644 includes/common.inc diff --git a/includes/apiclient.inc b/includes/apiclient.inc new file mode 100644 index 0000000..4caad24 --- /dev/null +++ b/includes/apiclient.inc @@ -0,0 +1,134 @@ + + * porting to Drupal 6 + * @author Heshan Wanigasooriya + * @todo + */ + + +/** +* When an include file requires to read an xml to receive information, such as for thumbnails, +* this script can be used to request the xml and return it as an array. +* Note that this is a modified function from the flickr.module, made to handle this type of +* call more generically. also, i suspect it could be done easier (and more quickly) in php 5. +* @param $provider +* the string of the third party provider, such as 'youtube' or 'google' +* @param $url +* the url for the xml request +* @param $args +* an array of args to pass to the xml url +* @param $cacheable +* optional; if true, the result of this xml request will be cached. good to play nice w/ +* the third party folks so they don't stop providing service to your site... +* @return +* the xml results returned as an array +*/ +function _video_apiclient_request_xml($provider, $url, $args = array(), $cacheable = true) { + ksort($args); + + // build an argument hash that we'll use for the cache id and api signing + $arghash = $provider . ':'; + foreach($args as $k => $v){ + $arghash .= $k . $v; + } + + // build the url + foreach ($args as $k => $v){ + $encoded_params[] = urlencode($k).'='.urlencode($v); + } + $url .= '?'. implode('&', $encoded_params); + + // if it's a cachable request, try to load a cached value + if ($cacheable) { + if ($cache = cache_get($arghash, 'cache')) { + return unserialize($cache->data); + } + } + + // connect and fetch a value + $result = drupal_http_request($url); + + if ($result->code == 200) { + $parser = drupal_xml_parser_create($result->data); + $vals = array(); + $index = array(); + xml_parse_into_struct($parser, $result->data, $vals, $index); + xml_parser_free($parser); + + $params = array(); + $level = array(); + $start_level = 1; + foreach ($vals as $xml_elem) { + if ($xml_elem['type'] == 'open') { + if (array_key_exists('attributes',$xml_elem)) { + list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']); + } else { + $level[$xml_elem['level']] = $xml_elem['tag']; + } + } + if ($xml_elem['type'] == 'complete') { + $php_stmt = '$params'; + while($start_level < $xml_elem['level']) { + $php_stmt .= '[$level['.$start_level.']]'; + $start_level ++; + } + $php_stmt .= '[$xml_elem[\'tag\']][] = $xml_elem[\'value\'];'; + eval($php_stmt); + $start_level--; + } + } + + // save a cacheable result for future use + if ($cacheable) { + cache_set($arghash, 'cache', time() + 3600, serialize($params)); + } + return $params; + } + return array(); +} + + +/** +* Create a file object from thumbnail images from providers +* to allow for automatic thumbnailing of videos from providers +* @param $node +* the video node being called +* @return +* a file object containing the thumbnail file +*/ +/* +function _video_apiclient_provider_auto_thumbnail($node) { + // get thumbnail url + if(_video_get_filetype($node->vidfile) == 'youtube') { + $thumbnail = _video_apiclient_youtube_thumbnail($node->vidfile); + } + else { + $thumbnail = _video_apiclient_google_thumbnail($node->vidfile); + } + + // save image to temp directory for processing + $image = image_gd_open($thumbnail, 'jpeg'); + $location = file_directory_temp() .'/'. $node->vidfile .'.jpg'; + image_gd_close($image, $location, 'jpeg'); + + + // get info and build a file object + $filepath = file_create_path($location, file_directory_temp()); + $info = image_get_info($filepath); + + $file = new stdClass(); + $file->filepath = realpath($filepath); + $file->filename = basename($file->filepath); + $file->filesize = $info['file_size']; + $file->filemime = $info['mime_type']; + + return $file; +} +*/ + diff --git a/includes/common.inc b/includes/common.inc new file mode 100644 index 0000000..221f27e --- /dev/null +++ b/includes/common.inc @@ -0,0 +1,423 @@ + + * porting to Drupal 6 + * @author Heshan Wanigasooriya + * @todo + */ + + + + + +/** + * Get the object for the suitable player for the parameter resource +*/ +function _video_common_get_player($node) { + switch (_video_get_filetype($node->vidfile)) { + case 'divx': + return theme('video_play_divx', $node); + case 'mov': + case 'mp4': + case '3gp': + case '3g2': + case 'mpg': + return theme('video_play_quicktime', $node); + case 'rm': + return theme('video_play_realmedia', $node); + case 'flv': + return theme('video_play_flash', $node); + case 'swf': + return theme('video_play_swf', $node); + case 'dir': + case 'dcr': + return theme('video_play_dcr', $node); + case 'asf': + case 'wmv': + case 'avi': + return theme('video_play_windowsmedia', $node); + case 'ogg': + return theme('video_play_ogg_theora', $node); + case 'youtube': + return theme('video_play_youtube', $node); + case 'googlevideo': + return theme('video_play_googlevideo', $node); + default: + drupal_set_message('Video type not supported', 'error'); + break; + } +} + +/********************************************************************* + * Themeable functions for playing videos. They print a page with a player embedded. + *********************************************************************/ + + /** + * Play videos from in FLV Flash video format + * + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_play_flash($node) { + $loader_location = variable_get('video_flvplayerloader', 'FlowPlayer.swf'); + + $url = _video_get_fileurl($node->vidfile); + $file = basename($url); + $base_url = substr($url, 0, strrpos($url, '/')); + + $height = $node->video_scaled_y + 24; // add commands height + + // this will be executed by not Internet Explorer browsers + $output = ' + + ' . "\n"; + + // this will be executed by Internet Explorer + $output .= '' . "\n"; + + // params will be passed to both IE or not IE browsers + $output .= ' + + + + ' . "\n" + . _video_get_parameters($node) . + '

'. t('Your browser is not able to display this multimedia content.') .'

+
'; + + $output = theme('video_format_play', $output, t('http://www.macromedia.com/go/getflashplayer'), + t('Link to Macromedia Flash Player Download Page'), + t('Download latest Flash Player')); + return $output; +} + +/** + * Play Flash .swf files. + * + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_play_swf($node) { + + $url = _video_get_fileurl($node->vidfile); + + // this will be executed by not Internet Explorer browsers + $output = ' + + ' . "\n"; + + // this will be executed by Internet Explorer + $output .= '' . "\n"; + + // params will be passed to both IE or not IE browsers + $output .= ''. "\n" . + '' . "\n" + . _video_get_parameters($node) . + '

'. t('Your browser is not able to display this multimedia content.') .'

+
'; + + $output = theme('video_format_play', $output, t('http://www.macromedia.com/go/getflashplayer'), t('Link to Flash player download'), t('Download the latest Flash player')); + return $output; +} + + + +/** + * Play Director .dcr/.dir files. + * + * @param $node + * object with node information + * + * @return + * string of content to display + */ + +function theme_video_play_dcr($node) { + + $url = _video_get_fileurl($node->vidfile); + + // this will be executed by not Internet Explorer browsers + $output = ' + + ' . "\n"; + + // this will be executed by Internet Explorer + $output .= '' . "\n"; + +// params will be passed to both IE or not IE browsers + $output .= '' . "\n" + . _video_get_parameters($node) . + '

'. t('Your browser is not able to display this multimedia content.') .'

+
'; + + $output = theme('video_format_play', $output, t('http://www.macromedia.com/shockwave/download/'), + t('Link to Macromedia Shockwave Player Download Page'), + t('Download latest Shockwave Player')); + return $output; +} + +/** + * Play videos from in DivX format + * + * @see http://developer.apple.com/internet/ieembedprep.html + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_play_divx($node) { + //Increase the height to accommodate the player controls on the bottom. + $height = $node->video_scaled_y + 20; + + $url = _video_get_fileurl($node->vidfile); + + $output = ' + + '. "\n"; + // this will be executed by not Internet Explorer browsers + $output = ' + + '."\n"; + + $output .= ''."\n"; + $output .= ''."\n"; + $output .= ''; + $output = theme('video_format_play', $output,t('http://www.divx.com/divx/webplayer/'), + t('Link to DivX Download Page'), + t('Download latest DivX Web Player')); + return $output; +} + +/** + * Play videos from in Quicktime format + * + * @see http://developer.apple.com/internet/ieembedprep.html + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_play_quicktime($node) { + //Increase the height to accommodate the player controls on the bottom. + $height = $node->video_scaled_y + 16; + + $url = _video_get_fileurl($node->vidfile); + + + // this will be executed by not Internet Explorer browsers + $output = ' + + ' . "\n"; + + // this will be executed by Internet Explorer + $output .= '' . "\n"; + + // params will be passed to both IE or not IE browsers + $output .= ' + + ' . "\n" + . _video_get_parameters($node) . + '

'. t('Your browser is not able to display this multimedia content.') .'

+
'; // only one
needed becouse only one opening tag has been parsed by browsers + + + /* + $output = ''; + */ + + + $output = theme('video_format_play', $output, t('http://www.apple.com/quicktime/download'), + t('Link to QuickTime Download Page'), + t('Download latest Quicktime Player')); + return $output; +} + +/** + * Play videos from in Realmedia format + * + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_play_realmedia($node) { + // Real's embeded player includes the controls + // in the height + $node->video_scaled_y += 40; + + $url = _video_get_fileurl($node->vidfile); + + // this will be executed by not Internet Explorer browsers + $output = ' + + ' . "\n"; + + // this will be executed by Internet Explorer + $output .= '' . "\n"; + + // params will be passed to both IE or not IE browsers + $output .= ' + + + + + + + + + + + + + ' + . _video_get_parameters($node) . + '

'. t('Your browser is not able to display this multimedia content.') .'

+
'; // only one needed becouse only one opening tag has been parsed by browsers + + + $output = theme('video_format_play', $output, t('http://www.real.com/'), + t('Link to Real'), + t('Download latest Realmedia Player')); + return $output; +} + +/** + * Play videos from in WindowsMediaVideo format + * + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_play_windowsmedia($node) { + // Windows Media's embeded player includes the controls in the height + $node->video_scaled_y += 68; + $url = _video_get_fileurl($node->vidfile); + + // this will be executed by not Internet Explorer browsers + $output = ' + + ' . "\n"; + + // this will be executed by Internet Explorer + $output .= '' . "\n"; + + // params will be passed to both IE or not IE browsers + $output .= ' + + + + + + ' + . _video_get_parameters($node) . + '

'. t('Your browser is not able to display this multimedia content.') .'

+
'; // only one needed becouse only one opening tag has been parsed by browsers + + + $output = theme('video_format_play', $output, t('http://windowsupdate.microsoft.com/'), + t('Link to Windows Update'), + t('Download latest Windows Media Player')); + return $output; +} + + + + +/** + * Play Ogg Theora videos with Cortado Applet + * + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_play_ogg_theora($node) { + global $base_url; + $cortado_location = variable_get('video_cortado', $base_url . '/cortado.jar'); + $url = _video_get_fileurl($node->vidfile); + + $width = ($node->video_scaled_x ? $node->video_scaled_x : '425'); + $height = ($node->video_scaled_y ? $node->video_scaled_y : '350'); + + $output = ' + + + + + + + + + + + + + + + + + + + + This browser does not have a Java Plug-in.
+ + Get the latest Java Plug-in here. + +
+
+ '; + + $output = theme('video_format_play', $output, + t('http://java.com/download/'), t('Link to java.com'), t('Download Java')); + return $output; +} + -- cgit v1.2.3