root / drupal7 / sites / all / modules / media / media.api.php @ d808fa20
1 |
<?php
|
---|---|
2 |
|
3 |
/**
|
4 |
* @file
|
5 |
* Hooks provided by the Media module.
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
* Parses a url or embedded code into a unique URI.
|
10 |
*
|
11 |
* @param string $url
|
12 |
* The original URL or embed code to parse.
|
13 |
*
|
14 |
* @return array
|
15 |
* The unique URI for the file, based on its stream wrapper, or NULL.
|
16 |
*
|
17 |
* @see hook_media_parse_alter()
|
18 |
* @see media_parse_to_file()
|
19 |
* @see media_add_from_url_validate()
|
20 |
*/
|
21 |
function hook_media_parse($url) { |
22 |
// Only parse URLs from our website of choice: examplevideo.com
|
23 |
if (substr($url, 0, 27) == 'http://www.examplevideo.com') { |
24 |
// Each video has a 5 digit ID, i.e. http://www.examplevideo.com/12345
|
25 |
// Grab the ID and use it in our URI.
|
26 |
$id = substr($url, 28, 33); |
27 |
return file_stream_wrapper_uri_normalize('examplevideo://video/' . $id); |
28 |
} |
29 |
} |
30 |
|
31 |
/**
|
32 |
* Alters the parsing of urls and embedded codes into unique URIs.
|
33 |
*
|
34 |
* @param string $success
|
35 |
* The unique URI for the file, based on its stream wrapper, or NULL.
|
36 |
* @param array $context
|
37 |
* A nested array of contextual information containing the following keys:
|
38 |
* - url: The original URL or embed code to parse.
|
39 |
* - module: The name of the module which is attempting to parse the url or
|
40 |
* embedded code into a unique URI.
|
41 |
*
|
42 |
* @see hook_media_parse()
|
43 |
* @see hook_media_browser_plugin_info()
|
44 |
* @see media_get_browser_plugin_info()
|
45 |
*/
|
46 |
function hook_media_parse_alter(&$success, $context) { |
47 |
$url = $context['url']; |
48 |
$url_info = parse_url($url); |
49 |
|
50 |
// Restrict users to only embedding secure links.
|
51 |
if ($url_info['scheme'] != 'https') { |
52 |
$success = NULL; |
53 |
} |
54 |
|
55 |
// Use a custom handler for detecting YouTube videos.
|
56 |
if ($context['module' == 'media_youtube']) { |
57 |
$handler = new CustomYouTubeHandler($url); |
58 |
$success = $handler->parse($url); |
59 |
} |
60 |
} |
61 |
|
62 |
/**
|
63 |
* Returns a list of plugins for the media browser.
|
64 |
*
|
65 |
* @return array
|
66 |
* A nested array of plugin information, keyed by plugin name. Each plugin
|
67 |
* info array may have the following keys:
|
68 |
* - title: (required) A name for the tab in the media browser.
|
69 |
* - class: (required) The class name of the handler. This class must
|
70 |
* implement a view() method, and may (should) extend the
|
71 |
* @link MediaBrowserPlugin MediaBrowserPlugin @endlink class.
|
72 |
* - weight: (optional) Integer to determine the tab order. Defaults to 0.
|
73 |
* - access callback: (optional) A callback for user access checks.
|
74 |
* - access arguments: (optional) An array of arguments for the user access
|
75 |
* check.
|
76 |
*
|
77 |
* Additional custom keys may be provided for use by the handler.
|
78 |
*
|
79 |
* @see hook_media_browser_plugin_info_alter()
|
80 |
* @see media_get_browser_plugin_info()
|
81 |
*/
|
82 |
function hook_media_browser_plugin_info() { |
83 |
$info['media_upload'] = array( |
84 |
'title' => t('Upload'), |
85 |
'class' => 'MediaBrowserUpload', |
86 |
'weight' => -10, |
87 |
'access callback' => 'user_access', |
88 |
'access arguments' => array('create files'), |
89 |
); |
90 |
|
91 |
return $info; |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Alter the list of plugins for the media browser.
|
96 |
*
|
97 |
* @param array $info
|
98 |
* The associative array of media browser plugin definitions from
|
99 |
* hook_media_browser_plugin_info().
|
100 |
*
|
101 |
* @see hook_media_browser_plugin_info()
|
102 |
* @see media_get_browser_plugin_info()
|
103 |
*/
|
104 |
function hook_media_browser_plugin_info_alter(&$info) { |
105 |
$info['media_upload']['title'] = t('Upload 2.0'); |
106 |
$info['media_upload']['class'] = 'MediaBrowserUploadImproved'; |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Alter the plugins before they are rendered.
|
111 |
*
|
112 |
* @param array $plugin_output
|
113 |
* The associative array of media browser plugin information from
|
114 |
* media_get_browser_plugin_info().
|
115 |
*
|
116 |
* @see hook_media_browser_plugin_info()
|
117 |
* @see media_get_browser_plugin_info()
|
118 |
*/
|
119 |
function hook_media_browser_plugins_alter(&$plugin_output) { |
120 |
$plugin_output['upload']['form']['upload']['#title'] = t('Upload 2.0'); |
121 |
$plugin_output['media_internet']['form']['embed_code']['#size'] = 100; |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Alter a singleton of the params passed to the media browser.
|
126 |
*
|
127 |
* @param array $stored_params
|
128 |
* An array of parameters provided when a media_browser is launched.
|
129 |
*
|
130 |
* @see media_browser()
|
131 |
* @see media_set_browser_params()
|
132 |
*/
|
133 |
function hook_media_browser_params_alter(&$stored_params) { |
134 |
$stored_params['view_mode'] = 'custom'; |
135 |
$stored_params['types'][] = 'document'; |
136 |
unset($stored_params['enabledPlugins'][0]); |
137 |
} |