1 package OpenILS::WWW::SuperCat;
2 use strict; use warnings;
6 use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
7 use APR::Const -compile => qw(:error SUCCESS);
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO ();
10 use Apache2::RequestUtil;
14 use OpenSRF::EX qw(:try);
15 use OpenSRF::Utils qw/:datetime/;
16 use OpenSRF::Utils::Cache;
18 use OpenSRF::AppSession;
23 use Unicode::Normalize;
24 use OpenILS::Utils::Fieldmapper;
25 use OpenILS::WWW::SuperCat::Feed;
26 use OpenSRF::Utils::Logger qw/$logger/;
29 # set the bootstrap config when this module is loaded
30 my ($bootstrap, $cstore, $supercat, $actor, $parser, $search, $xslt, $cn_browse_xslt, %browse_types);
32 $browse_types{call_number}{xml} = sub {
35 my $year = (gmtime())[5] + 1900;
38 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
41 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
42 $cn_class =~ s/Fieldmapper-//gso;
44 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
45 my $cn_lib = $cn->owning_lib->shortname;
46 my $cn_label = $cn->label;
48 $cn_label =~ s/\n//gos;
49 $cn_label =~ s/'/'/go;
51 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
52 $ou_class =~ s/Fieldmapper-//gso;
54 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
55 my $ou_name = $cn->owning_lib->name;
57 $ou_name =~ s/\n//gos;
58 $ou_name =~ s/'/'/go;
60 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
61 $rec_class =~ s/Fieldmapper-//gso;
63 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
65 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
66 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
68 my $r_doc = $parser->parse_string($cn->record->marc);
69 $r_doc->documentElement->setAttribute( id => $rec_tag );
70 $content .= entityize($r_doc->documentElement->toString);
72 $content .= "</hold:volume>";
75 $content .= '</hold:volumes>';
76 return ("Content-type: application/xml\n\n",$content);
80 $browse_types{call_number}{html} = sub {
85 if (!$cn_browse_xslt) {
86 $cn_browse_xslt = $parser->parse_file(
87 OpenSRF::Utils::SettingsClient
89 ->config_value( dirs => 'xsl' ).
92 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
95 my (undef,$xml) = $browse_types{call_number}{xml}->($tree);
98 "Content-type: text/html\n\n",
100 $cn_browse_xslt->transform(
101 $parser->parse_string( $xml ),
116 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
118 my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
119 Fieldmapper->import(IDL => $idl);
121 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
122 $cstore = OpenSRF::AppSession->create('open-ils.cstore');
123 $actor = OpenSRF::AppSession->create('open-ils.actor');
124 $search = OpenSRF::AppSession->create('open-ils.search');
125 $parser = new XML::LibXML;
126 $xslt = new XML::LibXSLT;
128 $cn_browse_xslt = $parser->parse_file(
129 OpenSRF::Utils::SettingsClient
131 ->config_value( dirs => 'xsl' ).
135 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
142 return Apache2::Const::DECLINED if (-e $apache->filename);
144 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
147 ->request("open-ils.supercat.oisbn", $isbn)
150 print "Content-type: application/xml; charset=utf-8\n\n";
151 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
153 unless (exists $$list{metarecord}) {
155 return Apache2::Const::OK;
158 print "<idlist metarecord='$$list{metarecord}'>\n";
160 for ( keys %{ $$list{record_list} } ) {
161 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
162 print " <isbn record='$_'>$o</isbn>\n"
167 return Apache2::Const::OK;
173 return Apache2::Const::DECLINED if (-e $apache->filename);
178 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
179 my $rel_name = $cgi->url(-relative=>1);
180 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
183 my $url = $cgi->url(-path_info=>$add_path);
184 my $root = (split 'unapi', $url)[0];
185 my $base = (split 'unapi', $url)[0] . 'unapi';
188 my $uri = $cgi->param('id') || '';
189 my $host = $cgi->virtual_host || $cgi->server_name;
191 my $format = $cgi->param('format');
192 my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
193 (my $base_format = $format) =~ s/-full$//o;
194 my ($id,$type,$command,$lib) = ('','','');
197 my $body = "Content-type: application/xml; charset=utf-8\n\n";
199 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))$}o) {
203 $type = 'metarecord' if ($1 =~ /^m/o);
206 ->request("open-ils.supercat.$type.formats")
209 if ($type eq 'record' or $type eq 'isbn') {
210 $body .= <<" FORMATS";
212 <format name='opac' type='text/html'/>
213 <format name='html' type='text/html'/>
214 <format name='htmlholdings' type='text/html'/>
215 <format name='html-full' type='text/html'/>
216 <format name='htmlholdings-full' type='text/html'/>
218 } elsif ($type eq 'metarecord') {
219 $body .= <<" FORMATS";
221 <format name='opac' type='text/html'/>
226 my ($type) = keys %$h;
227 $body .= "\t<format name='$type' type='application/xml'";
229 for my $part ( qw/namespace_uri docs schema_location/ ) {
230 $body .= " $part='$$h{$type}{$part}'"
231 if ($$h{$type}{$part});
236 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
237 $body .= "\t<format name='$type-full' type='application/xml'";
239 for my $part ( qw/namespace_uri docs schema_location/ ) {
240 $body .= " $part='$$h{$type}{$part}'"
241 if ($$h{$type}{$part});
248 $body .= "</formats>\n";
252 ->request("open-ils.supercat.record.formats")
257 ->request("open-ils.supercat.metarecord.formats")
261 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
262 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
264 $body .= <<" FORMATS";
266 <format name='opac' type='text/html'/>
267 <format name='html' type='text/html'/>
268 <format name='htmlholdings' type='text/html'/>
269 <format name='html-full' type='text/html'/>
270 <format name='htmlholdings-full' type='text/html'/>
275 my ($type) = keys %$h;
276 $body .= "\t<format name='$type' type='application/xml'";
278 for my $part ( qw/namespace_uri docs schema_location/ ) {
279 $body .= " $part='$$h{$type}{$part}'"
280 if ($$h{$type}{$part});
285 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
286 $body .= "\t<format name='$type-full' type='application/xml'";
288 for my $part ( qw/namespace_uri docs schema_location/ ) {
289 $body .= " $part='$$h{$type}{$part}'"
290 if ($$h{$type}{$part});
297 $body .= "</formats>\n";
301 return Apache2::Const::OK;
304 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))?}o) {
308 $type = 'metarecord' if ($1 =~ /^metabib/o);
309 $type = 'isbn' if ($1 =~ /^isbn/o);
310 $type = 'call_number' if ($1 =~ /^call_number/o);
311 $command = 'retrieve';
312 $command = 'browse' if ($type eq 'call_number');
315 if (!$lib || $lib eq '-') {
316 $lib = $actor->request(
317 'open-ils.actor.org_unit_list.search' => parent_ou => undef
318 )->gather(1)->[0]->shortname;
321 my $lib_object = $actor->request(
322 'open-ils.actor.org_unit_list.search' => shortname => $lib
324 my $lib_id = $lib_object->id;
326 my $ou_types = $actor->request( 'open-ils.actor.org_types.retrieve' )->gather(1);
327 my $lib_depth = (grep { $_->id == $lib_object->ou_type } @$ou_types)[0]->depth;
329 if ($type eq 'call_number' and $command eq 'browse') {
330 print "Location: $root/browse/$base_format/call_number/$lib/$id\n\n";
334 if ($type eq 'isbn') {
335 my $rec = $supercat->request('open-ils.supercat.isbn.object.retrieve',$id)->gather(1);
337 print "Content-type: text/html; charset=utf-8\n\n";
338 $apache->custom_response( 404, <<" HTML");
341 <title>Type [$type] with id [$id] not found!</title>
345 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
356 { (keys(%$_))[0] eq $base_format }
357 @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
359 { $_ eq $base_format }
360 qw/opac html htmlholdings/
362 print "Content-type: text/html; charset=utf-8\n\n";
363 $apache->custom_response( 406, <<" HTML");
366 <title>Invalid format [$format] for type [$type]!</title>
370 <center>Sorry, format $format is not valid for type $type.</center>
377 if ($format eq 'opac') {
378 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id&l=$lib_id&d=$lib_depth\n\n"
379 if ($type eq 'metarecord');
380 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id&l=$lib_id&d=$lib_depth\n\n"
381 if ($type eq 'record');
383 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
384 my $feed = create_record_feed(
393 print "Content-type: text/html; charset=utf-8\n\n";
394 $apache->custom_response( 404, <<" HTML");
397 <title>Type [$type] with id [$id] not found!</title>
401 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
409 $feed->creator($host);
410 $feed->update_ts(gmtime_ISO8601());
411 $feed->link( unapi => $base) if ($flesh_feed);
413 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
414 print entityize($feed->toString) . "\n";
416 return Apache2::Const::OK;
419 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
420 my $data = $req->gather(1);
422 if ($req->failed || !$data) {
423 print "Content-type: text/html; charset=utf-8\n\n";
424 $apache->custom_response( 404, <<" HTML");
427 <title>$type $id not found!</title>
431 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
438 print "Content-type: application/xml; charset=utf-8\n\n$data";
440 return Apache2::Const::OK;
446 return Apache2::Const::DECLINED if (-e $apache->filename);
451 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
452 my $rel_name = $cgi->url(-relative=>1);
453 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
456 my $url = $cgi->url(-path_info=>$add_path);
457 my $root = (split 'supercat', $url)[0];
458 my $base = (split 'supercat', $url)[0] . 'supercat';
459 my $unapi = (split 'supercat', $url)[0] . 'unapi';
461 my $host = $cgi->virtual_host || $cgi->server_name;
463 my $path = $cgi->path_info;
464 my ($id,$type,$format,$command) = reverse split '/', $path;
465 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
466 (my $base_format = $format) =~ s/-full$//o;
468 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
469 print "Content-type: application/xml; charset=utf-8\n";
472 ->request("open-ils.supercat.$1.formats")
480 <type>text/html</type>
483 if ($1 eq 'record' or $1 eq 'isbn') {
485 <name>htmlholdings</name>
486 <type>text/html</type>
490 <type>text/html</type>
493 <name>htmlholdings-full</name>
494 <type>text/html</type>
497 <name>html-full</name>
498 <type>text/html</type>
503 my ($type) = keys %$h;
504 print "<format><name>$type</name><type>application/xml</type>";
506 for my $part ( qw/namespace_uri docs schema_location/ ) {
507 print "<$part>$$h{$type}{$part}</$part>"
508 if ($$h{$type}{$part});
513 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
514 print "<format><name>$type-full</name><type>application/xml</type>";
516 for my $part ( qw/namespace_uri docs schema_location/ ) {
517 print "<$part>$$h{$type}{$part}</$part>"
518 if ($$h{$type}{$part});
526 print "</formats>\n";
528 return Apache2::Const::OK;
532 ->request("open-ils.supercat.record.formats")
537 ->request("open-ils.supercat.metarecord.formats")
541 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
542 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
547 <type>text/html</type>
550 <name>htmlholdings</name>
551 <type>text/html</type>
555 <type>text/html</type>
558 <name>htmlholdings-full</name>
559 <type>text/html</type>
562 <name>html-full</name>
563 <type>text/html</type>
567 my ($type) = keys %$h;
568 print "<format><name>$type</name><type>application/xml</type>";
570 for my $part ( qw/namespace_uri docs schema_location/ ) {
571 print "<$part>$$h{$type}{$part}</$part>"
572 if ($$h{$type}{$part});
577 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
578 print "<format><name>$type-full</name><type>application/xml</type>";
580 for my $part ( qw/namespace_uri docs schema_location/ ) {
581 print "<$part>$$h{$type}{$part}</$part>"
582 if ($$h{$type}{$part});
590 print "</formats>\n";
593 return Apache2::Const::OK;
596 if ($format eq 'opac') {
597 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
598 if ($type eq 'metarecord');
599 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
600 if ($type eq 'record');
602 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
603 my $feed = create_record_feed(
611 $feed->creator($host);
612 $feed->update_ts(gmtime_ISO8601());
613 $feed->link( unapi => $base) if ($flesh_feed);
615 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
616 print entityize($feed->toString) . "\n";
618 return Apache2::Const::OK;
621 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
625 print "Content-type: text/html; charset=utf-8\n\n";
626 $apache->custom_response( 404, <<" HTML");
629 <title>$type $id not found!</title>
633 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
640 print "Content-type: application/xml; charset=utf-8\n\n";
641 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
643 return Apache2::Const::OK;
649 return Apache2::Const::DECLINED if (-e $apache->filename);
653 my $year = (gmtime())[5] + 1900;
654 my $host = $cgi->virtual_host || $cgi->server_name;
657 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
658 my $rel_name = $cgi->url(-relative=>1);
659 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
662 my $url = $cgi->url(-path_info=>$add_path);
663 my $root = (split 'feed', $url)[0] . '/';
664 my $base = (split 'bookbag', $url)[0] . '/bookbag';
665 my $unapi = (split 'feed', $url)[0] . '/unapi';
667 $root =~ s{(?<!http:)//}{/}go;
668 $base =~ s{(?<!http:)//}{/}go;
669 $unapi =~ s{(?<!http:)//}{/}go;
671 my $path = $cgi->path_info;
672 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
674 my ($id,$type) = reverse split '/', $path;
675 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
677 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
678 return Apache2::Const::NOT_FOUND unless($bucket);
680 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
681 if ($type eq 'opac') {
682 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
683 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
688 my $feed = create_record_feed(
691 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
698 $feed->title("Items in Book Bag [".$bucket->name."]");
699 $feed->creator($host);
700 $feed->update_ts(gmtime_ISO8601());
702 $feed->link(rss => $base . "/rss2-full/$id" => 'application/rss+xml');
703 $feed->link(alternate => $base . "/atom-full/$id" => 'application/atom+xml');
704 $feed->link(html => $base . "/html-full/$id" => 'text/html');
705 $feed->link(unapi => $unapi);
709 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
710 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
715 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
716 print entityize($feed->toString) . "\n";
718 return Apache2::Const::OK;
723 return Apache2::Const::DECLINED if (-e $apache->filename);
727 my $year = (gmtime())[5] + 1900;
728 my $host = $cgi->virtual_host || $cgi->server_name;
731 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
732 my $rel_name = $cgi->url(-relative=>1);
733 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
736 my $url = $cgi->url(-path_info=>$add_path);
737 my $root = (split 'feed', $url)[0];
738 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
739 my $unapi = (split 'feed', $url)[0] . 'unapi';
741 my $path = $cgi->path_info;
742 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
744 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
746 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
747 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
750 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
752 #if ($type eq 'opac') {
753 # print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
754 # join('&', map { "rl=" . $_ } @$list) .
759 my $feed = create_record_feed( 'record', $type, $list, $unapi, undef, $flesh_feed);
763 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
765 $feed->title("$limit most recent $rtype ${axis}s");
768 $feed->creator($host);
769 $feed->update_ts(gmtime_ISO8601());
771 $feed->link(rss => $base . "/rss2-full/$rtype/$axis/$limit/$date" => 'application/rss+xml');
772 $feed->link(alternate => $base . "/atom-full/$rtype/$axis/$limit/$date" => 'application/atom+xml');
773 $feed->link(html => $base . "/html-full/$rtype/$axis/$limit/$date" => 'text/html');
774 $feed->link(unapi => $unapi);
778 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
779 join('&', map { 'rl=' . $_} @$list ),
784 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
785 print entityize($feed->toString) . "\n";
787 return Apache2::Const::OK;
796 if ($version eq '1.0') {
798 Content-type: application/opensearchdescription+xml; charset=utf-8
800 <?xml version="1.0" encoding="UTF-8"?>
801 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
802 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
803 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
804 <ShortName>$lib</ShortName>
805 <LongName>Search $lib</LongName>
806 <Description>Search the $lib OPAC by $class.</Description>
807 <Tags>$lib book library</Tags>
808 <SampleSearch>harry+potter</SampleSearch>
809 <Developer>Mike Rylander for GPLS/PINES</Developer>
810 <Contact>feedback\@open-ils.org</Contact>
811 <SyndicationRight>open</SyndicationRight>
812 <AdultContent>false</AdultContent>
813 </OpenSearchDescription>
817 Content-type: application/opensearchdescription+xml; charset=utf-8
819 <?xml version="1.0" encoding="UTF-8"?>
820 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
821 <ShortName>$lib</ShortName>
822 <Description>Search the $lib OPAC by $class.</Description>
823 <Tags>$lib book library</Tags>
824 <Url type="application/rss+xml"
825 template="$base/1.1/$lib/rss2-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
826 <Url type="application/atom+xml"
827 template="$base/1.1/$lib/atom-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
828 <Url type="application/x-mods3+xml"
829 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
830 <Url type="application/x-mods+xml"
831 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
832 <Url type="application/x-marcxml+xml"
833 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
834 <Url type="text/html"
835 template="$base/1.1/$lib/html-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
836 <LongName>Search $lib</LongName>
837 <Query role="example" searchTerms="harry+potter" />
838 <Developer>Mike Rylander for GPLS/PINES</Developer>
839 <Contact>feedback\@open-ils.org</Contact>
840 <SyndicationRight>open</SyndicationRight>
841 <AdultContent>false</AdultContent>
842 <Language>en-US</Language>
843 <OutputEncoding>UTF-8</OutputEncoding>
844 <InputEncoding>UTF-8</InputEncoding>
845 </OpenSearchDescription>
849 return Apache2::Const::OK;
852 sub opensearch_feed {
854 return Apache2::Const::DECLINED if (-e $apache->filename);
857 my $year = (gmtime())[5] + 1900;
859 my $host = $cgi->virtual_host || $cgi->server_name;
862 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
863 my $rel_name = $cgi->url(-relative=>1);
864 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
867 my $url = $cgi->url(-path_info=>$add_path);
868 my $root = (split 'opensearch', $url)[0];
869 my $base = (split 'opensearch', $url)[0] . 'opensearch';
870 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
872 my $path = $cgi->path_info;
873 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
875 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
881 if (!$lib || $lib eq '-') {
882 $lib = $actor->request(
883 'open-ils.actor.org_unit_list.search' => parent_ou => undef
884 )->gather(1)->[0]->shortname;
891 return opensearch_osd($version, $lib, $class, $base);
895 my $page = $cgi->param('startPage') || 1;
896 my $offset = $cgi->param('startIndex') || 1;
897 my $limit = $cgi->param('count') || 10;
899 $page = 1 if ($page !~ /^\d+$/);
900 $offset = 1 if ($offset !~ /^\d+$/);
901 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
904 $offset = ($page - 1) * $limit;
909 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = ('','','','','','','','');
910 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
912 $lang = $cgi->param('searchLang') if $cgi->param('searchLang');
913 $sort = $cgi->param('searchSort') if $cgi->param('searchSort');
914 $sortdir = $cgi->param('searchSortDir') if $cgi->param('searchSortDir');
915 $terms .= " " . $cgi->param('searchTerms') if $cgi->param('searchTerms');
917 $class = $cgi->param('searchClass') if $cgi->param('searchClass');
920 $type = $cgi->param('responseType') if $cgi->param('responseType');
923 $org = $cgi->param('searchOrg') if $cgi->param('searchOrg');
927 my $kwt = $cgi->param('kw');
928 my $tit = $cgi->param('ti');
929 my $aut = $cgi->param('au');
930 my $sut = $cgi->param('su');
931 my $set = $cgi->param('se');
933 $terms .= " keyword: $kwt" if ($kwt);
934 $terms .= " title: $tit" if ($tit);
935 $terms .= " author: $aut" if ($aut);
936 $terms .= " subject: $sut" if ($sut);
937 $terms .= " series: $set" if ($set);
939 if ($version eq '1.0') {
941 } elsif ($type eq '-') {
944 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
946 $terms = decode_utf8($terms);
949 $terms =~ s/^\s+//go;
950 my $term_copy = $terms;
952 my $complex_terms = 0;
953 if ($terms eq 'help') {
954 print $cgi->header(-type => 'text/html');
958 <title>just type something!</title>
961 <p>You are in a maze of dark, twisty stacks, all alike.</p>
965 return Apache2::Const::OK;
970 while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
971 my ($c,$t) = split ':' => $1;
976 } elsif ($c eq 'sort') {
977 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
978 } elsif ($c eq 'dir') {
979 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
980 } elsif ($c eq 'lang') {
981 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
983 $$searches{$c}{term} .= ' '.$t;
984 $cache_key .= $c . $t;
991 $class = 'keyword' if ($class eq '-');
992 $$searches{$class}{term} .= " $term_copy";
993 $cache_key .= $class . $term_copy;
998 $org_unit = $actor->request(
999 'open-ils.actor.org_unit_list.search' => parent_ou => undef
1002 $org_unit = $actor->request(
1003 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
1007 { no warnings; $cache_key .= $org.$sort.$sortdir.$lang; }
1009 my $rs_name = $cgi->cookie('os_session');
1010 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
1013 if (!($recs = $$cached_res{os_results}{$cache_key})) {
1014 $rs_name = $cgi->remote_host . '::' . rand(time);
1015 $recs = $search->request(
1016 'open-ils.search.biblio.multiclass' => {
1017 searches => $searches,
1018 org_unit => $org_unit->[0]->id,
1021 ($sort ? ( 'sort' => $sort ) : ()),
1022 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
1023 ($lang ? ( 'language' => $lang ) : ()),
1027 $$cached_res{os_results}{$cache_key} = $recs;
1028 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
1029 } catch Error with {
1030 warn "supercat unable to store IDs in memcache server\n";
1031 $logger->error("supercat unable to store IDs in memcache server");
1035 my $feed = create_record_feed(
1038 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
1045 $feed->search($terms);
1046 $feed->class($class);
1048 if ($complex_terms) {
1049 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
1051 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
1054 $feed->creator($host);
1055 $feed->update_ts(gmtime_ISO8601());
1057 $feed->_create_node(
1058 $feed->{item_xpath},
1059 'http://a9.com/-/spec/opensearch/1.1/',
1064 $feed->_create_node(
1065 $feed->{item_xpath},
1066 'http://a9.com/-/spec/opensearch/1.1/',
1071 $feed->_create_node(
1072 $feed->{item_xpath},
1073 'http://a9.com/-/spec/opensearch/1.1/',
1080 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
1081 'application/opensearch+xml'
1082 ) if ($offset + $limit < $recs->{count});
1086 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
1087 'application/opensearch+xml'
1092 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1093 'application/opensearch+xml'
1098 $base . "/$version/$org/rss2-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1099 'application/rss+xml'
1104 $base . "/$version/$org/atom-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1105 'application/atom+xml'
1110 $base . "/$version/$org/html/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1116 $base . "/$version/$org/html-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1120 $feed->link( 'unapi-server' => $unapi);
1124 # $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
1125 # join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
1130 -type => $feed->type,
1131 -charset => 'UTF-8',
1132 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
1135 print entityize($feed->toString) . "\n";
1137 return Apache2::Const::OK;
1140 sub create_record_feed {
1143 my $records = shift;
1146 my $lib = uc(shift()) || '-';
1148 $flesh = 1 if (!defined($flesh));
1151 my $base = $cgi->url;
1152 my $host = $cgi->virtual_host || $cgi->server_name;
1154 my $year = (gmtime())[5] + 1900;
1156 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
1158 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
1159 $feed->base($base) if ($flesh);
1160 $feed->unapi($unapi) if ($flesh);
1162 $type = 'atom' if ($type eq 'html');
1163 $type = 'marcxml' if ($type eq 'htmlholdings');
1165 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
1168 for my $record (@$records) {
1169 next unless($record);
1171 #my $rec = $record->id;
1174 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
1175 $item_tag = "tag:$host,$year:isbn/$rec/$lib" if ($search eq 'isbn');
1177 my $xml = $supercat->request(
1178 "open-ils.supercat.$search.$type.retrieve",
1183 my $node = $feed->add_item($xml);
1187 if ($lib && $type eq 'marcxml' && $flesh) {
1188 my $r = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib );
1189 while ( !$r->complete ) {
1190 $xml .= join('', map {$_->content} $r->recv);
1192 $xml .= join('', map {$_->content} $r->recv);
1193 $node->add_holdings($xml);
1196 $node->id($item_tag) if ($flesh);
1197 #$node->update_ts(clense_ISO8601($record->edit_date));
1198 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
1199 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
1200 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
1201 $node->link('unapi-id' => $item_tag) if ($flesh);
1208 my $stuff = NFC(shift());
1209 $stuff =~ s/&(?!\S+;)/&/gso;
1210 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1216 return Apache2::Const::DECLINED if (-e $apache->filename);
1219 my $year = (gmtime())[5] + 1900;
1221 my $host = $cgi->virtual_host || $cgi->server_name;
1224 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1225 my $rel_name = $cgi->url(-relative=>1);
1226 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1229 my $url = $cgi->url(-path_info=>$add_path);
1230 my $root = (split 'browse', $url)[0];
1231 my $base = (split 'browse', $url)[0] . 'browse';
1232 my $unapi = (split 'browse', $url)[0] . 'unapi';
1234 my $path = $cgi->path_info;
1237 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1238 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1240 $site ||= $cgi->param('searchOrg');
1241 $page ||= $cgi->param('startPage') || 0;
1242 $page_size ||= $cgi->param('count') || 9;
1244 $page = 0 if ($page !~ /^-?\d+$/);
1246 my $prev = join('/', $base,$format,$axis,$site,$string,$page - 1,$page_size);
1247 my $next = join('/', $base,$format,$axis,$site,$string,$page + 1,$page_size);
1249 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1250 warn "something's wrong...";
1251 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1255 $string = decode_utf8($string);
1256 $string =~ s/\+/ /go;
1259 my $tree = $supercat->request(
1260 "open-ils.supercat.$axis.browse",
1267 my ($header,$content) = $browse_types{$axis}{$format}->($tree,$prev,$next);
1268 print $header.$content;
1269 return Apache2::Const::OK;