1 package OpenILS::WWW::SuperCat;
2 use strict; use warnings;
5 use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
6 use APR::Const -compile => qw(:error SUCCESS);
7 use Apache2::RequestRec ();
8 use Apache2::RequestIO ();
9 use Apache2::RequestUtil;
13 use OpenSRF::EX qw(:try);
14 use OpenSRF::Utils qw/:datetime/;
15 use OpenSRF::Utils::Cache;
17 use OpenSRF::AppSession;
22 use Unicode::Normalize;
23 use OpenILS::Utils::Fieldmapper;
24 use OpenILS::WWW::SuperCat::Feed;
25 use OpenSRF::Utils::Logger qw/$logger/;
30 # set the bootstrap config when this module is loaded
31 my ($bootstrap, $cstore, $supercat, $actor, $parser, $search, $xslt, $cn_browse_xslt, %browse_types);
33 $browse_types{call_number}{xml} = sub {
36 my $year = (gmtime())[5] + 1900;
39 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
42 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
43 $cn_class =~ s/Fieldmapper-//gso;
45 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
46 my $cn_lib = $cn->owning_lib->shortname;
47 my $cn_label = $cn->label;
49 $cn_label =~ s/\n//gos;
50 $cn_label =~ s/'/'/go;
52 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
53 $ou_class =~ s/Fieldmapper-//gso;
55 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
56 my $ou_name = $cn->owning_lib->name;
58 $ou_name =~ s/\n//gos;
59 $ou_name =~ s/'/'/go;
61 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
62 $rec_class =~ s/Fieldmapper-//gso;
64 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
66 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
67 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
69 my $r_doc = $parser->parse_string($cn->record->marc);
70 $r_doc->documentElement->setAttribute( id => $rec_tag );
71 $content .= entityize($r_doc->documentElement->toString);
73 $content .= "</hold:volume>";
76 $content .= '</hold:volumes>';
77 return ("Content-type: application/xml\n\n",$content);
81 $browse_types{call_number}{html} = sub {
86 if (!$cn_browse_xslt) {
87 $cn_browse_xslt = $parser->parse_file(
88 OpenSRF::Utils::SettingsClient
90 ->config_value( dirs => 'xsl' ).
93 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
96 my (undef,$xml) = $browse_types{call_number}{xml}->($tree);
99 "Content-type: text/html\n\n",
101 $cn_browse_xslt->transform(
102 $parser->parse_string( $xml ),
117 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
119 my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
120 Fieldmapper->import(IDL => $idl);
122 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
123 $cstore = OpenSRF::AppSession->create('open-ils.cstore');
124 $actor = OpenSRF::AppSession->create('open-ils.actor');
125 $search = OpenSRF::AppSession->create('open-ils.search');
126 $parser = new XML::LibXML;
127 $xslt = new XML::LibXSLT;
129 $cn_browse_xslt = $parser->parse_file(
130 OpenSRF::Utils::SettingsClient
132 ->config_value( dirs => 'xsl' ).
136 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
143 return Apache2::Const::DECLINED if (-e $apache->filename);
145 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
148 ->request("open-ils.supercat.oisbn", $isbn)
151 print "Content-type: application/xml; charset=utf-8\n\n";
152 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
154 unless (exists $$list{metarecord}) {
156 return Apache2::Const::OK;
159 print "<idlist metarecord='$$list{metarecord}'>\n";
161 for ( keys %{ $$list{record_list} } ) {
162 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
163 print " <isbn record='$_'>$o</isbn>\n"
168 return Apache2::Const::OK;
174 return Apache2::Const::DECLINED if (-e $apache->filename);
179 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
180 my $rel_name = $cgi->url(-relative=>1);
181 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
184 my $url = $cgi->url(-path_info=>$add_path);
185 my $root = (split 'unapi', $url)[0];
186 my $base = (split 'unapi', $url)[0] . 'unapi';
189 my $uri = $cgi->param('id') || '';
190 my $host = $cgi->virtual_host || $cgi->server_name;
192 my $format = $cgi->param('format');
193 my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
194 (my $base_format = $format) =~ s/-full$//o;
195 my ($id,$type,$command,$lib) = ('','','');
198 my $body = "Content-type: application/xml; charset=utf-8\n\n";
200 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))$}o) {
204 $type = 'metarecord' if ($1 =~ /^m/o);
207 ->request("open-ils.supercat.$type.formats")
210 if ($type eq 'record' or $type eq 'isbn') {
211 $body .= <<" FORMATS";
213 <format name='opac' type='text/html'/>
214 <format name='html' type='text/html'/>
215 <format name='htmlholdings' type='text/html'/>
216 <format name='html-full' type='text/html'/>
217 <format name='htmlholdings-full' type='text/html'/>
219 } elsif ($type eq 'metarecord') {
220 $body .= <<" FORMATS";
222 <format name='opac' type='text/html'/>
227 my ($type) = keys %$h;
228 $body .= "\t<format name='$type' type='application/xml'";
230 for my $part ( qw/namespace_uri docs schema_location/ ) {
231 $body .= " $part='$$h{$type}{$part}'"
232 if ($$h{$type}{$part});
237 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
238 $body .= "\t<format name='$type-full' type='application/xml'";
240 for my $part ( qw/namespace_uri docs schema_location/ ) {
241 $body .= " $part='$$h{$type}{$part}'"
242 if ($$h{$type}{$part});
249 $body .= "</formats>\n";
253 ->request("open-ils.supercat.record.formats")
258 ->request("open-ils.supercat.metarecord.formats")
262 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
263 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
265 $body .= <<" FORMATS";
267 <format name='opac' type='text/html'/>
268 <format name='html' type='text/html'/>
269 <format name='htmlholdings' type='text/html'/>
270 <format name='html-full' type='text/html'/>
271 <format name='htmlholdings-full' type='text/html'/>
276 my ($type) = keys %$h;
277 $body .= "\t<format name='$type' type='application/xml'";
279 for my $part ( qw/namespace_uri docs schema_location/ ) {
280 $body .= " $part='$$h{$type}{$part}'"
281 if ($$h{$type}{$part});
286 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
287 $body .= "\t<format name='$type-full' type='application/xml'";
289 for my $part ( qw/namespace_uri docs schema_location/ ) {
290 $body .= " $part='$$h{$type}{$part}'"
291 if ($$h{$type}{$part});
298 $body .= "</formats>\n";
302 return Apache2::Const::OK;
305 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))?}o) {
309 $type = 'metarecord' if ($1 =~ /^metabib/o);
310 $type = 'isbn' if ($1 =~ /^isbn/o);
311 $type = 'call_number' if ($1 =~ /^call_number/o);
312 $command = 'retrieve';
313 $command = 'browse' if ($type eq 'call_number');
316 if (!$lib || $lib eq '-') {
317 $lib = $actor->request(
318 'open-ils.actor.org_unit_list.search' => parent_ou => undef
319 )->gather(1)->[0]->shortname;
322 my $lib_object = $actor->request(
323 'open-ils.actor.org_unit_list.search' => shortname => $lib
325 my $lib_id = $lib_object->id;
327 my $ou_types = $actor->request( 'open-ils.actor.org_types.retrieve' )->gather(1);
328 my $lib_depth = (grep { $_->id == $lib_object->ou_type } @$ou_types)[0]->depth;
330 if ($type eq 'call_number' and $command eq 'browse') {
331 print "Location: $root/browse/$base_format/call_number/$lib/$id\n\n";
335 if ($type eq 'isbn') {
336 my $rec = $supercat->request('open-ils.supercat.isbn.object.retrieve',$id)->gather(1);
338 print "Content-type: text/html; charset=utf-8\n\n";
339 $apache->custom_response( 404, <<" HTML");
342 <title>Type [$type] with id [$id] not found!</title>
346 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
357 { (keys(%$_))[0] eq $base_format }
358 @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
360 { $_ eq $base_format }
361 qw/opac html htmlholdings/
363 print "Content-type: text/html; charset=utf-8\n\n";
364 $apache->custom_response( 406, <<" HTML");
367 <title>Invalid format [$format] for type [$type]!</title>
371 <center>Sorry, format $format is not valid for type $type.</center>
378 if ($format eq 'opac') {
379 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id&l=$lib_id&d=$lib_depth\n\n"
380 if ($type eq 'metarecord');
381 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id&l=$lib_id&d=$lib_depth\n\n"
382 if ($type eq 'record');
384 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
385 my $feed = create_record_feed(
394 print "Content-type: text/html; charset=utf-8\n\n";
395 $apache->custom_response( 404, <<" HTML");
398 <title>Type [$type] with id [$id] not found!</title>
402 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
410 $feed->creator($host);
411 $feed->update_ts(gmtime_ISO8601());
412 $feed->link( unapi => $base) if ($flesh_feed);
414 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
415 print entityize($feed->toString) . "\n";
417 return Apache2::Const::OK;
420 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
421 my $data = $req->gather(1);
423 if ($req->failed || !$data) {
424 print "Content-type: text/html; charset=utf-8\n\n";
425 $apache->custom_response( 404, <<" HTML");
428 <title>$type $id not found!</title>
432 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
439 print "Content-type: application/xml; charset=utf-8\n\n$data";
441 return Apache2::Const::OK;
447 return Apache2::Const::DECLINED if (-e $apache->filename);
452 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
453 my $rel_name = $cgi->url(-relative=>1);
454 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
457 my $url = $cgi->url(-path_info=>$add_path);
458 my $root = (split 'supercat', $url)[0];
459 my $base = (split 'supercat', $url)[0] . 'supercat';
460 my $unapi = (split 'supercat', $url)[0] . 'unapi';
462 my $host = $cgi->virtual_host || $cgi->server_name;
464 my $path = $cgi->path_info;
465 my ($id,$type,$format,$command) = reverse split '/', $path;
466 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
467 (my $base_format = $format) =~ s/-full$//o;
469 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
470 print "Content-type: application/xml; charset=utf-8\n";
473 ->request("open-ils.supercat.$1.formats")
481 <type>text/html</type>
484 if ($1 eq 'record' or $1 eq 'isbn') {
486 <name>htmlholdings</name>
487 <type>text/html</type>
491 <type>text/html</type>
494 <name>htmlholdings-full</name>
495 <type>text/html</type>
498 <name>html-full</name>
499 <type>text/html</type>
504 my ($type) = keys %$h;
505 print "<format><name>$type</name><type>application/xml</type>";
507 for my $part ( qw/namespace_uri docs schema_location/ ) {
508 print "<$part>$$h{$type}{$part}</$part>"
509 if ($$h{$type}{$part});
514 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
515 print "<format><name>$type-full</name><type>application/xml</type>";
517 for my $part ( qw/namespace_uri docs schema_location/ ) {
518 print "<$part>$$h{$type}{$part}</$part>"
519 if ($$h{$type}{$part});
527 print "</formats>\n";
529 return Apache2::Const::OK;
533 ->request("open-ils.supercat.record.formats")
538 ->request("open-ils.supercat.metarecord.formats")
542 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
543 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
548 <type>text/html</type>
551 <name>htmlholdings</name>
552 <type>text/html</type>
556 <type>text/html</type>
559 <name>htmlholdings-full</name>
560 <type>text/html</type>
563 <name>html-full</name>
564 <type>text/html</type>
568 my ($type) = keys %$h;
569 print "<format><name>$type</name><type>application/xml</type>";
571 for my $part ( qw/namespace_uri docs schema_location/ ) {
572 print "<$part>$$h{$type}{$part}</$part>"
573 if ($$h{$type}{$part});
578 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
579 print "<format><name>$type-full</name><type>application/xml</type>";
581 for my $part ( qw/namespace_uri docs schema_location/ ) {
582 print "<$part>$$h{$type}{$part}</$part>"
583 if ($$h{$type}{$part});
591 print "</formats>\n";
594 return Apache2::Const::OK;
597 if ($format eq 'opac') {
598 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
599 if ($type eq 'metarecord');
600 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
601 if ($type eq 'record');
604 } elsif ($base_format eq 'marc21') {
608 my $bib = $supercat->request( "open-ils.supercat.record.object.retrieve", $id )->gather(1)->[0];
610 my $r = MARC::Record->new_from_xml( $bib->marc, 'UTF-8', 'USMARC' );
611 $r->delete_field( $_ ) for ($r->field(901));
616 a => $bib->tcn_value,
617 b => $bib->tcn_source,
622 print "Content-type: application/octet-stream\n\n";
628 print "Content-type: text/html; charset=utf-8\n\n";
629 $apache->custom_response( 404, <<" HTML");
636 <center>Couldn't fetch $id as MARC21.</center>
643 return Apache2::Const::OK;
645 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
646 my $feed = create_record_feed(
654 $feed->creator($host);
655 $feed->update_ts(gmtime_ISO8601());
656 $feed->link( unapi => $base) if ($flesh_feed);
658 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
659 print entityize($feed->toString) . "\n";
661 return Apache2::Const::OK;
664 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
668 print "Content-type: text/html; charset=utf-8\n\n";
669 $apache->custom_response( 404, <<" HTML");
672 <title>$type $id not found!</title>
676 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
683 print "Content-type: application/xml; charset=utf-8\n\n";
684 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
686 return Apache2::Const::OK;
692 return Apache2::Const::DECLINED if (-e $apache->filename);
696 my $year = (gmtime())[5] + 1900;
697 my $host = $cgi->virtual_host || $cgi->server_name;
700 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
701 my $rel_name = $cgi->url(-relative=>1);
702 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
705 my $url = $cgi->url(-path_info=>$add_path);
706 my $root = (split 'feed', $url)[0] . '/';
707 my $base = (split 'bookbag', $url)[0] . '/bookbag';
708 my $unapi = (split 'feed', $url)[0] . '/unapi';
710 $root =~ s{(?<!http:)//}{/}go;
711 $base =~ s{(?<!http:)//}{/}go;
712 $unapi =~ s{(?<!http:)//}{/}go;
714 my $path = $cgi->path_info;
715 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
717 my ($id,$type) = reverse split '/', $path;
718 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
720 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
721 return Apache2::Const::NOT_FOUND unless($bucket);
723 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
724 if ($type eq 'opac') {
725 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
726 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
731 my $feed = create_record_feed(
734 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
741 $feed->title("Items in Book Bag [".$bucket->name."]");
742 $feed->creator($host);
743 $feed->update_ts(gmtime_ISO8601());
745 $feed->link(rss => $base . "/rss2-full/$id" => 'application/rss+xml');
746 $feed->link(alternate => $base . "/atom-full/$id" => 'application/atom+xml');
747 $feed->link(html => $base . "/html-full/$id" => 'text/html');
748 $feed->link(unapi => $unapi);
752 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
753 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
758 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
759 print entityize($feed->toString) . "\n";
761 return Apache2::Const::OK;
766 return Apache2::Const::DECLINED if (-e $apache->filename);
770 my $year = (gmtime())[5] + 1900;
771 my $host = $cgi->virtual_host || $cgi->server_name;
774 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
775 my $rel_name = $cgi->url(-relative=>1);
776 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
779 my $url = $cgi->url(-path_info=>$add_path);
780 my $root = (split 'feed', $url)[0];
781 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
782 my $unapi = (split 'feed', $url)[0] . 'unapi';
784 my $path = $cgi->path_info;
785 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
787 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
789 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
790 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
793 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
795 #if ($type eq 'opac') {
796 # print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
797 # join('&', map { "rl=" . $_ } @$list) .
802 my $feed = create_record_feed( 'record', $type, $list, $unapi, undef, $flesh_feed);
806 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
808 $feed->title("$limit most recent $rtype ${axis}s");
811 $feed->creator($host);
812 $feed->update_ts(gmtime_ISO8601());
814 $feed->link(rss => $base . "/rss2-full/$rtype/$axis/$limit/$date" => 'application/rss+xml');
815 $feed->link(alternate => $base . "/atom-full/$rtype/$axis/$limit/$date" => 'application/atom+xml');
816 $feed->link(html => $base . "/html-full/$rtype/$axis/$limit/$date" => 'text/html');
817 $feed->link(unapi => $unapi);
821 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
822 join('&', map { 'rl=' . $_} @$list ),
827 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
828 print entityize($feed->toString) . "\n";
830 return Apache2::Const::OK;
839 if ($version eq '1.0') {
841 Content-type: application/opensearchdescription+xml; charset=utf-8
843 <?xml version="1.0" encoding="UTF-8"?>
844 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
845 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
846 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
847 <ShortName>$lib</ShortName>
848 <LongName>Search $lib</LongName>
849 <Description>Search the $lib OPAC by $class.</Description>
850 <Tags>$lib book library</Tags>
851 <SampleSearch>harry+potter</SampleSearch>
852 <Developer>Mike Rylander for GPLS/PINES</Developer>
853 <Contact>feedback\@open-ils.org</Contact>
854 <SyndicationRight>open</SyndicationRight>
855 <AdultContent>false</AdultContent>
856 </OpenSearchDescription>
860 Content-type: application/opensearchdescription+xml; charset=utf-8
862 <?xml version="1.0" encoding="UTF-8"?>
863 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
864 <ShortName>$lib</ShortName>
865 <Description>Search the $lib OPAC by $class.</Description>
866 <Tags>$lib book library</Tags>
867 <Url type="application/rss+xml"
868 template="$base/1.1/$lib/rss2-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
869 <Url type="application/atom+xml"
870 template="$base/1.1/$lib/atom-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
871 <Url type="application/x-mods3+xml"
872 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
873 <Url type="application/x-mods+xml"
874 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
875 <Url type="application/x-marcxml+xml"
876 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
877 <Url type="text/html"
878 template="$base/1.1/$lib/html-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
879 <LongName>Search $lib</LongName>
880 <Query role="example" searchTerms="harry+potter" />
881 <Developer>Mike Rylander for GPLS/PINES</Developer>
882 <Contact>feedback\@open-ils.org</Contact>
883 <SyndicationRight>open</SyndicationRight>
884 <AdultContent>false</AdultContent>
885 <Language>en-US</Language>
886 <OutputEncoding>UTF-8</OutputEncoding>
887 <InputEncoding>UTF-8</InputEncoding>
888 </OpenSearchDescription>
892 return Apache2::Const::OK;
895 sub opensearch_feed {
897 return Apache2::Const::DECLINED if (-e $apache->filename);
900 my $year = (gmtime())[5] + 1900;
902 my $host = $cgi->virtual_host || $cgi->server_name;
905 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
906 my $rel_name = $cgi->url(-relative=>1);
907 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
910 my $url = $cgi->url(-path_info=>$add_path);
911 my $root = (split 'opensearch', $url)[0];
912 my $base = (split 'opensearch', $url)[0] . 'opensearch';
913 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
915 my $path = $cgi->path_info;
916 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
918 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
924 if (!$lib || $lib eq '-') {
925 $lib = $actor->request(
926 'open-ils.actor.org_unit_list.search' => parent_ou => undef
927 )->gather(1)->[0]->shortname;
934 return opensearch_osd($version, $lib, $class, $base);
938 my $page = $cgi->param('startPage') || 1;
939 my $offset = $cgi->param('startIndex') || 1;
940 my $limit = $cgi->param('count') || 10;
942 $page = 1 if ($page !~ /^\d+$/);
943 $offset = 1 if ($offset !~ /^\d+$/);
944 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
947 $offset = ($page - 1) * $limit;
952 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = ('','','','','','','','');
953 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
955 $lang = $cgi->param('searchLang') if $cgi->param('searchLang');
956 $lang = '' if ($lang eq '*');
958 $sort = $cgi->param('searchSort') if $cgi->param('searchSort');
959 $sortdir = $cgi->param('searchSortDir') if $cgi->param('searchSortDir');
960 $terms .= " " . $cgi->param('searchTerms') if $cgi->param('searchTerms');
962 $class = $cgi->param('searchClass') if $cgi->param('searchClass');
965 $type = $cgi->param('responseType') if $cgi->param('responseType');
968 $org = $cgi->param('searchOrg') if $cgi->param('searchOrg');
972 my $kwt = $cgi->param('kw');
973 my $tit = $cgi->param('ti');
974 my $aut = $cgi->param('au');
975 my $sut = $cgi->param('su');
976 my $set = $cgi->param('se');
978 $terms .= " keyword: $kwt" if ($kwt);
979 $terms .= " title: $tit" if ($tit);
980 $terms .= " author: $aut" if ($aut);
981 $terms .= " subject: $sut" if ($sut);
982 $terms .= " series: $set" if ($set);
984 if ($version eq '1.0') {
986 } elsif ($type eq '-') {
989 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
991 $terms = decode_utf8($terms);
994 $terms =~ s/^\s+//go;
995 my $term_copy = $terms;
997 my $complex_terms = 0;
998 if ($terms eq 'help') {
999 print $cgi->header(-type => 'text/html');
1003 <title>just type something!</title>
1006 <p>You are in a maze of dark, twisty stacks, all alike.</p>
1010 return Apache2::Const::OK;
1015 while ($term_copy =~ s/((?:keyword(?:\|\w+)?|title(?:\|\w+)?|author(?:\|\w+)?|subject(?:\|\w+)?|series(?:\|\w+)?|site|dir|sort|lang):[^:]+)$//so) {
1016 my ($c,$t) = split ':' => $1;
1021 } elsif ($c eq 'sort') {
1022 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
1023 } elsif ($c eq 'dir') {
1024 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
1025 } elsif ($c eq 'lang') {
1026 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
1028 $$searches{$c}{term} .= ' '.$t;
1029 $cache_key .= $c . $t;
1034 $lang = 'eng' if ($lang eq 'en-US');
1038 $class = 'keyword' if ($class eq '-');
1039 $$searches{$class}{term} .= " $term_copy";
1040 $cache_key .= $class . $term_copy;
1045 $org_unit = $actor->request(
1046 'open-ils.actor.org_unit_list.search' => parent_ou => undef
1049 $org_unit = $actor->request(
1050 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
1054 { no warnings; $cache_key .= $org.$sort.$sortdir.$lang; }
1056 my $rs_name = $cgi->cookie('os_session');
1057 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
1060 if (!($recs = $$cached_res{os_results}{$cache_key})) {
1061 $rs_name = $cgi->remote_host . '::' . rand(time);
1062 $recs = $search->request(
1063 'open-ils.search.biblio.multiclass' => {
1064 searches => $searches,
1065 org_unit => $org_unit->[0]->id,
1068 ($sort ? ( 'sort' => $sort ) : ()),
1069 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
1070 ($lang ? ( 'language' => $lang ) : ()),
1074 $$cached_res{os_results}{$cache_key} = $recs;
1075 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
1076 } catch Error with {
1077 warn "supercat unable to store IDs in memcache server\n";
1078 $logger->error("supercat unable to store IDs in memcache server");
1082 my $feed = create_record_feed(
1085 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
1092 $feed->search($terms);
1093 $feed->class($class);
1095 if ($complex_terms) {
1096 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
1098 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
1101 $feed->creator($host);
1102 $feed->update_ts(gmtime_ISO8601());
1104 $feed->_create_node(
1105 $feed->{item_xpath},
1106 'http://a9.com/-/spec/opensearch/1.1/',
1111 $feed->_create_node(
1112 $feed->{item_xpath},
1113 'http://a9.com/-/spec/opensearch/1.1/',
1118 $feed->_create_node(
1119 $feed->{item_xpath},
1120 'http://a9.com/-/spec/opensearch/1.1/',
1127 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
1128 'application/opensearch+xml'
1129 ) if ($offset + $limit < $recs->{count});
1133 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
1134 'application/opensearch+xml'
1139 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1140 'application/opensearch+xml'
1145 $base . "/$version/$org/rss2-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1146 'application/rss+xml'
1151 $base . "/$version/$org/atom-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1152 'application/atom+xml'
1157 $base . "/$version/$org/html/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1163 $base . "/$version/$org/html-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1167 $feed->link( 'unapi-server' => $unapi);
1171 # $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
1172 # join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
1177 -type => $feed->type,
1178 -charset => 'UTF-8',
1179 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
1182 print entityize($feed->toString) . "\n";
1184 return Apache2::Const::OK;
1187 sub create_record_feed {
1190 my $records = shift;
1193 my $lib = uc(shift()) || '-';
1195 $flesh = 1 if (!defined($flesh));
1198 my $base = $cgi->url;
1199 my $host = $cgi->virtual_host || $cgi->server_name;
1201 my $year = (gmtime())[5] + 1900;
1203 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
1205 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
1206 $feed->base($base) if ($flesh);
1207 $feed->unapi($unapi) if ($flesh);
1209 $type = 'atom' if ($type eq 'html');
1210 $type = 'marcxml' if ($type eq 'htmlholdings');
1212 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
1215 for my $record (@$records) {
1216 next unless($record);
1218 #my $rec = $record->id;
1221 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
1222 $item_tag = "tag:$host,$year:isbn/$rec/$lib" if ($search eq 'isbn');
1224 my $xml = $supercat->request(
1225 "open-ils.supercat.$search.$type.retrieve",
1230 my $node = $feed->add_item($xml);
1234 if ($lib && $type eq 'marcxml' && $flesh) {
1235 my $r = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib );
1236 while ( !$r->complete ) {
1237 $xml .= join('', map {$_->content} $r->recv);
1239 $xml .= join('', map {$_->content} $r->recv);
1240 $node->add_holdings($xml);
1243 $node->id($item_tag) if ($flesh);
1244 #$node->update_ts(clense_ISO8601($record->edit_date));
1245 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
1246 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
1247 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
1248 $node->link('unapi-id' => $item_tag) if ($flesh);
1255 my $stuff = NFC(shift());
1256 $stuff =~ s/&(?!\S+;)/&/gso;
1257 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1263 return Apache2::Const::DECLINED if (-e $apache->filename);
1266 my $year = (gmtime())[5] + 1900;
1268 my $host = $cgi->virtual_host || $cgi->server_name;
1271 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1272 my $rel_name = $cgi->url(-relative=>1);
1273 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1276 my $url = $cgi->url(-path_info=>$add_path);
1277 my $root = (split 'browse', $url)[0];
1278 my $base = (split 'browse', $url)[0] . 'browse';
1279 my $unapi = (split 'browse', $url)[0] . 'unapi';
1281 my $path = $cgi->path_info;
1284 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1285 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1287 $site ||= $cgi->param('searchOrg');
1288 $page ||= $cgi->param('startPage') || 0;
1289 $page_size ||= $cgi->param('count') || 9;
1291 $page = 0 if ($page !~ /^-?\d+$/);
1293 my $prev = join('/', $base,$format,$axis,$site,$string,$page - 1,$page_size);
1294 my $next = join('/', $base,$format,$axis,$site,$string,$page + 1,$page_size);
1296 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1297 warn "something's wrong...";
1298 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1302 $string = decode_utf8($string);
1303 $string =~ s/\+/ /go;
1306 my $tree = $supercat->request(
1307 "open-ils.supercat.$axis.browse",
1314 my ($header,$content) = $browse_types{$axis}{$format}->($tree,$prev,$next);
1315 print $header.$content;
1316 return Apache2::Const::OK;