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;
27 # set the bootstrap config when this module is loaded
28 my ($bootstrap, $cstore, $supercat, $actor, $parser, $search);
37 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
38 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
39 $cstore = OpenSRF::AppSession->create('open-ils.cstore');
40 $actor = OpenSRF::AppSession->create('open-ils.actor');
41 $search = OpenSRF::AppSession->create('open-ils.search');
42 $parser = new XML::LibXML;
48 return Apache2::Const::DECLINED if (-e $apache->filename);
50 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
53 ->request("open-ils.supercat.oisbn", $isbn)
56 print "Content-type: application/xml; charset=utf-8\n\n";
57 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
59 unless (exists $$list{metarecord}) {
61 return Apache2::Const::OK;
64 print "<idlist metarecord='$$list{metarecord}'>\n";
66 for ( keys %{ $$list{record_list} } ) {
67 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
68 print " <isbn record='$_'>$o</isbn>\n"
73 return Apache2::Const::OK;
79 return Apache2::Const::DECLINED if (-e $apache->filename);
84 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
85 my $rel_name = $cgi->url(-relative=>1);
86 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
89 my $url = $cgi->url(-path_info=>$add_path);
90 my $root = (split 'unapi', $url)[0];
91 my $base = (split 'unapi', $url)[0] . 'unapi';
94 my $uri = $cgi->param('id') || '';
95 my $host = $cgi->virtual_host || $cgi->server_name;
97 my $format = $cgi->param('format');
98 my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
99 (my $base_format = $format) =~ s/-full$//o;
100 my ($id,$type,$command,$lib) = ('','','');
103 my $body = "Content-type: application/xml; charset=utf-8\n\n";
105 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) {
109 $type = 'metarecord' if ($1 =~ /^m/o);
112 ->request("open-ils.supercat.$type.formats")
115 if ($type eq 'record') {
116 $body = <<" FORMATS";
118 <format name='opac' type='text/html'/>
119 <format name='html' type='text/html'/>
120 <format name='htmlholdings' type='text/html'/>
121 <format name='html-full' type='text/html'/>
122 <format name='htmlholdings-full' type='text/html'/>
124 } elsif ($type eq 'metarecord') {
125 $body = <<" FORMATS";
127 <format name='opac' type='text/html'/>
132 my ($type) = keys %$h;
133 $body .= "\t<format name='$type' type='application/xml'";
135 for my $part ( qw/namespace_uri docs schema_location/ ) {
136 $body .= " $part='$$h{$type}{$part}'"
137 if ($$h{$type}{$part});
142 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
143 $body .= "\t<format name='$type-full' type='application/xml'";
145 for my $part ( qw/namespace_uri docs schema_location/ ) {
146 $body .= " $part='$$h{$type}{$part}'"
147 if ($$h{$type}{$part});
154 $body .= "</formats>\n";
158 ->request("open-ils.supercat.record.formats")
163 ->request("open-ils.supercat.metarecord.formats")
167 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
168 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
170 $body = <<" FORMATS";
172 <format name='opac' type='text/html'/>
173 <format name='html' type='text/html'/>
174 <format name='htmlholdings' type='text/html'/>
175 <format name='html-full' type='text/html'/>
176 <format name='htmlholdings-full' type='text/html'/>
181 my ($type) = keys %$h;
182 $body .= "\t<format name='$type' type='application/xml'";
184 for my $part ( qw/namespace_uri docs schema_location/ ) {
185 $body .= " $part='$$h{$type}{$part}'"
186 if ($$h{$type}{$part});
191 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
192 $body .= "\t<format name='$type-full' type='application/xml'";
194 for my $part ( qw/namespace_uri docs schema_location/ ) {
195 $body .= " $part='$$h{$type}{$part}'"
196 if ($$h{$type}{$part});
203 $body .= "</formats>\n";
206 $apache->custom_response( 300, $body);
211 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)(?:/(.+))?}o) {
215 $type = 'metarecord' if ($1 =~ /^m/o);
216 $command = 'retrieve';
219 if ($format eq 'opac') {
220 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
221 if ($type eq 'metarecord');
222 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
223 if ($type eq 'record');
225 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
226 my $feed = create_record_feed(
234 $feed->creator($host);
235 $feed->update_ts(gmtime_ISO8601());
236 $feed->link( unapi => $base) if ($flesh_feed);
238 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
239 print entityize($feed->toString) . "\n";
241 return Apache2::Const::OK;
244 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
248 print "Content-type: text/html; charset=utf-8\n\n";
249 $apache->custom_response( 404, <<" HTML");
252 <title>$type $id not found!</title>
256 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
263 print "Content-type: application/xml; charset=utf-8\n\n";
264 print $req->gather(1);
266 return Apache2::Const::OK;
272 return Apache2::Const::DECLINED if (-e $apache->filename);
277 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
278 my $rel_name = $cgi->url(-relative=>1);
279 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
282 my $url = $cgi->url(-path_info=>$add_path);
283 my $root = (split 'supercat', $url)[0];
284 my $base = (split 'supercat', $url)[0] . 'supercat';
285 my $unapi = (split 'supercat', $url)[0] . 'unapi';
287 my $host = $cgi->virtual_host || $cgi->server_name;
289 my $path = $cgi->path_info;
290 my ($id,$type,$format,$command) = reverse split '/', $path;
291 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
292 (my $base_format = $format) =~ s/-full$//o;
294 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
295 print "Content-type: application/xml; charset=utf-8\n";
298 ->request("open-ils.supercat.$1.formats")
306 <type>text/html</type>
309 if ($1 eq 'record') {
311 <name>htmlholdings</name>
312 <type>text/html</type>
316 <type>text/html</type>
319 <name>htmlholdings-full</name>
320 <type>text/html</type>
323 <name>html-full</name>
324 <type>text/html</type>
329 my ($type) = keys %$h;
330 print "<format><name>$type</name><type>application/xml</type>";
332 for my $part ( qw/namespace_uri docs schema_location/ ) {
333 print "<$part>$$h{$type}{$part}</$part>"
334 if ($$h{$type}{$part});
339 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
340 print "<format><name>$type-full</name><type>application/xml</type>";
342 for my $part ( qw/namespace_uri docs schema_location/ ) {
343 print "<$part>$$h{$type}{$part}</$part>"
344 if ($$h{$type}{$part});
352 print "</formats>\n";
354 return Apache2::Const::OK;
358 ->request("open-ils.supercat.record.formats")
363 ->request("open-ils.supercat.metarecord.formats")
367 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
368 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
373 <type>text/html</type>
376 <name>htmlholdings</name>
377 <type>text/html</type>
381 <type>text/html</type>
384 <name>htmlholdings-full</name>
385 <type>text/html</type>
388 <name>html-full</name>
389 <type>text/html</type>
393 my ($type) = keys %$h;
394 print "<format><name>$type</name><type>application/xml</type>";
396 for my $part ( qw/namespace_uri docs schema_location/ ) {
397 print "<$part>$$h{$type}{$part}</$part>"
398 if ($$h{$type}{$part});
403 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
404 print "<format><name>$type-full</name><type>application/xml</type>";
406 for my $part ( qw/namespace_uri docs schema_location/ ) {
407 print "<$part>$$h{$type}{$part}</$part>"
408 if ($$h{$type}{$part});
416 print "</formats>\n";
419 return Apache2::Const::OK;
422 if ($format eq 'opac') {
423 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
424 if ($type eq 'metarecord');
425 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
426 if ($type eq 'record');
428 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
429 my $feed = create_record_feed(
436 $feed->creator($host);
437 $feed->update_ts(gmtime_ISO8601());
438 $feed->link( unapi => $base) if ($flesh_feed);
440 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
441 print entityize($feed->toString) . "\n";
443 return Apache2::Const::OK;
446 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
450 print "Content-type: text/html; charset=utf-8\n\n";
451 $apache->custom_response( 404, <<" HTML");
454 <title>$type $id not found!</title>
458 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
465 print "Content-type: application/xml; charset=utf-8\n\n";
466 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
468 return Apache2::Const::OK;
474 return Apache2::Const::DECLINED if (-e $apache->filename);
478 my $year = (gmtime())[5] + 1900;
479 my $host = $cgi->virtual_host || $cgi->server_name;
482 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
483 my $rel_name = $cgi->url(-relative=>1);
484 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
487 my $url = $cgi->url(-path_info=>$add_path);
488 my $root = (split 'feed', $url)[0];
489 my $base = (split 'bookbag', $url)[0] . 'bookbag';
490 my $unapi = (split 'feed', $url)[0] . 'unapi';
493 my $path = $cgi->path_info;
494 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
496 my ($id,$type) = reverse split '/', $path;
497 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
499 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
500 return Apache2::Const::NOT_FOUND unless($bucket);
502 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
503 if ($type eq 'opac') {
504 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
505 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
510 my $feed = create_record_feed(
512 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
519 $feed->title("Items in Book Bag [".$bucket->name."]");
520 $feed->creator($host);
521 $feed->update_ts(gmtime_ISO8601());
523 $feed->link(rss => $base . "/rss2/$id" => 'application/rss+xml');
524 $feed->link(alternate => $base . "/atom/$id" => 'application/atom+xml');
525 $feed->link(html => $base . "/html/$id" => 'text/html');
526 $feed->link(unapi => $unapi);
530 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
531 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
536 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
537 print entityize($feed->toString) . "\n";
539 return Apache2::Const::OK;
544 return Apache2::Const::DECLINED if (-e $apache->filename);
548 my $year = (gmtime())[5] + 1900;
549 my $host = $cgi->virtual_host || $cgi->server_name;
552 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
553 my $rel_name = $cgi->url(-relative=>1);
554 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
557 my $url = $cgi->url(-path_info=>$add_path);
558 my $root = (split 'feed', $url)[0];
559 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
560 my $unapi = (split 'feed', $url)[0] . 'unapi';
562 my $path = $cgi->path_info;
563 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
565 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
567 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
568 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
571 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
573 if ($type eq 'opac') {
574 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
575 join('&', map { "rl=" . $_ } @$list) .
580 my $feed = create_record_feed( $type, $list, $unapi, undef, $flesh_feed);
584 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
586 $feed->title("$limit most recent $rtype ${axis}s");
589 $feed->creator($host);
590 $feed->update_ts(gmtime_ISO8601());
592 $feed->link(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml');
593 $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml');
594 $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html');
595 $feed->link(unapi => $unapi);
599 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
600 join('&', map { 'rl=' . $_} @$list ),
605 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
606 print entityize($feed->toString) . "\n";
608 return Apache2::Const::OK;
617 if ($version eq '1.0') {
619 Content-type: application/opensearchdescription+xml; charset=utf-8
621 <?xml version="1.0" encoding="UTF-8"?>
622 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
623 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
624 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
625 <ShortName>$lib</ShortName>
626 <LongName>Search $lib</LongName>
627 <Description>Search the $lib OPAC by $class.</Description>
628 <Tags>$lib book library</Tags>
629 <SampleSearch>harry+potter</SampleSearch>
630 <Developer>Mike Rylander for GPLS/PINES</Developer>
631 <Contact>feedback\@open-ils.org</Contact>
632 <SyndicationRight>open</SyndicationRight>
633 <AdultContent>false</AdultContent>
634 </OpenSearchDescription>
638 Content-type: application/opensearchdescription+xml; charset=utf-8
640 <?xml version="1.0" encoding="UTF-8"?>
641 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
642 <ShortName>$lib</ShortName>
643 <Description>Search the $lib OPAC by $class.</Description>
644 <Tags>$lib book library</Tags>
645 <Url type="application/rss+xml"
646 template="$base/1.1/$lib/rss2/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
647 <Url type="application/atom+xml"
648 template="$base/1.1/$lib/atom/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
649 <Url type="application/x-mods3+xml"
650 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
651 <Url type="application/x-mods+xml"
652 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
653 <Url type="application/x-marcxml+xml"
654 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
655 <LongName>Search $lib</LongName>
656 <Query role="example" searchTerms="harry+potter" />
657 <Developer>Mike Rylander for GPLS/PINES</Developer>
658 <Contact>feedback\@open-ils.org</Contact>
659 <SyndicationRight>open</SyndicationRight>
660 <AdultContent>false</AdultContent>
661 <Language>en-US</Language>
662 <OutputEncoding>UTF-8</OutputEncoding>
663 <InputEncoding>UTF-8</InputEncoding>
664 </OpenSearchDescription>
668 return Apache2::Const::OK;
671 sub opensearch_feed {
673 return Apache2::Const::DECLINED if (-e $apache->filename);
676 my $year = (gmtime())[5] + 1900;
678 my $host = $cgi->virtual_host || $cgi->server_name;
681 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
682 my $rel_name = $cgi->url(-relative=>1);
683 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
686 my $url = $cgi->url(-path_info=>$add_path);
687 my $root = (split 'opensearch', $url)[0];
688 my $base = (split 'opensearch', $url)[0] . 'opensearch';
689 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
691 my $path = $cgi->path_info;
692 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
694 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
701 $lib = $actor->request(
702 'open-ils.actor.org_unit_list.search' => parent_ou => undef
703 )->gather(1)->[0]->shortname;
710 return opensearch_osd($version, $lib, $class, $base);
714 my $page = $cgi->param('startPage') || 1;
715 my $offset = $cgi->param('startIndex') || 1;
716 my $limit = $cgi->param('count') || 10;
718 $page = 1 if ($page !~ /^\d+$/);
719 $offset = 1 if ($offset !~ /^\d+$/);
720 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
723 $offset = ($page - 1) * $limit;
728 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang);
729 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
731 $lang ||= $cgi->param('searchLang');
732 $sort ||= $cgi->param('searchSort');
733 $sortdir ||= $cgi->param('searchSortDir');
734 $terms ||= $cgi->param('searchTerms');
735 $class ||= $cgi->param('searchClass') || '-';
736 $type ||= $cgi->param('responseType') || '-';
737 $org ||= $cgi->param('searchOrg') || '-';
739 if ($version eq '1.0') {
741 } elsif ($type eq '-') {
744 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
746 $terms = decode_utf8($terms);
749 my $term_copy = $terms;
751 my $complex_terms = 0;
752 if ($terms eq 'help') {
753 print $cgi->header(-type => 'text/html');
757 <title>just type something!</title>
760 <p>You are in a maze of dark, twisty stacks, all alike.</p>
764 return Apache2::Const::OK;
769 while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
770 my ($c,$t) = split ':' => $1;
775 } elsif ($c eq 'sort') {
776 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
777 } elsif ($c eq 'dir') {
778 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
779 } elsif ($c eq 'lang') {
780 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
782 $$searches{$c}{term} .= ' '.$t;
783 $cache_key .= $c . $t;
790 $class = 'keyword' if ($class eq '-');
791 $$searches{$class}{term} .= " $term_copy";
792 $cache_key .= $class . $term_copy;
797 $org_unit = $actor->request(
798 'open-ils.actor.org_unit_list.search' => parent_ou => undef
801 $org_unit = $actor->request(
802 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
806 $cache_key .= $org.$sort.$sortdir.$lang;
808 my $rs_name = $cgi->cookie('os_session');
809 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
812 if (!($recs = $$cached_res{os_results}{$cache_key})) {
813 $rs_name = $cgi->remote_host . '::' . rand(time);
814 $recs = $search->request(
815 'open-ils.search.biblio.multiclass' => {
816 searches => $searches,
817 org_unit => $org_unit->[0]->id,
820 ($sort ? ( 'sort' => $sort ) : ()),
821 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
822 ($lang ? ( 'language' => $lang ) : ()),
826 $$cached_res{os_results}{$cache_key} = $recs;
827 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
833 my $feed = create_record_feed(
835 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
842 $feed->search($terms);
843 $feed->class($class);
845 if ($complex_terms) {
846 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
848 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
851 $feed->creator($host);
852 $feed->update_ts(gmtime_ISO8601());
856 'http://a9.com/-/spec/opensearch/1.1/',
863 'http://a9.com/-/spec/opensearch/1.1/',
870 'http://a9.com/-/spec/opensearch/1.1/',
877 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
878 'application/opensearch+xml'
879 ) if ($offset + $limit < $recs->{count});
883 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
884 'application/opensearch+xml'
889 $base . "/$version/$org/$type/$class?searchTerms=$terms" =>
890 'application/opensearch+xml'
895 $base . "/$version/$org/rss2/$class?searchTerms=$terms" =>
896 'application/rss+xml'
901 $base . "/$version/$org/atom/$class?searchTerms=$terms" =>
902 'application/atom+xml'
907 $base . "/$version/$org/html/$class?searchTerms=$terms" =>
913 $base . "/$version/$org/html-full/$class?searchTerms=$terms" =>
917 $feed->link( unapi => $unapi);
921 $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
922 join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
927 -type => $feed->type,
929 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
932 print entityize($feed->toString) . "\n";
934 return Apache2::Const::OK;
937 sub create_record_feed {
942 my $lib = shift || '-';
944 $flesh = 1 if (!defined($flesh));
947 my $base = $cgi->url;
948 my $host = $cgi->virtual_host || $cgi->server_name;
950 my $year = (gmtime())[5] + 1900;
952 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
954 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
955 $feed->base($base) if ($flesh);
956 $feed->unapi($unapi) if ($flesh);
958 $type = 'atom' if ($type eq 'html');
959 $type = 'marcxml' if ($type eq 'htmlholdings');
961 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
963 for my $record (@$records) {
964 next unless($record);
966 #my $rec = $record->id;
969 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
971 my $xml = $supercat->request(
972 "open-ils.supercat.record.$type.retrieve",
977 my $node = $feed->add_item($xml);
980 if ($lib && $type eq 'marcxml' && $flesh) {
981 $xml = $supercat->request( "open-ils.supercat.record.holdings_xml.retrieve", $rec, $lib )->gather(1);
982 $node->add_holdings($xml);
985 $node->id($item_tag) if ($flesh);
986 #$node->update_ts(clense_ISO8601($record->edit_date));
987 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
988 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
989 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
990 $node->link('unapi-id' => $item_tag) if ($flesh);
997 my $stuff = NFC(shift());
998 $stuff =~ s/&(?!\S+;)/&/gso;
999 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1003 my %browse_types = (
1008 my $year = (gmtime())[5] + 1900;
1011 $content .= "Content-type: application/xml\n\n";
1012 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
1014 for my $cn (@$tree) {
1015 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
1016 $cn_class =~ s/Fieldmapper-//gso;
1018 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
1019 my $cn_lib = $cn->owning_lib->shortname;
1020 my $cn_label = $cn->label;
1022 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
1023 $ou_class =~ s/Fieldmapper-//gso;
1025 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
1026 my $ou_name = $cn->owning_lib->name;
1028 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
1029 $rec_class =~ s/Fieldmapper-//gso;
1031 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
1033 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
1034 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
1036 my $r_doc = $parser->parse_string($cn->record->marc);
1037 $r_doc->documentElement->setAttribute( id => $rec_tag );
1038 $content .= entityize($r_doc->documentElement->toString);
1040 $content .= "</hold:volume>";
1043 $content .= '</hold:volumes>';
1051 return Apache2::Const::DECLINED if (-e $apache->filename);
1054 my $year = (gmtime())[5] + 1900;
1056 my $host = $cgi->virtual_host || $cgi->server_name;
1059 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1060 my $rel_name = $cgi->url(-relative=>1);
1061 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1064 my $url = $cgi->url(-path_info=>$add_path);
1065 my $root = (split 'browse', $url)[0];
1066 my $base = (split 'browse', $url)[0] . 'browse';
1067 my $unapi = (split 'browse', $url)[0] . 'unapi';
1069 my $path = $cgi->path_info;
1072 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1073 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1076 $site ||= $cgi->param('searchOrg');
1077 $page ||= $cgi->param('startPage') || 0;
1078 $page_size ||= $cgi->param('count') || 9;
1080 $page = 0 if ($page !~ /^\d+$/);
1082 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1083 warn "something's wrong...";
1084 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1088 $string = decode_utf8($string);
1089 $string =~ s/\+/ /go;
1092 my $tree = $supercat->request(
1093 "open-ils.supercat.$axis.browse",
1100 my $content = $browse_types{$axis}{$format}->($tree);
1102 return Apache2::Const::OK;