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 ($id,$type,$command,$lib) = ('','','');
101 my $body = "Content-type: application/xml; charset=utf-8\n\n";
103 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) {
107 $type = 'metarecord' if ($1 =~ /^m/o);
110 ->request("open-ils.supercat.$type.formats")
113 if ($type eq 'record') {
114 $body = <<" FORMATS";
116 <format name='opac' type='text/html'/>
117 <format name='html' type='text/html'/>
118 <format name='htmlcard' type='text/html'/>
119 <format name='htmlholdings' type='text/html'/>
121 } elsif ($type eq 'metarecord') {
122 $body = <<" FORMATS";
124 <format name='opac' type='text/html'/>
129 my ($type) = keys %$h;
130 $body .= "\t<format name='$type' type='application/xml'";
132 for my $part ( qw/namespace_uri docs schema_location/ ) {
133 $body .= " $part='$$h{$type}{$part}'"
134 if ($$h{$type}{$part});
140 $body .= "</formats>\n";
144 ->request("open-ils.supercat.record.formats")
149 ->request("open-ils.supercat.metarecord.formats")
153 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
154 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
156 $body = <<" FORMATS";
158 <format name='opac' type='text/html'/>
159 <format name='html' type='text/html'/>
160 <format name='htmlcard' type='text/html'/>
161 <format name='htmlholdings' type='text/html'/>
166 my ($type) = keys %$h;
167 $body .= "\t<format name='$type' type='application/xml'";
169 for my $part ( qw/namespace_uri docs schema_location/ ) {
170 $body .= " $part='$$h{$type}{$part}'"
171 if ($$h{$type}{$part});
177 $body .= "</formats>\n";
180 $apache->custom_response( 300, $body);
185 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)(?:/(.+))?}o) {
189 $type = 'metarecord' if ($1 =~ /^m/o);
190 $command = 'retrieve';
193 if ($format eq 'opac') {
194 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
195 if ($type eq 'metarecord');
196 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
197 if ($type eq 'record');
199 } elsif (OpenILS::WWW::SuperCat::Feed->exists($format)) {
200 my $feed = create_record_feed(
207 $feed->creator($host);
208 $feed->update_ts(gmtime_ISO8601());
209 $feed->link( unapi => $base);
211 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
212 print entityize($feed->toString) . "\n";
214 return Apache2::Const::OK;
217 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
221 print "Content-type: text/html; charset=utf-8\n\n";
222 $apache->custom_response( 404, <<" HTML");
225 <title>$type $id not found!</title>
229 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
236 print "Content-type: application/xml; charset=utf-8\n\n";
237 print $req->gather(1);
239 return Apache2::Const::OK;
245 return Apache2::Const::DECLINED if (-e $apache->filename);
250 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
251 my $rel_name = $cgi->url(-relative=>1);
252 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
255 my $url = $cgi->url(-path_info=>$add_path);
256 my $root = (split 'supercat', $url)[0];
257 my $base = (split 'supercat', $url)[0] . 'supercat';
258 my $path = (split 'supercat', $url)[1];
259 my $unapi = (split 'supercat', $url)[0] . 'unapi';
261 my $host = $cgi->virtual_host || $cgi->server_name;
263 my ($id,$type,$format,$command) = reverse split '/', $path;
266 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
267 print "Content-type: application/xml; charset=utf-8\n";
270 ->request("open-ils.supercat.$1.formats")
278 <type>text/html</type>
281 if ($1 eq 'record') {
283 <name>htmlcard</name>
284 <type>text/html</type>
287 <name>htmlholdings</name>
288 <type>text/html</type>
292 <type>text/html</type>
297 my ($type) = keys %$h;
298 print "<format><name>$type</name><type>application/xml</type>";
300 for my $part ( qw/namespace_uri docs schema_location/ ) {
301 print "<$part>$$h{$type}{$part}</$part>"
302 if ($$h{$type}{$part});
308 print "</formats>\n";
310 return Apache2::Const::OK;
314 ->request("open-ils.supercat.record.formats")
319 ->request("open-ils.supercat.metarecord.formats")
323 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
324 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
329 <type>text/html</type>
332 <name>htmlcard</name>
333 <type>text/html</type>
336 <name>htmlholdings</name>
337 <type>text/html</type>
341 <type>text/html</type>
345 my ($type) = keys %$h;
346 print "<format><name>$type</name><type>application/xml</type>";
348 for my $part ( qw/namespace_uri docs schema_location/ ) {
349 print "<$part>$$h{$type}{$part}</$part>"
350 if ($$h{$type}{$part});
356 print "</formats>\n";
359 return Apache2::Const::OK;
362 if ($format eq 'opac') {
363 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
364 if ($type eq 'metarecord');
365 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
366 if ($type eq 'record');
368 } elsif (OpenILS::WWW::SuperCat::Feed->exists($format)) {
369 my $feed = create_record_feed(
375 $feed->creator($host);
376 $feed->update_ts(gmtime_ISO8601());
377 $feed->link( unapi => $base);
379 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
380 print entityize($feed->toString) . "\n";
382 return Apache2::Const::OK;
385 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
389 print "Content-type: text/html; charset=utf-8\n\n";
390 $apache->custom_response( 404, <<" HTML");
393 <title>$type $id not found!</title>
397 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
404 print "Content-type: application/xml; charset=utf-8\n\n";
405 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
407 return Apache2::Const::OK;
413 return Apache2::Const::DECLINED if (-e $apache->filename);
417 my $year = (gmtime())[5] + 1900;
418 my $host = $cgi->virtual_host || $cgi->server_name;
421 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
422 my $rel_name = $cgi->url(-relative=>1);
423 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
426 my $url = $cgi->url(-path_info=>$add_path);
427 my $root = (split 'feed', $url)[0];
428 my $base = (split 'bookbag', $url)[0] . 'bookbag';
429 my $path = (split 'bookbag', $url)[1];
430 my $unapi = (split 'feed', $url)[0] . 'unapi';
433 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
435 my ($id,$type) = reverse split '/', $path;
437 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
438 return Apache2::Const::NOT_FOUND unless($bucket);
440 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
441 if ($type eq 'opac') {
442 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
443 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
448 my $feed = create_record_feed(
450 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
455 $feed->title("Items in Book Bag [".$bucket->name."]");
456 $feed->creator($host);
457 $feed->update_ts(gmtime_ISO8601());
459 $feed->link(rss => $base . "/rss2/$id" => 'application/rss+xml');
460 $feed->link(alternate => $base . "/atom/$id" => 'application/atom+xml');
461 $feed->link(html => $base . "/html/$id" => 'text/html');
462 $feed->link(unapi => $unapi);
466 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
467 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
472 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
473 print entityize($feed->toString) . "\n";
475 return Apache2::Const::OK;
480 return Apache2::Const::DECLINED if (-e $apache->filename);
484 my $year = (gmtime())[5] + 1900;
485 my $host = $cgi->virtual_host || $cgi->server_name;
488 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
489 my $rel_name = $cgi->url(-relative=>1);
490 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
493 my $url = $cgi->url(-path_info=>$add_path);
494 my $root = (split 'feed', $url)[0];
495 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
496 my $path = (split 'freshmeat', $url)[1];
497 my $unapi = (split 'feed', $url)[0] . 'unapi';
500 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
504 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
507 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
509 if ($type eq 'opac') {
510 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
511 join('&', map { "rl=" . $_ } @$list) .
516 my $feed = create_record_feed( $type, $list, $unapi);
520 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
522 $feed->title("$limit most recent $rtype ${axis}s");
525 $feed->creator($host);
526 $feed->update_ts(gmtime_ISO8601());
528 $feed->link(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml');
529 $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml');
530 $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html');
531 $feed->link(unapi => $unapi);
535 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
536 join('&', map { 'rl=' . $_} @$list ),
541 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
542 print entityize($feed->toString) . "\n";
544 return Apache2::Const::OK;
553 if ($version eq '1.0') {
555 Content-type: application/opensearchdescription+xml; charset=utf-8
557 <?xml version="1.0" encoding="UTF-8"?>
558 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
559 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
560 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
561 <ShortName>$lib</ShortName>
562 <LongName>Search $lib</LongName>
563 <Description>Search the $lib OPAC by $class.</Description>
564 <Tags>$lib book library</Tags>
565 <SampleSearch>harry+potter</SampleSearch>
566 <Developer>Mike Rylander for GPLS/PINES</Developer>
567 <Contact>feedback\@open-ils.org</Contact>
568 <SyndicationRight>open</SyndicationRight>
569 <AdultContent>false</AdultContent>
570 </OpenSearchDescription>
574 Content-type: application/opensearchdescription+xml; charset=utf-8
576 <?xml version="1.0" encoding="UTF-8"?>
577 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
578 <ShortName>$lib</ShortName>
579 <Description>Search the $lib OPAC by $class.</Description>
580 <Tags>$lib book library</Tags>
581 <Url type="application/rss+xml"
582 template="$base/1.1/$lib/rss2/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
583 <Url type="application/atom+xml"
584 template="$base/1.1/$lib/atom/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
585 <Url type="application/x-mods3+xml"
586 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
587 <Url type="application/x-mods+xml"
588 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
589 <Url type="application/x-marcxml+xml"
590 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
591 <LongName>Search $lib</LongName>
592 <Query role="example" searchTerms="harry+potter" />
593 <Developer>Mike Rylander for GPLS/PINES</Developer>
594 <Contact>feedback\@open-ils.org</Contact>
595 <SyndicationRight>open</SyndicationRight>
596 <AdultContent>false</AdultContent>
597 <Language>en-US</Language>
598 <OutputEncoding>UTF-8</OutputEncoding>
599 <InputEncoding>UTF-8</InputEncoding>
600 </OpenSearchDescription>
604 return Apache2::Const::OK;
607 sub opensearch_feed {
609 return Apache2::Const::DECLINED if (-e $apache->filename);
612 my $year = (gmtime())[5] + 1900;
614 my $host = $cgi->virtual_host || $cgi->server_name;
617 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
618 my $rel_name = $cgi->url(-relative=>1);
619 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
622 my $url = $cgi->url(-path_info=>$add_path);
623 my $root = (split 'opensearch', $url)[0];
624 my $base = (split 'opensearch', $url)[0] . 'opensearch';
625 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
628 my $path = $cgi->path_info;
630 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
632 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
639 $lib = $actor->request(
640 'open-ils.actor.org_unit_list.search' => parent_ou => undef
641 )->gather(1)->[0]->shortname;
648 return opensearch_osd($version, $lib, $class, $base);
652 my $page = $cgi->param('startPage') || 1;
653 my $offset = $cgi->param('startIndex') || 1;
654 my $limit = $cgi->param('count') || 10;
656 $page = 1 if ($page !~ /^\d+$/);
657 $offset = 1 if ($offset !~ /^\d+$/);
658 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
661 $offset = ($page - 1) * $limit;
666 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang);
667 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
669 $lang ||= $cgi->param('searchLang');
670 $sort ||= $cgi->param('searchSort');
671 $sortdir ||= $cgi->param('searchSortDir');
672 $terms ||= $cgi->param('searchTerms');
673 $class ||= $cgi->param('searchClass') || '-';
674 $type ||= $cgi->param('responseType') || '-';
675 $org ||= $cgi->param('searchOrg') || '-';
677 if ($version eq '1.0') {
679 } elsif ($type eq '-') {
684 $terms = decode_utf8($terms);
687 my $term_copy = $terms;
689 my $complex_terms = 0;
690 if ($terms eq 'help') {
691 print $cgi->header(-type => 'text/html');
695 <title>just type something!</title>
698 <p>You are in a maze of dark, twisty stacks, all alike.</p>
702 return Apache2::Const::OK;
707 while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
708 my ($c,$t) = split ':' => $1;
713 } elsif ($c eq 'sort') {
714 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
715 } elsif ($c eq 'dir') {
716 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
717 } elsif ($c eq 'lang') {
718 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
720 $$searches{$c}{term} .= ' '.$t;
721 $cache_key .= $c . $t;
728 $class = 'keyword' if ($class eq '-');
729 $$searches{$class}{term} .= " $term_copy";
730 $cache_key .= $class . $term_copy;
735 $org_unit = $actor->request(
736 'open-ils.actor.org_unit_list.search' => parent_ou => undef
739 $org_unit = $actor->request(
740 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
744 $cache_key .= $org.$sort.$sortdir.$lang;
746 my $rs_name = $cgi->cookie('os_session');
747 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
750 if (!($recs = $$cached_res{os_results}{$cache_key})) {
751 $rs_name = $cgi->remote_host . '::' . rand(time);
752 $recs = $search->request(
753 'open-ils.search.biblio.multiclass' => {
754 searches => $searches,
755 org_unit => $org_unit->[0]->id,
758 ($sort ? ( 'sort' => $sort ) : ()),
759 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
760 ($lang ? ( 'language' => $lang ) : ()),
764 $$cached_res{os_results}{$cache_key} = $recs;
765 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
771 my $feed = create_record_feed(
773 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
779 $feed->search($terms);
780 $feed->class($class);
782 if ($complex_terms) {
783 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
785 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
788 $feed->creator($host);
789 $feed->update_ts(gmtime_ISO8601());
793 'http://a9.com/-/spec/opensearch/1.1/',
800 'http://a9.com/-/spec/opensearch/1.1/',
807 'http://a9.com/-/spec/opensearch/1.1/',
814 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
815 'application/opensearch+xml'
816 ) if ($offset + $limit < $recs->{count});
820 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
821 'application/opensearch+xml'
826 $base . "/$version/$org/$type/$class?searchTerms=$terms" =>
827 'application/opensearch+xml'
832 $base . "/$version/$org/rss2/$class?searchTerms=$terms" =>
833 'application/rss+xml'
838 $base . "/$version/$org/atom/$class?searchTerms=$terms" =>
839 'application/atom+xml'
844 $base . "/$version/$org/html/$class?searchTerms=$terms" =>
848 $feed->link( unapi => $unapi);
852 $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
853 join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
858 -type => $feed->type,
860 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
863 print entityize($feed->toString) . "\n";
865 return Apache2::Const::OK;
868 sub create_record_feed {
873 my $lib = shift || '-';
876 my $base = $cgi->url;
877 my $host = $cgi->virtual_host || $cgi->server_name;
879 my $year = (gmtime())[5] + 1900;
881 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
883 $feed->unapi($unapi);
885 $type = 'atom' if ($type eq 'html');
886 $type = 'marcxml' if ($type eq 'htmlcard' or $type eq 'htmlholdings');
888 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
890 for my $record (@$records) {
891 next unless($record);
893 #my $rec = $record->id;
896 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
898 my $xml = $supercat->request(
899 "open-ils.supercat.record.$type.retrieve",
904 my $node = $feed->add_item($xml);
907 if ($lib && $type eq 'marcxml') {
908 $xml = $supercat->request( "open-ils.supercat.record.holdings_xml.retrieve", $rec, $lib )->gather(1);
909 $node->add_holdings($xml);
912 $node->id($item_tag);
913 #$node->update_ts(clense_ISO8601($record->edit_date));
914 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings" => 'text/html');
915 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac");
916 $node->link(unapi => $feed->unapi . "?id=$item_tag");
917 $node->link('unapi-id' => $item_tag);
924 my $stuff = NFC(shift());
925 $stuff =~ s/&(?!\S+;)/&/gso;
926 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
935 my $year = (gmtime())[5] + 1900;
938 $content .= "Content-type: application/xml\n\n";
939 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
941 for my $cn (@$tree) {
942 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
943 $cn_class =~ s/Fieldmapper-//gso;
945 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
946 my $cn_lib = $cn->owning_lib->shortname;
947 my $cn_label = $cn->label;
949 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
950 $ou_class =~ s/Fieldmapper-//gso;
952 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
953 my $ou_name = $cn->owning_lib->name;
955 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
956 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
957 $content .= $cn->record->marc;
958 $content .= "</hold:volume>";
961 $content .= '</hold:volumes>';
969 return Apache2::Const::DECLINED if (-e $apache->filename);
972 my $year = (gmtime())[5] + 1900;
974 my $host = $cgi->virtual_host || $cgi->server_name;
977 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
978 my $rel_name = $cgi->url(-relative=>1);
979 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
982 my $url = $cgi->url(-path_info=>$add_path);
983 my $root = (split 'browse', $url)[0];
984 my $base = (split 'browse', $url)[0] . 'browse';
985 my $unapi = (split 'browse', $url)[0] . 'unapi';
988 my $path = (split 'browse', $url)[1];
990 my (undef,$format,$axis,$site,$string,$page,$page_size) = split '/', $path;
993 $site ||= $cgi->param('searchOrg');
994 $page ||= $cgi->param('startPage') || 0;
995 $page_size ||= $cgi->param('count') || 9;
997 $page = 0 if ($page !~ /^\d+$/);
999 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1000 warn "something's wrong...";
1004 $string = decode_utf8($string);
1005 $string =~ s/\+/ /go;
1008 my $tree = $supercat->request(
1009 "open-ils.supercat.$axis.browse",
1016 my $content = $browse_types{$axis}{$format}->($tree);
1018 return Apache2::Const::OK;