From 8914e5e66485a1cb9ee1fb741ae47a561167104e Mon Sep 17 00:00:00 2001 From: Heshan Wanigasooriya Date: Mon, 27 Apr 2009 09:40:04 +0000 Subject: add video types to the latest version --- types/video_google/video_google.module | 248 +++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 types/video_google/video_google.module (limited to 'types/video_google/video_google.module') diff --git a/types/video_google/video_google.module b/types/video_google/video_google.module new file mode 100644 index 0000000..88e17c7 --- /dev/null +++ b/types/video_google/video_google.module @@ -0,0 +1,248 @@ + + * porting to Drupal 6 + * @author Heshan Wanigasooriya + * @todo + */ + + +/** + * Implementation of hook_menu +*/ +function video_google_menu() { + $items = array(); + $maycache=true; + if($maycache) { + $items['node/add/video/google'] = array( + 'title' => 'Google', + 'access arguments' => array('create video') + ); + } + return $items; +} + + +/** + * Implementation of hook_v_help +*/ +function video_google_v_help() { + + $help = array(); + $help['google']['data'] = '' . t('Google Video support') . ''; + $help['google']['children'] = array(t('You can host videos on video.google.com and put them on your site. + To do this, after you upload the video on Google video you just have to get the URL of the video.')); + + return $help; +} + + +/** + * Implementation of hook_v_info() +*/ +function video_google_v_info() { + $info['google'] = array( + '#name' => 'Google Video', + '#description' => t('Post a video available on !link to this website.', array('!link' => l(t('Google Video'), 'http://video.google.com'), NULL, NULL, NULL, TRUE)), + '#autothumbable' => true, + '#autoresolution' => true, + '#autoplaytime' => false, // seems that thereisn't a video lenght field in the google video xml + ); + + return $info; +} + + +/** + * Implementation of hook_v_form() +*/ +function video_google_v_form(&$node, &$form) { + + $form['video']['vidfile'] = array( + '#type' => 'textfield', + '#title' => t('Google Video URL'), + '#default_value' => $node->vidfile, + '#maxlength' => 700, + '#required' => TRUE, + '#weight' => -20, + '#description' => t('Insert the URL to the google video. ') . l(t('More information.'), 'video/help', array('fragment' => 'videofile'))); + + return $form; +} + + + +/** + * implementation of hook_v_validate +*/ +function video_google_v_validate($node) { + // TODO: use youtube REST or XML-RPC to query youtube: check video available and embeddable + if(!preg_match("/^http:\/\/video\.google\.com\/videoplay\?docid=/", $node->vidfile)) { + form_set_error('vidfile', t('The Google Video URL field must be similar to http://video.google.com/videoplay?docid=1806507480014945777')); + } + else { + //get the video id + $id = _video_google_get_id($node->vidfile); + + $response = _video_apiclient_google_request($id); + if(count($response) == 0) { // google video wasn't able to find the video + form_set_error('vidfile', t('The system was not able to find this video on Google Video. Please check the URL of your Google video.')); + } + } +} + + +/** + * Implementation of hook_v_play +*/ +function video_google_v_play($node) { + return theme('video_google_play', $node); +} + + + +/** AUTOTHUMBNAILING LOGIC */ + +define('VIDEO_GOOGLE_XML', 'http://video.google.com/videofeed'); + +function _video_apiclient_google_request($id, $cacheable = TRUE) { + $args = array('docid' => $id); + return _video_apiclient_request_xml('google', VIDEO_GOOGLE_XML, $args, $cacheable); +} + +function _video_apiclient_google_get_thumbnail_url($id) { + + $xml = _video_apiclient_google_request($id); + + // we *should* be able to use media:thumbnail + // but unfortunately, that is stripped out from the request hook + // so instead, we'll parse it from the description, where it's repeated. + // TODO: look into how to fix this... + $desc = $xml['ITEM']['DESCRIPTION'][0]; + $regex = '@vidfile) { + _video_image_thumbnail_debug(t('No new video to thumbnail')); + return NULL; + } + if ($_POST['tempimage']['fids']['_original']) { + _video_image_thumbnail_debug(t('Video already thumbnailed')); + return NULL; + } + } + // let's include apiclient logic + + //get the video id + if (!$node->vidfile && count($_POST)) { + $vidfile = $_POST['vidfile']; + } else { + $vidfile = $node->vidfile; + } + $id = _video_google_get_id($vidfile); + // get thumbnail url + $thumbnail_url = _video_apiclient_google_get_thumbnail_url($id); + + return _video_image_get_thumb_file_object($thumbnail_url, $id); +} + + +/** + * Implementation of hook_v_auto_resolution +*/ +function video_google_v_auto_resolution(&$node) { + // we set google videos to 400x326 by default + return array(400, 326); +} + + + +/** THEMEABLE FUNCTIONS */ + +/** + * Play videos hosted on video.google.com + * Allows users to host videos on video.google.com and then use the video ID to post it in the module. + * + * @param $node + * object with node information + * + * @return + * string of content to display + */ +function theme_video_google_play($node) { + $width = ($node->video_scaled_x ? $node->video_scaled_x : '425'); + $height = ($node->video_scaled_y ? $node->video_scaled_y : '350'); + // Strip heading "google:" + $videoid = _video_google_get_id(check_plain($node->vidfile)); + //$videoid = substr($node->vidfile, 7); + + // 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"; + // following a list of params simply copied from old embed tag params. I don't know if this are really needed. + $output .= ' + + + + + + ' + . _video_get_parameters($node) . + '

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

+
'; + + + $output = theme('video_format_play', $output, t('http://video.google.com/support'), t('Link to video.google.com'), t('video.google.com')); + return $output; +} + + + +/** HELPER FUNCTIONS */ + +/** + * Get the docid from an URL +*/ +function _video_google_get_id($url) { + $pattern = '/-?[0-9]+/'; // maybe too weak? some id have a leading - + preg_match_all($pattern, $url, $matches, PREG_PATTERN_ORDER); + return $matches[0][0]; +} + +/** + * Implementation of hook_theme(). + */ +function video_google_theme() { + return array( + 'video_google_play' => array( + 'arguments' => array('node' => NULL), + ), + ); +} + +module_load_include('inc', 'video', 'includes/apiclient'); -- cgit v1.2.3