Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 54 lines (44 sloc) 1.592 kb
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
<?php

class Download {

//a small class to wrap a CURL, it takes an array with two values: the hostname and the rest of the query
//returns data on success and false on fail

function url($url){
$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,1);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($session, CURLOPT_HTTPHEADER, array("Content-Type: application/rdf+xml"));
$data = curl_exec($session);
$responseHeader = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session);

if ($responseHeader == 200){
$return = $data;
}
else {
$return = false;
}
unset($url);
unset($session);
unset($data);
unset($responseHeader);
return $return;
}
}

//Using the xISBN service, get an OCLCNumber in order to return an OCLC Work ID
function getOWI($data){
//create instance of Download class and find an OCLC Number associated with the submitted isbn
$d = new Download();
$url = 'http://xisbn.worldcat.org/webservices/xid/isbn/'.urlencode($data).'?method=getEditions&format=xml&fl=oclcnum';
$isbndata = $d->url($url);
//match the OCLC Number
preg_match('/oclcnum="([^"\s]+)"/i',$isbndata,$m);
if ($m[1]) {
//Request the metadata associated with the OCLC Number, including the OCLC Work Number; if found return this
$owi = $d->url('http://xisbn.worldcat.org/webservices/xid/oclcnum/'.urlencode($m[1]).'?method=getMetadata&format=xml&fl=owi');
preg_match('/owi="([^"]+)"/i',$owi,$m);
if ($m[1]){echo $m[1];}
else {return 0;}
}
else {return 0;}

}

getOWI(htmlspecialchars($_GET['isbn']));

?>

Something went wrong with that request. Please try again.