#!/usr/bin/perl
print "Content-type: text/html\n\n";
use POSIX;
use CGI::Carp "fatalsToBrowser";
my $StripNumber = 1;
use LWP::Simple;
# https://www.webmasterworld.com/perl/5018940.htm
# use HTTP::Tiny;
# sub get {
# my ($url) = @_;
# return HTTP::Tiny->new->get($url)->{content};
# }
# https://stackoverflow.com/a/63796968/1424877
# use WWW::Curl::Simple;
# sub get {
# my ($url) = @_;
# my $curl = WWW::Curl::Simple->new();
# return $curl->get($url)->content;
# }
#sub get {
# my ($url) = @_;
# return `curl "$url"`
#}
# Simplified from the HTML::Entities package.
sub num_entity {
return '<' if ($_ eq '<');
return '>' if ($_ eq '>');
return '"' if ($_ eq '"');
return '&' if ($_ eq '&');
my $result = sprintf "%X;", ord($_[0]);
return $result;
}
sub encode_entities {
my $ref;
if (defined wantarray) {
my $x = $_[0];
$ref = \$x; # copy
} else {
$ref = \$_[0]; # modify in-place
}
# Encode control chars, high-bit chars, and <&>'"
$$ref =~ s/([^\n\r\t !\#\$%\(-;=?-~])/num_entity($1)/ge;
}
sub unpack_args {
my $cgi_args = join('&', @_);
@_ = split(/&/, $cgi_args);
foreach my $i (@_) {
my $varname;
my $vardata;
($varname, $vardata) = split(/=/, $i);
if ($varname eq "q") {
$StripNumber = int($vardata);
}
}
}
sub htmlize($) {
my ($foo) = @_;
$foo =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr(hex($1))/ge;
$foo =~ s/"/"/gs;
$foo =~ s/<//gs;
$foo =~ s/&/&/gs;
$foo =~ s/\n/
/gs;
return $foo;
}
sub get_page {
# get the original page from Qwantz
my $qwantz_url = "https://www.qwantz.com/index.php?comic=${StripNumber}";
$content = get($qwantz_url);
# read in whole file, not just one line or paragraph
undef $/;
# Get the date.
$content =~ m/
${titletext} END ; } # Get the contact e-mail subject joke. # The first several comics have no e-mail subject line. # For an example of an e-mail body, see comic #250. $content =~ m/mailto:ryan\@qwantz.com\?subject=([^"]*)"/sg; my $emailtext = $1; my $replytext = ""; # LWP::Simple::get() encodes "&body=" as "%26body%3D" # for some reason. Decode percent-sign hex values here. $emailtext =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr(hex($1))/ge; my $numfields = ($emailtext =~ /([^\&]*)\&body=(.*)/s); print ""; if ($numfields >= 1 && !($2 eq "")) { $emailtext = htmlize($1); $replytext = htmlize($2); } else { $emailtext = htmlize($emailtext); } if ($replytext eq "") { print "
Subject: ${emailtext}\n\n"; } else { print "
Subject: ${emailtext} ${replytext}\n\n";
}
}
my $query;
if (!defined $ENV{'QUERY_STRING'}) {
$query = "";
} else {
$query = $ENV{'QUERY_STRING'};
}
my @args = split('&', $query);
unpack_args(@args);
print <
previous — —
— next
END
;
} else {
print <
first strip — — — next
END
;
}
print <