root / drupal7 / sites / all / modules / media / media.api.php @ f4462ddf
1 | 85ad3d82 | Assos Assos | <?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 media_parse_to_file()
|
||
18 | * @see media_add_from_url_validate()
|
||
19 | */
|
||
20 | function hook_media_parse($url) { |
||
21 | // Only parse URLs from our website of choice: examplevideo.com
|
||
22 | if (substr($url, 0, 27) == 'http://www.examplevideo.com') { |
||
23 | // Each video has a 5 digit ID, i.e. http://www.examplevideo.com/12345
|
||
24 | // Grab the ID and use it in our URI.
|
||
25 | $id = substr($url, 28, 33); |
||
26 | return file_stream_wrapper_uri_normalize('examplevideo://video/' . $id); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | /**
|
||
31 | * Returns a list of plugins for the media browser.
|
||
32 | *
|
||
33 | * @return array
|
||
34 | * A nested array of plugin information, keyed by plugin name. Each plugin
|
||
35 | * info array may have the following keys:
|
||
36 | * - title: (required) A name for the tab in the media browser.
|
||
37 | * - class: (required) The class name of the handler. This class must
|
||
38 | * implement a view() method, and may (should) extend the
|
||
39 | * @link MediaBrowserPlugin MediaBrowserPlugin @endlink class.
|
||
40 | * - weight: (optional) Integer to determine the tab order. Defaults to 0.
|
||
41 | * - access callback: (optional) A callback for user access checks.
|
||
42 | * - access arguments: (optional) An array of arguments for the user access
|
||
43 | * check.
|
||
44 | *
|
||
45 | * Additional custom keys may be provided for use by the handler.
|
||
46 | *
|
||
47 | * @see hook_media_browser_plugin_info_alter()
|
||
48 | * @see media_get_browser_plugin_info()
|
||
49 | */
|
||
50 | function hook_media_browser_plugin_info() { |
||
51 | $info['media_upload'] = array( |
||
52 | 'title' => t('Upload'), |
||
53 | 'class' => 'MediaBrowserUpload', |
||
54 | 'weight' => -10, |
||
55 | 'access callback' => 'user_access', |
||
56 | 'access arguments' => array('create files'), |
||
57 | ); |
||
58 | |||
59 | return $info; |
||
60 | } |
||
61 | |||
62 | /**
|
||
63 | * Alter the list of plugins for the media browser.
|
||
64 | *
|
||
65 | * @param array $info
|
||
66 | * The associative array of media browser plugin definitions from
|
||
67 | * hook_media_browser_plugin_info().
|
||
68 | *
|
||
69 | * @see hook_media_browser_plugin_info()
|
||
70 | * @see media_get_browser_plugin_info()
|
||
71 | */
|
||
72 | function hook_media_browser_plugin_info_alter(&$info) { |
||
73 | $info['media_upload']['title'] = t('Upload 2.0'); |
||
74 | $info['media_upload']['class'] = 'MediaBrowserUploadImproved'; |
||
75 | } |
||
76 | |||
77 | /**
|
||
78 | * Alter the plugins before they are rendered.
|
||
79 | *
|
||
80 | * @param array $plugin_output
|
||
81 | * The associative array of media browser plugin information from
|
||
82 | * media_get_browser_plugin_info().
|
||
83 | *
|
||
84 | * @see hook_media_browser_plugin_info()
|
||
85 | * @see media_get_browser_plugin_info()
|
||
86 | */
|
||
87 | function hook_media_browser_plugins_alter(&$plugin_output) { |
||
88 | $plugin_output['upload']['form']['upload']['#title'] = t('Upload 2.0'); |
||
89 | $plugin_output['media_internet']['form']['embed_code']['#size'] = 100; |
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * Alter a singleton of the params passed to the media browser.
|
||
94 | *
|
||
95 | * @param array $stored_params
|
||
96 | * An array of parameters provided when a media_browser is launched.
|
||
97 | *
|
||
98 | * @see media_browser()
|
||
99 | * @see media_set_browser_params()
|
||
100 | */
|
||
101 | function hook_media_browser_params_alter(&$stored_params) { |
||
102 | $stored_params['types'][] = 'document'; |
||
103 | unset($stored_params['enabledPlugins'][0]); |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * Alter a list of view modes allowed for a file embedded in the WYSIWYG.
|
||
108 | *
|
||
109 | * @param array $view_modes
|
||
110 | * An array of view modes that can be used on the file when embedded in the
|
||
111 | * WYSIWYG.
|
||
112 | * @param object $file
|
||
113 | * A file entity.
|
||
114 | *
|
||
115 | * @see media_get_wysiwyg_allowed_view_modes()
|
||
116 | */
|
||
117 | function hook_media_wysiwyg_allowed_view_modes_alter(&$view_modes, $file) { |
||
118 | $view_modes['default']['label'] = t('Display an unmodified version of the file'); |
||
119 | unset($view_modes['preview']); |
||
120 | } |
||
121 | |||
122 | /**
|
||
123 | * Alter the WYSIWYG view mode selection form.
|
||
124 | *
|
||
125 | * Similar to a form_alter, but runs first so that modules can add
|
||
126 | * fields specific to a given file type (like alt tags on images) before alters
|
||
127 | * begin to work on the fields.
|
||
128 | *
|
||
129 | * @param array $form
|
||
130 | * An associative array containing the structure of the form.
|
||
131 | * @param array $form_state
|
||
132 | * An associative array containing the current state of the form.
|
||
133 | * @param object $file
|
||
134 | * A file entity.
|
||
135 | *
|
||
136 | * @see media_format_form()
|
||
137 | */
|
||
138 | function hook_media_format_form_prepare_alter(&$form, &$form_state, $file) { |
||
139 | $form['preview']['#access'] = FALSE; |
||
140 | |||
141 | $file = $form['#media']; |
||
142 | $form['heading']['#markup'] = t('Embedding %filename of type %filetype', array('%filename' => $file->filename, '%filetype' => $file->type)); |
||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * Alter the output generated by Media filter tags.
|
||
147 | *
|
||
148 | * @param array $element
|
||
149 | * The renderable array of output generated for the filter tag.
|
||
150 | * @param array $tag_info
|
||
151 | * The filter tag converted into an associative array by
|
||
152 | * media_token_to_markup() with the following elements:
|
||
153 | * - 'fid': The ID of the media file being rendered.
|
||
154 | * - 'file': The object from file_load() of the media file being rendered.
|
||
155 | * - 'view_mode': The view mode being used to render the file.
|
||
156 | * - 'attributes': An additional array of attributes that could be output
|
||
157 | * with media_get_file_without_label().
|
||
158 | * @param array $settings
|
||
159 | * An additional array of settings.
|
||
160 | * - 'wysiwyg': A boolean if the output is for the WYSIWYG preview or FALSE
|
||
161 | * if for normal rendering.
|
||
162 | *
|
||
163 | * @see media_token_to_markup()
|
||
164 | */
|
||
165 | function hook_media_token_to_markup_alter(&$element, $tag_info, $settings) { |
||
166 | if (empty($settings['wysiwyg'])) { |
||
167 | $element['#attributes']['alt'] = t('This media has been output using the @mode view mode.', array('@mode' => $tag_info['view_mode'])); |
||
168 | } |
||
169 | } |