| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
define('VIDEO_CCK_USTREAM_MAIN_URL', 'http://www.ustream.tv/');
|
| 5 |
define('VIDEO_CCK_USTREAM_API_INFO', 'http://developer.ustream.tv/');
|
| 6 |
define('VIDEO_CCK_USTREAM_API_APPLICATION_URL', 'http://developer.ustream.tv/apps/register');
|
| 7 |
// define('VIDEO_CCK_USTREAM_REST_ENDPOINT', 'http://www.ustream.tv/api2_rest');
|
| 8 |
// define('VIDEO_CCK_USTREAM_COLOR1_DEFAULT', '#FFFFFF');
|
| 9 |
// define('VIDEO_CCK_USTREAM_COLOR2_DEFAULT', '#CCCCCC');
|
| 10 |
|
| 11 |
/**
|
| 12 |
* hook video_cck_PROVIDER_info
|
| 13 |
* this returns information relevant to a specific 3rd party video provider
|
| 14 |
* @return
|
| 15 |
* an array of strings requested by various admin and other forms
|
| 16 |
* 'name' => the translated name of the provider
|
| 17 |
* 'url' => the url to the main page for the provider
|
| 18 |
* 'settings_description' => a description of the provider that will be posted in the admin settings form
|
| 19 |
* 'supported_features' => an array of rows describing the state of certain supported features by the provider.
|
| 20 |
* These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
|
| 21 |
*/
|
| 22 |
function video_cck_ustream_info() {
|
| 23 |
$name = t('UStream.TV');
|
| 24 |
$features = array(
|
| 25 |
array(t('Autoplay'), t('No'), ''),
|
| 26 |
array(t('RSS Attachment'), t('No'), ''),
|
| 27 |
array(t('Thumbnails'), t('No'), t('')),
|
| 28 |
);
|
| 29 |
return array(
|
| 30 |
'provider' => 'ustream',
|
| 31 |
'name' => $name,
|
| 32 |
'url' => VIDEO_CCK_USTREAM_MAIN_URL,
|
| 33 |
'settings_description' => t('These settings specifically affect videos displayed from !ustream. You can learn more about its !api here.', array('!ustream' => l($name, VIDEO_CCK_USTREAM_MAIN_URL, array('target' => '_blank')), '!api' => l(t('API'), VIDEO_CCK_USTREAM_API_INFO, array('target' => '_blank')))),
|
| 34 |
'supported_features' => $features,
|
| 35 |
);
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* hook video_cck_PROVIDER_settings
|
| 40 |
* this should return a subform to be added to the video_cck_settings() admin settings page.
|
| 41 |
* note that a form field will already be provided, at $form['PROVIDER'] (such as $form['ustream'])
|
| 42 |
* so if you want specific provider settings within that field, you can add the elements to that form field.
|
| 43 |
*/
|
| 44 |
function video_cck_ustream_settings() {
|
| 45 |
$form['ustream']['api'] = array(
|
| 46 |
'#type' => 'fieldset',
|
| 47 |
'#title' => t('UStream.TV API'),
|
| 48 |
'#description' => t('The API is required for thumbnails and other features.You will first need to apply for an API Developer Key from the !ustream.', array('!ustream' => l(t('Ustream Application Registration page'), VIDEO_CCK_USTREAM_API_APPLICATION_URL, array('target' => '_blank')))),
|
| 49 |
'#collapsible' => TRUE,
|
| 50 |
'#collapsed' => TRUE,
|
| 51 |
);
|
| 52 |
$form['ustream']['api']['video_cck_ustream_api_key'] = array(
|
| 53 |
'#type' => 'textfield',
|
| 54 |
'#title' => t('UStream.TV API Key'),
|
| 55 |
'#default_value' => variable_get('video_cck_ustream_api_key', ''),
|
| 56 |
'#description' => t('Please enter your UStream.TV API Key here.'),
|
| 57 |
);
|
| 58 |
return $form;
|
| 59 |
}
|
| 60 |
|
| 61 |
/**
|
| 62 |
* this is a wrapper for video_cck_request_xml that includes ustream's api key
|
| 63 |
*/
|
| 64 |
function video_cck_ustream_request($code = '', $cached = TRUE) {
|
| 65 |
$key = trim(variable_get('video_cck_ustream_api_key', ''));
|
| 66 |
$url = "http://api.ustream.tv/php/video/$code/getInfo?key=$key";
|
| 67 |
|
| 68 |
return module_invoke('emfield', 'request_xml', 'ustream', $url, array(), $cached, FALSE, $code, TRUE);
|
| 69 |
}
|
| 70 |
|
| 71 |
function video_cck_ustream_data($field, $item) {
|
| 72 |
$data = video_cck_ustream_request($item['value']);
|
| 73 |
$data['ustream_api_version'] = 1;
|
| 74 |
return $data;
|
| 75 |
}
|
| 76 |
|
| 77 |
/**
|
| 78 |
* hook video_cck_PROVIDER_extract
|
| 79 |
* this is called to extract the video code from a pasted URL or embed code.
|
| 80 |
* @param $embed
|
| 81 |
* an optional string with the pasted URL or embed code
|
| 82 |
* @return
|
| 83 |
* either an array of regex expressions to be tested, or a string with the video code to be used
|
| 84 |
* if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array.
|
| 85 |
* otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
|
| 86 |
*/
|
| 87 |
function video_cck_ustream_extract($embed = '') {
|
| 88 |
// http://www.ustream.tv/recorded/570233
|
| 89 |
return array(
|
| 90 |
'@ustream\.tv/recorded/([^"\&\?]+)@i',
|
| 91 |
);
|
| 92 |
}
|
| 93 |
|
| 94 |
/**
|
| 95 |
* hook video_cck_PROVIDER_embedded_link($video_code)
|
| 96 |
* returns a link to view the video at the provider's site
|
| 97 |
* @param $video_code
|
| 98 |
* the string containing the video to watch
|
| 99 |
* @return
|
| 100 |
* a string containing the URL to view the video at the original provider's site
|
| 101 |
*/
|
| 102 |
function video_cck_ustream_embedded_link($video_code) {
|
| 103 |
return 'http://www.ustream.tv/recorded/' . $video_code;
|
| 104 |
}
|
| 105 |
|
| 106 |
/**
|
| 107 |
* the embedded flash displaying the ustream video
|
| 108 |
*/
|
| 109 |
function theme_video_cck_ustream_flash($embed, $width, $height, $autoplay, $options = array()) {
|
| 110 |
static $counter;
|
| 111 |
if ($embed) {
|
| 112 |
$counter++;
|
| 113 |
$autoplay = isset($options['autoplay']) ? $options['autoplay'] : $autoplay;
|
| 114 |
$autoplay_value = $autoplay ? 'true' : 'false';
|
| 115 |
|
| 116 |
$output .= "<object type='application/x-shockwave-flash' height='$height' width='$width' data='http://ustream.tv/flash/video/$embed' id='ustream-video-$counter' ><param name='movie' value='http://www.ustream.tv/flash/video/$embed' /><param name='allowScriptAccess' value='always' /><param name='quality' value='best' /><param name='scale' value='noScale' /><param name='wmode' value='transparent' /><param name='FlashVars' value='autoplay=$autoplay_value' /><param name='allowfullscreen' value='true' /></object>";
|
| 117 |
}
|
| 118 |
return $output;
|
| 119 |
}
|
| 120 |
|
| 121 |
/**
|
| 122 |
* hook video_cck_PROVIDER_thumbnail
|
| 123 |
* returns the external url for a thumbnail of a specific video
|
| 124 |
* TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
|
| 125 |
* @param $field
|
| 126 |
* the field of the requesting node
|
| 127 |
* @param $item
|
| 128 |
* the actual content of the field from the requesting node
|
| 129 |
* @return
|
| 130 |
* a URL pointing to the thumbnail
|
| 131 |
*/
|
| 132 |
function video_cck_ustream_thumbnail($field, $item, $formatter, $node, $width, $height, $options = array()) {
|
| 133 |
$ustream_id = $item['value'];
|
| 134 |
// old code to grab thumbnail via api
|
| 135 |
// $request = video_cck_ustream_request('ustream.videos.get_details', array('video_id' => $ustream_id));
|
| 136 |
// $tn = $request['THUMBNAIL_URL'][0];
|
| 137 |
|
| 138 |
// if we have a large thumbnail size, then get the larger version available.
|
| 139 |
if ($width > 130 || $height > 97) {
|
| 140 |
$tn = "http://img.ustream.tv/vi/$ustream_id/0.jpg";
|
| 141 |
} else {
|
| 142 |
// ustream offers 3 thumbnails. select one randomly.
|
| 143 |
$rand = rand(0, 2) + 1;
|
| 144 |
$tn = "http://img.ustream.tv/vi/$ustream_id/$rand.jpg";
|
| 145 |
}
|
| 146 |
return $tn;
|
| 147 |
}
|
| 148 |
|
| 149 |
/**
|
| 150 |
* hook video_cck_PROVIDER_video
|
| 151 |
* this actually displays the full/normal-sized video we want, usually on the default page view
|
| 152 |
* @param $embed
|
| 153 |
* the video code for the video to embed
|
| 154 |
* @param $width
|
| 155 |
* the width to display the video
|
| 156 |
* @param $height
|
| 157 |
* the height to display the video
|
| 158 |
* @param $field
|
| 159 |
* the field info from the requesting node
|
| 160 |
* @param $item
|
| 161 |
* the actual content from the field
|
| 162 |
* @return
|
| 163 |
* the html of the embedded video
|
| 164 |
*/
|
| 165 |
function video_cck_ustream_video($embed, $width, $height, $field, $item, $autoplay, $options = array()) {
|
| 166 |
// print_r($item);
|
| 167 |
$output = theme('video_cck_ustream_flash', $embed, $width, $height, $autoplay, $options);
|
| 168 |
return $output;
|
| 169 |
}
|
| 170 |
|
| 171 |
/**
|
| 172 |
* hook video_cck_PROVIDER_video
|
| 173 |
* this actually displays the preview-sized video we want, commonly for the teaser
|
| 174 |
* @param $embed
|
| 175 |
* the video code for the video to embed
|
| 176 |
* @param $width
|
| 177 |
* the width to display the video
|
| 178 |
* @param $height
|
| 179 |
* the height to display the video
|
| 180 |
* @param $field
|
| 181 |
* the field info from the requesting node
|
| 182 |
* @param $item
|
| 183 |
* the actual content from the field
|
| 184 |
* @return
|
| 185 |
* the html of the embedded video
|
| 186 |
*/
|
| 187 |
function video_cck_ustream_preview($embed, $width, $height, $field, $item, $autoplay, $options = array()) {
|
| 188 |
$output = theme('video_cck_ustream_flash', $embed, $width, $height, $autoplay, $options);
|
| 189 |
return $output;
|
| 190 |
}
|