diff options
Diffstat (limited to 'types/video_google/video_google.module')
-rw-r--r-- | types/video_google/video_google.module | 245 |
1 files changed, 0 insertions, 245 deletions
diff --git a/types/video_google/video_google.module b/types/video_google/video_google.module deleted file mode 100644 index 280275e..0000000 --- a/types/video_google/video_google.module +++ /dev/null @@ -1,245 +0,0 @@ -<?php -//$Id$ -/** - * @file - * Enable Google Video support for video module. - * - * @author Fabio Varesano <fvaresano at yahoo dot it> - * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw at gmail dot com> - * @todo - */ - - -/** - * Implementation of hook_menu -*/ -function video_google_menu() { - $items = array(); - $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'] = '<b><a href="http://video.google.com" name="video_google">' . t('Google Video support') . '</a></b>'; - $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 <em>http://video.google.com/videoplay?docid=1806507480014945777</em>')); - } - 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 = '@<img src="([^"]*)"@'; - if (preg_match($regex, $desc, $matches)) { - return $matches[1]; - } - return null; -} - - -/** - * Implementation of hook_v_auto_thumbnail -*/ -function video_google_v_auto_thumbnail($node) { - if (count($_POST)) { - if ($_POST['vidfile'] == $node->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 = '<!--[if !IE]> <--> -<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'" -data="http://video.google.com/googleplayer.swf?docId='. check_plain($videoid) .'"> -<!--> <![endif]-->' . "\n"; - - // this will be executed by Internet Explorer - $output .= '<!--[if IE]> -<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'" -classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" -codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"> -<![endif]-->' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= '<param name="movie" value="http://video.google.com/googleplayer.swf?docId=' . check_plain($videoid) . '" />' . "\n"; - // following a list of params simply copied from old embed tag params. I don't know if this are really needed. - $output .= '<param name="quality" value="best" /> - <param name="bgcolor" value="#ffffff" /> - <param name="allowScriptAccess" value="sameDomain" /> - <param name="scale" value="noScale" /> - <param name="wmode" value="transparent" /> - <param name="salign" value="TL" /> - <param name="FlashVars" value="playerMode=embedded" />' - . _video_get_parameters($node) . - '<p>'. t('Your browser is not able to display this multimedia content.') .'</p> -</object>'; - - - $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'); |