media_soundcloud.module
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @file media_soundcloud/media_soundcloud.module
*
* Media: SoundCloud provides a stream wrapper and formatters for audio provided
* by SoundCloud, available at http://soundcloud.com/.
*
* @TODO:
* Tie in SoundCloud API.
* Allow editors to search for audio to display on the browser.
* Allow editors to put in a soundcloud username to display on the browser.
* Allow editors to log in w/ their credentials.
* Allow editors to upload audio to SoundCloud.
*/
// A registry of variable_get defaults.
include_once('includes/media_soundcloud.variables.inc');
// Hooks and callbacks for integrating with Styles module for display.
// @todo Can save a little overhead for people without Styles module by wrapping
// this inside a module_exists('styles'). However, is that safe to do in
// global context? If not, is there any down side to doing it in hook_init()?
include_once('includes/media_soundcloud.styles.inc');
// Hooks and callbacks for integrating with File Entity module for display.
include_once('includes/media_soundcloud.formatters.inc');
/**
* Implements hook_media_internet_providers().
*/
function media_soundcloud_media_internet_providers() {
$path = drupal_get_path('module', 'media_soundcloud');
return array(
'MediaInternetSoundCloudHandler' => array(
'title' => 'soundcloud',
'image' => $path . '/images/stream-soundcloud.png'
),
);
}
/**
* Implements hook_stream_wrappers().
*/
function media_soundcloud_stream_wrappers() {
return array(
'soundcloud' => array(
'name' => t('SoundCloud audio'),
'class' => 'MediaSoundCloudStreamWrapper',
'description' => t('Audio provided by SoundCloud.'),
'type' => STREAM_WRAPPERS_READ_VISIBLE,
),
);
}
/**
* Implements hook_theme().
*/
function media_soundcloud_theme($existing, $type, $theme, $path) {
return array(
'media_soundcloud_preview_style' => array(
'variables' => array('style_name' => NULL),
'file' => 'media_soundcloud.theme.inc',
'path' => $path . '/includes/themes',
),
'media_soundcloud_field_formatter_styles' => array(
'variables' => array('element' => NULL, 'style' => NULL),
'file' => 'media_soundcloud.theme.inc',
'path' => $path . '/includes/themes',
),
'media_soundcloud_audio' => array(
'variables' => array('uri' => NULL, 'width' => NULL, 'autoplay' => NULL, 'extra_params' => NULL),
'file' => 'media_soundcloud.theme.inc',
'path' => $path . '/includes/themes',
'template' => 'media-soundcloud-audio',
),
'media_soundcloud_embed' => array(
'variables' => array('style_name' => NULL, 'uri' => NULL, 'alt' => NULL, 'title' => NULL),
'file' => 'media_soundcloud.theme.inc',
'path' => $path . '/includes/themes',
),
'media_soundcloud_styles' => array(
'variables' => array('element' => NULL, 'style' => NULL),
'file' => 'media_soundcloud.theme.inc',
'path' => $path . '/includes/themes',
),
);
}
/**
* Implements hook_media_parse().
*
* @todo This hook should be deprecated. Refactor Media module to not call it
* any more, since media_internet should be able to automatically route to the
* appropriate handler.
*/
function media_soundcloud_media_parse($embed_code) {
$handler = new MediaInternetSoundCloudHandler($embed_code);
return $handler->parse($embed_code);
}
/**
* Implements hook_media_format_form_prepare_alter().
*/
function media_soundcloud_media_format_form_prepare_alter(&$form, &$form_state, $media) {
$settings = array('autosubmit' => ($media->type == "audio"));
drupal_add_js(array('media_format_form' => $settings), 'setting');
}
/**
* Implements hook_ctools_plugin_api().
*/
function media_soundcloud_ctools_plugin_api($owner, $api) {
static $api_versions = array(
'file_entity' => array(
'file_default_displays' => 1,
),
);
if (isset($api_versions[$owner][$api])) {
return array('version' => $api_versions[$owner][$api]);
}
}
/**
* Implements hook_file_mimetype_mapping_alter().
*
* Create a fake mimetype so it will be compatible with File Entity's dev changes
* which now requires each file type to select supported mime types
*/
function media_soundcloud_file_mimetype_mapping_alter(&$mapping) {
$mapping['mimetypes'][] = 'audio/soundcloud';
}
/*
* Implements hook_file_default_types_alter().
*
* Adds the audio/soundcloud fake mimetype to audio files.
*/
function media_soundcloud_file_default_types_alter(&$types) {
$types['audio']->mimetypes[] = 'audio/soundcloud';
}