brightcove_media.module in Brightcove Video Connect 7.4
Same filename and directory in other branches
This module provide the hook implementations for the integration with Media module.
File
brightcove_media/brightcove_media.moduleView source
<?php
/**
* @file
* This module provide the hook implementations for the integration with
* Media module.
*/
/**
* Implements hook_menu().
*
* @return array
*/
function brightcove_media_menu() {
$items = array();
$items['brightcove/media/list'] = array(
'title' => '',
'page callback' => 'brightcove_media_list',
'access arguments' => array(
'browse videos',
),
'type' => MENU_CALLBACK,
);
$items['brightcove/media/playlist/list'] = array(
'title' => 'Available playlist',
'description' => 'This menu return the available playlist in JSON.',
'type' => MENU_CALLBACK,
'access arguments' => array(
'browse playlists',
),
'page callback' => 'brightcove_media_playlist_list',
);
return $items;
}
/**
* Implements hook_stream_wrappers().
*
* @return array
*/
function brightcove_media_stream_wrappers() {
return array(
'brightcove' => array(
'name' => t('Brightcove videos'),
'class' => 'MediaBrightcoveVideoStreamWrapper',
'description' => t('Videos provided by Brightcove.'),
'type' => STREAM_WRAPPERS_READ_VISIBLE,
),
'brightcove-playlist' => array(
'name' => t('Brightcove playlist'),
'class' => 'MediaBrightcovePlaylistStreamWrapper',
'description' => t('Playlists provided by Brightcove'),
'type' => STREAM_WRAPPERS_READ_VISIBLE,
),
);
}
/**
* Implements hook_media_internet_providers().
*
* @return array
*/
function brightcove_media_internet_providers() {
return array(
'MediaInternetBrightcoveHandler' => array(
'title' => 'brightcove',
'image' => 'http://img.brightcove.com/logo-corporate-new.png',
),
);
}
/**
* Implements hook_media_parse().
*
* @param $embed_code
* @return null|string
*/
function brightcove_media_media_parse($embed_code) {
$handler = new MediaInternetBrightcoveHandler($embed_code);
return $handler
->parse($embed_code);
}
/**
* Implements hook_file_formatter_info().
*
* @return array
*/
function brightcove_media_file_formatter_info() {
$formatters = array();
$formatters['brightcove_media_video'] = array(
'label' => t('Brightcove Video'),
'file types' => array(
'video',
),
'default settings' => array(),
'view callback' => 'brightcove_media_file_formatter_video_view',
'settings callback' => 'brightcove_media_file_formatter_video_settings',
);
$formatters['brightcove_media_playlist'] = array(
'label' => t('Brightcove Playlist'),
'file types' => array(
'video',
),
'default settings' => array(),
'view callback' => 'brightcove_media_file_formatter_playlist_view',
'settings callback' => 'brightcove_media_file_formatter_video_settings',
);
$formatters['brightcove_media_image'] = array(
'label' => t('Brightcove Preview Image'),
'file types' => array(
'video',
),
'default settings' => array(
'image_style' => '',
),
'view callback' => 'brightcove_media_file_formatter_image_view',
'settings callback' => 'brightcove_media_file_formatter_image_settings',
);
return $formatters;
}
/**
* Implements hook_theme().
*
* @param $existing
* @param $type
* @param $theme
* @param $path
* @return array
*/
function brightcove_media_theme($existing, $type, $theme, $path) {
return array(
'brightcove_media_browser_filter_form' => array(
'render element' => 'form',
),
'brightcove_media_playlist_browser_form' => array(
'render element' => 'form',
),
'brightcove_media_image' => array(
'render element' => 'elements',
),
);
}
/**
* The brightcove_media_video_file_formatter view callback.
*
* @param $file
* @param $display
* @param $langcode
* @return array|null
*/
function brightcove_media_file_formatter_video_view($file, $display, $langcode) {
$scheme = file_uri_scheme($file->uri);
if ($scheme == 'brightcove') {
$element = array(
'#theme' => 'brightcove_field_embed',
'#type' => $scheme,
'#brightcove_id' => parse_url($file->uri, PHP_URL_HOST),
'#player' => variable_get('brightcove_player_default', ''),
'#attached' => array(
'js' => array(
'http://admin.brightcove.com/js/BrightcoveExperiences.js' => array(
'type' => 'external',
),
),
),
);
// add player override
if (isset($display['settings']['player']) && $display['settings']['player']) {
$element['#player'] = $display['settings']['player'];
}
foreach (array(
'width',
'height',
) as $setting) {
if (isset($display['settings'][$setting]) && $display['settings'][$setting]) {
$element['#params'][$setting] = $display['settings'][$setting];
}
}
return $element;
}
return NULL;
}
/**
* The brightcove_media_playlist_file_formatter view callback.
*
* @param $file
* @param $display
* @param $langcode
* @return array|null
*/
function brightcove_media_file_formatter_playlist_view($file, $display, $langcode) {
$scheme = file_uri_scheme($file->uri);
if ($scheme == 'brightcove-playlist') {
$element = array(
'#theme' => 'brightcove_field_embed',
'#type' => $scheme,
'#brightcove_id' => parse_url($file->uri, PHP_URL_HOST),
'#player' => variable_get('brightcove_player_default', ''),
'#attached' => array(
'js' => array(
'http://admin.brightcove.com/js/BrightcoveExperiences.js' => array(
'type' => 'external',
),
),
),
);
// add player override
if (isset($display['settings']['player']) && $display['settings']['player']) {
$element['#player'] = $display['settings']['player'];
}
foreach (array(
'width',
'height',
) as $setting) {
if (isset($display['settings'][$setting]) && $display['settings'][$setting]) {
$element['#params'][$setting] = $display['settings'][$setting];
}
}
return $element;
}
return NULL;
}
/**
* The brightcove_media_image file formatter view callback.
*
* @param $file
* @param $display
* @param $langcode
* @return array|null
*/
function brightcove_media_file_formatter_image_view($file, $display, $langcode) {
$scheme = file_uri_scheme($file->uri);
if ($scheme == 'brightcove' || $scheme == 'brightcove-playlist') {
$video = NULL;
$id = parse_url($file->uri, PHP_URL_HOST);
if ($scheme == 'brightcove') {
$video = brightcove_video_load($id);
}
elseif ($scheme == 'brightcove-playlist') {
$video = brightcove_playlist_load($id);
}
$element = array(
'#theme' => 'brightcove_media_image',
'#video' => $video,
);
return $element;
}
return NULL;
}
/**
* The brightcove_media_image file formatter theme function.
*
* @param $variables
* @return null
*/
function theme_brightcove_media_image($variables) {
$output = NULL;
$elements = $variables['elements'];
$image_type = isset($variables['#brightcove_image_type']) ? $elements['#brightcove_image_type'] : 'thumbnailURL';
$image_style = isset($elements['#brightcove_image_style']) ? $elements['#brightcove_image_style'] : 'thumbnail';
if (isset($elements['#video'])) {
$destination = NULL;
if (isset($elements['#video']->{$image_type})) {
$destination = brightcove_remote_image($elements['#video']->{$image_type});
}
else {
$destination = brightcove_get_default_image();
}
$styled_path = image_style_path($image_style, $destination);
$style = image_style_load($image_style);
image_style_create_derivative($style, $destination, $styled_path);
$output = theme('image', array(
'path' => $styled_path,
));
}
return $output;
}
/**
* The brightcove_media_video file formatter settings callback.
*
* @param $form
* @param $form_state
* @param $settings
* @return array
*/
function brightcove_media_file_formatter_video_settings($form, $form_state, $settings) {
$element = array();
$element['player'] = array(
'#title' => t('Player'),
'#type' => 'radios',
'#options' => brightcove_player_list(),
'#default_value' => isset($settings['player']) ? $settings['player'] : '',
);
$element['width'] = array(
'#title' => t('Player Width'),
'#type' => 'textfield',
'#default_value' => isset($settings['width']) ? $settings['width'] : '',
);
$element['height'] = array(
'#title' => t('Player Height'),
'#type' => 'textfield',
'#default_value' => isset($settings['height']) ? $settings['height'] : '',
);
return $element;
}
/**
* The brightcove_media_image file formatter settings callback.
*
* @param $form
* @param $form_state
* @param $settings
* @return array
*/
function brightcove_media_file_formatter_image_settings($form, $form_state, $settings) {
$element = array();
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#default_value' => isset($settings['image_style']) ? $settings['image_style'] : '',
'#empty_option' => t('None (original image)'),
);
return $element;
}
///**
// * Implements hook_file_formatter_default_displays().
// *
// * @return array
// */
//function brightcove_media_file_default_displays() {
// $default_displays = array();
//
// $video_display_settings = array(
// 'media_large' => array(),
// 'media_original' => array(),
// 'media_gallery_detail' => array(),
// 'media_gallery_lightbox' => array(),
// );
// foreach ($video_display_settings as $view_mode => $settings) {
// $display_name = "video__{$view_mode}__brightcove_media_video";
// $default_displays[$display_name] = (object) array(
// 'api_version' => 1,
// 'name' => $display_name,
// 'status' => 1,
// 'weight' => 1,
// 'settings' => $settings,
// );
// }
//
// $image_display_styles = array(
// 'media_preview' => '',
// 'media_large' => '',
// 'media_original' => '',
// 'media_gallery_thumbnail' => '',
// 'media_gallery_block_thumbnail' => '',
// 'media_gallery_collection_thumbnail' => '',
// );
// foreach ($image_display_styles as $view_mode => $image_style) {
// $display_name = "video__{$view_mode}__brightcove_media_image";
// $default_displays[$display_name] = (object) array(
// 'api_version' => 1,
// 'name' => $display_name,
// 'status' => 1,
// 'weight' => 2,
// 'settings' => array('image_style' => $image_style),
// );
// }
//
// return $default_displays;
//}
/**
* Implements hook_media_browser_plugin_info().
*
* @return array
*/
function brightcove_media_media_browser_plugin_info() {
$info = array();
$info['brightcove'] = array(
'title' => t('Brightcove'),
'weight' => 0,
'class' => 'MediaBrowserBrightcoveVideo',
);
$info['brightcove_playlist'] = array(
'title' => t('Brightcove Playlist'),
'weight' => 2,
'class' => 'MediaBrowserBrightcovePlaylist',
);
return $info;
}
/**
* Upload form for brightcove media.
*/
function brightcove_media_upload_form($form, &$form_state) {
$form['uploadform'] = array(
'#type' => 'fieldset',
'#title' => t('Upload video'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('It takes several minutes (depending on processing time in Brightcove cloud), until video is available after upload. Clicking \'Upload and attach\' uploads video to Brightcove then closes the dialog and attaches the video.'),
);
$form['uploadform'] += _brightcove_upload_form($form, $form_state);
$form['uploadform']['upload'] = array(
'#type' => 'button',
'#name' => 'upload',
'#value' => t('Upload and attach'),
'#ajax' => array(
'callback' => 'ajax_brightcove_media_upload_callback',
'wrapper' => 'bc-upload-form',
),
);
$form['#prefix'] = '<div id="bc-upload-form">';
$form['#suffix'] = '</div>';
return $form;
}
/**
* Filter form for brightcove media video browser.
*
* @param $form
* @param $form_state
* @return array
*/
function brightcove_media_browser_filter_form($form, &$form_state) {
$form['searchform'] = array(
'#type' => 'fieldset',
'#title' => t('Filter videos'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['searchform']['keywords'] = array(
'#type' => 'textfield',
'#title' => t('Keywords'),
'#size' => 25,
'#default_value' => '',
'#description' => t('Comma separated keywords to search for. (do not add space after comma)'),
);
$form['searchform']['search'] = array(
'#type' => 'radios',
'#title' => t('Search in'),
'#options' => array(
'name' => t('Names and descriptions'),
'tags' => t('Tags: at least one of these'),
'and_tags' => t('Tags: all of these'),
),
'#default_value' => 'name',
'#attributes' => array(
'class' => array(
'search-radio',
),
),
'#description' => t('"Names and descriptions" searches in Video name, short and long descriptions. Tags searches in Video associated tags.'),
);
$form['searchform']['filter'] = array(
'#type' => 'button',
'#name' => 'filter',
'#value' => t('Filter'),
);
$form['searchform']['reset'] = array(
'#type' => 'button',
'#name' => 'reset',
'#value' => t('Reset'),
);
$form['#prefix'] = '<div id="bc-filter-form">';
$form['#suffix'] = '</div>';
$form['submitted-video'] = array(
'#type' => 'hidden',
'#default_value' => FALSE,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#submit' => array(
'brightcove_media_browser_form_submit',
),
'#value' => t('Submit'),
);
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => '',
'#attributes' => array(
'class' => array(
'button',
'button-no',
'fake-cancel',
'brightcove',
),
),
'#weight' => 100,
);
return $form;
}
/**
* The brightcove_media_browser_filter_form form theme function.
*
* @param $variables
* @return string
*/
function theme_brightcove_media_browser_filter_form(&$variables) {
$output = '';
$form = $variables['form'];
$output .= drupal_render($form['searchform']);
$output .= drupal_render($form['actions']);
$output .= '<ul id="media-browser-library-list" class="media-list-thumbnails"></ul>';
$output .= '<div id="status"></div>';
$output .= drupal_render_children($form);
return $output;
}
/**
* The media browser playlist tab theme function.
*
* @param $variables
* @return string
*/
function theme_brightcove_media_playlist_browser_form(&$variables) {
$output = NULL;
$form = $variables['form'];
$output .= '<div id="container">';
$output .= drupal_render($form['actions']);
$output .= '<div id="scrollbox">';
$output .= '<ul id="media-browser-library-list" class="media-list-thumbnails"></ul>';
$output .= '<div id="status"></div>';
$output .= '</div></div>';
$output .= drupal_render_children($form);
return $output;
}
/**
* The brightcove_media_browser_filter_form submit callback function.
*
* @param $form
* @param $form_state
* @return mixed
*/
function brightcove_media_browser_form_submit($form, &$form_state) {
$uri = $form_state['values']['submitted-video'];
try {
// Save the remote file
$file = file_uri_to_object($uri, TRUE);
file_save($file);
} catch (Exception $e) {
form_set_error('url', $e
->getMessage());
return;
}
if (!$file->fid) {
form_set_error('url', t('The file %file could not be saved. An unknown error has occurred.', array(
'%file' => $uri,
)));
return;
}
else {
$form_state['file'] = $file;
$form_state['redirect'] = array(
'media/browser',
array(
'query' => array(
'render' => 'media-popup',
'fid' => $file->fid,
),
),
);
}
}
/**
* Get the avaliable videos from brightcove.
*
* @return JSON list of available brightcove vieos.
*/
function brightcove_media_list() {
global $user;
module_load_include('browser.inc', 'media', 'includes/media');
$default_items_per_page = 20;
$params = drupal_get_query_parameters();
$limit = isset($params['limit']) ? $params['limit'] : $default_items_per_page;
$start = isset($params['start']) ? ceil($params['start'] / $limit) : 0;
$media = array();
$bc_find_params = array();
if (isset($params['filter'])) {
switch ($params['filter']['search']) {
case 'tags':
$method = 'find_videos_by_tags';
$bc_find_params = array(
'or_tags' => $params['filter']['keywords'],
);
break;
case 'and_tags':
$method = 'find_videos_by_tags';
$bc_find_params = array(
'and_tags' => $params['filter']['keywords'],
);
break;
case 'name':
default:
$method = 'find_videos_by_text';
$bc_find_params = array(
'text' => join(' ', explode(',', $params['filter']['keywords'])),
);
break;
}
}
else {
$method = 'find_all_videos';
}
$bc_find_params['page_size'] = $limit;
$bc_find_params['page_number'] = $start;
// Try to load the data from cache. It uses different key than the cache of field browse results,
// because it has a different output.
$cid = 'brightcove:video:list:media';
foreach ($bc_find_params as $key => $param) {
$cid .= ":{$key}:{$param}";
}
$result = brightcove_cache_get($cid);
if (!$result) {
try {
$bc = brightcove_initialize();
$result = $bc
->find($method, $bc_find_params);
brightcove_cache_set($cid, $result);
} catch (Exception $e) {
watchdog('brightcove', 'Retrieving media list failed.', array(), WATCHDOG_ERROR);
}
}
if (count($result)) {
foreach ($result as $video) {
$uri = file_stream_wrapper_uri_normalize("brightcove://{$video->id}");
$file = file_uri_to_object($uri);
$file->filename = $video->name;
$file->type = 'video';
if (!isset($file->fid)) {
$file->fid = 0;
}
media_browser_build_media_item($file);
$file->preview = l($file->preview, 'media/browser', array(
'html' => TRUE,
'attributes' => array(
'data-uri' => $uri,
),
'query' => array(
'render' => 'media-popup',
'uri' => $uri,
),
));
$files[$uri] = $file;
$media[] = $file;
}
}
drupal_add_js(array(
'brightcove' => array(
'files' => $files,
),
), 'setting');
drupal_json_output($media);
exit;
}
/**
* Implements hook_ctools_plugin_api().
*
* @param $owner
* @param $api
* @return array|null
*/
function brightcove_media_ctools_plugin_api($owner, $api) {
static $api_versions = array(
'file_entity' => array(
'file_default_displays' => 1,
),
);
return isset($api_versions[$owner][$api]) ? array(
'version' => $api_versions[$owner][$api],
) : NULL;
}
/**
* Implements hook_element_info_alter().
*
* @param $type
*/
function brightcove_media_element_info_alter(&$type) {
if (isset($type['media']['#process'])) {
array_unshift($type['media']['#process'], 'brightcove_media_media_element_process');
}
}
/**
* Media type element process function.
*
* @param $element
* @param $form_state
* @return mixed
*/
function brightcove_media_media_element_process(&$element, &$form_state) {
global $user;
if (isset($element['#value']['fid']) && strpos($element['#value']['fid'], 'v') === 0) {
$video_id = substr($element['#value']['fid'], 1);
$candidates = file_load_multiple(array(), array(
'uri' => "brightcove://{$video_id}",
));
if (count($candidates)) {
$element['#value']['fid'] = array_shift($candidates)->fid;
}
else {
$handler = new MediaInternetBrightcoveHandler($video_id);
if (!isset($_SESSION['brightcove']["video_just_uploaded_{$user->uid}"])) {
$bc = brightcove_initialize();
try {
$result = $bc
->find('find_video_by_id', $video_id);
if (count($result)) {
$file = (object) $result;
$_SESSION['brightcove']["selected_video_{$user->uid}"] = $file;
}
} catch (Exception $e) {
watchdog('brightcove', 'Retrieving media list failed.', array(), WATCHDOG_ERROR);
}
}
$element['#value']['fid'] = $handler
->save()->fid;
}
form_set_value($element, $element['#value'], $form_state);
}
return $element;
}
/**
* Implements hook_node_presave().
* (needed for media gallery)
*
* @param $node
*/
function brightcove_media_node_presave($node) {
global $user;
if (isset($node->media_gallery_media[LANGUAGE_NONE])) {
foreach ($node->media_gallery_media[LANGUAGE_NONE] as &$file) {
if (isset($file['fid']) && strpos($file['fid'], 'v') === 0) {
$video_id = substr($file['fid'], 1);
$candidates = file_load_multiple(array(), array(
'uri' => "brightcove://{$video_id}",
));
if (count($candidates)) {
$file['fid'] = array_shift($candidates)->fid;
}
else {
$handler = new MediaInternetBrightcoveHandler($video_id);
if (!isset($_SESSION['brightcove']["video_just_uploaded_{$user->uid}"])) {
$bc = brightcove_initialize();
try {
$result = $bc
->find('find_video_by_id', $video_id);
if (count($result)) {
$_SESSION['brightcove']["selected_video_{$user->uid}"] = (object) $result;
}
} catch (Exception $e) {
watchdog('brightcove', 'Retrieving media list failed.', array(), WATCHDOG_ERROR);
}
}
$file['fid'] = $handler
->save()->fid;
}
}
}
}
}
/**
* Ajax callback for upload form
*
* @param $form
* @param $form_state
* @return Validated form with messages
*/
function ajax_brightcove_media_upload_callback($form, $form_state) {
global $user;
// Make sure it is not set, might be needed if a user changes mind after upload and wants to upload another.
unset($_SESSION['brightcove']["video_just_uploaded_{$user->uid}"]);
$video = _brightcove_upload_form_callback($form, $form_state);
if (is_array($video) || is_bool($video)) {
return $video;
}
$uri = file_stream_wrapper_uri_normalize("brightcove://{$video->id}");
$file = file_uri_to_object($uri);
$file->filename = $video->name;
$file->filemime = 'media/brightcove';
$file->type = 'video';
if (!isset($file->fid)) {
$file->fid = 0;
}
media_browser_build_media_item($file);
$_SESSION['brightcove']["video_just_uploaded_{$user->uid}"] = $file;
$commands = array();
$commands[] = ajax_command_brightcove_media_upload($file);
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}
/**
* @param $data
* @param null $settings
* @return array
*/
function ajax_command_brightcove_media_upload($data, $settings = NULL) {
return array(
'command' => 'brightcove_media_upload',
'data' => $data,
'settings' => $settings,
);
}
/**
* Helper function MediaInternetBrightcoveHandler class getFileObject method.
*
* @param $uri
* @param bool $use_existing
* @return mixed|StdClass
*/
function brightcove_media_file_uri_to_object($uri, $use_existing = FALSE) {
if ($use_existing) {
$query = db_select('file_managed', 'f')
->fields('f', array(
'fid',
))
->condition('uri', $uri)
->execute()
->fetchCol();
if (!empty($query)) {
$file = file_load(array_shift($query));
}
}
if (!isset($file)) {
global $user;
$uri = file_stream_wrapper_uri_normalize($uri);
$wrapper = file_stream_wrapper_get_instance_by_uri($uri);
$file = new StdClass();
// This is gagged because some uris will not support it.
$file->filesize = @filesize($uri);
$file->timestamp = REQUEST_TIME;
$file->status = FILE_STATUS_PERMANENT;
$file->is_new = TRUE;
$file->uri = $uri;
$file->filemime = file_get_mimetype($uri);
$file->uid = $user->uid;
if (isset($_SESSION['brightcove']["video_just_uploaded_{$user->uid}"])) {
$uploaded_video = $_SESSION['brightcove']["video_just_uploaded_{$user->uid}"];
$file->filename = $uploaded_video->filename;
unset($_SESSION['brightcove']["video_just_uploaded_{$user->uid}"]);
}
else {
if (isset($_SESSION['brightcove']["selected_video_{$user->uid}"])) {
$selected_video = $_SESSION['brightcove']["selected_video_{$user->uid}"];
$file->filename = $selected_video->name;
unset($_SESSION['brightcove']["selected_video_{$user->uid}"]);
}
else {
$file->filename = basename($uri);
}
}
}
return $file;
}
/**
* Media browser brightcove playlist form.
*
* @param array $form
* @param array $form_state
* @return array $form
*/
function brightcove_media_playlist_browser_form($form, &$form_state) {
$form['submitted-video'] = array(
'#type' => 'hidden',
'#default_value' => FALSE,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => array(
'brightcove_media_browser_form_submit',
),
);
return $form;
}
/**
* brightcove/media/playlist/list menu callback function.
*
* @return JSON
* available playlists.
*/
function brightcove_media_playlist_list() {
module_load_include('browser.inc', 'media', 'includes/media');
$media = array();
$files = array();
$default_items_per_page = 20;
$params = drupal_get_query_parameters();
$limit = isset($params['limit']) ? $params['limit'] : $default_items_per_page;
$start = isset($params['start']) ? ceil($params['start'] / $limit) : 0;
$method = 'find_all_playlists';
$bc_find_params = array();
$bc_find_params['page_size'] = $limit;
$bc_find_params['page_number'] = $start;
// Try to load the data from cache. It uses different key than the cache of field browse results,
// because it has a different output.
$cid = 'brightcove:playlist:list:media';
foreach ($bc_find_params as $key => $param) {
$cid .= ":{$key}:{$param}";
}
$result = brightcove_cache_get($cid);
if (!$result) {
try {
$bc = brightcove_initialize();
$result = $bc
->find($method, $bc_find_params);
brightcove_cache_set($cid, $result);
} catch (Exception $e) {
watchdog('brightcove', 'Retrieving media list failed.', array(), WATCHDOG_ERROR);
}
}
if (count($result)) {
foreach ($result as $playlist) {
$uri = file_stream_wrapper_uri_normalize("brightcove-playlist://{$playlist->id}");
$file = file_uri_to_object($uri);
$file->filename = $playlist->name;
$file->type = 'video';
if (!isset($file->fid)) {
$file->fid = 0;
}
media_browser_build_media_item($file);
$file->preview = l($file->preview, 'media/browser', array(
'html' => TRUE,
'attributes' => array(
'data-uri' => $uri,
),
'query' => array(
'render' => 'media-popup',
'uri' => $uri,
),
));
$files[$uri] = $file;
$media[] = $file;
}
}
drupal_add_js(array(
'brightcove_playlist' => array(
'files' => $files,
),
), 'setting');
drupal_json_output($media);
exit;
}
/**
* Implements hook_file_type_alter().
*/
function brightcove_media_file_type_alter(&$types, $file) {
if (strpos($file->filemime, 'brightcove')) {
$types = array(
'video',
);
}
}
/**
* Implements hook_media_file_presave().
*/
function brightcove_media_file_presave($file) {
if (strpos($file->filemime, 'brightcove') && $file->filename == basename($file->uri)) {
$bc_file = brightcove_video_load($file->filename);
$file->filename = $bc_file->name;
}
}