You are here

function brightcove_media_file_uri_to_object in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove_media/brightcove_media.module \brightcove_media_file_uri_to_object()
  2. 7.2 brightcove_media/brightcove_media.module \brightcove_media_file_uri_to_object()
  3. 7.3 brightcove_media/brightcove_media.module \brightcove_media_file_uri_to_object()
  4. 7.4 brightcove_media/brightcove_media.module \brightcove_media_file_uri_to_object()

Helper function MediaInternetBrightcoveHandler class getFileObject method.

Parameters

$uri:

bool $use_existing:

Return value

mixed|StdClass

1 call to brightcove_media_file_uri_to_object()
MediaInternetBrightcoveHandler::getFileObject in brightcove_media/includes/MediaInternetBrightcoveHandler.inc
Returns a file object which can be used for validation

File

brightcove_media/brightcove_media.module, line 680
This module provide the hook implementations for the integration with Media module.

Code

function brightcove_media_file_uri_to_object($uri, $use_existing = FALSE) {
  if ($use_existing) {
    $query = db_select('file_managed', 'f')
      ->fields('f', [
      'fid',
    ])
      ->condition('uri', $uri)
      ->execute()
      ->fetchCol();
    if (!empty($query)) {
      $file = file_load(array_shift($query));
    }
  }
  if (!isset($file)) {
    $uri = file_stream_wrapper_uri_normalize($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 = $GLOBALS['user']->uid;
    if ($uploaded_video = _brightcove_media_session_value_get(BRIGHTCOVE_MEDIA_SESSION_VALUE_NAME_UPLOADED)) {
      $file->filename = $uploaded_video->filename;
      _brightcove_media_session_value_set(BRIGHTCOVE_MEDIA_SESSION_VALUE_NAME_UPLOADED, NULL);
    }
    else {
      if ($selected_video = _brightcove_media_session_value_get(BRIGHTCOVE_MEDIA_SESSION_VALUE_NAME_SELECTED)) {
        $file->filename = $selected_video->name;
        _brightcove_media_session_value_set(BRIGHTCOVE_MEDIA_SESSION_VALUE_NAME_SELECTED, NULL);
      }
      else {
        $parsed = brightcove_media_parse_uri($uri, TRUE);
        brightcove_try_client($parsed['account'], function ($client_entity) use ($parsed, $file) {

          /** @var \Brightcove\API\CMS $cms */
          list($cms) = brightcove_create_classes($client_entity);
          $video = $cms
            ->getVideo($parsed['id']);
          $file->filename = $video
            ->getName();
        });
      }
    }
  }
  return $file;
}