-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathislandora_scopus.module
85 lines (81 loc) · 2.62 KB
/
islandora_scopus.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
<?php
/**
* @file
* Normal module functions.
*/
/**
* Implements hook_menu().
*/
function islandora_scopus_menu() {
return array(
'admin/islandora/tools/badges/scopus' => array(
'title' => 'Scopus',
'description' => 'Configure Scopus integration.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_scopus_admin_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
'file' => 'includes/admin.form.inc',
),
);
}
/**
* Implements hook_block_info().
*/
function islandora_scopus_block_info() {
return array(
'islandora_scopus_badge' => array(
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'islandora/object/*',
'cache' => DRUPAL_CACHE_PER_PAGE,
'info' => t('Islandora Scopus Badge'),
),
);
}
/**
* Implements hook_block_view().
*/
function islandora_scopus_block_view($delta = '') {
module_load_include('inc', 'islandora_badges', 'includes/utilities');
module_load_include('inc', 'islandora_scopus', 'includes/utilities');
$to_render = array();
if ($delta == 'islandora_scopus_badge') {
$api_key = variable_get('islandora_scopus_api_key', '');
if ($api_key) {
$object = menu_get_object('islandora_object', 2);
if ($object) {
if (islandora_badges_show_for_cmodel($object)) {
$doi = islandora_badges_get_doi($object);
if ($doi) {
$id = islandora_scopus_get_id('doi', $doi);
}
// TODO: Extend to allow PMID, etc.
if (isset($id)) {
$headers = array('Accept' => 'text/html', 'X-ELS-APIKey' => $api_key);
$data = http_build_query(array(
'scopus_id' => $id,
'apiKey' => $api_key,
'httpAccept' => 'text/html',
));
$scopus_endpoint = variable_get('islandora_scopus_api_endpoint', 'https://api.elsevier.com/content/abstract/citation-count');
$scopus_query = $scopus_endpoint . '?' . $data;
$response = drupal_http_request($scopus_query, array('headers' => $headers));
// Hit the API.
if ($response->code == 200) {
if (!preg_match('/alt=\"unavailable\"/', $response->data)) {
$to_render['content']['islandora_scopus'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => 'islandora_scopus_embed',
),
'#children' => $response->data,
);
}
}
}
}
}
}
}
return $to_render;
}