-
Notifications
You must be signed in to change notification settings - Fork 1
/
islandora_repository_connection_config.module
114 lines (110 loc) · 4.94 KB
/
islandora_repository_connection_config.module
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
<?php
/**
* @file
* General hook implementations.
*/
/**
* Implements hook_islandora_repository_connection_construction_alter().
*/
function islandora_repository_connection_config_islandora_repository_connection_construction_alter($instance) {
foreach (variable_get('islandora_repository_connection_config', islandora_repository_connection_config_get_defaults()) as $key => $value) {
$instance->{$key} = $value;
}
}
/**
* Implements hook_form_islandora_repository_admin_form_alter().
*/
function islandora_repository_connection_config_form_islandora_repository_admin_alter(&$form, &$form_state) {
$connection_default = variable_get('islandora_repository_connection_config', islandora_repository_connection_config_get_defaults());
$form['islandora_tabs']['islandora_repository_connection_config'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Tuque connection config'),
'#description' => t('Many of these parameters will reference parameters from the <a href="@curl_url">PHP cURL Library</a>.', array(
'@curl_url' => 'http://php.net/manual/function.curl-setopt.php',
)),
'cookies' => array(
'#title' => t('Cookies'),
'#type' => 'checkbox',
'#description' => t('Indicate if the HTTP connection should use cookies.'),
'#default_value' => $connection_default['cookies'],
),
'verifyHost' => array(
'#title' => t('Verify SSL Host'),
'#description' => t('Check for existence and match of the common name, setting "CURLOPT_SSL_VERIFYHOST" to 2.'),
'#type' => 'checkbox',
'#default_value' => $connection_default['verifyHost'],
),
'verifyPeer' => array(
'#title' => t('Verify SSL Peer'),
'#description' => t('Verify peer certificates, corresponding to "CURLOPT_SSL_VERIFYPEER".'),
'#type' => 'checkbox',
'#default_value' => $connection_default['verifyPeer'],
),
'timeout' => array(
'#title' => t('Total timeout'),
'#description' => t('An amount of time in seconds (empty or 0 uses the cURL default). CURL calls will be aborted if they pass this threshold. Corresponds to "CURLOPT_TIMEOUT".'),
'#type' => 'textfield',
'#default_value' => $connection_default['timeout'],
'#element_validate' => array('islandora_repository_connection_config_zero_or_positive_integer_validate'),
),
'connectTimeout' => array(
'#title' => t('Connection timeout'),
'#description' => t('An upper bound on the amount of time in seconds to wait while attempting to establish the connection, corresponding to "CURLOPT_CONNECTTIMEOUT". 0 will attempt to wait indefinitely.'),
'#type' => 'textfield',
'#default_value' => $connection_default['connectTimeout'],
'#element_validate' => array('islandora_repository_connection_config_zero_or_positive_integer_validate'),
),
'userAgent' => array(
'#title' => t('User Agent'),
'#description' => t('The string as which Tuque will identify, corresponding to "CURLOPT_USERAGENT". See <a href="@rfc_link">RFC 7231, Section 5.5.3</a> for details on the contents. The empty string will cause cURL to use its default.', array(
'@rfc_link' => 'http://tools.ietf.org/html/rfc7231#section-5.5.3',
)),
'#type' => 'textfield',
'#default_value' => $connection_default['userAgent'],
),
'reuseConnection' => array(
'#title' => t('Reuse Connection'),
'#description' => t('Causes the cURL context (and ideally the underlying TCP connection) to be reused between (most) Tuque requests.'),
'#type' => 'checkbox',
'#default_value' => $connection_default['reuseConnection'],
),
'debug' => array(
'#title' => t('Debug mode'),
'#description' => t('Corresponds to "CURLOPT_VERBOSE"; outputs additional information to STDERR (likely showing up in your server error logs, but ultimately dependent on how the code is being run).'),
'#type' => 'checkbox',
'#default_value' => $connection_default['debug'],
),
);
}
/**
* Element validation handler.
*
* Sets a form error if the value is not zero or a positive integer.
*/
function islandora_repository_connection_config_zero_or_positive_integer_validate($element, &$form_state) {
// Largely copy/pasta from Drupal's element_validate_integer_positive().
$value = $element['#value'];
if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value < 0)) {
form_error($element, t('%name must be either zero or a positive integer.', array('%name' => $element['#title'])));
}
}
/**
* Helper to define the array of defaults.
*
* @return array
* An associative array representing the defaults for the
* 'islandora_repository_connection_config' variable.
*/
function islandora_repository_connection_config_get_defaults() {
return array(
'cookies' => TRUE,
'verifyHost' => TRUE,
'verifyPeer' => TRUE,
'timeout' => NULL,
'connectTimeout' => 5,
'userAgent' => NULL,
'reuseConnection' => TRUE,
'debug' => FALSE,
);
}