-
Notifications
You must be signed in to change notification settings - Fork 6
/
refworks.inc
57 lines (55 loc) · 1.83 KB
/
refworks.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
<?php
/**
* @file
*
*/
function scholar_refworks_add_form($pid = NULL) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'scholar', 'bibutils/Bibutils');
if ($pid != NULL) {
$object = new Fedora_Item($pid);
$ds_array = $object->get_datastreams_list_as_array();
if (array_key_exists('MODS', $ds_array)) {
$mods = $object->get_datastream_dissemination('MODS');
$rnd = rand('1000', '9999');
$mods_filename = file_directory_path() . '/mods' . $rnd . '.temp';
$mods_handle = fopen($mods_filename, 'w');
fwrite($mods_handle, $mods);
fclose($mods_handle);
$ris_filename = file_directory_path() . '/ris' . $rnd . '.temp';
Bibutils::Convert($mods_filename, 'MODS', $ris_filename, 'RIS');
$ris = file_get_contents($ris_filename);
$xml = new SimpleXMLElement($mods);
$xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3');
$genre = $xml->xpath('//mods:genre');
$genre_str = (string) $genre[0];
$ty = scholar_refworks_get_ris_type($genre_str);
$ris = str_replace('STD', $ty, $ris);
echo trim($ris);
}
else {
drupal_set_message(t('Could not export to Refworks. MODS record not found for item @pid!', array('@pid' => $pid)), 'error');
}
}
}
function scholar_refworks_get_ris_type($genre) {
$type = array('Abstract' => 'Abstract',
'Journal Article' => 'JOUR',
'Art' => 'ART',
'Book, Whole' => 'BOOK',
'Book, Edited' => 'EDBOOK',
'Book, Section' => 'CHAP',
'Conference Proceedings' => 'CONF',
'Magazine Article' => 'MGZN',
'Newspaper Article' => 'NEWS',
'Report' => 'RPRT',
'Dissertation/Thesis' => 'THES',
'Unpublished Material' => 'UNPB',
'Video' => 'VIDEO',
);
$ty = $type[$genre];
if(!isset($ty)){
$ty = 'STD';
}
return $ty;
}