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 );
39 my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
40 Fieldmapper->import(IDL => $idl);
42 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
43 $cstore = OpenSRF::AppSession->create('open-ils.cstore');
44 $actor = OpenSRF::AppSession->create('open-ils.actor');
45 $search = OpenSRF::AppSession->create('open-ils.search');
46 $parser = new XML::LibXML;
52 return Apache2::Const::DECLINED if (-e $apache->filename);
54 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
57 ->request("open-ils.supercat.oisbn", $isbn)
60 print "Content-type: application/xml; charset=utf-8\n\n";
61 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
63 unless (exists $$list{metarecord}) {
65 return Apache2::Const::OK;
68 print "<idlist metarecord='$$list{metarecord}'>\n";
70 for ( keys %{ $$list{record_list} } ) {
71 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
72 print " <isbn record='$_'>$o</isbn>\n"
77 return Apache2::Const::OK;
83 return Apache2::Const::DECLINED if (-e $apache->filename);
88 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
89 my $rel_name = $cgi->url(-relative=>1);
90 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
93 my $url = $cgi->url(-path_info=>$add_path);
94 my $root = (split 'unapi', $url)[0];
95 my $base = (split 'unapi', $url)[0] . 'unapi';
98 my $uri = $cgi->param('id') || '';
99 my $host = $cgi->virtual_host || $cgi->server_name;
101 my $format = $cgi->param('format');
102 my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
103 (my $base_format = $format) =~ s/-full$//o;
104 my ($id,$type,$command,$lib) = ('','','');
107 my $body = "Content-type: application/xml; charset=utf-8\n\n";
109 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) {
113 $type = 'metarecord' if ($1 =~ /^m/o);
116 ->request("open-ils.supercat.$type.formats")
119 if ($type eq 'record') {
120 $body = <<" FORMATS";
122 <format name='opac' type='text/html'/>
123 <format name='html' type='text/html'/>
124 <format name='htmlholdings' type='text/html'/>
125 <format name='html-full' type='text/html'/>
126 <format name='htmlholdings-full' type='text/html'/>
128 } elsif ($type eq 'metarecord') {
129 $body = <<" FORMATS";
131 <format name='opac' type='text/html'/>
136 my ($type) = keys %$h;
137 $body .= "\t<format name='$type' type='application/xml'";
139 for my $part ( qw/namespace_uri docs schema_location/ ) {
140 $body .= " $part='$$h{$type}{$part}'"
141 if ($$h{$type}{$part});
146 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
147 $body .= "\t<format name='$type-full' type='application/xml'";
149 for my $part ( qw/namespace_uri docs schema_location/ ) {
150 $body .= " $part='$$h{$type}{$part}'"
151 if ($$h{$type}{$part});
158 $body .= "</formats>\n";
162 ->request("open-ils.supercat.record.formats")
167 ->request("open-ils.supercat.metarecord.formats")
171 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
172 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
174 $body = <<" FORMATS";
176 <format name='opac' type='text/html'/>
177 <format name='html' type='text/html'/>
178 <format name='htmlholdings' type='text/html'/>
179 <format name='html-full' type='text/html'/>
180 <format name='htmlholdings-full' type='text/html'/>
185 my ($type) = keys %$h;
186 $body .= "\t<format name='$type' type='application/xml'";
188 for my $part ( qw/namespace_uri docs schema_location/ ) {
189 $body .= " $part='$$h{$type}{$part}'"
190 if ($$h{$type}{$part});
195 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
196 $body .= "\t<format name='$type-full' type='application/xml'";
198 for my $part ( qw/namespace_uri docs schema_location/ ) {
199 $body .= " $part='$$h{$type}{$part}'"
200 if ($$h{$type}{$part});
207 $body .= "</formats>\n";
210 $apache->custom_response( 300, $body);
215 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)(?:/(.+))?}o) {
219 $type = 'metarecord' if ($1 =~ /^m/o);
220 $command = 'retrieve';
223 if ($format eq 'opac') {
224 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
225 if ($type eq 'metarecord');
226 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
227 if ($type eq 'record');
229 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
230 my $feed = create_record_feed(
238 $feed->creator($host);
239 $feed->update_ts(gmtime_ISO8601());
240 $feed->link( unapi => $base) if ($flesh_feed);
242 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
243 print entityize($feed->toString) . "\n";
245 return Apache2::Const::OK;
248 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
252 print "Content-type: text/html; charset=utf-8\n\n";
253 $apache->custom_response( 404, <<" HTML");
256 <title>$type $id not found!</title>
260 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
267 print "Content-type: application/xml; charset=utf-8\n\n";
268 print $req->gather(1);
270 return Apache2::Const::OK;
276 return Apache2::Const::DECLINED if (-e $apache->filename);
281 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
282 my $rel_name = $cgi->url(-relative=>1);
283 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
286 my $url = $cgi->url(-path_info=>$add_path);
287 my $root = (split 'supercat', $url)[0];
288 my $base = (split 'supercat', $url)[0] . 'supercat';
289 my $unapi = (split 'supercat', $url)[0] . 'unapi';
291 my $host = $cgi->virtual_host || $cgi->server_name;
293 my $path = $cgi->path_info;
294 my ($id,$type,$format,$command) = reverse split '/', $path;
295 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
296 (my $base_format = $format) =~ s/-full$//o;
298 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
299 print "Content-type: application/xml; charset=utf-8\n";
302 ->request("open-ils.supercat.$1.formats")
310 <type>text/html</type>
313 if ($1 eq 'record') {
315 <name>htmlholdings</name>
316 <type>text/html</type>
320 <type>text/html</type>
323 <name>htmlholdings-full</name>
324 <type>text/html</type>
327 <name>html-full</name>
328 <type>text/html</type>
333 my ($type) = keys %$h;
334 print "<format><name>$type</name><type>application/xml</type>";
336 for my $part ( qw/namespace_uri docs schema_location/ ) {
337 print "<$part>$$h{$type}{$part}</$part>"
338 if ($$h{$type}{$part});
343 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
344 print "<format><name>$type-full</name><type>application/xml</type>";
346 for my $part ( qw/namespace_uri docs schema_location/ ) {
347 print "<$part>$$h{$type}{$part}</$part>"
348 if ($$h{$type}{$part});
356 print "</formats>\n";
358 return Apache2::Const::OK;
362 ->request("open-ils.supercat.record.formats")
367 ->request("open-ils.supercat.metarecord.formats")
371 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
372 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
377 <type>text/html</type>
380 <name>htmlholdings</name>
381 <type>text/html</type>
385 <type>text/html</type>
388 <name>htmlholdings-full</name>
389 <type>text/html</type>
392 <name>html-full</name>
393 <type>text/html</type>
397 my ($type) = keys %$h;
398 print "<format><name>$type</name><type>application/xml</type>";
400 for my $part ( qw/namespace_uri docs schema_location/ ) {
401 print "<$part>$$h{$type}{$part}</$part>"
402 if ($$h{$type}{$part});
407 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
408 print "<format><name>$type-full</name><type>application/xml</type>";
410 for my $part ( qw/namespace_uri docs schema_location/ ) {
411 print "<$part>$$h{$type}{$part}</$part>"
412 if ($$h{$type}{$part});
420 print "</formats>\n";
423 return Apache2::Const::OK;
426 if ($format eq 'opac') {
427 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
428 if ($type eq 'metarecord');
429 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
430 if ($type eq 'record');
432 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
433 my $feed = create_record_feed(
440 $feed->creator($host);
441 $feed->update_ts(gmtime_ISO8601());
442 $feed->link( unapi => $base) if ($flesh_feed);
444 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
445 print entityize($feed->toString) . "\n";
447 return Apache2::Const::OK;
450 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
454 print "Content-type: text/html; charset=utf-8\n\n";
455 $apache->custom_response( 404, <<" HTML");
458 <title>$type $id not found!</title>
462 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
469 print "Content-type: application/xml; charset=utf-8\n\n";
470 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
472 return Apache2::Const::OK;
478 return Apache2::Const::DECLINED if (-e $apache->filename);
482 my $year = (gmtime())[5] + 1900;
483 my $host = $cgi->virtual_host || $cgi->server_name;
486 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
487 my $rel_name = $cgi->url(-relative=>1);
488 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
491 my $url = $cgi->url(-path_info=>$add_path);
492 my $root = (split 'feed', $url)[0];
493 my $base = (split 'bookbag', $url)[0] . 'bookbag';
494 my $unapi = (split 'feed', $url)[0] . 'unapi';
497 my $path = $cgi->path_info;
498 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
500 my ($id,$type) = reverse split '/', $path;
501 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
503 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
504 return Apache2::Const::NOT_FOUND unless($bucket);
506 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
507 if ($type eq 'opac') {
508 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
509 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
514 my $feed = create_record_feed(
516 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
523 $feed->title("Items in Book Bag [".$bucket->name."]");
524 $feed->creator($host);
525 $feed->update_ts(gmtime_ISO8601());
527 $feed->link(rss => $base . "/rss2/$id" => 'application/rss+xml');
528 $feed->link(alternate => $base . "/atom/$id" => 'application/atom+xml');
529 $feed->link(html => $base . "/html/$id" => 'text/html');
530 $feed->link(unapi => $unapi);
534 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
535 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
540 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
541 print entityize($feed->toString) . "\n";
543 return Apache2::Const::OK;
548 return Apache2::Const::DECLINED if (-e $apache->filename);
552 my $year = (gmtime())[5] + 1900;
553 my $host = $cgi->virtual_host || $cgi->server_name;
556 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
557 my $rel_name = $cgi->url(-relative=>1);
558 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
561 my $url = $cgi->url(-path_info=>$add_path);
562 my $root = (split 'feed', $url)[0];
563 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
564 my $unapi = (split 'feed', $url)[0] . 'unapi';
566 my $path = $cgi->path_info;
567 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
569 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
571 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
572 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
575 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
577 if ($type eq 'opac') {
578 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
579 join('&', map { "rl=" . $_ } @$list) .
584 my $feed = create_record_feed( $type, $list, $unapi, undef, $flesh_feed);
588 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
590 $feed->title("$limit most recent $rtype ${axis}s");
593 $feed->creator($host);
594 $feed->update_ts(gmtime_ISO8601());
596 $feed->link(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml');
597 $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml');
598 $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html');
599 $feed->link(unapi => $unapi);
603 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
604 join('&', map { 'rl=' . $_} @$list ),
609 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
610 print entityize($feed->toString) . "\n";
612 return Apache2::Const::OK;
621 if ($version eq '1.0') {
623 Content-type: application/opensearchdescription+xml; charset=utf-8
625 <?xml version="1.0" encoding="UTF-8"?>
626 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
627 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
628 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
629 <ShortName>$lib</ShortName>
630 <LongName>Search $lib</LongName>
631 <Description>Search the $lib OPAC by $class.</Description>
632 <Tags>$lib book library</Tags>
633 <SampleSearch>harry+potter</SampleSearch>
634 <Developer>Mike Rylander for GPLS/PINES</Developer>
635 <Contact>feedback\@open-ils.org</Contact>
636 <SyndicationRight>open</SyndicationRight>
637 <AdultContent>false</AdultContent>
638 </OpenSearchDescription>
642 Content-type: application/opensearchdescription+xml; charset=utf-8
644 <?xml version="1.0" encoding="UTF-8"?>
645 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
646 <ShortName>$lib</ShortName>
647 <Description>Search the $lib OPAC by $class.</Description>
648 <Tags>$lib book library</Tags>
649 <Url type="application/rss+xml"
650 template="$base/1.1/$lib/rss2/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
651 <Url type="application/atom+xml"
652 template="$base/1.1/$lib/atom/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
653 <Url type="application/x-mods3+xml"
654 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
655 <Url type="application/x-mods+xml"
656 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
657 <Url type="application/x-marcxml+xml"
658 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
659 <LongName>Search $lib</LongName>
660 <Query role="example" searchTerms="harry+potter" />
661 <Developer>Mike Rylander for GPLS/PINES</Developer>
662 <Contact>feedback\@open-ils.org</Contact>
663 <SyndicationRight>open</SyndicationRight>
664 <AdultContent>false</AdultContent>
665 <Language>en-US</Language>
666 <OutputEncoding>UTF-8</OutputEncoding>
667 <InputEncoding>UTF-8</InputEncoding>
668 </OpenSearchDescription>
672 return Apache2::Const::OK;
675 sub opensearch_feed {
677 return Apache2::Const::DECLINED if (-e $apache->filename);
680 my $year = (gmtime())[5] + 1900;
682 my $host = $cgi->virtual_host || $cgi->server_name;
685 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
686 my $rel_name = $cgi->url(-relative=>1);
687 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
690 my $url = $cgi->url(-path_info=>$add_path);
691 my $root = (split 'opensearch', $url)[0];
692 my $base = (split 'opensearch', $url)[0] . 'opensearch';
693 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
695 my $path = $cgi->path_info;
696 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
698 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
705 $lib = $actor->request(
706 'open-ils.actor.org_unit_list.search' => parent_ou => undef
707 )->gather(1)->[0]->shortname;
714 return opensearch_osd($version, $lib, $class, $base);
718 my $page = $cgi->param('startPage') || 1;
719 my $offset = $cgi->param('startIndex') || 1;
720 my $limit = $cgi->param('count') || 10;
722 $page = 1 if ($page !~ /^\d+$/);
723 $offset = 1 if ($offset !~ /^\d+$/);
724 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
727 $offset = ($page - 1) * $limit;
732 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang);
733 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
735 $lang ||= $cgi->param('searchLang');
736 $sort ||= $cgi->param('searchSort');
737 $sortdir ||= $cgi->param('searchSortDir');
738 $terms ||= $cgi->param('searchTerms');
739 $class ||= $cgi->param('searchClass') || '-';
740 $type ||= $cgi->param('responseType') || '-';
741 $org ||= $cgi->param('searchOrg') || '-';
743 if ($version eq '1.0') {
745 } elsif ($type eq '-') {
748 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
750 $terms = decode_utf8($terms);
753 my $term_copy = $terms;
755 my $complex_terms = 0;
756 if ($terms eq 'help') {
757 print $cgi->header(-type => 'text/html');
761 <title>just type something!</title>
764 <p>You are in a maze of dark, twisty stacks, all alike.</p>
768 return Apache2::Const::OK;
773 while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
774 my ($c,$t) = split ':' => $1;
779 } elsif ($c eq 'sort') {
780 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
781 } elsif ($c eq 'dir') {
782 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
783 } elsif ($c eq 'lang') {
784 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
786 $$searches{$c}{term} .= ' '.$t;
787 $cache_key .= $c . $t;
794 $class = 'keyword' if ($class eq '-');
795 $$searches{$class}{term} .= " $term_copy";
796 $cache_key .= $class . $term_copy;
801 $org_unit = $actor->request(
802 'open-ils.actor.org_unit_list.search' => parent_ou => undef
805 $org_unit = $actor->request(
806 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
810 $cache_key .= $org.$sort.$sortdir.$lang;
812 my $rs_name = $cgi->cookie('os_session');
813 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
816 if (!($recs = $$cached_res{os_results}{$cache_key})) {
817 $rs_name = $cgi->remote_host . '::' . rand(time);
818 $recs = $search->request(
819 'open-ils.search.biblio.multiclass' => {
820 searches => $searches,
821 org_unit => $org_unit->[0]->id,
824 ($sort ? ( 'sort' => $sort ) : ()),
825 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
826 ($lang ? ( 'language' => $lang ) : ()),
830 $$cached_res{os_results}{$cache_key} = $recs;
831 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
837 my $feed = create_record_feed(
839 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
846 $feed->search($terms);
847 $feed->class($class);
849 if ($complex_terms) {
850 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
852 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
855 $feed->creator($host);
856 $feed->update_ts(gmtime_ISO8601());
860 'http://a9.com/-/spec/opensearch/1.1/',
867 'http://a9.com/-/spec/opensearch/1.1/',
874 'http://a9.com/-/spec/opensearch/1.1/',
881 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
882 'application/opensearch+xml'
883 ) if ($offset + $limit < $recs->{count});
887 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
888 'application/opensearch+xml'
893 $base . "/$version/$org/$type/$class?searchTerms=$terms" =>
894 'application/opensearch+xml'
899 $base . "/$version/$org/rss2/$class?searchTerms=$terms" =>
900 'application/rss+xml'
905 $base . "/$version/$org/atom/$class?searchTerms=$terms" =>
906 'application/atom+xml'
911 $base . "/$version/$org/html/$class?searchTerms=$terms" =>
917 $base . "/$version/$org/html-full/$class?searchTerms=$terms" =>
921 $feed->link( unapi => $unapi);
925 $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
926 join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
931 -type => $feed->type,
933 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
936 print entityize($feed->toString) . "\n";
938 return Apache2::Const::OK;
941 sub create_record_feed {
946 my $lib = shift || '-';
948 $flesh = 1 if (!defined($flesh));
951 my $base = $cgi->url;
952 my $host = $cgi->virtual_host || $cgi->server_name;
954 my $year = (gmtime())[5] + 1900;
956 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
958 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
959 $feed->base($base) if ($flesh);
960 $feed->unapi($unapi) if ($flesh);
962 $type = 'atom' if ($type eq 'html');
963 $type = 'marcxml' if ($type eq 'htmlholdings');
965 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
967 for my $record (@$records) {
968 next unless($record);
970 #my $rec = $record->id;
973 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
975 my $xml = $supercat->request(
976 "open-ils.supercat.record.$type.retrieve",
981 my $node = $feed->add_item($xml);
984 if ($lib && $type eq 'marcxml' && $flesh) {
985 $xml = $supercat->request( "open-ils.supercat.record.holdings_xml.retrieve", $rec, $lib )->gather(1);
986 $node->add_holdings($xml);
989 $node->id($item_tag) if ($flesh);
990 #$node->update_ts(clense_ISO8601($record->edit_date));
991 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
992 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
993 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
994 $node->link('unapi-id' => $item_tag) if ($flesh);
1001 my $stuff = NFC(shift());
1002 $stuff =~ s/&(?!\S+;)/&/gso;
1003 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1007 my %browse_types = (
1012 my $year = (gmtime())[5] + 1900;
1015 $content .= "Content-type: application/xml\n\n";
1016 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
1018 for my $cn (@$tree) {
1019 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
1020 $cn_class =~ s/Fieldmapper-//gso;
1022 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
1023 my $cn_lib = $cn->owning_lib->shortname;
1024 my $cn_label = $cn->label;
1026 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
1027 $ou_class =~ s/Fieldmapper-//gso;
1029 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
1030 my $ou_name = $cn->owning_lib->name;
1032 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
1033 $rec_class =~ s/Fieldmapper-//gso;
1035 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
1037 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
1038 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
1040 my $r_doc = $parser->parse_string($cn->record->marc);
1041 $r_doc->documentElement->setAttribute( id => $rec_tag );
1042 $content .= entityize($r_doc->documentElement->toString);
1044 $content .= "</hold:volume>";
1047 $content .= '</hold:volumes>';
1055 return Apache2::Const::DECLINED if (-e $apache->filename);
1058 my $year = (gmtime())[5] + 1900;
1060 my $host = $cgi->virtual_host || $cgi->server_name;
1063 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1064 my $rel_name = $cgi->url(-relative=>1);
1065 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1068 my $url = $cgi->url(-path_info=>$add_path);
1069 my $root = (split 'browse', $url)[0];
1070 my $base = (split 'browse', $url)[0] . 'browse';
1071 my $unapi = (split 'browse', $url)[0] . 'unapi';
1073 my $path = $cgi->path_info;
1076 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1077 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1080 $site ||= $cgi->param('searchOrg');
1081 $page ||= $cgi->param('startPage') || 0;
1082 $page_size ||= $cgi->param('count') || 9;
1084 $page = 0 if ($page !~ /^\d+$/);
1086 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1087 warn "something's wrong...";
1088 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1092 $string = decode_utf8($string);
1093 $string =~ s/\+/ /go;
1096 my $tree = $supercat->request(
1097 "open-ils.supercat.$axis.browse",
1104 my $content = $browse_types{$axis}{$format}->($tree);
1106 return Apache2::Const::OK;