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 $unapi = (split 'supercat', $url)[0] . 'unapi';
260 my $host = $cgi->virtual_host || $cgi->server_name;
262 my $path = $cgi->path_info;
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 $unapi = (split 'feed', $url)[0] . 'unapi';
432 my $path = $cgi->path_info;
433 #warn "URL breakdown: $url -> $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 $unapi = (split 'feed', $url)[0] . 'unapi';
498 my $path = $cgi->path_info;
499 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
501 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
503 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
506 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
508 if ($type eq 'opac') {
509 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
510 join('&', map { "rl=" . $_ } @$list) .
515 my $feed = create_record_feed( $type, $list, $unapi);
519 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
521 $feed->title("$limit most recent $rtype ${axis}s");
524 $feed->creator($host);
525 $feed->update_ts(gmtime_ISO8601());
527 $feed->link(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml');
528 $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml');
529 $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html');
530 $feed->link(unapi => $unapi);
534 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
535 join('&', map { 'rl=' . $_} @$list ),
540 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
541 print entityize($feed->toString) . "\n";
543 return Apache2::Const::OK;
552 if ($version eq '1.0') {
554 Content-type: application/opensearchdescription+xml; charset=utf-8
556 <?xml version="1.0" encoding="UTF-8"?>
557 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
558 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
559 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
560 <ShortName>$lib</ShortName>
561 <LongName>Search $lib</LongName>
562 <Description>Search the $lib OPAC by $class.</Description>
563 <Tags>$lib book library</Tags>
564 <SampleSearch>harry+potter</SampleSearch>
565 <Developer>Mike Rylander for GPLS/PINES</Developer>
566 <Contact>feedback\@open-ils.org</Contact>
567 <SyndicationRight>open</SyndicationRight>
568 <AdultContent>false</AdultContent>
569 </OpenSearchDescription>
573 Content-type: application/opensearchdescription+xml; charset=utf-8
575 <?xml version="1.0" encoding="UTF-8"?>
576 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
577 <ShortName>$lib</ShortName>
578 <Description>Search the $lib OPAC by $class.</Description>
579 <Tags>$lib book library</Tags>
580 <Url type="application/rss+xml"
581 template="$base/1.1/$lib/rss2/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
582 <Url type="application/atom+xml"
583 template="$base/1.1/$lib/atom/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
584 <Url type="application/x-mods3+xml"
585 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
586 <Url type="application/x-mods+xml"
587 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
588 <Url type="application/x-marcxml+xml"
589 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
590 <LongName>Search $lib</LongName>
591 <Query role="example" searchTerms="harry+potter" />
592 <Developer>Mike Rylander for GPLS/PINES</Developer>
593 <Contact>feedback\@open-ils.org</Contact>
594 <SyndicationRight>open</SyndicationRight>
595 <AdultContent>false</AdultContent>
596 <Language>en-US</Language>
597 <OutputEncoding>UTF-8</OutputEncoding>
598 <InputEncoding>UTF-8</InputEncoding>
599 </OpenSearchDescription>
603 return Apache2::Const::OK;
606 sub opensearch_feed {
608 return Apache2::Const::DECLINED if (-e $apache->filename);
611 my $year = (gmtime())[5] + 1900;
613 my $host = $cgi->virtual_host || $cgi->server_name;
616 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
617 my $rel_name = $cgi->url(-relative=>1);
618 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
621 my $url = $cgi->url(-path_info=>$add_path);
622 my $root = (split 'opensearch', $url)[0];
623 my $base = (split 'opensearch', $url)[0] . 'opensearch';
624 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
626 my $path = $cgi->path_info;
627 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
629 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
636 $lib = $actor->request(
637 'open-ils.actor.org_unit_list.search' => parent_ou => undef
638 )->gather(1)->[0]->shortname;
645 return opensearch_osd($version, $lib, $class, $base);
649 my $page = $cgi->param('startPage') || 1;
650 my $offset = $cgi->param('startIndex') || 1;
651 my $limit = $cgi->param('count') || 10;
653 $page = 1 if ($page !~ /^\d+$/);
654 $offset = 1 if ($offset !~ /^\d+$/);
655 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
658 $offset = ($page - 1) * $limit;
663 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang);
664 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
666 $lang ||= $cgi->param('searchLang');
667 $sort ||= $cgi->param('searchSort');
668 $sortdir ||= $cgi->param('searchSortDir');
669 $terms ||= $cgi->param('searchTerms');
670 $class ||= $cgi->param('searchClass') || '-';
671 $type ||= $cgi->param('responseType') || '-';
672 $org ||= $cgi->param('searchOrg') || '-';
674 if ($version eq '1.0') {
676 } elsif ($type eq '-') {
681 $terms = decode_utf8($terms);
684 my $term_copy = $terms;
686 my $complex_terms = 0;
687 if ($terms eq 'help') {
688 print $cgi->header(-type => 'text/html');
692 <title>just type something!</title>
695 <p>You are in a maze of dark, twisty stacks, all alike.</p>
699 return Apache2::Const::OK;
704 while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
705 my ($c,$t) = split ':' => $1;
710 } elsif ($c eq 'sort') {
711 ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
712 } elsif ($c eq 'dir') {
713 ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
714 } elsif ($c eq 'lang') {
715 ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
717 $$searches{$c}{term} .= ' '.$t;
718 $cache_key .= $c . $t;
725 $class = 'keyword' if ($class eq '-');
726 $$searches{$class}{term} .= " $term_copy";
727 $cache_key .= $class . $term_copy;
732 $org_unit = $actor->request(
733 'open-ils.actor.org_unit_list.search' => parent_ou => undef
736 $org_unit = $actor->request(
737 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
741 $cache_key .= $org.$sort.$sortdir.$lang;
743 my $rs_name = $cgi->cookie('os_session');
744 my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
747 if (!($recs = $$cached_res{os_results}{$cache_key})) {
748 $rs_name = $cgi->remote_host . '::' . rand(time);
749 $recs = $search->request(
750 'open-ils.search.biblio.multiclass' => {
751 searches => $searches,
752 org_unit => $org_unit->[0]->id,
755 ($sort ? ( 'sort' => $sort ) : ()),
756 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
757 ($lang ? ( 'language' => $lang ) : ()),
761 $$cached_res{os_results}{$cache_key} = $recs;
762 OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
768 my $feed = create_record_feed(
770 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
776 $feed->search($terms);
777 $feed->class($class);
779 if ($complex_terms) {
780 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
782 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
785 $feed->creator($host);
786 $feed->update_ts(gmtime_ISO8601());
790 'http://a9.com/-/spec/opensearch/1.1/',
797 'http://a9.com/-/spec/opensearch/1.1/',
804 'http://a9.com/-/spec/opensearch/1.1/',
811 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
812 'application/opensearch+xml'
813 ) if ($offset + $limit < $recs->{count});
817 $base . "/$version/$org/$type/$class?searchTerms=$terms&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
818 'application/opensearch+xml'
823 $base . "/$version/$org/$type/$class?searchTerms=$terms" =>
824 'application/opensearch+xml'
829 $base . "/$version/$org/rss2/$class?searchTerms=$terms" =>
830 'application/rss+xml'
835 $base . "/$version/$org/atom/$class?searchTerms=$terms" =>
836 'application/atom+xml'
841 $base . "/$version/$org/html/$class?searchTerms=$terms" =>
845 $feed->link( unapi => $unapi);
849 $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
850 join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
855 -type => $feed->type,
857 -cookie => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
860 print entityize($feed->toString) . "\n";
862 return Apache2::Const::OK;
865 sub create_record_feed {
870 my $lib = shift || '-';
873 my $base = $cgi->url;
874 my $host = $cgi->virtual_host || $cgi->server_name;
876 my $year = (gmtime())[5] + 1900;
878 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
880 $feed->unapi($unapi);
882 $type = 'atom' if ($type eq 'html');
883 $type = 'marcxml' if ($type eq 'htmlcard' or $type eq 'htmlholdings');
885 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
887 for my $record (@$records) {
888 next unless($record);
890 #my $rec = $record->id;
893 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
895 my $xml = $supercat->request(
896 "open-ils.supercat.record.$type.retrieve",
901 my $node = $feed->add_item($xml);
904 if ($lib && $type eq 'marcxml') {
905 $xml = $supercat->request( "open-ils.supercat.record.holdings_xml.retrieve", $rec, $lib )->gather(1);
906 $node->add_holdings($xml);
909 $node->id($item_tag);
910 #$node->update_ts(clense_ISO8601($record->edit_date));
911 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings" => 'text/html');
912 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac");
913 $node->link(unapi => $feed->unapi . "?id=$item_tag");
914 $node->link('unapi-id' => $item_tag);
921 my $stuff = NFC(shift());
922 $stuff =~ s/&(?!\S+;)/&/gso;
923 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
932 my $year = (gmtime())[5] + 1900;
935 $content .= "Content-type: application/xml\n\n";
936 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
938 for my $cn (@$tree) {
939 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
940 $cn_class =~ s/Fieldmapper-//gso;
942 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
943 my $cn_lib = $cn->owning_lib->shortname;
944 my $cn_label = $cn->label;
946 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
947 $ou_class =~ s/Fieldmapper-//gso;
949 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
950 my $ou_name = $cn->owning_lib->name;
952 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
953 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
954 $content .= $cn->record->marc;
955 $content .= "</hold:volume>";
958 $content .= '</hold:volumes>';
966 return Apache2::Const::DECLINED if (-e $apache->filename);
969 my $year = (gmtime())[5] + 1900;
971 my $host = $cgi->virtual_host || $cgi->server_name;
974 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
975 my $rel_name = $cgi->url(-relative=>1);
976 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
979 my $url = $cgi->url(-path_info=>$add_path);
980 my $root = (split 'browse', $url)[0];
981 my $base = (split 'browse', $url)[0] . 'browse';
982 my $unapi = (split 'browse', $url)[0] . 'unapi';
984 my $path = $cgi->path_info;
987 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
988 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
991 $site ||= $cgi->param('searchOrg');
992 $page ||= $cgi->param('startPage') || 0;
993 $page_size ||= $cgi->param('count') || 9;
995 $page = 0 if ($page !~ /^\d+$/);
997 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
998 warn "something's wrong...";
999 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1003 $string = decode_utf8($string);
1004 $string =~ s/\+/ /go;
1007 my $tree = $supercat->request(
1008 "open-ils.supercat.$axis.browse",
1015 my $content = $browse_types{$axis}{$format}->($tree);
1017 return Apache2::Const::OK;