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/;
28 # set the bootstrap config when this module is loaded
29 my ($bootstrap, $cstore, $supercat, $actor, $parser, $search, $xslt, $cn_browse_xslt, %browse_types);
31 $browse_types{call_number}{xml} = sub {
34 my $year = (gmtime())[5] + 1900;
37 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
40 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
41 $cn_class =~ s/Fieldmapper-//gso;
43 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
44 my $cn_lib = $cn->owning_lib->shortname;
45 my $cn_label = $cn->label;
47 $cn_label =~ s/\n//gos;
48 $cn_label =~ s/'/'/go;
50 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
51 $ou_class =~ s/Fieldmapper-//gso;
53 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
54 my $ou_name = $cn->owning_lib->name;
56 $ou_name =~ s/\n//gos;
57 $ou_name =~ s/'/'/go;
59 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
60 $rec_class =~ s/Fieldmapper-//gso;
62 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
64 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
65 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
67 my $r_doc = $parser->parse_string($cn->record->marc);
68 $r_doc->documentElement->setAttribute( id => $rec_tag );
69 $content .= entityize($r_doc->documentElement->toString);
71 $content .= "</hold:volume>";
74 $content .= '</hold:volumes>';
75 return ("Content-type: application/xml\n\n",$content);
79 $browse_types{call_number}{html} = sub {
84 if (!$cn_browse_xslt) {
85 $cn_browse_xslt = $parser->parse_file(
86 OpenSRF::Utils::SettingsClient
88 ->config_value( dirs => 'xsl' ).
91 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
94 my (undef,$xml) = $browse_types{call_number}{xml}->($tree);
97 "Content-type: text/html\n\n",
99 $cn_browse_xslt->transform(
100 $parser->parse_string( $xml ),
115 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
117 my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
118 Fieldmapper->import(IDL => $idl);
120 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
121 $cstore = OpenSRF::AppSession->create('open-ils.cstore');
122 $actor = OpenSRF::AppSession->create('open-ils.actor');
123 $search = OpenSRF::AppSession->create('open-ils.search');
124 $parser = new XML::LibXML;
125 $xslt = new XML::LibXSLT;
127 $cn_browse_xslt = $parser->parse_file(
128 OpenSRF::Utils::SettingsClient
130 ->config_value( dirs => 'xsl' ).
134 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
141 return Apache2::Const::DECLINED if (-e $apache->filename);
143 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
146 ->request("open-ils.supercat.oisbn", $isbn)
149 print "Content-type: application/xml; charset=utf-8\n\n";
150 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
152 unless (exists $$list{metarecord}) {
154 return Apache2::Const::OK;
157 print "<idlist metarecord='$$list{metarecord}'>\n";
159 for ( keys %{ $$list{record_list} } ) {
160 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
161 print " <isbn record='$_'>$o</isbn>\n"
166 return Apache2::Const::OK;
172 return Apache2::Const::DECLINED if (-e $apache->filename);
177 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
178 my $rel_name = $cgi->url(-relative=>1);
179 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
182 my $url = $cgi->url(-path_info=>$add_path);
183 my $root = (split 'unapi', $url)[0];
184 my $base = (split 'unapi', $url)[0] . 'unapi';
187 my $uri = $cgi->param('id') || '';
188 my $host = $cgi->virtual_host || $cgi->server_name;
190 my $format = $cgi->param('format');
191 my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
192 (my $base_format = $format) =~ s/-full$//o;
193 my ($id,$type,$command,$lib) = ('','','');
196 my $body = "Content-type: application/xml; charset=utf-8\n\n";
198 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))$}o) {
202 $type = 'metarecord' if ($1 =~ /^m/o);
205 ->request("open-ils.supercat.$type.formats")
208 if ($type eq 'record' or $type eq 'isbn') {
209 $body .= <<" FORMATS";
211 <format name='opac' type='text/html'/>
212 <format name='html' type='text/html'/>
213 <format name='htmlholdings' type='text/html'/>
214 <format name='html-full' type='text/html'/>
215 <format name='htmlholdings-full' type='text/html'/>
217 } elsif ($type eq 'metarecord') {
218 $body .= <<" FORMATS";
220 <format name='opac' type='text/html'/>
225 my ($type) = keys %$h;
226 $body .= "\t<format name='$type' type='application/xml'";
228 for my $part ( qw/namespace_uri docs schema_location/ ) {
229 $body .= " $part='$$h{$type}{$part}'"
230 if ($$h{$type}{$part});
235 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
236 $body .= "\t<format name='$type-full' type='application/xml'";
238 for my $part ( qw/namespace_uri docs schema_location/ ) {
239 $body .= " $part='$$h{$type}{$part}'"
240 if ($$h{$type}{$part});
247 $body .= "</formats>\n";
251 ->request("open-ils.supercat.record.formats")
256 ->request("open-ils.supercat.metarecord.formats")
260 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
261 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
263 $body .= <<" FORMATS";
265 <format name='opac' type='text/html'/>
266 <format name='html' type='text/html'/>
267 <format name='htmlholdings' type='text/html'/>
268 <format name='html-full' type='text/html'/>
269 <format name='htmlholdings-full' type='text/html'/>
274 my ($type) = keys %$h;
275 $body .= "\t<format name='$type' type='application/xml'";
277 for my $part ( qw/namespace_uri docs schema_location/ ) {
278 $body .= " $part='$$h{$type}{$part}'"
279 if ($$h{$type}{$part});
284 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
285 $body .= "\t<format name='$type-full' type='application/xml'";
287 for my $part ( qw/namespace_uri docs schema_location/ ) {
288 $body .= " $part='$$h{$type}{$part}'"
289 if ($$h{$type}{$part});
296 $body .= "</formats>\n";
300 return Apache2::Const::OK;
303 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))?}o) {
307 $type = 'metarecord' if ($1 =~ /^metabib/o);
308 $type = 'isbn' if ($1 =~ /^isbn/o);
309 $type = 'call_number' if ($1 =~ /^call_number/o);
310 $command = 'retrieve';
311 $command = 'browse' if ($type eq 'call_number');
314 if (!$lib || $lib eq '-') {
315 $lib = $actor->request(
316 'open-ils.actor.org_unit_list.search' => parent_ou => undef
317 )->gather(1)->[0]->shortname;
320 my $lib_object = $actor->request(
321 'open-ils.actor.org_unit_list.search' => shortname => $lib
323 my $lib_id = $lib_object->id;
325 my $ou_types = $actor->request( 'open-ils.actor.org_types.retrieve' )->gather(1);
326 my $lib_depth = (grep { $_->id == $lib_object->ou_type } @$ou_types)[0]->depth;
328 if ($type eq 'call_number' and $command eq 'browse') {
329 print "Location: $root/browse/$base_format/call_number/$lib/$id\n\n";
333 if ($type eq 'isbn') {
334 my $rec = $supercat->request('open-ils.supercat.isbn.object.retrieve',$id)->gather(1);
336 print "Content-type: text/html; charset=utf-8\n\n";
337 $apache->custom_response( 404, <<" HTML");
340 <title>Type [$type] with id [$id] not found!</title>
344 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
355 { (keys(%$_))[0] eq $base_format }
356 @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
358 { $_ eq $base_format }
359 qw/opac html htmlholdings/
361 print "Content-type: text/html; charset=utf-8\n\n";
362 $apache->custom_response( 406, <<" HTML");
365 <title>Invalid format [$format] for type [$type]!</title>
369 <center>Sorry, format $format is not valid for type $type.</center>
376 if ($format eq 'opac') {
377 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id&l=$lib_id&d=$lib_depth\n\n"
378 if ($type eq 'metarecord');
379 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id&l=$lib_id&d=$lib_depth\n\n"
380 if ($type eq 'record');
382 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
383 my $feed = create_record_feed(
392 print "Content-type: text/html; charset=utf-8\n\n";
393 $apache->custom_response( 404, <<" HTML");
396 <title>Type [$type] with id [$id] not found!</title>
400 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
408 $feed->creator($host);
409 $feed->update_ts(gmtime_ISO8601());
410 $feed->link( unapi => $base) if ($flesh_feed);
412 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
413 print entityize($feed->toString) . "\n";
415 return Apache2::Const::OK;
418 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
419 my $data = $req->gather(1);
421 if ($req->failed || !$data) {
422 print "Content-type: text/html; charset=utf-8\n\n";
423 $apache->custom_response( 404, <<" HTML");
426 <title>$type $id not found!</title>
430 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
437 print "Content-type: application/xml; charset=utf-8\n\n$data";
439 return Apache2::Const::OK;
445 return Apache2::Const::DECLINED if (-e $apache->filename);
450 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
451 my $rel_name = $cgi->url(-relative=>1);
452 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
455 my $url = $cgi->url(-path_info=>$add_path);
456 my $root = (split 'supercat', $url)[0];
457 my $base = (split 'supercat', $url)[0] . 'supercat';
458 my $unapi = (split 'supercat', $url)[0] . 'unapi';
460 my $host = $cgi->virtual_host || $cgi->server_name;
462 my $path = $cgi->path_info;
463 my ($id,$type,$format,$command) = reverse split '/', $path;
464 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
465 (my $base_format = $format) =~ s/-full$//o;
467 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
468 print "Content-type: application/xml; charset=utf-8\n";
471 ->request("open-ils.supercat.$1.formats")
479 <type>text/html</type>
482 if ($1 eq 'record' or $1 eq 'isbn') {
484 <name>htmlholdings</name>
485 <type>text/html</type>
489 <type>text/html</type>
492 <name>htmlholdings-full</name>
493 <type>text/html</type>
496 <name>html-full</name>
497 <type>text/html</type>
502 my ($type) = keys %$h;
503 print "<format><name>$type</name><type>application/xml</type>";
505 for my $part ( qw/namespace_uri docs schema_location/ ) {
506 print "<$part>$$h{$type}{$part}</$part>"
507 if ($$h{$type}{$part});
512 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
513 print "<format><name>$type-full</name><type>application/xml</type>";
515 for my $part ( qw/namespace_uri docs schema_location/ ) {
516 print "<$part>$$h{$type}{$part}</$part>"
517 if ($$h{$type}{$part});
525 print "</formats>\n";
527 return Apache2::Const::OK;
531 ->request("open-ils.supercat.record.formats")
536 ->request("open-ils.supercat.metarecord.formats")
540 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
541 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
546 <type>text/html</type>
549 <name>htmlholdings</name>
550 <type>text/html</type>
554 <type>text/html</type>
557 <name>htmlholdings-full</name>
558 <type>text/html</type>
561 <name>html-full</name>
562 <type>text/html</type>
566 my ($type) = keys %$h;
567 print "<format><name>$type</name><type>application/xml</type>";
569 for my $part ( qw/namespace_uri docs schema_location/ ) {
570 print "<$part>$$h{$type}{$part}</$part>"
571 if ($$h{$type}{$part});
576 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
577 print "<format><name>$type-full</name><type>application/xml</type>";
579 for my $part ( qw/namespace_uri docs schema_location/ ) {
580 print "<$part>$$h{$type}{$part}</$part>"
581 if ($$h{$type}{$part});
589 print "</formats>\n";
592 return Apache2::Const::OK;
595 if ($format eq 'opac') {
596 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
597 if ($type eq 'metarecord');
598 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
599 if ($type eq 'record');
601 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
602 my $feed = create_record_feed(
610 $feed->creator($host);
611 $feed->update_ts(gmtime_ISO8601());
612 $feed->link( unapi => $base) if ($flesh_feed);
614 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
615 print entityize($feed->toString) . "\n";
617 return Apache2::Const::OK;
620 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
624 print "Content-type: text/html; charset=utf-8\n\n";
625 $apache->custom_response( 404, <<" HTML");
628 <title>$type $id not found!</title>
632 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
639 print "Content-type: application/xml; charset=utf-8\n\n";
640 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
642 return Apache2::Const::OK;
648 return Apache2::Const::DECLINED if (-e $apache->filename);
652 my $year = (gmtime())[5] + 1900;
653 my $host = $cgi->virtual_host || $cgi->server_name;
656 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
657 my $rel_name = $cgi->url(-relative=>1);
658 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
661 my $url = $cgi->url(-path_info=>$add_path);
662 my $root = (split 'feed', $url)[0] . '/';
663 my $base = (split 'bookbag', $url)[0] . '/bookbag';
664 my $unapi = (split 'feed', $url)[0] . '/unapi';
666 $root =~ s{(?<!http:)//}{/}go;
667 $base =~ s{(?<!http:)//}{/}go;
668 $unapi =~ s{(?<!http:)//}{/}go;
670 my $path = $cgi->path_info;
671 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
673 my ($id,$type) = reverse split '/', $path;
674 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
676 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
677 return Apache2::Const::NOT_FOUND unless($bucket);
679 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
680 if ($type eq 'opac') {
681 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
682 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
687 my $feed = create_record_feed(
690 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
697 $feed->title("Items in Book Bag [".$bucket->name."]");
698 $feed->creator($host);
699 $feed->update_ts(gmtime_ISO8601());
701 $feed->link(rss => $base . "/rss2-full/$id" => 'application/rss+xml');
702 $feed->link(alternate => $base . "/atom-full/$id" => 'application/atom+xml');
703 $feed->link(html => $base . "/html-full/$id" => 'text/html');
704 $feed->link(unapi => $unapi);
708 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
709 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
714 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
715 print entityize($feed->toString) . "\n";
717 return Apache2::Const::OK;
722 return Apache2::Const::DECLINED if (-e $apache->filename);
726 my $year = (gmtime())[5] + 1900;
727 my $host = $cgi->virtual_host || $cgi->server_name;
730 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
731 my $rel_name = $cgi->url(-relative=>1);
732 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
735 my $url = $cgi->url(-path_info=>$add_path);
736 my $root = (split 'feed', $url)[0];
737 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
738 my $unapi = (split 'feed', $url)[0] . 'unapi';
740 my $path = $cgi->path_info;
741 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
743 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
745 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
746 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
749 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
751 #if ($type eq 'opac') {
752 # print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
753 # join('&', map { "rl=" . $_ } @$list) .
758 my $feed = create_record_feed( 'record', $type, $list, $unapi, undef, $flesh_feed);
762 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
764 $feed->title("$limit most recent $rtype ${axis}s");
767 $feed->creator($host);
768 $feed->update_ts(gmtime_ISO8601());
770 $feed->link(rss => $base . "/rss2-full/$rtype/$axis/$limit/$date" => 'application/rss+xml');
771 $feed->link(alternate => $base . "/atom-full/$rtype/$axis/$limit/$date" => 'application/atom+xml');
772 $feed->link(html => $base . "/html-full/$rtype/$axis/$limit/$date" => 'text/html');
773 $feed->link(unapi => $unapi);
777 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
778 join('&', map { 'rl=' . $_} @$list ),
783 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
784 print entityize($feed->toString) . "\n";
786 return Apache2::Const::OK;
795 if ($version eq '1.0') {
797 Content-type: application/opensearchdescription+xml; charset=utf-8
799 <?xml version="1.0" encoding="UTF-8"?>
800 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
801 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
802 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
803 <ShortName>$lib</ShortName>
804 <LongName>Search $lib</LongName>
805 <Description>Search the $lib OPAC by $class.</Description>
806 <Tags>$lib book library</Tags>
807 <SampleSearch>harry+potter</SampleSearch>
808 <Developer>Mike Rylander for GPLS/PINES</Developer>
809 <Contact>feedback\@open-ils.org</Contact>
810 <SyndicationRight>open</SyndicationRight>
811 <AdultContent>false</AdultContent>
812 </OpenSearchDescription>
816 Content-type: application/opensearchdescription+xml; charset=utf-8
818 <?xml version="1.0" encoding="UTF-8"?>
819 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
820 <ShortName>$lib</ShortName>
821 <Description>Search the $lib OPAC by $class.</Description>
822 <Tags>$lib book library</Tags>
823 <Url type="application/rss+xml"
824 template="$base/1.1/$lib/rss2-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
825 <Url type="application/atom+xml"
826 template="$base/1.1/$lib/atom-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
827 <Url type="application/x-mods3+xml"
828 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
829 <Url type="application/x-mods+xml"
830 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
831 <Url type="application/x-marcxml+xml"
832 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
833 <Url type="text/html"
834 template="$base/1.1/$lib/html-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
835 <LongName>Search $lib</LongName>
836 <Query role="example" searchTerms="harry+potter" />
837 <Developer>Mike Rylander for GPLS/PINES</Developer>
838 <Contact>feedback\@open-ils.org</Contact>
839 <SyndicationRight>open</SyndicationRight>
840 <AdultContent>false</AdultContent>
841 <Language>en-US</Language>
842 <OutputEncoding>UTF-8</OutputEncoding>
843 <InputEncoding>UTF-8</InputEncoding>
844 </OpenSearchDescription>
848 return Apache2::Const::OK;
851 sub opensearch_feed {
853 return Apache2::Const::DECLINED if (-e $apache->filename);
856 my $year = (gmtime())[5] + 1900;
858 my $host = $cgi->virtual_host || $cgi->server_name;
861 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
862 my $rel_name = $cgi->url(-relative=>1);
863 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
866 my $url = $cgi->url(-path_info=>$add_path);
867 my $root = (split 'opensearch', $url)[0];
868 my $base = (split 'opensearch', $url)[0] . 'opensearch';
869 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
871 my $path = $cgi->path_info;
872 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
874 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
880 if (!$lib || $lib eq '-') {
881 $lib = $actor->request(
882 'open-ils.actor.org_unit_list.search' => parent_ou => undef
883 )->gather(1)->[0]->shortname;
890 return opensearch_osd($version, $lib, $class, $base);
894 my $page = $cgi->param('startPage') || 1;
895 my $offset = $cgi->param('startIndex') || 1;
896 my $limit = $cgi->param('count') || 10;
898 $page = 1 if ($page !~ /^\d+$/);
899 $offset = 1 if ($offset !~ /^\d+$/);
900 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
903 $offset = ($page - 1) * $limit;
908 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = ('','','','','','','','');
909 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
911 $lang = $cgi->param('searchLang') if $cgi->param('searchLang');
912 $sort = $cgi->param('searchSort') if $cgi->param('searchSort');
913 $sortdir = $cgi->param('searchSortDir') if $cgi->param('searchSortDir');
914 $terms .= " " . $cgi->param('searchTerms') if $cgi->param('searchTerms');
916 $class = $cgi->param('searchClass') if $cgi->param('searchClass');
919 $type = $cgi->param('responseType') if $cgi->param('responseType');
922 $org = $cgi->param('searchOrg') if $cgi->param('searchOrg');
926 my $kwt = $cgi->param('kw');
927 my $tit = $cgi->param('ti');
928 my $aut = $cgi->param('au');
929 my $sut = $cgi->param('su');
930 my $set = $cgi->param('se');
932 $terms .= " keyword: $kwt" if ($kwt);
933 $terms .= " title: $tit" if ($tit);
934 $terms .= " author: $aut" if ($aut);
935 $terms .= " subject: $sut" if ($sut);
936 $terms .= " series: $set" if ($set);
938 if ($version eq '1.0') {
940 } elsif ($type eq '-') {
943 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
945 $terms = decode_utf8($terms);
948 $terms =~ s/^\s+//go;
949 my $term_copy = $terms;
951 my $complex_terms = 0;
952 if ($terms eq 'help') {
953 print $cgi->header(-type => 'text/html');
957 <title>just type something!</title>
960 <p>You are in a maze of dark, twisty stacks, all alike.</p>
964 return Apache2::Const::OK;
969 while ($term_copy =~ s/((?:keyword(?:\|\w+)?|title(?:\|\w+)?|author(?:\|\w+)?|subject(?:\|\w+)?|series(?:\|\w+)?|site|dir|sort|lang):[^:]+)$//so) {
970 my ($c,$t) = split ':' => $1;
975 } elsif ($c eq 'sort') {
976 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
977 } elsif ($c eq 'dir') {
978 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
979 } elsif ($c eq 'lang') {
980 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
982 $$searches{$c}{term} .= ' '.$t;
983 $cache_key .= $c . $t;
988 $lang = 'eng' if ($lang eq 'en-US');
992 $class = 'keyword' if ($class eq '-');
993 $$searches{$class}{term} .= " $term_copy";
994 $cache_key .= $class . $term_copy;
999 $org_unit = $actor->request(
1000 'open-ils.actor.org_unit_list.search' => parent_ou => undef
1003 $org_unit = $actor->request(
1004 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
1008 { no warnings; $cache_key .= $org.$sort.$sortdir.$lang; }
1010 my $rs_name = $cgi->cookie('os_session');
1011 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
1014 if (!($recs = $$cached_res{os_results}{$cache_key})) {
1015 $rs_name = $cgi->remote_host . '::' . rand(time);
1016 $recs = $search->request(
1017 'open-ils.search.biblio.multiclass' => {
1018 searches => $searches,
1019 org_unit => $org_unit->[0]->id,
1022 ($sort ? ( 'sort' => $sort ) : ()),
1023 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
1024 ($lang ? ( 'language' => $lang ) : ()),
1028 $$cached_res{os_results}{$cache_key} = $recs;
1029 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
1030 } catch Error with {
1031 warn "supercat unable to store IDs in memcache server\n";
1032 $logger->error("supercat unable to store IDs in memcache server");
1036 my $feed = create_record_feed(
1039 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
1046 $feed->search($terms);
1047 $feed->class($class);
1049 if ($complex_terms) {
1050 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
1052 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
1055 $feed->creator($host);
1056 $feed->update_ts(gmtime_ISO8601());
1058 $feed->_create_node(
1059 $feed->{item_xpath},
1060 'http://a9.com/-/spec/opensearch/1.1/',
1065 $feed->_create_node(
1066 $feed->{item_xpath},
1067 'http://a9.com/-/spec/opensearch/1.1/',
1072 $feed->_create_node(
1073 $feed->{item_xpath},
1074 'http://a9.com/-/spec/opensearch/1.1/',
1081 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
1082 'application/opensearch+xml'
1083 ) if ($offset + $limit < $recs->{count});
1087 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
1088 'application/opensearch+xml'
1093 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1094 'application/opensearch+xml'
1099 $base . "/$version/$org/rss2-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1100 'application/rss+xml'
1105 $base . "/$version/$org/atom-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1106 'application/atom+xml'
1111 $base . "/$version/$org/html/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1117 $base . "/$version/$org/html-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1121 $feed->link( 'unapi-server' => $unapi);
1125 # $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
1126 # join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
1131 -type => $feed->type,
1132 -charset => 'UTF-8',
1133 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
1136 print entityize($feed->toString) . "\n";
1138 return Apache2::Const::OK;
1141 sub create_record_feed {
1144 my $records = shift;
1147 my $lib = uc(shift()) || '-';
1149 $flesh = 1 if (!defined($flesh));
1152 my $base = $cgi->url;
1153 my $host = $cgi->virtual_host || $cgi->server_name;
1155 my $year = (gmtime())[5] + 1900;
1157 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
1159 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
1160 $feed->base($base) if ($flesh);
1161 $feed->unapi($unapi) if ($flesh);
1163 $type = 'atom' if ($type eq 'html');
1164 $type = 'marcxml' if ($type eq 'htmlholdings');
1166 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
1169 for my $record (@$records) {
1170 next unless($record);
1172 #my $rec = $record->id;
1175 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
1176 $item_tag = "tag:$host,$year:isbn/$rec/$lib" if ($search eq 'isbn');
1178 my $xml = $supercat->request(
1179 "open-ils.supercat.$search.$type.retrieve",
1184 my $node = $feed->add_item($xml);
1188 if ($lib && $type eq 'marcxml' && $flesh) {
1189 my $r = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib );
1190 while ( !$r->complete ) {
1191 $xml .= join('', map {$_->content} $r->recv);
1193 $xml .= join('', map {$_->content} $r->recv);
1194 $node->add_holdings($xml);
1197 $node->id($item_tag) if ($flesh);
1198 #$node->update_ts(clense_ISO8601($record->edit_date));
1199 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
1200 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
1201 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
1202 $node->link('unapi-id' => $item_tag) if ($flesh);
1209 my $stuff = NFC(shift());
1210 $stuff =~ s/&(?!\S+;)/&/gso;
1211 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1217 return Apache2::Const::DECLINED if (-e $apache->filename);
1220 my $year = (gmtime())[5] + 1900;
1222 my $host = $cgi->virtual_host || $cgi->server_name;
1225 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1226 my $rel_name = $cgi->url(-relative=>1);
1227 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1230 my $url = $cgi->url(-path_info=>$add_path);
1231 my $root = (split 'browse', $url)[0];
1232 my $base = (split 'browse', $url)[0] . 'browse';
1233 my $unapi = (split 'browse', $url)[0] . 'unapi';
1235 my $path = $cgi->path_info;
1238 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1239 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1241 $site ||= $cgi->param('searchOrg');
1242 $page ||= $cgi->param('startPage') || 0;
1243 $page_size ||= $cgi->param('count') || 9;
1245 $page = 0 if ($page !~ /^-?\d+$/);
1247 my $prev = join('/', $base,$format,$axis,$site,$string,$page - 1,$page_size);
1248 my $next = join('/', $base,$format,$axis,$site,$string,$page + 1,$page_size);
1250 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1251 warn "something's wrong...";
1252 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1256 $string = decode_utf8($string);
1257 $string =~ s/\+/ /go;
1260 my $tree = $supercat->request(
1261 "open-ils.supercat.$axis.browse",
1268 my ($header,$content) = $browse_types{$axis}{$format}->($tree,$prev,$next);
1269 print $header.$content;
1270 return Apache2::Const::OK;