| 1 |
<?php
|
| 2 |
// $Id: google.inc,v 1.7 2008/05/11 04:00:41 alexua Exp $
|
| 3 |
|
| 4 |
define('VIDEO_CCK_GOOGLE_MAIN_URL', 'http://video.google.com/');
|
| 5 |
define('VIDEO_CCK_GOOGLE_XML', 'http://video.google.com/videofeed');
|
| 6 |
define('VIDEO_CCK_GOOGLE_DOMAIN_DEFAULT', 'com');
|
| 7 |
|
| 8 |
function video_cck_google_info() {
|
| 9 |
$name = t('Google');
|
| 10 |
$features = array(
|
| 11 |
array(t('Autoplay'), t('Yes'), ''),
|
| 12 |
array(t('RSS Attachment'), t('Yes'), ''),
|
| 13 |
array(t('Thumbnails'), t('Yes'), ''),
|
| 14 |
);
|
| 15 |
return array(
|
| 16 |
'provider' => 'google',
|
| 17 |
'name' => $name,
|
| 18 |
'url' => VIDEO_CCK_GOOGLE_MAIN_URL,
|
| 19 |
'settings_description' => t('These settings specifically affect videos displayed from !google.', array('!google' => l($name, VIDEO_CCK_GOOGLE_MAIN_URL, array('target' => '_blank')))),
|
| 20 |
'supported_features' => $features,
|
| 21 |
);
|
| 22 |
}
|
| 23 |
|
| 24 |
function video_cck_google_settings() {
|
| 25 |
$form = array();
|
| 26 |
$form['video_cck_google_domain'] = array(
|
| 27 |
'#type' => 'textfield',
|
| 28 |
'#title' => t('Google video domain'),
|
| 29 |
'#default_value' => variable_get('video_cck_google_domain', VIDEO_CCK_GOOGLE_DOMAIN_DEFAULT),
|
| 30 |
'#description' => t('Google hosts their videos on various servers throughout the world. By default, videos from Google will be displayed from the United States, at their google.<b><em>com</em></b> servers. If you wish to display the video from another Google server, please enter the domain here, without the initial dot. For instance, you might enter <b><em>it</em></b> for the Italian Google servers at google.it, or <b><em>ca</em></b> for their Canadian servers.'),
|
| 31 |
);
|
| 32 |
return $form;
|
| 33 |
}
|
| 34 |
|
| 35 |
function video_cck_google_extract($embed) {
|
| 36 |
return array(
|
| 37 |
'@http://video\.google(?:\.[a-z]{2,4})+/videoplay\?docid=([^\&]*)\&@i',
|
| 38 |
'@http://video\.google(?:\.[a-z]{2,4})+/videoplay\?docid=([^\&]*)\&@i',
|
| 39 |
'@http://video\.google(?:\.[a-z]{2,4})+/videoplay\?docid=(.*)@i',
|
| 40 |
'@http://video\.google(?:\.[a-z]{2,4})+/googleplayer\.swf\?docId=(-?\d*)@i',
|
| 41 |
'@http://video\.google(?:\.[a-z]{2,4})+/url\?docid=([^\&]*)\&@i',
|
| 42 |
);
|
| 43 |
}
|
| 44 |
|
| 45 |
function video_cck_google_request($embed, $cacheable = TRUE) {
|
| 46 |
$args = array('docid' => $embed);
|
| 47 |
return module_invoke('emfield', 'request_xml', 'google', VIDEO_CCK_GOOGLE_XML, $args, $cacheable);
|
| 48 |
}
|
| 49 |
|
| 50 |
function video_cck_google_video_link($video_code) {
|
| 51 |
return 'http://video.google.'. variable_get('video_cck_google_domain', VIDEO_CCK_GOOGLE_DOMAIN_DEFAULT) .'/videoplay?docid='. $video_code;
|
| 52 |
}
|
| 53 |
|
| 54 |
function theme_video_cck_google_flash($embed, $width, $height, $autoplay) {
|
| 55 |
if ($embed) {
|
| 56 |
$autoplay = $autoplay ? '&autoPlay=true' : '';
|
| 57 |
// this will be executed by not Internet Explorer browsers
|
| 58 |
$output = '<!--[if !IE]> <-->
|
| 59 |
<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
|
| 60 |
data="http://video.google.'. variable_get('video_cck_google_domain', VIDEO_CCK_GOOGLE_DOMAIN_DEFAULT) .'/googleplayer.swf?docId='. check_plain($embed) . $autoplay .'">
|
| 61 |
<!--> <![endif]-->'."\n";
|
| 62 |
|
| 63 |
// this will be executed by Internet Explorer
|
| 64 |
$output .= '<!--[if IE]>
|
| 65 |
<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
|
| 66 |
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
|
| 67 |
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
|
| 68 |
<![endif]-->'."\n";
|
| 69 |
|
| 70 |
// params will be passed to both IE or not IE browsers
|
| 71 |
$output .= '<param name="movie" value="http://video.google.'. variable_get('video_cck_google_domain', VIDEO_CCK_GOOGLE_DOMAIN_DEFAULT) .'/googleplayer.swf?docId='. check_plain($embed) . $autoplay .'" />'."\n";
|
| 72 |
// following a list of params simply copied from old embed tag params. I don't know if this are really needed.
|
| 73 |
$output .= '<param name="quality" value="best" />
|
| 74 |
<param name="bgcolor" value="#ffffff" />
|
| 75 |
<param name="allowScriptAccess" value="sameDomain" />
|
| 76 |
<param name="scale" value="noScale" />
|
| 77 |
<param name="wmode" value="transparent" />
|
| 78 |
<param name="salign" value="TL" />
|
| 79 |
<param name="FlashVars" value="playerMode=embedded" />
|
| 80 |
<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
|
| 81 |
</object>';
|
| 82 |
}
|
| 83 |
return $output;
|
| 84 |
}
|
| 85 |
|
| 86 |
/**
|
| 87 |
* hook emfield_PROVIDER_data
|
| 88 |
*
|
| 89 |
* provides an array to be serialised and made available with $item elsewhere
|
| 90 |
*/
|
| 91 |
function video_cck_google_data($field, $item) {
|
| 92 |
$data = array();
|
| 93 |
// create some 'field' version control
|
| 94 |
//$data['video_cck_google_version'] = 1;
|
| 95 |
|
| 96 |
$rss = video_cck_google_request($item['value']);
|
| 97 |
|
| 98 |
if (
|
| 99 |
is_array($rss['ITEM']) &&
|
| 100 |
is_array($rss['ITEM']['MEDIA:GROUP']) &&
|
| 101 |
is_array($rss['ITEM']['MEDIA:GROUP']['MEDIA:CONTENT']) &&
|
| 102 |
is_array($rss['ITEM']['MEDIA:GROUP']['MEDIA:CONTENT'][1])
|
| 103 |
) {
|
| 104 |
$video = $rss['ITEM']['MEDIA:GROUP']['MEDIA:CONTENT'][1];
|
| 105 |
$data['filepath'] = $video['URL'];
|
| 106 |
$data['filemime'] = $video['TYPE'];
|
| 107 |
$data['medium'] = $video['MEDIUM'];
|
| 108 |
$data['expression'] = $video['EXPRESSION'];
|
| 109 |
$data['duration'] = $video['DURATION'];
|
| 110 |
$data['width'] = $video['WIDTH'];
|
| 111 |
$data['height'] = $video['HEIGHT'];
|
| 112 |
}
|
| 113 |
|
| 114 |
if (is_array($rss['MEDIA:GROUP'])) {
|
| 115 |
if (is_array($rss['MEDIA:GROUP']['MEDIA:THUMBNAIL']) && is_array($rss['MEDIA:GROUP']['MEDIA:THUMBNAIL'][1])) {
|
| 116 |
$thumbnail = $rss['MEDIA:GROUP']['MEDIA:THUMBNAIL'][1];
|
| 117 |
$data['thumbnail']['filepath'] = $thumbnail['URL'];
|
| 118 |
$data['thumbnail']['width'] = $thumbnail['WIDTH'];
|
| 119 |
$data['thumbnail']['height'] = $thumbnail['HEIGHT'];
|
| 120 |
}
|
| 121 |
if (is_array($rss['MEDIA:GROUP']['MEDIA:PLAYER']) && is_array($rss['MEDIA:GROUP']['MEDIA:PLAYER'][1])) {
|
| 122 |
$data['player']['filepath'] = $rss['MEDIA:GROUP']['MEDIA:PLAYER'][1]['URL'];
|
| 123 |
}
|
| 124 |
}
|
| 125 |
|
| 126 |
if ($data['thumbnail']['filepath'] == '') {
|
| 127 |
// for whatever reason the thumbnail failed try the old method
|
| 128 |
// we'll parse it from the description, where it's repeated.
|
| 129 |
$desc = $rss['ITEM']['DESCRIPTION'][0];
|
| 130 |
$regex = '@<img src="([^"]*)"@';
|
| 131 |
if (preg_match($regex, $desc, $matches)) {
|
| 132 |
$data['thumbnail']['filepath'] = $matches[1];
|
| 133 |
}
|
| 134 |
}
|
| 135 |
|
| 136 |
// google rss doesn't actually have <embeded> media, just MRSS, and no size
|
| 137 |
// so not actually really really necessary or really useful but for completeness
|
| 138 |
$play = 'http://video.google.'. variable_get('video_cck_google_domain', VIDEO_CCK_GOOGLE_DOMAIN_DEFAULT) .'/googleplayer.swf?docId='. check_plain($item['embed']);
|
| 139 |
$response = emfield_request_header('google', $play, FALSE, FALSE);
|
| 140 |
|
| 141 |
if ($response->code == 200) {
|
| 142 |
$data['filesize'] = $response->headers['Content-Length'];
|
| 143 |
}
|
| 144 |
|
| 145 |
return $data;
|
| 146 |
}
|
| 147 |
|
| 148 |
function video_cck_google_rss($item, $teaser) {
|
| 149 |
if ($item['value']) {
|
| 150 |
if ($item['data']['video_cck_google_data_version'] >= 1000000) {
|
| 151 |
$data = $item['data'];
|
| 152 |
}
|
| 153 |
else {
|
| 154 |
$data = video_cck_google_data(NULL, $item);
|
| 155 |
}
|
| 156 |
|
| 157 |
return $data;
|
| 158 |
}
|
| 159 |
}
|
| 160 |
|
| 161 |
function video_cck_google_thumbnail($field, $item, $formatter, $node, $width, $height) {
|
| 162 |
if ($item['data']['video_cck_google_data_version'] >= 1) {
|
| 163 |
$data = $item['data'];
|
| 164 |
}
|
| 165 |
else {
|
| 166 |
$data = video_cck_google_data($field, $item);
|
| 167 |
}
|
| 168 |
|
| 169 |
return $data['thumbnail']['filepath'];
|
| 170 |
|
| 171 |
return NULL;
|
| 172 |
}
|
| 173 |
|
| 174 |
function video_cck_google_video($embed, $width, $height, $field, $item, $autoplay) {
|
| 175 |
$output = theme('video_cck_google_flash', $embed, $width, $height, $autoplay);
|
| 176 |
return $output;
|
| 177 |
}
|
| 178 |
|
| 179 |
function video_cck_google_preview($embed, $width, $height, $field, $item, $autoplay) {
|
| 180 |
$output = theme('video_cck_google_flash', $embed, $width, $height, $autoplay);
|
| 181 |
return $output;
|
| 182 |
}
|