class MediaInternetBrightcoveHandler in Brightcove Video Connect 7.4
Same name and namespace in other branches
- 7.7 brightcove_media/includes/MediaInternetBrightcoveHandler.inc \MediaInternetBrightcoveHandler
- 7.2 brightcove_media/MediaInternetBrightcoveHandler.inc \MediaInternetBrightcoveHandler
- 7.3 brightcove_media/MediaInternetBrightcoveHandler.inc \MediaInternetBrightcoveHandler
- 7.6 brightcove_media/includes/MediaInternetBrightcoveHandler.inc \MediaInternetBrightcoveHandler
@file Internet handler for Brightcove videos.
Hierarchy
- class \MediaInternetBrightcoveHandler extends \MediaInternetBaseHandler
Expanded class hierarchy of MediaInternetBrightcoveHandler
File
- brightcove_media/
includes/ MediaInternetBrightcoveHandler.inc, line 7 - Internet handler for Brightcove videos.
View source
class MediaInternetBrightcoveHandler extends MediaInternetBaseHandler {
/**
* Parse the video id from an embedcode.
*
* @param $embedCode
* @return null|string
*/
public function parse($embedCode) {
// Special handling for the shortened urls.
if (preg_match('#^http://bcove.me/[a-z0-9]+$#i', $embedCode)) {
$resp = drupal_http_request($embedCode);
if ($resp) {
$full_url = $resp->redirect_url;
$matches = NULL;
preg_match('#&bctid=([0-9]+)#i', $full_url, $matches);
if (isset($matches[1])) {
return file_stream_wrapper_uri_normalize("brightcove://{$matches[1]}");
}
}
}
// Using regexes are right here, because brightcove provides badly
// formatted html files.
$regexes = array(
'#^([0-9]+)$#i',
'#name="@videoPlayer" value="([0-9]+)"#i',
'#@videoPlayer=([0-9]+)&#i',
);
foreach ($regexes as $regex) {
$matches = NULL;
preg_match($regex, $embedCode, $matches);
if (isset($matches[1])) {
return file_stream_wrapper_uri_normalize("brightcove://{$matches[1]}");
}
}
return NULL;
}
/**
* Set the claim attribute.
*
* @param string $embedCode
* @return bool
*/
public function claim($embedCode) {
return (bool) $this
->parse($embedCode);
}
/**
* Validate the embedCode.
*
* @throws MediaInternetValidationException
*/
public function validate() {
$uri = $this
->parse($this->embedCode);
$existing_files = file_load_multiple(array(), array(
'uri' => $uri,
));
if (count($existing_files)) {
throw new MediaInternetValidationException(t('You have entered a URL for a video that is already in your library.'));
}
}
/**
* Save the file object.
*
* @return StdClass
*/
public function save() {
$file = $this
->getFileObject();
file_save($file);
return $file;
}
/**
* Returns a file object which can be used for validation
*
* @return StdClass
*/
public function getFileObject() {
$uri = $this
->parse($this->embedCode);
return brightcove_media_file_uri_to_object($uri);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MediaInternetBrightcoveHandler:: |
public | function | Set the claim attribute. | |
MediaInternetBrightcoveHandler:: |
public | function | Returns a file object which can be used for validation | |
MediaInternetBrightcoveHandler:: |
public | function | Parse the video id from an embedcode. | |
MediaInternetBrightcoveHandler:: |
public | function | Save the file object. | |
MediaInternetBrightcoveHandler:: |
public | function | Validate the embedCode. |