#!/usr/bin/perl -w # gus_atom_xsl.pl # Sort-order switch for Atom feeds. use CGI::Carp qw{fatalsToBrowser}; print "Content-Type: text/xml; charset=utf-8\n\n"; # Split on '!' versus '&' for GET because source doc is XML. # Uses only GET never POST. if ($ENV{'REQUEST_METHOD'} eq "GET") { @pairs = split /!|%21/, $ENV{'QUERY_STRING'}; } else { print "

Use GET method only!

"; } foreach $pair (@pairs) { ($key, $value) = split (/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack ("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack ("C", hex($1))/eg; $value =~ s///g; if ($form_data{$key}) { $form_data{$key} .= ", $value"; } else { $form_data{$key} = $value; } } my $http_base = '/home/your_own_account/'; my $http_url = 'your_own_domain.us'; my $flag = 1; if (open $ATOM, "<$http_base" . $form_data{atom}) { while (<$ATOM>) { # Edit the stylesheet link to escape the cgi-bin. if ($flag && $_ =~ /gus_atom.xsl/) { $_ =~ s{href="\.\/gus_atom.xsl}{href="../gus_atom.xsl}; } # Edit the self-link to fix the url for cgi-bin. if ($flag && $_ =~ /rel="self"/) { $_ =~ s{http://$http_url/}{http://$http_url/cgi-bin/gus_atom_xsl.pl?atom=}; $_ =~ s{\.xml}{.xml!sort_order=$form_data{sort_order}}; if ($ENV{'QUERY_STRING'} =~ /%21/) { $_ =~ s/!/%21/g } $flag = 0; } print $_; } } else { print "OOPS! Cannot open $http_base" . "$form_data{atom}" } # How Perl/CGI gets a URL and the regular way... # href="http://69.51.152.43/cgi-bin/gus_atom_xsl.pl?atom=starling_us_atom.xml%21sort_order=Title" # href="http://69.51.152.43/starling_us_atom.xml"