brightcove_cck.browse.inc in Brightcove Video Connect 6.2
Same filename and directory in other branches
brightcove_cck.browse.inc Holds a method to list all BC videos that are attachable to a field.
File
brightcove_cck/brightcove_cck.browse.incView source
<?php
/**
* @file brightcove_cck.browse.inc
* Holds a method to list all BC videos that are attachable to a field.
*/
/**
* This function is a callback for modalframe window, providing an access to browse videos.
*
* @see brightcove_cck_menu()
*
* @param none
*
* @return A list of available videos that can be attached to a field.
*
* TODO: Allow limiting videos by user (own videos only).
* TODO: Interesting feature would be to detect multiple values allowed in the
* parent field and allow attaching all videos at once.
*/
function brightcove_cck_browse() {
global $pager_from_array, $pager_total, $pager_page_array;
$items_per_page = 20;
modalframe_child_js();
//dialog internal area
drupal_add_css(drupal_get_path('module', 'brightcove_cck') . '/styles/browse.css');
drupal_add_js(drupal_get_path('module', 'brightcove_cck') . '/js/attach.js');
// Issue a BC request to list videos
// For all videos, get a thumbnail URL
// Theme a table with videos and a button to attach.
$bc = _brightcove_initialize();
$matches = array();
$page = isset($_GET['page']) ? intval($_GET['page']) : '0';
$params = array();
if (isset($_SESSION['brightcove_cck_filter'])) {
switch ($_SESSION['brightcove_cck_filter']['search']) {
case 'tags':
$method = 'find_videos_by_tags';
$params = array(
'or_tags' => $_SESSION['brightcove_cck_filter']['keywords'],
);
break;
case 'and_tags':
$method = 'find_videos_by_tags';
$params = array(
'and_tags' => $_SESSION['brightcove_cck_filter']['keywords'],
);
break;
case 'name':
default:
$method = 'find_videos_by_text';
$params = array(
'text' => join(' ', split(',', $_SESSION['brightcove_cck_filter']['keywords'])),
);
break;
}
}
else {
$method = 'find_all_videos';
}
$result = NULL;
try {
$params['page_size'] = $items_per_page;
$params['page_number'] = $page;
$result = $bc
->find($method, $params);
} catch (Exception $error) {
watchdog('brightcove', 'Finding videos in autocomplete failed.', array(), WATCHDOG_ERROR);
}
$pager_page_array = explode(',', $page);
$pager_total[0] = ceil($bc->total_count / $items_per_page);
$pager_page_array[0] = max(0, min((int) $pager_page_array[0], (int) $pager_total[0] - 1));
$items = array();
if (count($result)) {
foreach ($result as $video) {
$item = array();
$item['title'] = check_plain($video->name);
$item['video_id'] = $video->id;
if (!empty($video->thumbnailURL)) {
if (module_exists('imagecache')) {
$item['thumbnail'] = theme('imagecache', 'brightcove_browser', brightcove_remote_image($video->thumbnailURL));
}
else {
$item['thumbnail'] = theme('image', $video->thumbnailURL, '', '', NULL, FALSE);
}
}
else {
$item['thumbnail'] = theme('image', brightcove_get_default_image(), '', '', array(
'width' => 120,
'height' => 120,
), FALSE);
}
$items[] = $item;
}
}
$pager = theme('pager', NULL, $items_per_page, 0);
$filter_form = drupal_get_form('brightcove_cck_filter_form');
return '<div class="brightcove-browse-table">' . $filter_form . $pager . theme('brightcove_cck_browse_items', $items) . $pager . '</div>';
}
/**
* Menu callback for brightcove_cck/autocomplete.
*
* @param $field_name
* Field name - CCK field name that is requesting autocomplete. Unused, will be utilized to limit access to certain videos for certain fields.
* @param $string
* String to search for - will match videos by this text.
* @return
* JSON object with matched videos.
*/
function brightcove_cck_autocomplete($field_name, $string = '') {
$bc = _brightcove_initialize();
$matches = array();
try {
$result = $bc
->find('find_videos_by_text', array(
'text' => $string,
));
} catch (Exception $error) {
watchdog('brightcove', 'Finding videos in autocomplete failed.', array(), WATCHDOG_ERROR);
}
foreach ((array) $result as $video) {
// Note: Video ID is autogenerated by Brightcove and thus doesn't require XSS protection.
$matches[check_plain($video->name) . ' [id:' . $video->id . ']'] = check_plain($video->name) . ' [id: ' . $video->id . ']';
}
return drupal_json($matches);
}
function brightcove_cck_upload() {
modalframe_child_js();
//dialog internal area
drupal_add_css(drupal_get_path('module', 'brightcove_cck') . '/brightcove_cck.upload.css');
// drupal_add_js(drupal_get_path('module', 'brightcove_cck') . '/js/attach.js');
return drupal_get_form('brightcove_cck_upload_form');
}
Functions
Name | Description |
---|---|
brightcove_cck_autocomplete | Menu callback for brightcove_cck/autocomplete. |
brightcove_cck_browse | This function is a callback for modalframe window, providing an access to browse videos. |
brightcove_cck_upload |