Projet

Général

Profil

Paste
Télécharger (3,15 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / media.api.php @ 87dbc3bf

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 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
}