| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
define('VIDEO_CCK_USTREAMLIVE_MAIN_URL', 'http://www.ustream.tv/');
|
| 5 |
define('VIDEO_CCK_USTREAMLIVE_API_INFO', 'http://developer.ustream.tv/');
|
| 6 |
define('VIDEO_CCK_USTREAMLIVE_API_APPLICATION_URL', 'http://developer.ustream.tv/apps/register');
|
| 7 |
// define('VIDEO_CCK_USTREAMLIVE_REST_ENDPOINT', 'http://www.ustream.tv/api2_rest');
|
| 8 |
// define('VIDEO_CCK_USTREAMLIVE_COLOR1_DEFAULT', '#FFFFFF');
|
| 9 |
// define('VIDEO_CCK_USTREAMLIVE_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_ustreamlive_info() {
|
| 23 |
$name = t('UStream.TV (Live Streams)');
|
| 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_USTREAMLIVE_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_USTREAMLIVE_MAIN_URL, array('target' => '_blank')), '!api' => l(t('API'), VIDEO_CCK_USTREAMLIVE_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['ustreamlive'])
|
| 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_ustreamlive_settings() {
|
| 45 |
$form['ustreamlive']['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 !ustreamlive.', array('!ustreamlive' => l(t('Ustream Application Registration page'), VIDEO_CCK_USTREAMLIVE_API_APPLICATION_URL, array('target' => '_blank')))),
|
| 49 |
'#collapsible' => TRUE,
|
| 50 |
'#collapsed' => TRUE,
|
| 51 |
);
|
| 52 |
$form['ustreamlive']['api']['video_cck_ustreamlive_api_key'] = array(
|
| 53 |
'#type' => 'textfield',
|
| 54 |
'#title' => t('UStream.TV API Key'),
|
| 55 |
'#default_value' => variable_get('video_cck_ustreamlive_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 ustreamlive's api key
|
| 63 |
*/
|
| 64 |
function video_cck_ustreamlive_request($code = '', $cached = TRUE) {
|
| 65 |
$key = trim(variable_get('video_cck_ustreamlive_api_key', ''));
|
| 66 |
$url = "http://api.ustreamlive.tv/php/video/$code/getInfo?key=$key";
|
| 67 |
|
| 68 |
return module_invoke('emfield', 'request_xml', 'ustreamlive', $url, array(), $cached, FALSE, $code, TRUE);
|
| 69 |
}
|
| 70 |
|
| 71 |
function video_cck_ustreamlive_data($field, $item) {
|
| 72 |
$data = video_cck_ustreamlive_request($item['value']);
|
| 73 |
$data['ustreamlive_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_ustreamlive_extract($embed = '') {
|
| 88 |
// <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="320" id="utv654382"><param name="flashvars" value="viewcount=false&autoplay=false&brand=embed"/><param name="allowfullscreen" value="true"/><param name="allowscriptaccess" value="always"/><param name="movie" value="http://www.ustream.tv/flash/live/240437"/><embed flashvars="viewcount=false&autoplay=false&brand=embed" width="400" height="320" allowfullscreen="true" allowscriptaccess="always" id="utv654382" name="utv_n_741085" src="http://www.ustream.tv/flash/live/240437" type="application/x-shockwave-flash" /></object><a href="http://www.ustream.tv/" style="padding:2px 0px 4px;width:400px;background:#FFFFFF;display:block;color:#000000;font-weight:normal;font-size:10px;text-decoration:underline;text-align:center;" target="_blank">Stream videos at Ustream</a>
|
| 89 |
return array(
|
| 90 |
'@ustream\.tv/flash/live/([^"\&\?]+)@i',
|
| 91 |
// '@ustreamlive\.tv/recorded/([^"\&\?]+)@i',
|
| 92 |
);
|
| 93 |
}
|
| 94 |
|
| 95 |
/**
|
| 96 |
* hook video_cck_PROVIDER_embedded_link($video_code)
|
| 97 |
* returns a link to view the video at the provider's site
|
| 98 |
* @param $video_code
|
| 99 |
* the string containing the video to watch
|
| 100 |
* @return
|
| 101 |
* a string containing the URL to view the video at the original provider's site
|
| 102 |
*/
|
| 103 |
function video_cck_ustreamlive_embedded_link($video_code) {
|
| 104 |
return 'http://www.ustreamlive.tv/flash/live/' . $video_code;
|
| 105 |
}
|
| 106 |
|
| 107 |
/**
|
| 108 |
* the embedded flash displaying the ustreamlive video
|
| 109 |
*/
|
| 110 |
function theme_video_cck_ustreamlive_flash($embed, $width, $height, $autoplay, $options = array()) {
|
| 111 |
static $counter;
|
| 112 |
if ($embed) {
|
| 113 |
$counter++;
|
| 114 |
$autoplay = isset($options['autoplay']) ? $options['autoplay'] : $autoplay;
|
| 115 |
$autoplay_value = $autoplay ? 'true' : 'false';
|
| 116 |
$id = 'utv654382';
|
| 117 |
|
| 118 |
$output .= <<<USTREAM
|
| 119 |
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="$width" height="$height" id="$id"><param name="flashvars" value="viewcount=false&autoplay=$autoplay_value&brand=embed"/><param name="allowfullscreen" value="true"/><param name="allowscriptaccess" value="always"/><param name="movie" value="http://www.ustream.tv/flash/live/$embed"/><embed flashvars="viewcount=false&autoplay=$autoplay_value&brand=embed" width="$width" height="$height" allowfullscreen="true" allowscriptaccess="always" id="$id" name="utv_n_741085" src="http://www.ustream.tv/flash/live/$embed" type="application/x-shockwave-flash" /></object>
|
| 120 |
USTREAM;
|
| 121 |
// $output .= "<object type='application/x-shockwave-flash' height='$height' width='$width' data='http://ustreamlive.tv/flash/video/$embed' id='ustreamlive-video-$counter' ><param name='movie' value='http://www.ustreamlive.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>";
|
| 122 |
}
|
| 123 |
return $output;
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* hook video_cck_PROVIDER_thumbnail
|
| 128 |
* returns the external url for a thumbnail of a specific video
|
| 129 |
* TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
|
| 130 |
* @param $field
|
| 131 |
* the field of the requesting node
|
| 132 |
* @param $item
|
| 133 |
* the actual content of the field from the requesting node
|
| 134 |
* @return
|
| 135 |
* a URL pointing to the thumbnail
|
| 136 |
*/
|
| 137 |
function video_cck_ustreamlive_thumbnail($field, $item, $formatter, $node, $width, $height, $options = array()) {
|
| 138 |
$ustreamlive_id = $item['value'];
|
| 139 |
// old code to grab thumbnail via api
|
| 140 |
// $request = video_cck_ustreamlive_request('ustreamlive.videos.get_details', array('video_id' => $ustreamlive_id));
|
| 141 |
// $tn = $request['THUMBNAIL_URL'][0];
|
| 142 |
|
| 143 |
// if we have a large thumbnail size, then get the larger version available.
|
| 144 |
if ($width > 130 || $height > 97) {
|
| 145 |
$tn = "http://img.ustreamlive.tv/vi/$ustreamlive_id/0.jpg";
|
| 146 |
} else {
|
| 147 |
// ustreamlive offers 3 thumbnails. select one randomly.
|
| 148 |
$rand = rand(0, 2) + 1;
|
| 149 |
$tn = "http://img.ustreamlive.tv/vi/$ustreamlive_id/$rand.jpg";
|
| 150 |
}
|
| 151 |
return $tn;
|
| 152 |
}
|
| 153 |
|
| 154 |
/**
|
| 155 |
* hook video_cck_PROVIDER_video
|
| 156 |
* this actually displays the full/normal-sized video we want, usually on the default page view
|
| 157 |
* @param $embed
|
| 158 |
* the video code for the video to embed
|
| 159 |
* @param $width
|
| 160 |
* the width to display the video
|
| 161 |
* @param $height
|
| 162 |
* the height to display the video
|
| 163 |
* @param $field
|
| 164 |
* the field info from the requesting node
|
| 165 |
* @param $item
|
| 166 |
* the actual content from the field
|
| 167 |
* @return
|
| 168 |
* the html of the embedded video
|
| 169 |
*/
|
| 170 |
function video_cck_ustreamlive_video($embed, $width, $height, $field, $item, $autoplay, $options = array()) {
|
| 171 |
// print_r($item);
|
| 172 |
$output = theme('video_cck_ustreamlive_flash', $embed, $width, $height, $autoplay, $options);
|
| 173 |
return $output;
|
| 174 |
}
|
| 175 |
|
| 176 |
/**
|
| 177 |
* hook video_cck_PROVIDER_video
|
| 178 |
* this actually displays the preview-sized video we want, commonly for the teaser
|
| 179 |
* @param $embed
|
| 180 |
* the video code for the video to embed
|
| 181 |
* @param $width
|
| 182 |
* the width to display the video
|
| 183 |
* @param $height
|
| 184 |
* the height to display the video
|
| 185 |
* @param $field
|
| 186 |
* the field info from the requesting node
|
| 187 |
* @param $item
|
| 188 |
* the actual content from the field
|
| 189 |
* @return
|
| 190 |
* the html of the embedded video
|
| 191 |
*/
|
| 192 |
function video_cck_ustreamlive_preview($embed, $width, $height, $field, $item, $autoplay, $options = array()) {
|
| 193 |
$output = theme('video_cck_ustreamlive_flash', $embed, $width, $height, $autoplay, $options);
|
| 194 |
return $output;
|
| 195 |
}
|