v2.22 release
authorJuerd Waalboer <juerd@cpan.org>
Wed, 2 May 2001 11:28:05 +0000 (11:28 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 18 Mar 2008 08:14:24 +0000 (08:14 +0000)
.htaccess [new file with mode: 0644]
INSTALL [new file with mode: 0644]
plp.cgi
plpfunc.pm

diff --git a/.htaccess b/.htaccess
new file mode 100644 (file)
index 0000000..1d3d6e5
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,2 @@
+RemoveHandler .cgi
+ForceType text/plain
\ No newline at end of file
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..b34f4bf
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,9 @@
+# httpd.conf +=
+
+AddHandler plp-document .plp
+Action plp-document /cgi-bin/plp.cgi
+
+# /cgi-bin/ can be any globaly existing directory (I use /COMMON/ because
+# cgi-bin's are local (mod_vhost_alias))
+
+# read http://plp.juerd.nl/
\ No newline at end of file
diff --git a/plp.cgi b/plp.cgi
index 3bf77f9882d17b093afc6e4943ab31745105494a..4c6e41ef9eea938095e3b1bea4a9b6be95e4d6fd 100755 (executable)
--- a/plp.cgi
+++ b/plp.cgi
@@ -2,9 +2,12 @@
 use strict;
 use vars qw($VERSION %INTERNAL %get %post %fields %header %cookie %BLOCK $DEBUG $output);
 
-$VERSION = '2.21';
+$VERSION = '2.22';
 $DEBUG = 1;
 
+# We put most everything in %INTERNAL, just so the user won't screw it.
+# We could also have used packages, but let's keep it simple.
+
 $INTERNAL{file} = $ENV{PATH_TRANSLATED};
 unless (-e $INTERNAL{file}){
     $ENV{REDIRECT_STATUS} = '404';
@@ -26,8 +29,8 @@ use plp;
 $INTERNAL{qq} = "\10"; #^P
 $INTERNAL{q}  = "\17"; #^Q
 
-$header{'content-type'} = 'text/html';
-$header{status} = '200 OK';
+$header{'Content-Type'} = 'text/html';
+$header{Status} = '200 OK';
 
 $INTERNAL{code} = ReadFile($INTERNAL{file});
 
@@ -49,6 +52,8 @@ $INTERNAL{code} =~ s(\\\\\r?\n)()g;
 $INTERNAL{code} =~ s(<\[([^>]*?):(.*?)\]>)($BLOCK{"${1}-1"}$2$BLOCK{"${1}-2"})g;
 $INTERNAL{code} =~ s(<\[(?!/)(.*?)\]>)($BLOCK{"${1}-1"})g;
 $INTERNAL{code} =~ s(<\[/(.*?)\]>)($BLOCK{"${1}-2"})g;
+
+
 $INTERNAL{code} =~ s(<{[ \08\09]*)($INTERNAL{q};print qq$INTERNAL{qq})g;
 $INTERNAL{code} =~ s([ \08\09]*}>)($INTERNAL{qq};print q$INTERNAL{q})g;
 $INTERNAL{code} = "print q$INTERNAL{q}$INTERNAL{code}$INTERNAL{q};";
@@ -68,10 +73,21 @@ while ($INTERNAL{code} =~ s/<_(.*?)_>//s){
     }
 }
 
-for (keys %header){
-    print "$_: $header{$_}\n";
+print "\n\n" if $DEBUG == 2;
+
+{
+    my %HEADER;
+    for (sort keys %header){ # Sort, so lowercase and underscores come first)
+       my $copy = $_;
+       tr/_/-/;
+       s/\b(\w)(\w*)/\U$1\E\L$2\E/g;
+       $HEADER{$_} = $header{$copy};
+    }
+    for (keys %HEADER){
+        print "$_: $HEADER{$_}\n";
+    }
+    print "\n";
 }
-print "\n";
 
 {
     no strict;
index 49bb63cd8922b5bb44ea7013059b304ee75e4e27..a113c76615a303a0d7c6a89db19eb791c8d0d033 100644 (file)
@@ -31,7 +31,7 @@ sub Entity(@){
            s/</&lt;/g;
            s/>/&gt;/g;
            s/\n/<br>\n/g;
-           s/\t/    /eg;
+           s/\t/&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;/g;
            s/  /&nbsp;&nbsp;/g;
        };
        if ($@){ return defined wantarray ? @_ : undef }
@@ -108,6 +108,7 @@ sub Counter($){
 }
 
 sub AutoURL($){
+    # This sub assumes your string does not match /(["<>])\cC\1/
     my $ref;    
     if (defined wantarray){
        $ref = \(my $copy = $_[0]);
@@ -115,19 +116,21 @@ sub AutoURL($){
        $ref = \$_[0];
     }
     eval {
-       my ($p, $b, $c);
-       $$ref =~ s/&quot;/"\cC"/g;
-       $$ref =~ s/&gt;/>\cC>/g;
+       $$ref =~ s/&quot;/"\cC"/g; # Single characters are easier to match :)
+       $$ref =~ s/&gt;/>\cC>/g;   # so we can just use a character class []
        $$ref =~ s/&lt;/<\cC</g;
+       
        # Now this is a big, ugly regex! But hey - it works :)    
        $$ref =~ s{((\w+://|www\.|WWW\.)[a-zA-Z0-9\.\@:-]+[^\"\'>< \r\t\n]*)}{
-           local $_ = $1, $p = $2, ((($b) = /([\.,!\?\(\)\[\]]+$)/) ? s/// :
-           undef), s/&(?!\x23?\w+;)/&amp;/g, s/\"/&quot;/g, $c = 
-           ($p eq 'www.' || $p eq 'WWW.' ? "http://$_" : $_),
-           qq{<a href="$c" target="_blank">$_</a>$b}
+           local $_ = $1;
+           my $scheme = $2;
+           s/// if (my $trailing) = /([\.,!\?\(\)\[\]]+$)/;
+           s/&(?!\x23?\w+;)/&amp;/g;
+           s/\"/&quot;/g;
+           my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
+           qq{<a href="$href" target="_blank">$_</a>$trailing};
        }eg;
 
-
        $$ref =~ s/"\cC"/&quot;/g;
        $$ref =~ s/>\cC>/&gt;/g;
        $$ref =~ s/<\cC</&lt;/g;