media_soundcloud.variables.inc
3.88 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
<?php
/**
* @file media_soundcloud/includes/media_soundcloud.variables.inc
* Variable defaults for Media: SoundCloud.
*/
/**
* Define our constants.
*/
/**
* This is the variable namespace, automatically prepended to module variables.
*/
define('MEDIA_SOUNDCLOUD_NAMESPACE', 'media_soundcloud__');
/**
* Wrapper for variable_get() using the Media: SoundCloud variable registry.
*
* @param string $name
* The variable name to retrieve. Note that it will be namespaced by
* pre-pending MEDIA_SOUNDCLOUD_NAMESPACE, as to avoid variable collisions
* with other modules.
* @param unknown $default
* An optional default variable to return if the variable hasn't been set
* yet. Note that within this module, all variables should already be set
* in the media_soundcloud_variable_default() function.
* @return unknown
* Returns the stored variable or its default.
*
* @see media_soundcloud_variable_set()
* @see media_soundcloud_variable_del()
* @see media_soundcloud_variable_default()
*/
function media_soundcloud_variable_get($name, $default = NULL) {
// Allow for an override of the default.
// Useful when a variable is required (like $path), but namespacing is still
// desired.
if (!isset($default)) {
$default = media_soundcloud_variable_default($name);
}
// Namespace all variables.
$variable_name = MEDIA_SOUNDCLOUD_NAMESPACE . $name;
return variable_get($variable_name, $default);
}
/**
* Wrapper for variable_set() using the Media: SoundCloud variable registry.
*
* @param string $name
* The variable name to set. Note that it will be namespaced by
* pre-pending MEDIA_SOUNDCLOUD_NAMESPACE, as to avoid variable collisions with
* other modules.
* @param unknown $value
* The value for which to set the variable.
* @return unknown
* Returns the stored variable after setting.
*
* @see media_soundcloud_variable_get()
* @see media_soundcloud_variable_del()
* @see media_soundcloud_variable_default()
*/
function media_soundcloud_variable_set($name, $value) {
$variable_name = MEDIA_SOUNDCLOUD_NAMESPACE . $name;
return variable_set($variable_name, $value);
}
/**
* Wrapper for variable_del() using the Media: SoundCloud variable registry.
*
* @param string $name
* The variable name to delete. Note that it will be namespaced by
* pre-pending MEDIA_SOUNDCLOUD_NAMESPACE, as to avoid variable collisions with
* other modules.
*
* @see media_soundcloud_variable_get()
* @see media_soundcloud_variable_set()
* @see media_soundcloud_variable_default()
*/
function media_soundcloud_variable_del($name) {
$variable_name = MEDIA_SOUNDCLOUD_NAMESPACE . $name;
variable_del($variable_name);
}
/**
* The default variables within the Media: SoundCloud namespace.
*
* @param string $name
* Optional variable name to retrieve the default. Note that it has not yet
* been pre-pended with the MEDIA_SOUNDCLOUD_NAMESPACE namespace at this time.
* @return unknown
* The default value of this variable, if it's been set, or NULL, unless
* $name is NULL, in which case we return an array of all default values.
*
* @see media_soundcloud_variable_get()
* @see media_soundcloud_variable_set()
* @see media_soundcloud_variable_del()
*/
function media_soundcloud_variable_default($name = NULL) {
static $defaults;
if (!isset($defaults)) {
$defaults = array(
'width' => "100%",
'autoplay' => FALSE,
'extra_params' => "",
'preview_uri' => 'soundcloud://u/djandrewz/a/hope-one',
);
}
if (!isset($name)) {
return $defaults;
}
if (isset($defaults[$name])) {
return $defaults[$name];
}
}
/**
* Return the fully namespace variable name.
*
* @param string $name
* The variable name to retrieve the namespaced name.
* @return string
* The fully namespace variable name, prepended with
* MEDIA_SOUNDCLOUD_NAMESPACE.
*/
function media_soundcloud_variable_name($name) {
return MEDIA_SOUNDCLOUD_NAMESPACE . $name;
}