forked from cyberwolf/cnapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnapi.admin.inc
195 lines (179 loc) · 6.39 KB
/
cnapi.admin.inc
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* @file
* Callback and handler implementations for administration pages.
*/
/**
* Configuration form for general settings.
*
* @ingroup forms
* @see system_settings_form()
*/
function cnapi_admin_settings() {
// general api settings
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Configuration'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['settings']['cnapi_api_location'] = array(
'#type' => 'textfield',
'#title' => t('API location'),
'#description' => t('The URL where the CultuurNet API resides. End with a slash. Example: http://build.uitdatabank.be/'),
'#default_value' => variable_get('cnapi_api_location', CNAPI_API_LOCATION),
);
$form['settings']['cnapi_api_key'] = array(
'#type' => 'textfield',
'#title' => t('API key'),
'#description' => t('Your CultuurNet API key.'),
'#default_value' => variable_get('cnapi_api_key', ''),
'#size' => 40,
'#maxlength' => 40,
);
$form['settings']['cnapi_api_output_type'] = array(
'#type' => 'textfield',
'#title' => t('Output type'),
'#description' => t('Your CultuurNet API output type.'),
'#default_value' => variable_get('cnapi_api_output_type', 1),
'#size' => 2,
'#maxlength' => 2,
);
$form['settings']['cnapi_lib_version'] = array(
'#type' => 'textfield',
'#title' => t('Library version'),
'#description' => t('Version identifier of the values XML files.'),
'#default_value' => variable_get('cnapi_lib_version', ''),
'#size' => 4,
'#maxlength' => 4,
);
// proxy settings
$form['proxy'] = array(
'#type' => 'fieldset',
'#title' => t('Proxy server'),
'#description' => t('If you are connecting over a proxy server, specify its settings here.'),
'#collapsible' => TRUE,
'#collapsed' => !variable_get('cnapi_proxy_enabled', FALSE),
);
$form['proxy']['cnapi_proxy_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Connect over a proxy server'),
'#default_value' => variable_get('cnapi_proxy_enabled', FALSE),
);
$form['proxy']['cnapi_proxy_server'] = array(
'#type' => 'textfield',
'#title' => t('Web proxy server'),
'#description' => t('The HTTP proxy to tunnel requests through.'),
'#default_value' => variable_get('cnapi_proxy_server', ''),
'#states' => array(
'invisible' => array(
'input[name="cnapi_proxy_enabled"]' => array('checked' => FALSE),
),
),
);
$form['proxy']['cnapi_proxy_port'] = array(
'#type' => 'textfield',
'#title' => t('Port'),
'#description' => t('Specify the port number of the proxy to connect to. Leave empty for default.'),
'#default_value' => variable_get('cnapi_proxy_port', ''),
'#states' => array(
'invisible' => array(
'input[name="cnapi_proxy_enabled"]' => array('checked' => FALSE),
),
),
);
$form['proxy']['cnapi_proxy_username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#description' => t('Specify the username for the proxy to connect to. Leave empty for no username.'),
'#default_value' => variable_get('cnapi_proxy_username', ''),
'#states' => array(
'invisible' => array(
'input[name="cnapi_proxy_enabled"]' => array('checked' => FALSE),
),
),
);
$form['proxy']['cnapi_proxy_password'] = array(
'#type' => 'textfield',
'#title' => t('Password'),
'#description' => t('Specify the password for the proxy to connect to. Leave empty for no password.'),
'#default_value' => variable_get('cnapi_proxy_password', ''),
'#states' => array(
'invisible' => array(
'input[name="cnapi_proxy_enabled"]' => array('checked' => FALSE),
),
),
);
return system_settings_form($form);
}
/**
* Configuration form for API defaults.
*
* @ingroup forms
* @see system_settings_form()
*/
function cnapi_admin_defaults() {
$pagelength_options = drupal_map_assoc(array(5, 10, 15, 20, 25, 50, 100));
$combined_sort_options = array();
$sort_options = cnapi_get_sort_options();
$sort_direction_options = cnapi_get_sort_direction_options();
foreach ($sort_options as $sort_option_key => $sort_option_value) {
foreach ($sort_direction_options as $sort_direction_option_key => $sort_direction_option_value) {
$combined_sort_options[$sort_option_key . ' ' . strtoupper($sort_direction_option_key)] = $sort_option_value . ' ' . $sort_direction_option_value;
}
}
$contexts = array(
'general' => array(
'name' => t('General listings'),
),
'event' => array(
'name' => t('Event listings'),
),
'production' => array(
'name' => t('Production listings'),
),
'actor' => array(
'name' => t('Actor listings'),
),
);
$form['defaults']['#tree'] = TRUE;
foreach ($contexts as $context => $info) {
$context_default_specified = _cnapi_default_values('pagelength', $context) != -1 || _cnapi_default_values('sort', $context) != -1;
$form['defaults'][$context] = array(
'#type' => 'fieldset',
'#title' => $info['name'],
'#collapsible' => TRUE,
'#collapsed' => !$context_default_specified,
);
$form['defaults'][$context]['pagelength'] = array(
'#type' => 'select',
'#title' => t('Items per page'),
'#description' => t('The amount of items to request by default per API call.'),
'#options' => array(-1 => t('Use general pagelength settings')) + $pagelength_options,
'#default_value' => _cnapi_default_values('pagelength', $context),
);
$form['defaults'][$context]['sort'] = array(
'#type' => 'select',
'#title' => t('Sort'),
'#description' => t('The sort field by default per API call.'),
'#options' => array(-1 => t('Use general pagelength settings')) + $combined_sort_options,
'#default_value' => _cnapi_default_values('sort', $context),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Submit handler for configuration form for API defaults.
*/
function cnapi_admin_defaults_submit($form, &$form_state) {
$defaults = $form_state['values']['defaults'];
variable_set('cnapi_defaults', $defaults['general']);
variable_set('cnapi_defaults_events', $defaults['event']);
variable_set('cnapi_defaults_productions', $defaults['production']);
variable_set('cnapi_defaults_actors', $defaults['actor']);
drupal_set_message(t('Your defaults have been saved.'));
}