#!/usr/bin/perl BEGIN { my $homedir = ( getpwuid($>) )[7]; my @user_include; foreach my $path (@INC) { if ( -d $homedir . '/perl' . $path ) { push @user_include, $homedir . '/perl' . $path; } } unshift @INC, @user_include; } # # This code may be freely reproduced, distributed, transmitted, used, modified, # built upon, or otherwise exploited by anyone for any purpose, commercial or non-commercial, # and in any way, including by methods that have not yet been invented or conceived. # # Purpose: Provide link/citation directly to various US Federal legislative docs and sublevels # Example URL: http://LegisLink.org/us?PL-110-234-5 # DOCUMENTATION # # CODE CONTRIBUTORS # Joe Carmel, # CHANGE HISTORY use HTTP::Lite; $http = new HTTP::Lite; # Get URL string after the ? from the URL. $posted_information=$ENV{QUERY_STRING}; print "Content-type: text/html\n\n"; ######################################## # Public Law Sections ######################################## if ($posted_information=~m|act-(\d+)-(\d+)-(\d+)|i) { $year=$1; $num=$2; $sec=$3; # Get the file from GPO $legdoc=GetPublicLawTxtDocFromGPO($congress,$plnum); # Add the HTML anchor to the text file. $legdoc=~s|\nSEC\. ($plsection)\.|\n\nSEC. \1.|; # Store the file and Display the Stored File with the Anchor. $outfn="PublicLaws/".$congress."-".$plnum.".html"; $anchor="SEC"; StoreFileandDisplayToAnchor($legdoc,$outfn,"SEC"); } ######################################## # Public Act, whole ######################################## elsif ($posted_information=~m|public-act-(\d+)-(\d+)|i) { $year=$1; $num=$2; $website=sprintf("http://www.legislation.govt.nz/act/public/%d/%04d/latest/whole.html",$year,$num); RedirectToWebsite($website); exit; } ######################################## # Private Act, whole ######################################## elsif ($posted_information=~m|private-act-(\d+)-(\d+)|i) { $year=$1; $num=$2; $website=sprintf("http://www.legislation.govt.nz/act/private/%d/%04d/latest/whole.html",$year,$num); RedirectToWebsite($website); exit; } ######################################## # Display the list of LegisLink formats ######################################## else { print ""; # When the following line is uncommented, the page disappears in IE # print "Electronic Citations for New Zealand Legislation.<title></head>\n"; print "<body>"; print "<center><h1>LegisLink<a href=\"http://legislink.org\">*</a> for New Zealand Legislation</h1>"; print "<h2>Simplified Electronic Links for Legislation</h2></center>\n"; print "<p><b>Public Acts</b><br/>\n"; print "   <b>Format: </b>Act-[year]-[act-number]]<br/>\n"; print "   <b>Example:</b> <a href=\"http://legislink.org/nz?public-act-2009-28\">http://legislink.org/nz?public-act-2009-28</a><br/>"; print "   <b>Source:</b> <a href=\"http://www.legislation.govt.nz\">New Zealand Legislation: Act (HTML)</a><br/>"; print "   <b>Availability:</b> 1275 - 2009<br/>\n"; print "<p><b>Private Acts</b><br/>\n"; print "   <b>Format: </b>Act-[year]-[act-number]]<br/>\n"; print "   <b>Example:</b> <a href=\"http://legislink.org/nz?private-act-1981-5\">http://legislink.org/nz?private-act-1981-5</a><br/>"; print "   <b>Source:</b> <a href=\"http://www.legislation.govt.nz\">New Zealand Legislation: Act (HTML)</a><br/>"; print "   <b>Availability:</b> 1275 - 2009<br/>\n"; print "<br/><a rel=\"license\" href=\"http://creativecommons.org/licenses/publicdomain/\"><img alt=\"Creative Commons License\" "; print "style=\"border-width:0\" src=\"http://i.creativecommons.org/l/publicdomain/88x31.png\" /></a><br />"; print "This work is in the <a rel=\"license\" href=\"http://creativecommons.org/licenses/publicdomain/\">Public Domain</a>.\n"; print "</body></html>\n"; exit; } ####################################### # Redirect to Website ####################################### sub RedirectToWebsite { my $website=$_[0]; # Check for URL existence if (!($req = $http->request($website))) { print "<html><title>New Zealand Legialtion\n"; print "\n"; print "

The legislative document is unavailable from http://www.legislation.govt.nz at this time.

\n"; print ""; exit; } # my $body=""; # $body = $http->body(); print "\n"; print "\n"; print "\n"; print "\n"; print ""; print "

Redirecting page to ".$website."

\n"; print "\n"; exit; } ####################################### # StoreFileandDisplayToAnchor ####################################### sub StoreFileandDisplayToAnchor { my $doc=$_[0]; my $fn=$_[1]; my $anchor=$_[2]; my $prepend=$_[3]; # Store file locally open (OUT, ">$fn"); print OUT $prepend; print OUT $doc; close OUT; # Display file to user with redirect and anchor. print "\n"; print "\n"; print "\n"; print "\n"; print ""; print "

Redirecting page to http://www.legislink.org/".$fn."#".$anchor."

\n"; print "\n"; exit; } ####################################### # GetPublicLawTxtDocFromGPO ####################################### sub GetPublicLawTxtDocFromGPO { my $congress=$_[0]; my $plnum=$_[1]; # Zero padding of PL numbers under 100. if ($plnum<100) { $website=sprintf("http://frwebgate.access.gpo.gov/cgi-bin/getdoc.cgi?dbname=%d_cong_public_laws&docid=f:publ%03d.%d",$congress,$plnum,$congress); } else { $website=sprintf("http://frwebgate.access.gpo.gov/cgi-bin/getdoc.cgi?dbname=%3d_cong_public_laws&docid=f:publ%d.%d",$congress,$plnum,$congress); } # If the file at GPO can't be found if (!($req = $http->request($website))) { print "Public Law ".$congress."-".$plnum."\n"; print "\n"; print "

Public Law ".$congress."-".$plnum." is unavailable at GPO at this time.

\n"; print "

Here's a link to the Public Law you requested at GPO. ".$website.""; print ""; exit; } my $body=""; $body = $http->body(); # Text for availability if ($body=~m|this database is not available at this time|) { print ""; print "GPO is having a problem
"; print "

Here's a link to the Public Law you requested at GPO.
"; print "".$website.""; print ""; exit; } if ($body=~m|No such document \[publ|) { print "\n"; print "Public Law ".$congress."-".$plnum." does not exist.
"; print "

Here's a link to the Public Law you requested at GPO to double check the error."; print "
".$website.""; print ""; exit; } return($body); } ####################################### # GetUSCTxtDocFromLRC ####################################### sub GetUSCTxtDocFromLRC { my $title=$_[0]; my $section=$_[1]; for $key ( sort {$a<=>$b} keys %USCChap ) { # print "($key)->($USCChap{$key})\n"; if ($section>=$USCChap{$key}) { $lastchap=$key; } } $website=sprintf("http://uscode.house.gov/download/pls/%02dC%d.txt",$title,$lastchap); $websitecatalog=sprintf("http://uscode.house.gov/download/title_%02d.shtml",$title); # If the file at LRC can't be found if (!($req = $http->request($website))) { print "USC ".$title."\n"; print "\n"; print "

US Code Title ".$title." is unavailable from uscode.house.gov at this time.

\n"; print "

US Code Title ".$title." files are at ".$websitecatalog.""; print ""; exit; } my $body=""; $body = $http->body(); if ($body=~m|

The page cannot be found

|) { print "\n"; print "\n"; print "

US Code Title ".$title." is unavailable from uscode.house.gov.

\n"; print "

US Code Title ".$title." files are at ".$websitecatalog.""; print ""; exit; } return($body); } ####################################### # GetUSCChaptersforTitleFromLRC ####################################### sub GetUSCChaptersforTitleFromLRC { my $title=$_[0]; # Zero padding of USC Title numbers $website=sprintf("http://uscode.house.gov/download/pls/%02dT.txt",$title); $websitecatalog=sprintf("http://uscode.house.gov/download/title_%02d.shtml",$title); # If the file at LRC can't be found if (!($req = $http->request($website))) { print "USC ".$title."\n"; print "\n"; print "

US Code Title ".$title." is unavailable from uscode.house.gov at this time.

\n"; print "

US Code Title ".$title." files are at ".$websitecatalog.""; print ""; exit; } my $body=""; $body = $http->body(); if ($body=~m|

The page cannot be found

|) { print "\n"; print "\n"; print "

US Code Title ".$title." is unavailable from uscode.house.gov.

\n"; print "

US Code Title ".$title." files are at ".$websitecatalog.""; print ""; exit; } my @lines=split(/\n/,$body); my $j=0; my $tocfound=0; while ($lines[$j]<$#lines) { if ($lines[$j]=~m|^\s*Chap\.\s*Sec\.\s*$|) { $tocfound=1; } if ($tocfound==1 && $lines[$j]=~m|^\s*$|) { return; } elsif ($tocfound==1) { if ($lines[$j]=~m|^\s*(\d+)\.|) { $chap=$1; } if ($lines[$j]=~m|(\d+)\s*$|) { $sec=$1; $USCChap{$chap}=$sec; } } $j++; } }