1 |
ca0757b9
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Extends the MediaInternetBaseHandler class to handle videos from an imaginary example.com.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implementation of MediaInternetBaseHandler.
|
10 |
|
|
*
|
11 |
|
|
* @see hook_media_internet_providers().
|
12 |
|
|
*/
|
13 |
|
|
class MediaInternetTestHandler extends MediaInternetBaseHandler {
|
14 |
|
|
public function parse($embedCode) {
|
15 |
|
|
// http://example.com/video/*
|
16 |
|
|
$patterns = array(
|
17 |
|
|
'@example\.com/video/(\d+)@i',
|
18 |
|
|
);
|
19 |
|
|
|
20 |
|
|
foreach ($patterns as $pattern) {
|
21 |
|
|
preg_match($pattern, $embedCode, $matches);
|
22 |
|
|
if (isset($matches[1])) {
|
23 |
|
|
return file_stream_wrapper_uri_normalize('mediainternettest://video/' . $matches[1]);
|
24 |
|
|
}
|
25 |
|
|
}
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
public function claim($embedCode) {
|
29 |
|
|
if ($this->parse($embedCode)) {
|
30 |
|
|
return TRUE;
|
31 |
|
|
}
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
public function getFileObject() {
|
35 |
|
|
$uri = $this->parse($this->embedCode);
|
36 |
|
|
$file = file_uri_to_object($uri, TRUE);
|
37 |
|
|
|
38 |
|
|
// Override the default filename for testing purposes.
|
39 |
|
|
if (empty($file->fid)) {
|
40 |
|
|
$file->filename = 'Drupal';
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
return $file;
|
44 |
|
|
}
|
45 |
|
|
} |