v2.21 release
[perl/plp/.git] / plp.cgi
1 #!/usr/bin/perl
2 use strict;
3 use vars qw($VERSION %INTERNAL %get %post %fields %header %cookie %BLOCK $DEBUG $output);
4
5 $VERSION = '2.21';
6 $DEBUG = 1;
7
8 $INTERNAL{file} = $ENV{PATH_TRANSLATED};
9 unless (-e $INTERNAL{file}){
10     $ENV{REDIRECT_STATUS} = '404';
11     print STDERR "htmpl: Not found: $INTERNAL{file}\n";
12
13     #Change this if you have an error handling script.
14     print `/vhost/COMMON/err.cgi` || "Status: 404 Not found\n\nFile not found";
15     
16     exit;
17 }
18
19 ($INTERNAL{dir} = $INTERNAL{file}) =~ s{^(.*)/.*?$}[$1];
20 chdir $INTERNAL{dir};
21
22 ($ENV{PLP_NAME} = $ENV{REQUEST_URI}) =~ s/\?.*$//;
23
24 use plp;
25
26 $INTERNAL{qq} = "\10"; #^P
27 $INTERNAL{q}  = "\17"; #^Q
28
29 $header{'content-type'} = 'text/html';
30 $header{status} = '200 OK';
31
32 $INTERNAL{code} = ReadFile($INTERNAL{file});
33
34 while ($INTERNAL{code} =~ /<\((.*?)\)>/ ){
35     ($INTERNAL{file} = $1) =~ s/[<>\|]//g;
36     $INTERNAL{code} =~ s//ReadFile($INTERNAL{file})/e;
37 }
38
39 $INTERNAL{code} =~ s(<:)($INTERNAL{q};)g;
40 $INTERNAL{code} =~ s(:>)(;\nprint q$INTERNAL{q})g;
41
42 while ($INTERNAL{code} =~ /(<\[1(.*?)\]>(.*?)<\[2\]>(.*?)<\[3\]>)/s){
43     $INTERNAL{naam} = $2;
44     $BLOCK{"$INTERNAL{naam}-1"} = $3;
45     $BLOCK{"$INTERNAL{naam}-2"} = $4;
46     $INTERNAL{code} =~ s///;  #Redo last match
47 }
48 $INTERNAL{code} =~ s(\\\\\r?\n)()g;
49 $INTERNAL{code} =~ s(<\[([^>]*?):(.*?)\]>)($BLOCK{"${1}-1"}$2$BLOCK{"${1}-2"})g;
50 $INTERNAL{code} =~ s(<\[(?!/)(.*?)\]>)($BLOCK{"${1}-1"})g;
51 $INTERNAL{code} =~ s(<\[/(.*?)\]>)($BLOCK{"${1}-2"})g;
52 $INTERNAL{code} =~ s(<{[ \08\09]*)($INTERNAL{q};print qq$INTERNAL{qq})g;
53 $INTERNAL{code} =~ s([ \08\09]*}>)($INTERNAL{qq};print q$INTERNAL{q})g;
54 $INTERNAL{code} = "print q$INTERNAL{q}$INTERNAL{code}$INTERNAL{q};";
55
56 $INTERNAL{code} =~ s{print qq$INTERNAL{qq}$INTERNAL{qq};}[]g;
57 $INTERNAL{code} =~ s{print q$INTERNAL{q}$INTERNAL{q};}[]g;
58
59
60 while ($INTERNAL{code} =~ s/<_(.*?)_>//s){
61     $INTERNAL{pre} = $1;    
62     {
63         no strict;
64         eval $INTERNAL{pre};
65         if ($@ && $DEBUG){
66             print "\nDebug:\n $@";
67         }
68     }
69 }
70
71 for (keys %header){
72     print "$_: $header{$_}\n";
73 }
74 print "\n";
75
76 {
77     no strict;
78     eval $INTERNAL{code};
79     if ($@ && $DEBUG){
80         print "<hr><b>Debug</b><br>", Entity($@);
81     }
82 }