-
Notifications
You must be signed in to change notification settings - Fork 0
/
oclc.php
executable file
·66 lines (66 loc) · 3 KB
/
oclc.php
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
<?php
//this page's sole purpose is completing citation data by geting the record from OCLC.
if (!empty($oclcnum) || !empty($_REQUEST['oclcnum'])) {
$oclcnum = !empty($oclcnum) ? $oclcnum : $_REQUEST['oclcnum'];
$isn = $oclcnum;
} elseif (!empty($isbn) || !empty($_REQUEST['isbn'])) {
if (empty($isbn)) {
$isbn = $_REQUEST['isbn'];
}
$isn = 'isbn/' . $isbn;
} elseif (!empty($issn) || !empty($_REQUEST['issn'])) {
if (empty($issn)) {
$issn = $_REQUEST['issn'];
}
$isn = 'issn/' . $issn;
}
include_once($_SERVER['DOCUMENT_ROOT'] . '/webFiles/Alma_Primo/APIRequestFormAlma/vars/privateVar.php'); //file that includes variables for our APIkey, wskey, and URL for verification of patron hotspot eligibility
$oclc_url = "https://www.worldcat.org/webservices/catalog/content/$isn?wskey=$wskey"; //wskey is unique to the institution
//&format=json';
//I hate XML with a firey passion. Please give me JSON.
$oclc_xml = file_get_contents($oclc_url);
$xml = simplexml_load_string($oclc_xml);
$oclc_json = json_encode($xml, JSON_PRETTY_PRINT);
$oclc_array = json_decode($oclc_json, TRUE);
//the most important piece of info we need if we don't already have it is the OCLC#
if (empty($oclcnum)) {
$oclcnum = isset($oclc_array['controlfield'][0]) ? $oclc_array['controlfield'][0] : '';
}
//if we need data and have an array, let's go get it
if ((empty($issn) && empty($isbn) || empty($title) || empty($date)) && isset($oclc_array)) {
foreach ($oclc_array['datafield'] as $l => $q) {
if ($q['@attributes']['tag'] == '022') {
if (is_array($q['subfield'])) {
$issn = $q['subfield'][0];
} else {
$issn = $q['subfield'];
}
}
if ($q['@attributes']['tag'] == '020' && empty($isbn)) {
//just get the first one, if it is an array of isbns
$isbn = is_array($q['subfield']) ? $q['subfield'][0] : $q['subfield'];
}
if ($q['@attributes']['tag'] == '245' && empty($title)) { //only update the title if we don't have it or summit will break
$title = !is_array($q['subfield']) ? trim($q['subfield']) : trim($q['subfield'][0] . ' ' . $q['subfield'][1]);
}
if ($q['@attributes']['tag'] == '260' && empty($date) && empty($issn)) {
foreach ($q['subfield'] as $k => $v) {
if (preg_match('/.*?[0-9]{3,4}.*?/', $v)) {
$date = $v;
}
unset($k, $v);
}
//clean the sloppy datefield up
$date = str_replace('©', '', $date);
$date = str_replace('©', '', $date);
$date = str_replace('.', '', $date);
}
if ($q['@attributes']['tag'] == '264' && empty($date) && empty($issn)) {
$date = $q['subfield'][2];
//clean the sloppy datefield up
$date = trim(rtrim($date, '.'));
$date = str_replace('©', '', $date);
$date = str_replace('©', '', $date);
}
}
}