Partial fixes to enable unapi for non-zebra and non-public-facing sru
[koha.git] / opac / unapi
1 #!/usr/bin/perl
2 use CGI;
3 use strict;
4 use warnings;
5 use C4::Context;
6 use XML::Simple;
7 use LWP::Simple;
8
9 use LWP::UserAgent;
10 use HTTP::Request::Common;
11
12 my $cgi = new CGI;
13 binmode(STDOUT, "utf8"); #output as utf8
14 my $baseurl = C4::Context->preference('OPACBaseURL');
15 warn "Warning: OPACBaseURL not set in system preferences" unless $baseurl;
16
17 my $id = $cgi->param('id');
18 my $format = $cgi->param('format');
19 if ($id && $format) {
20
21     # koha:isbn:0152018484
22     if ($id =~ /isbn/) {
23         $id =~ s/koha:isbn://;
24
25         # two ways to do this, one via the SRU Zebra server (fast)
26         my $url = "http://$baseurl:9998/biblios?version=1.1&operation=searchRetrieve&query=$id&startRecord=1&maximumRecords=20&recordSchema=$format";
27         my $content= get($url);
28
29         # the other via XSL parsing (not as fast)
30         unless ($content) {
31             
32         eval {
33             my $conn = C4::Context->Zconn('biblioserver');
34             $conn->option(preferredRecordSyntax => $format);
35             my $rs = $conn->search_pqf('@attr 1=7 '.$id);
36             my $n = $rs->size();
37             $content = $rs->record(0)->raw();
38         };
39         if ($@) {
40             print "Error ", $@->code(), ": ", $@->message(), "\n";
41         }
42
43         }
44         print $cgi->header( -type =>'application/xml' );
45         print $content;
46     }
47 }
48
49 else {
50
51 print $cgi->header( -type =>'application/xml' );
52
53 print "<?xml version='1.0' encoding='utf-8'  ?>
54 <formats>
55 <!-- <format name=\"opac\" type=\"text/html\"/> -->
56 <!-- <format name=\"html\" type=\"text/html\"/> -->
57 <!-- <format name=\"htmlholdings\" type=\"text/html\"/> -->
58 <!-- <format name=\"html-full\" type=\"text/html\"/> -->
59 <!-- <format name=\"htmlholdings-full\" type=\"text/html\"/> -->
60 <!-- <format name=\"atom\" type=\"application/xml\" namespace_uri=\"http://www.w3.org/2005/Atom\" docs=\"http://www.ietf.org/rfc/rfc4287.txt\"/> -->
61 <!-- <format name=\"atom-full\" type=\"application/xml\" namespace_uri=\"http://www.w3.org/2005/Atom\" docs=\"http://www.ietf.org/rfc/rfc4287.txt\"/> -->
62 <format name=\"marcxml\" type=\"application/xml\" namespace_uri=\"http://www.loc.gov/MARC21/slim\" docs=\"http://www.loc.gov/marcxml/\" schema_location=\"http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd\"/>
63 <format name=\"marcxml-full\" type=\"application/xml\" namespace_uri=\"http://www.loc.gov/MARC21/slim\" docs=\"http://www.loc.gov/marcxml/\" schema_location=\"http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd\"/>
64 <format name=\"mods\" type=\"application/xml\" namespace_uri=\"http://www.loc.gov/mods/\" docs=\"http://www.loc.gov/mods/\" schema_location=\"http://www.loc.gov/standards/mods/mods.xsd\"/>
65 <format name=\"mods-full\" type=\"application/xml\" namespace_uri=\"http://www.loc.gov/mods/\" docs=\"http://www.loc.gov/mods/\" schema_location=\"http://www.loc.gov/standards/mods/mods.xsd\"/>
66 <format name=\"mods3\" type=\"application/xml\" namespace_uri=\"http://www.loc.gov/mods/v3\" docs=\"http://www.loc.gov/mods/\" schema_location=\"http://www.loc.gov/standards/mods/v3/mods-3-1.xsd\"/>
67 <format name=\"mods3-full\" type=\"application/xml\" namespace_uri=\"http://www.loc.gov/mods/v3\" docs=\"http://www.loc.gov/mods/\" schema_location=\"http://www.loc.gov/standards/mods/v3/mods-3-1.xsd\"/>
68 <format name=\"oai_dc\" type=\"application/xml\" namespace_uri=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" schema_location=\"http://www.openarchives.org/OAI/2.0/oai_dc.xsd\"/>
69 <format name=\"rdfdc\" type=\"application/xml\" namespace_uri=\"http://purl.org/dc/elements/1.1/\" schema_location=\"http://purl.org/dc/elements/1.1/\"/>
70 <format name=\"rss2\" type=\"application/xml\"/>
71 <format name=\"rss2-full\" type=\"application/xml\"/>
72 <format name=\"srw_dc\" type=\"application/xml\" namespace_uri=\"info:srw/schema/1/dc-schema\" schema_location=\"http://www.loc.gov/z3950/agency/zing/srw/dc-schema.xsd\"/>
73 </formats>
74 ";
75 }