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;
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);
38 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
40 my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
41 Fieldmapper->import(IDL => $idl);
43 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
44 $cstore = OpenSRF::AppSession->create('open-ils.cstore');
45 $actor = OpenSRF::AppSession->create('open-ils.actor');
46 $search = OpenSRF::AppSession->create('open-ils.search');
47 $parser = new XML::LibXML;
53 return Apache2::Const::DECLINED if (-e $apache->filename);
55 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
58 ->request("open-ils.supercat.oisbn", $isbn)
61 print "Content-type: application/xml; charset=utf-8\n\n";
62 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
64 unless (exists $$list{metarecord}) {
66 return Apache2::Const::OK;
69 print "<idlist metarecord='$$list{metarecord}'>\n";
71 for ( keys %{ $$list{record_list} } ) {
72 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
73 print " <isbn record='$_'>$o</isbn>\n"
78 return Apache2::Const::OK;
84 return Apache2::Const::DECLINED if (-e $apache->filename);
89 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
90 my $rel_name = $cgi->url(-relative=>1);
91 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
94 my $url = $cgi->url(-path_info=>$add_path);
95 my $root = (split 'unapi', $url)[0];
96 my $base = (split 'unapi', $url)[0] . 'unapi';
99 my $uri = $cgi->param('id') || '';
100 my $host = $cgi->virtual_host || $cgi->server_name;
102 my $format = $cgi->param('format');
103 my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
104 (my $base_format = $format) =~ s/-full$//o;
105 my ($id,$type,$command,$lib) = ('','','');
108 my $body = "Content-type: application/xml; charset=utf-8\n\n";
110 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))$}o) {
114 $type = 'metarecord' if ($1 =~ /^m/o);
117 ->request("open-ils.supercat.$type.formats")
120 if ($type eq 'record' or $type eq 'isbn') {
121 $body .= <<" FORMATS";
123 <format name='opac' type='text/html'/>
124 <format name='html' type='text/html'/>
125 <format name='htmlholdings' type='text/html'/>
126 <format name='html-full' type='text/html'/>
127 <format name='htmlholdings-full' type='text/html'/>
129 } elsif ($type eq 'metarecord') {
130 $body .= <<" FORMATS";
132 <format name='opac' type='text/html'/>
137 my ($type) = keys %$h;
138 $body .= "\t<format name='$type' type='application/xml'";
140 for my $part ( qw/namespace_uri docs schema_location/ ) {
141 $body .= " $part='$$h{$type}{$part}'"
142 if ($$h{$type}{$part});
147 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
148 $body .= "\t<format name='$type-full' type='application/xml'";
150 for my $part ( qw/namespace_uri docs schema_location/ ) {
151 $body .= " $part='$$h{$type}{$part}'"
152 if ($$h{$type}{$part});
159 $body .= "</formats>\n";
163 ->request("open-ils.supercat.record.formats")
168 ->request("open-ils.supercat.metarecord.formats")
172 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
173 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
175 $body .= <<" FORMATS";
177 <format name='opac' type='text/html'/>
178 <format name='html' type='text/html'/>
179 <format name='htmlholdings' type='text/html'/>
180 <format name='html-full' type='text/html'/>
181 <format name='htmlholdings-full' type='text/html'/>
186 my ($type) = keys %$h;
187 $body .= "\t<format name='$type' type='application/xml'";
189 for my $part ( qw/namespace_uri docs schema_location/ ) {
190 $body .= " $part='$$h{$type}{$part}'"
191 if ($$h{$type}{$part});
196 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
197 $body .= "\t<format name='$type-full' type='application/xml'";
199 for my $part ( qw/namespace_uri docs schema_location/ ) {
200 $body .= " $part='$$h{$type}{$part}'"
201 if ($$h{$type}{$part});
208 $body .= "</formats>\n";
212 return Apache2::Const::OK;
215 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))?}o) {
219 $type = 'metarecord' if ($1 =~ /^metabib/o);
220 $type = 'isbn' if ($1 =~ /^isbn/o);
221 $command = 'retrieve';
225 { (keys(%$_))[0] eq $base_format }
226 @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
228 { $_ eq $base_format }
229 qw/opac html htmlholdings/
231 print "Content-type: text/html; charset=utf-8\n\n";
232 $apache->custom_response( 406, <<" HTML");
235 <title>Invalid format [$format] for type [$type]!</title>
239 <center>Sorry, format $format is not valid for type $type.</center>
246 if ($format eq 'opac') {
247 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
248 if ($type eq 'metarecord');
249 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
250 if ($type eq 'record');
252 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
253 my $feed = create_record_feed(
262 print "Content-type: text/html; charset=utf-8\n\n";
263 $apache->custom_response( 404, <<" HTML");
266 <title>Type [$type] with id [$id] not found!</title>
270 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
278 $feed->creator($host);
279 $feed->update_ts(gmtime_ISO8601());
280 $feed->link( unapi => $base) if ($flesh_feed);
282 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
283 print entityize($feed->toString) . "\n";
285 return Apache2::Const::OK;
288 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
289 my $data = $req->gather(1);
291 if ($req->failed || !$data) {
292 print "Content-type: text/html; charset=utf-8\n\n";
293 $apache->custom_response( 404, <<" HTML");
296 <title>$type $id not found!</title>
300 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
307 print "Content-type: application/xml; charset=utf-8\n\n$data";
309 return Apache2::Const::OK;
315 return Apache2::Const::DECLINED if (-e $apache->filename);
320 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
321 my $rel_name = $cgi->url(-relative=>1);
322 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
325 my $url = $cgi->url(-path_info=>$add_path);
326 my $root = (split 'supercat', $url)[0];
327 my $base = (split 'supercat', $url)[0] . 'supercat';
328 my $unapi = (split 'supercat', $url)[0] . 'unapi';
330 my $host = $cgi->virtual_host || $cgi->server_name;
332 my $path = $cgi->path_info;
333 my ($id,$type,$format,$command) = reverse split '/', $path;
334 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
335 (my $base_format = $format) =~ s/-full$//o;
337 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
338 print "Content-type: application/xml; charset=utf-8\n";
341 ->request("open-ils.supercat.$1.formats")
349 <type>text/html</type>
352 if ($1 eq 'record' or $1 eq 'isbn') {
354 <name>htmlholdings</name>
355 <type>text/html</type>
359 <type>text/html</type>
362 <name>htmlholdings-full</name>
363 <type>text/html</type>
366 <name>html-full</name>
367 <type>text/html</type>
372 my ($type) = keys %$h;
373 print "<format><name>$type</name><type>application/xml</type>";
375 for my $part ( qw/namespace_uri docs schema_location/ ) {
376 print "<$part>$$h{$type}{$part}</$part>"
377 if ($$h{$type}{$part});
382 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
383 print "<format><name>$type-full</name><type>application/xml</type>";
385 for my $part ( qw/namespace_uri docs schema_location/ ) {
386 print "<$part>$$h{$type}{$part}</$part>"
387 if ($$h{$type}{$part});
395 print "</formats>\n";
397 return Apache2::Const::OK;
401 ->request("open-ils.supercat.record.formats")
406 ->request("open-ils.supercat.metarecord.formats")
410 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
411 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
416 <type>text/html</type>
419 <name>htmlholdings</name>
420 <type>text/html</type>
424 <type>text/html</type>
427 <name>htmlholdings-full</name>
428 <type>text/html</type>
431 <name>html-full</name>
432 <type>text/html</type>
436 my ($type) = keys %$h;
437 print "<format><name>$type</name><type>application/xml</type>";
439 for my $part ( qw/namespace_uri docs schema_location/ ) {
440 print "<$part>$$h{$type}{$part}</$part>"
441 if ($$h{$type}{$part});
446 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
447 print "<format><name>$type-full</name><type>application/xml</type>";
449 for my $part ( qw/namespace_uri docs schema_location/ ) {
450 print "<$part>$$h{$type}{$part}</$part>"
451 if ($$h{$type}{$part});
459 print "</formats>\n";
462 return Apache2::Const::OK;
465 if ($format eq 'opac') {
466 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
467 if ($type eq 'metarecord');
468 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
469 if ($type eq 'record');
471 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
472 my $feed = create_record_feed(
480 $feed->creator($host);
481 $feed->update_ts(gmtime_ISO8601());
482 $feed->link( unapi => $base) if ($flesh_feed);
484 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
485 print entityize($feed->toString) . "\n";
487 return Apache2::Const::OK;
490 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
494 print "Content-type: text/html; charset=utf-8\n\n";
495 $apache->custom_response( 404, <<" HTML");
498 <title>$type $id not found!</title>
502 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
509 print "Content-type: application/xml; charset=utf-8\n\n";
510 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
512 return Apache2::Const::OK;
518 return Apache2::Const::DECLINED if (-e $apache->filename);
522 my $year = (gmtime())[5] + 1900;
523 my $host = $cgi->virtual_host || $cgi->server_name;
526 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
527 my $rel_name = $cgi->url(-relative=>1);
528 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
531 my $url = $cgi->url(-path_info=>$add_path);
532 my $root = (split 'feed', $url)[0];
533 my $base = (split 'bookbag', $url)[0] . 'bookbag';
534 my $unapi = (split 'feed', $url)[0] . 'unapi';
537 my $path = $cgi->path_info;
538 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
540 my ($id,$type) = reverse split '/', $path;
541 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
543 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
544 return Apache2::Const::NOT_FOUND unless($bucket);
546 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
547 if ($type eq 'opac') {
548 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
549 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
554 my $feed = create_record_feed(
557 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
564 $feed->title("Items in Book Bag [".$bucket->name."]");
565 $feed->creator($host);
566 $feed->update_ts(gmtime_ISO8601());
568 $feed->link(rss => $base . "/rss2/$id" => 'application/rss+xml');
569 $feed->link(alternate => $base . "/atom/$id" => 'application/atom+xml');
570 $feed->link(html => $base . "/html/$id" => 'text/html');
571 $feed->link(unapi => $unapi);
575 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
576 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
581 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
582 print entityize($feed->toString) . "\n";
584 return Apache2::Const::OK;
589 return Apache2::Const::DECLINED if (-e $apache->filename);
593 my $year = (gmtime())[5] + 1900;
594 my $host = $cgi->virtual_host || $cgi->server_name;
597 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
598 my $rel_name = $cgi->url(-relative=>1);
599 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
602 my $url = $cgi->url(-path_info=>$add_path);
603 my $root = (split 'feed', $url)[0];
604 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
605 my $unapi = (split 'feed', $url)[0] . 'unapi';
607 my $path = $cgi->path_info;
608 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
610 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
612 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
613 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
616 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
618 #if ($type eq 'opac') {
619 # print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
620 # join('&', map { "rl=" . $_ } @$list) .
625 my $feed = create_record_feed( 'record', $type, $list, $unapi, undef, $flesh_feed);
629 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
631 $feed->title("$limit most recent $rtype ${axis}s");
634 $feed->creator($host);
635 $feed->update_ts(gmtime_ISO8601());
637 $feed->link(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml');
638 $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml');
639 $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html');
640 $feed->link(unapi => $unapi);
644 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
645 join('&', map { 'rl=' . $_} @$list ),
650 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
651 print entityize($feed->toString) . "\n";
653 return Apache2::Const::OK;
662 if ($version eq '1.0') {
664 Content-type: application/opensearchdescription+xml; charset=utf-8
666 <?xml version="1.0" encoding="UTF-8"?>
667 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
668 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
669 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
670 <ShortName>$lib</ShortName>
671 <LongName>Search $lib</LongName>
672 <Description>Search the $lib OPAC by $class.</Description>
673 <Tags>$lib book library</Tags>
674 <SampleSearch>harry+potter</SampleSearch>
675 <Developer>Mike Rylander for GPLS/PINES</Developer>
676 <Contact>feedback\@open-ils.org</Contact>
677 <SyndicationRight>open</SyndicationRight>
678 <AdultContent>false</AdultContent>
679 </OpenSearchDescription>
683 Content-type: application/opensearchdescription+xml; charset=utf-8
685 <?xml version="1.0" encoding="UTF-8"?>
686 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
687 <ShortName>$lib</ShortName>
688 <Description>Search the $lib OPAC by $class.</Description>
689 <Tags>$lib book library</Tags>
690 <Url type="application/rss+xml"
691 template="$base/1.1/$lib/rss2/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
692 <Url type="application/atom+xml"
693 template="$base/1.1/$lib/atom/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
694 <Url type="application/x-mods3+xml"
695 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
696 <Url type="application/x-mods+xml"
697 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
698 <Url type="application/x-marcxml+xml"
699 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
700 <LongName>Search $lib</LongName>
701 <Query role="example" searchTerms="harry+potter" />
702 <Developer>Mike Rylander for GPLS/PINES</Developer>
703 <Contact>feedback\@open-ils.org</Contact>
704 <SyndicationRight>open</SyndicationRight>
705 <AdultContent>false</AdultContent>
706 <Language>en-US</Language>
707 <OutputEncoding>UTF-8</OutputEncoding>
708 <InputEncoding>UTF-8</InputEncoding>
709 </OpenSearchDescription>
713 return Apache2::Const::OK;
716 sub opensearch_feed {
718 return Apache2::Const::DECLINED if (-e $apache->filename);
721 my $year = (gmtime())[5] + 1900;
723 my $host = $cgi->virtual_host || $cgi->server_name;
726 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
727 my $rel_name = $cgi->url(-relative=>1);
728 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
731 my $url = $cgi->url(-path_info=>$add_path);
732 my $root = (split 'opensearch', $url)[0];
733 my $base = (split 'opensearch', $url)[0] . 'opensearch';
734 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
736 my $path = $cgi->path_info;
737 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
739 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
746 $lib = $actor->request(
747 'open-ils.actor.org_unit_list.search' => parent_ou => undef
748 )->gather(1)->[0]->shortname;
755 return opensearch_osd($version, $lib, $class, $base);
759 my $page = $cgi->param('startPage') || 1;
760 my $offset = $cgi->param('startIndex') || 1;
761 my $limit = $cgi->param('count') || 10;
763 $page = 1 if ($page !~ /^\d+$/);
764 $offset = 1 if ($offset !~ /^\d+$/);
765 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
768 $offset = ($page - 1) * $limit;
773 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang);
774 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
776 $lang ||= $cgi->param('searchLang');
777 $sort ||= $cgi->param('searchSort');
778 $sortdir ||= $cgi->param('searchSortDir');
779 $terms ||= $cgi->param('searchTerms');
780 $class ||= $cgi->param('searchClass') || '-';
781 $type ||= $cgi->param('responseType') || '-';
782 $org ||= $cgi->param('searchOrg') || '-';
784 if ($version eq '1.0') {
786 } elsif ($type eq '-') {
789 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
791 $terms = decode_utf8($terms);
794 my $term_copy = $terms;
796 my $complex_terms = 0;
797 if ($terms eq 'help') {
798 print $cgi->header(-type => 'text/html');
802 <title>just type something!</title>
805 <p>You are in a maze of dark, twisty stacks, all alike.</p>
809 return Apache2::Const::OK;
814 while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
815 my ($c,$t) = split ':' => $1;
820 } elsif ($c eq 'sort') {
821 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
822 } elsif ($c eq 'dir') {
823 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
824 } elsif ($c eq 'lang') {
825 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
827 $$searches{$c}{term} .= ' '.$t;
828 $cache_key .= $c . $t;
835 $class = 'keyword' if ($class eq '-');
836 $$searches{$class}{term} .= " $term_copy";
837 $cache_key .= $class . $term_copy;
842 $org_unit = $actor->request(
843 'open-ils.actor.org_unit_list.search' => parent_ou => undef
846 $org_unit = $actor->request(
847 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
851 $cache_key .= $org.$sort.$sortdir.$lang;
853 my $rs_name = $cgi->cookie('os_session');
854 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
857 if (!($recs = $$cached_res{os_results}{$cache_key})) {
858 $rs_name = $cgi->remote_host . '::' . rand(time);
859 $recs = $search->request(
860 'open-ils.search.biblio.multiclass' => {
861 searches => $searches,
862 org_unit => $org_unit->[0]->id,
865 ($sort ? ( 'sort' => $sort ) : ()),
866 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
867 ($lang ? ( 'language' => $lang ) : ()),
871 $$cached_res{os_results}{$cache_key} = $recs;
872 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
874 warn "supercat unable to store IDs in memcache server\n";
875 $logger->error("supercat unable to store IDs in memcache server");
879 my $feed = create_record_feed(
882 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
889 $feed->search($terms);
890 $feed->class($class);
892 if ($complex_terms) {
893 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
895 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
898 $feed->creator($host);
899 $feed->update_ts(gmtime_ISO8601());
903 'http://a9.com/-/spec/opensearch/1.1/',
910 'http://a9.com/-/spec/opensearch/1.1/',
917 'http://a9.com/-/spec/opensearch/1.1/',
924 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
925 'application/opensearch+xml'
926 ) if ($offset + $limit < $recs->{count});
930 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
931 'application/opensearch+xml'
936 $base . "/$version/$org/$type/$class?searchTerms=$terms" =>
937 'application/opensearch+xml'
942 $base . "/$version/$org/rss2-full/$class?searchTerms=$terms" =>
943 'application/rss+xml'
948 $base . "/$version/$org/atom-full/$class?searchTerms=$terms" =>
949 'application/atom+xml'
954 $base . "/$version/$org/html/$class?searchTerms=$terms" =>
960 $base . "/$version/$org/html-full/$class?searchTerms=$terms" =>
964 $feed->link( 'unapi-server' => $unapi);
968 # $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
969 # join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
974 -type => $feed->type,
976 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
979 print entityize($feed->toString) . "\n";
981 return Apache2::Const::OK;
984 sub create_record_feed {
990 my $lib = shift || '-';
992 $flesh = 1 if (!defined($flesh));
995 my $base = $cgi->url;
996 my $host = $cgi->virtual_host || $cgi->server_name;
998 my $year = (gmtime())[5] + 1900;
1000 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
1002 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
1003 $feed->base($base) if ($flesh);
1004 $feed->unapi($unapi) if ($flesh);
1006 $type = 'atom' if ($type eq 'html');
1007 $type = 'marcxml' if ($type eq 'htmlholdings');
1009 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
1012 for my $record (@$records) {
1013 next unless($record);
1015 #my $rec = $record->id;
1018 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
1019 $item_tag = "tag:$host,$year:isbn/$rec/$lib" if ($search eq 'isbn');
1021 my $xml = $supercat->request(
1022 "open-ils.supercat.$search.$type.retrieve",
1027 my $node = $feed->add_item($xml);
1030 if ($lib && $type eq 'marcxml' && $flesh) {
1031 $xml = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib )->gather(1);
1032 $node->add_holdings($xml);
1035 $node->id($item_tag) if ($flesh);
1036 #$node->update_ts(clense_ISO8601($record->edit_date));
1037 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
1038 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
1039 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
1040 $node->link('unapi-id' => $item_tag) if ($flesh);
1047 my $stuff = NFC(shift());
1048 $stuff =~ s/&(?!\S+;)/&/gso;
1049 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1053 my %browse_types = (
1058 my $year = (gmtime())[5] + 1900;
1061 $content .= "Content-type: application/xml\n\n";
1062 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
1064 for my $cn (@$tree) {
1065 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
1066 $cn_class =~ s/Fieldmapper-//gso;
1068 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
1069 my $cn_lib = $cn->owning_lib->shortname;
1070 my $cn_label = $cn->label;
1072 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
1073 $ou_class =~ s/Fieldmapper-//gso;
1075 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
1076 my $ou_name = $cn->owning_lib->name;
1078 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
1079 $rec_class =~ s/Fieldmapper-//gso;
1081 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
1083 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
1084 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
1086 my $r_doc = $parser->parse_string($cn->record->marc);
1087 $r_doc->documentElement->setAttribute( id => $rec_tag );
1088 $content .= entityize($r_doc->documentElement->toString);
1090 $content .= "</hold:volume>";
1093 $content .= '</hold:volumes>';
1101 return Apache2::Const::DECLINED if (-e $apache->filename);
1104 my $year = (gmtime())[5] + 1900;
1106 my $host = $cgi->virtual_host || $cgi->server_name;
1109 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1110 my $rel_name = $cgi->url(-relative=>1);
1111 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1114 my $url = $cgi->url(-path_info=>$add_path);
1115 my $root = (split 'browse', $url)[0];
1116 my $base = (split 'browse', $url)[0] . 'browse';
1117 my $unapi = (split 'browse', $url)[0] . 'unapi';
1119 my $path = $cgi->path_info;
1122 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1123 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1126 $site ||= $cgi->param('searchOrg');
1127 $page ||= $cgi->param('startPage') || 0;
1128 $page_size ||= $cgi->param('count') || 9;
1130 $page = 0 if ($page !~ /^\d+$/);
1132 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1133 warn "something's wrong...";
1134 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1138 $string = decode_utf8($string);
1139 $string =~ s/\+/ /go;
1142 my $tree = $supercat->request(
1143 "open-ils.supercat.$axis.browse",
1150 my $content = $browse_types{$axis}{$format}->($tree);
1152 return Apache2::Const::OK;