-
Notifications
You must be signed in to change notification settings - Fork 10
/
islandora_altmetrics.module
79 lines (75 loc) · 2.66 KB
/
islandora_altmetrics.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
<?php
/**
* @file
* Main hooks for Islandora Altmentrics.
*/
/**
* Implements hook_menu().
*/
function islandora_altmetrics_menu() {
return array(
'admin/islandora/tools/badges/altmetrics' => array(
'title' => 'Altmetrics',
'description' => 'Configure Altmetrics integration.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_altmetrics_admin_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
'file' => 'includes/admin.form.inc',
),
);
}
/**
* Implements hook_block_info().
*/
function islandora_altmetrics_block_info() {
return array(
'islandora_altmetrics_altmetrics' => array(
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'islandora/object/*',
'cache' => DRUPAL_CACHE_PER_PAGE,
'info' => t('Islandora Altmetrics Badge'),
),
);
}
/**
* Implements hook_block_view().
*/
function islandora_altmetrics_block_view($delta) {
module_load_include('inc', 'islandora_badges', 'includes/utilities');
$to_render = array();
if ($delta == 'islandora_altmetrics_altmetrics') {
$object = menu_get_object('islandora_object', 2);
if ($object) {
if (islandora_badges_show_for_cmodel($object)) {
// Use new customizable list of cmodels.
foreach (islandora_badges_get_identifier_types() as $id_type => $id_vars) {
$id_xpath = $id_vars['xpath'];
$id_value = islandora_badges_get_identifier_value($object, $id_type, $id_xpath);
if ($id_value) {
// Only generate block if a result exists - check API callback.
$altmetrics_api_url = 'http://api.altmetric.com/v1/' . $id_type . '/' . $id_value . '?callback=my_callback';
$head_response = drupal_http_request($altmetrics_api_url, array('method' => 'HEAD'));
if ($head_response->code == 200) {
// Embed Altmetrics.
$to_render['content']['altmetrics'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('altmetric-embed'),
'data-badge-type' => variable_get('islandora_altmetrics_badge', 'Default'),
'data-' . $id_type => $id_value,
'data-badge-popover' => variable_get('islandora_altmetrics_popover', 'right'),
'data-hide-no-mentions' => 'true',
'data-link-target' => '_blank',
),
);
drupal_add_js('https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js', 'external');
break;
}
}
}
}
}
}
return $to_render;
}