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:[^:]+:([^\/]+)/(\d+)}o) {
114 $type = 'metarecord' if ($1 =~ /^m/o);
117 ->request("open-ils.supercat.$type.formats")
120 if ($type eq 'record') {
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";
211 $apache->custom_response( 300, $body);
216 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)(?:/(.+))?}o) {
220 $type = 'metarecord' if ($1 =~ /^m/o);
221 $command = 'retrieve';
224 if ($format eq 'opac') {
225 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
226 if ($type eq 'metarecord');
227 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
228 if ($type eq 'record');
230 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
231 my $feed = create_record_feed(
239 $feed->creator($host);
240 $feed->update_ts(gmtime_ISO8601());
241 $feed->link( unapi => $base) if ($flesh_feed);
243 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
244 print entityize($feed->toString) . "\n";
246 return Apache2::Const::OK;
249 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
253 print "Content-type: text/html; charset=utf-8\n\n";
254 $apache->custom_response( 404, <<" HTML");
257 <title>$type $id not found!</title>
261 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
268 print "Content-type: application/xml; charset=utf-8\n\n";
269 print $req->gather(1);
271 return Apache2::Const::OK;
277 return Apache2::Const::DECLINED if (-e $apache->filename);
282 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
283 my $rel_name = $cgi->url(-relative=>1);
284 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
287 my $url = $cgi->url(-path_info=>$add_path);
288 my $root = (split 'supercat', $url)[0];
289 my $base = (split 'supercat', $url)[0] . 'supercat';
290 my $unapi = (split 'supercat', $url)[0] . 'unapi';
292 my $host = $cgi->virtual_host || $cgi->server_name;
294 my $path = $cgi->path_info;
295 my ($id,$type,$format,$command) = reverse split '/', $path;
296 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
297 (my $base_format = $format) =~ s/-full$//o;
299 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
300 print "Content-type: application/xml; charset=utf-8\n";
303 ->request("open-ils.supercat.$1.formats")
311 <type>text/html</type>
314 if ($1 eq 'record') {
316 <name>htmlholdings</name>
317 <type>text/html</type>
321 <type>text/html</type>
324 <name>htmlholdings-full</name>
325 <type>text/html</type>
328 <name>html-full</name>
329 <type>text/html</type>
334 my ($type) = keys %$h;
335 print "<format><name>$type</name><type>application/xml</type>";
337 for my $part ( qw/namespace_uri docs schema_location/ ) {
338 print "<$part>$$h{$type}{$part}</$part>"
339 if ($$h{$type}{$part});
344 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
345 print "<format><name>$type-full</name><type>application/xml</type>";
347 for my $part ( qw/namespace_uri docs schema_location/ ) {
348 print "<$part>$$h{$type}{$part}</$part>"
349 if ($$h{$type}{$part});
357 print "</formats>\n";
359 return Apache2::Const::OK;
363 ->request("open-ils.supercat.record.formats")
368 ->request("open-ils.supercat.metarecord.formats")
372 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
373 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
378 <type>text/html</type>
381 <name>htmlholdings</name>
382 <type>text/html</type>
386 <type>text/html</type>
389 <name>htmlholdings-full</name>
390 <type>text/html</type>
393 <name>html-full</name>
394 <type>text/html</type>
398 my ($type) = keys %$h;
399 print "<format><name>$type</name><type>application/xml</type>";
401 for my $part ( qw/namespace_uri docs schema_location/ ) {
402 print "<$part>$$h{$type}{$part}</$part>"
403 if ($$h{$type}{$part});
408 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
409 print "<format><name>$type-full</name><type>application/xml</type>";
411 for my $part ( qw/namespace_uri docs schema_location/ ) {
412 print "<$part>$$h{$type}{$part}</$part>"
413 if ($$h{$type}{$part});
421 print "</formats>\n";
424 return Apache2::Const::OK;
427 if ($format eq 'opac') {
428 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
429 if ($type eq 'metarecord');
430 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
431 if ($type eq 'record');
433 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
434 my $feed = create_record_feed(
441 $feed->creator($host);
442 $feed->update_ts(gmtime_ISO8601());
443 $feed->link( unapi => $base) if ($flesh_feed);
445 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
446 print entityize($feed->toString) . "\n";
448 return Apache2::Const::OK;
451 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
455 print "Content-type: text/html; charset=utf-8\n\n";
456 $apache->custom_response( 404, <<" HTML");
459 <title>$type $id not found!</title>
463 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
470 print "Content-type: application/xml; charset=utf-8\n\n";
471 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
473 return Apache2::Const::OK;
479 return Apache2::Const::DECLINED if (-e $apache->filename);
483 my $year = (gmtime())[5] + 1900;
484 my $host = $cgi->virtual_host || $cgi->server_name;
487 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
488 my $rel_name = $cgi->url(-relative=>1);
489 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
492 my $url = $cgi->url(-path_info=>$add_path);
493 my $root = (split 'feed', $url)[0];
494 my $base = (split 'bookbag', $url)[0] . 'bookbag';
495 my $unapi = (split 'feed', $url)[0] . 'unapi';
498 my $path = $cgi->path_info;
499 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
501 my ($id,$type) = reverse split '/', $path;
502 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
504 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
505 return Apache2::Const::NOT_FOUND unless($bucket);
507 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
508 if ($type eq 'opac') {
509 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
510 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
515 my $feed = create_record_feed(
517 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
524 $feed->title("Items in Book Bag [".$bucket->name."]");
525 $feed->creator($host);
526 $feed->update_ts(gmtime_ISO8601());
528 $feed->link(rss => $base . "/rss2/$id" => 'application/rss+xml');
529 $feed->link(alternate => $base . "/atom/$id" => 'application/atom+xml');
530 $feed->link(html => $base . "/html/$id" => 'text/html');
531 $feed->link(unapi => $unapi);
535 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
536 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
541 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
542 print entityize($feed->toString) . "\n";
544 return Apache2::Const::OK;
549 return Apache2::Const::DECLINED if (-e $apache->filename);
553 my $year = (gmtime())[5] + 1900;
554 my $host = $cgi->virtual_host || $cgi->server_name;
557 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
558 my $rel_name = $cgi->url(-relative=>1);
559 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
562 my $url = $cgi->url(-path_info=>$add_path);
563 my $root = (split 'feed', $url)[0];
564 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
565 my $unapi = (split 'feed', $url)[0] . 'unapi';
567 my $path = $cgi->path_info;
568 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
570 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
572 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
573 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
576 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
578 if ($type eq 'opac') {
579 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
580 join('&', map { "rl=" . $_ } @$list) .
585 my $feed = create_record_feed( $type, $list, $unapi, undef, $flesh_feed);
589 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
591 $feed->title("$limit most recent $rtype ${axis}s");
594 $feed->creator($host);
595 $feed->update_ts(gmtime_ISO8601());
597 $feed->link(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml');
598 $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml');
599 $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html');
600 $feed->link(unapi => $unapi);
604 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
605 join('&', map { 'rl=' . $_} @$list ),
610 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
611 print entityize($feed->toString) . "\n";
613 return Apache2::Const::OK;
622 if ($version eq '1.0') {
624 Content-type: application/opensearchdescription+xml; charset=utf-8
626 <?xml version="1.0" encoding="UTF-8"?>
627 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
628 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
629 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
630 <ShortName>$lib</ShortName>
631 <LongName>Search $lib</LongName>
632 <Description>Search the $lib OPAC by $class.</Description>
633 <Tags>$lib book library</Tags>
634 <SampleSearch>harry+potter</SampleSearch>
635 <Developer>Mike Rylander for GPLS/PINES</Developer>
636 <Contact>feedback\@open-ils.org</Contact>
637 <SyndicationRight>open</SyndicationRight>
638 <AdultContent>false</AdultContent>
639 </OpenSearchDescription>
643 Content-type: application/opensearchdescription+xml; charset=utf-8
645 <?xml version="1.0" encoding="UTF-8"?>
646 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
647 <ShortName>$lib</ShortName>
648 <Description>Search the $lib OPAC by $class.</Description>
649 <Tags>$lib book library</Tags>
650 <Url type="application/rss+xml"
651 template="$base/1.1/$lib/rss2/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
652 <Url type="application/atom+xml"
653 template="$base/1.1/$lib/atom/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
654 <Url type="application/x-mods3+xml"
655 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
656 <Url type="application/x-mods+xml"
657 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
658 <Url type="application/x-marcxml+xml"
659 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
660 <LongName>Search $lib</LongName>
661 <Query role="example" searchTerms="harry+potter" />
662 <Developer>Mike Rylander for GPLS/PINES</Developer>
663 <Contact>feedback\@open-ils.org</Contact>
664 <SyndicationRight>open</SyndicationRight>
665 <AdultContent>false</AdultContent>
666 <Language>en-US</Language>
667 <OutputEncoding>UTF-8</OutputEncoding>
668 <InputEncoding>UTF-8</InputEncoding>
669 </OpenSearchDescription>
673 return Apache2::Const::OK;
676 sub opensearch_feed {
678 return Apache2::Const::DECLINED if (-e $apache->filename);
681 my $year = (gmtime())[5] + 1900;
683 my $host = $cgi->virtual_host || $cgi->server_name;
686 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
687 my $rel_name = $cgi->url(-relative=>1);
688 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
691 my $url = $cgi->url(-path_info=>$add_path);
692 my $root = (split 'opensearch', $url)[0];
693 my $base = (split 'opensearch', $url)[0] . 'opensearch';
694 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
696 my $path = $cgi->path_info;
697 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
699 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
706 $lib = $actor->request(
707 'open-ils.actor.org_unit_list.search' => parent_ou => undef
708 )->gather(1)->[0]->shortname;
715 return opensearch_osd($version, $lib, $class, $base);
719 my $page = $cgi->param('startPage') || 1;
720 my $offset = $cgi->param('startIndex') || 1;
721 my $limit = $cgi->param('count') || 10;
723 $page = 1 if ($page !~ /^\d+$/);
724 $offset = 1 if ($offset !~ /^\d+$/);
725 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
728 $offset = ($page - 1) * $limit;
733 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang);
734 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
736 $lang ||= $cgi->param('searchLang');
737 $sort ||= $cgi->param('searchSort');
738 $sortdir ||= $cgi->param('searchSortDir');
739 $terms ||= $cgi->param('searchTerms');
740 $class ||= $cgi->param('searchClass') || '-';
741 $type ||= $cgi->param('responseType') || '-';
742 $org ||= $cgi->param('searchOrg') || '-';
744 if ($version eq '1.0') {
746 } elsif ($type eq '-') {
749 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
751 $terms = decode_utf8($terms);
754 my $term_copy = $terms;
756 my $complex_terms = 0;
757 if ($terms eq 'help') {
758 print $cgi->header(-type => 'text/html');
762 <title>just type something!</title>
765 <p>You are in a maze of dark, twisty stacks, all alike.</p>
769 return Apache2::Const::OK;
774 while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
775 my ($c,$t) = split ':' => $1;
780 } elsif ($c eq 'sort') {
781 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
782 } elsif ($c eq 'dir') {
783 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
784 } elsif ($c eq 'lang') {
785 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
787 $$searches{$c}{term} .= ' '.$t;
788 $cache_key .= $c . $t;
795 $class = 'keyword' if ($class eq '-');
796 $$searches{$class}{term} .= " $term_copy";
797 $cache_key .= $class . $term_copy;
802 $org_unit = $actor->request(
803 'open-ils.actor.org_unit_list.search' => parent_ou => undef
806 $org_unit = $actor->request(
807 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
811 $cache_key .= $org.$sort.$sortdir.$lang;
813 my $rs_name = $cgi->cookie('os_session');
814 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
817 if (!($recs = $$cached_res{os_results}{$cache_key})) {
818 $rs_name = $cgi->remote_host . '::' . rand(time);
819 $recs = $search->request(
820 'open-ils.search.biblio.multiclass' => {
821 searches => $searches,
822 org_unit => $org_unit->[0]->id,
825 ($sort ? ( 'sort' => $sort ) : ()),
826 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
827 ($lang ? ( 'language' => $lang ) : ()),
831 $$cached_res{os_results}{$cache_key} = $recs;
832 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
834 warn "supercat unable to store IDs in memcache server\n";
835 $logger->error("supercat unable to store IDs in memcache server");
839 my $feed = create_record_feed(
841 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
848 $feed->search($terms);
849 $feed->class($class);
851 if ($complex_terms) {
852 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
854 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
857 $feed->creator($host);
858 $feed->update_ts(gmtime_ISO8601());
862 'http://a9.com/-/spec/opensearch/1.1/',
869 'http://a9.com/-/spec/opensearch/1.1/',
876 'http://a9.com/-/spec/opensearch/1.1/',
883 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
884 'application/opensearch+xml'
885 ) if ($offset + $limit < $recs->{count});
889 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
890 'application/opensearch+xml'
895 $base . "/$version/$org/$type/$class?searchTerms=$terms" =>
896 'application/opensearch+xml'
901 $base . "/$version/$org/rss2-full/$class?searchTerms=$terms" =>
902 'application/rss+xml'
907 $base . "/$version/$org/atom-full/$class?searchTerms=$terms" =>
908 'application/atom+xml'
913 $base . "/$version/$org/html/$class?searchTerms=$terms" =>
919 $base . "/$version/$org/html-full/$class?searchTerms=$terms" =>
923 $feed->link( 'unapi-server' => $unapi);
927 # $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
928 # join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
933 -type => $feed->type,
935 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
938 print entityize($feed->toString) . "\n";
940 return Apache2::Const::OK;
943 sub create_record_feed {
948 my $lib = shift || '-';
950 $flesh = 1 if (!defined($flesh));
953 my $base = $cgi->url;
954 my $host = $cgi->virtual_host || $cgi->server_name;
956 my $year = (gmtime())[5] + 1900;
958 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
960 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
961 $feed->base($base) if ($flesh);
962 $feed->unapi($unapi) if ($flesh);
964 $type = 'atom' if ($type eq 'html');
965 $type = 'marcxml' if ($type eq 'htmlholdings');
967 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
969 for my $record (@$records) {
970 next unless($record);
972 #my $rec = $record->id;
975 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
977 my $xml = $supercat->request(
978 "open-ils.supercat.record.$type.retrieve",
983 my $node = $feed->add_item($xml);
986 if ($lib && $type eq 'marcxml' && $flesh) {
987 $xml = $supercat->request( "open-ils.supercat.record.holdings_xml.retrieve", $rec, $lib )->gather(1);
988 $node->add_holdings($xml);
991 $node->id($item_tag) if ($flesh);
992 #$node->update_ts(clense_ISO8601($record->edit_date));
993 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
994 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
995 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
996 $node->link('unapi-id' => $item_tag) if ($flesh);
1003 my $stuff = NFC(shift());
1004 $stuff =~ s/&(?!\S+;)/&/gso;
1005 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1009 my %browse_types = (
1014 my $year = (gmtime())[5] + 1900;
1017 $content .= "Content-type: application/xml\n\n";
1018 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
1020 for my $cn (@$tree) {
1021 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
1022 $cn_class =~ s/Fieldmapper-//gso;
1024 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
1025 my $cn_lib = $cn->owning_lib->shortname;
1026 my $cn_label = $cn->label;
1028 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
1029 $ou_class =~ s/Fieldmapper-//gso;
1031 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
1032 my $ou_name = $cn->owning_lib->name;
1034 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
1035 $rec_class =~ s/Fieldmapper-//gso;
1037 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
1039 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
1040 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
1042 my $r_doc = $parser->parse_string($cn->record->marc);
1043 $r_doc->documentElement->setAttribute( id => $rec_tag );
1044 $content .= entityize($r_doc->documentElement->toString);
1046 $content .= "</hold:volume>";
1049 $content .= '</hold:volumes>';
1057 return Apache2::Const::DECLINED if (-e $apache->filename);
1060 my $year = (gmtime())[5] + 1900;
1062 my $host = $cgi->virtual_host || $cgi->server_name;
1065 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1066 my $rel_name = $cgi->url(-relative=>1);
1067 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1070 my $url = $cgi->url(-path_info=>$add_path);
1071 my $root = (split 'browse', $url)[0];
1072 my $base = (split 'browse', $url)[0] . 'browse';
1073 my $unapi = (split 'browse', $url)[0] . 'unapi';
1075 my $path = $cgi->path_info;
1078 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1079 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1082 $site ||= $cgi->param('searchOrg');
1083 $page ||= $cgi->param('startPage') || 0;
1084 $page_size ||= $cgi->param('count') || 9;
1086 $page = 0 if ($page !~ /^\d+$/);
1088 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1089 warn "something's wrong...";
1090 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1094 $string = decode_utf8($string);
1095 $string =~ s/\+/ /go;
1098 my $tree = $supercat->request(
1099 "open-ils.supercat.$axis.browse",
1106 my $content = $browse_types{$axis}{$format}->($tree);
1108 return Apache2::Const::OK;