-
Notifications
You must be signed in to change notification settings - Fork 3
/
islandora_doi.module
96 lines (75 loc) · 2.96 KB
/
islandora_doi.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
<?php
define('DATACITE_DOI_URL', 'mds.datacite.org/doi');
function islandora_doi_menu() {
$items = array();
$items['admin/settings/islandora_doi'] = array(
'title' => t('Islandora DOI'),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_doi_admin'),
'access arguments' => array('administer islandora doi'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function islandora_doi_perm() {
return array('administer islandora doi');
}
function islandora_doi_admin() {
$form = array();
$form['islandora_doi_prefix'] = array(
'#type' => 'textfield',
'#title' => t('DOI Prefix'),
'#default_value' => variable_get('islandora_doi_prefix', ''),
);
$form['islandora_doi_username'] = array(
'#type' => 'textfield',
'#title' => t('DataCite Username'),
'#default_value' => variable_get('islandora_doi_username', ''),
);
$form['islandora_doi_password'] = array(
'#type' => 'textfield',
'#title' => t('DataCite Password'),
'#default_value' => variable_get('islandora_doi_password', ''),
);
$form['islandora_doi_hostname'] = array(
'#type' => 'textfield',
'#title' => t('System hostname for minted DOI'),
'#default_value' => variable_get('islandora_doi_hostname', ''),
'#description' => t('The URL hostname to be used for DOI record. Ex: http://@host_name', array('@host_name' => $_SERVER['SERVER_NAME'])),
);
return system_settings_form($form);
}
function islandora_doi_mint($doi, $url) {
$prefix = variable_get('islandora_doi_prefix', '');
$doi = $prefix . '/' . $doi;
$data = drupal_query_string_encode(array('doi' => $doi, 'url' => $url));
$request_url = 'https://' . variable_get('islandora_doi_username', '') . ':' . variable_get('islandora_doi_password', '') . '@' . DATACITE_DOI_URL;
$response = drupal_http_request($request_url, array('Content-Type' => 'application/x-www-form-urlencoded', 'charset' => 'UTF-8'), 'POST', $data);
if ($response->code == '201') {
return $doi;
}
else {
watchdog('islandora_doi', 'DOI mint failed: ' . $response->data);
return FALSE;
}
}
function islandora_doi_form_alter(&$form, &$form_state, $form_id) {
if (!empty($form['DOI'])) {
$form['#submit'][] = 'islandora_doi_form_submit';
}
}
function islandora_doi_form_submit($form, &$form_state) {
if (!empty($form_state['values']['DOI']) && !empty($form_state['values']['pid'])) {
global $base_url;
$hostname = variable_get('islandora_doi_hostname', '');
if (empty($hostname)) {
$hostname = 'http://' . $_SERVER['SERVER_NAME'];
}
$object_url = $hostname . '/fedora/repository/' . $form_state['values']['pid'];
$ret = islandora_doi_mint($form_state['values']['DOI'], $object_url);
if ($ret) {
drupal_set_message(t('DOI minted: @doi for object: @pid', array('@doi' => $ret, '@pid' => $form_state['values']['pid'])));
module_invoke_all('islandora_doi_post_mint', $form_state['values']['pid'], $ret);
}
}
}