You are here

function brightcove_autocomplete_videos in Brightcove Video Connect 7.5

Same name and namespace in other branches
  1. 7.7 brightcove.module \brightcove_autocomplete_videos()
  2. 7.3 brightcove.module \brightcove_autocomplete_videos()
  3. 7.4 brightcove.module \brightcove_autocomplete_videos()
  4. 7.6 brightcove.module \brightcove_autocomplete_videos()

Autocomplete callback for listing videos.

Parameters

$string:

1 string reference to 'brightcove_autocomplete_videos'
brightcove_menu in ./brightcove.module
Implements hook_menu().

File

./brightcove.module, line 177
Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.

Code

function brightcove_autocomplete_videos($videos_typed) {
  $matches = array();
  $result = array();
  $bc = brightcove_initialize();
  $videos_typed = drupal_explode_tags($videos_typed);
  $video_last = drupal_strtolower(array_pop($videos_typed));
  try {
    $result = $bc
      ->find('find_videos_by_text', array(
      'text' => $video_last,
    ));
  } 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 . ']';
  }
  $prefix = count($videos_typed) ? drupal_implode_tags($videos_typed) . ', ' : '';
  $video_matches = array();
  foreach ($matches as $name) {
    $video_matches[$prefix . $name] = check_plain($name);
  }
  drupal_json_output($video_matches);
}