3 use vars qw($VERSION %INTERNAL %get %post %fields %header %cookie %BLOCK $DEBUG $output);
8 # We put most everything in %INTERNAL, just so the user won't screw it.
9 # We could also have used packages, but let's keep it simple.
11 $INTERNAL{file} = $ENV{PATH_TRANSLATED};
12 unless (-e $INTERNAL{file}){
13 $ENV{REDIRECT_STATUS} = '404';
14 print STDERR "htmpl: Not found: $INTERNAL{file}\n";
16 #Change this if you have an error handling script.
17 print `/vhost/COMMON/err.cgi` || "Status: 404 Not found\n\nFile not found";
22 ($INTERNAL{dir} = $INTERNAL{file}) =~ s{^(.*)/.*?$}[$1];
25 ($ENV{PLP_NAME} = $ENV{REQUEST_URI}) =~ s/\?.*$//;
29 $INTERNAL{qq} = "
\10"; #^P
30 $INTERNAL{q} = "
\17"; #^Q
32 $header{'Content-Type'} = 'text/html';
33 $header{Status} = '200 OK';
35 $INTERNAL{code} = ReadFile($INTERNAL{file});
37 while ($INTERNAL{code} =~ /<\((.*?)\)>/ ){
38 ($INTERNAL{file} = $1) =~ s/[<>\|]//g;
39 $INTERNAL{code} =~ s//ReadFile($INTERNAL{file})/e;
42 $INTERNAL{code} =~ s(<:)($INTERNAL{q};)g;
43 $INTERNAL{code} =~ s(:>)(;\nprint q$INTERNAL{q})g;
45 while ($INTERNAL{code} =~ /(<\[1(.*?)\]>(.*?)<\[2\]>(.*?)<\[3\]>)/s){
47 $BLOCK{"$INTERNAL{naam}-1"} = $3;
48 $BLOCK{"$INTERNAL{naam}-2"} = $4;
49 $INTERNAL{code} =~ s///; #Redo last match
51 $INTERNAL{code} =~ s(\\\\\r?\n)()g;
52 $INTERNAL{code} =~ s(<\[([^>]*?):(.*?)\]>)($BLOCK{"${1}-1"}$2$BLOCK{"${1}-2"})g;
53 $INTERNAL{code} =~ s(<\[(?!/)(.*?)\]>)($BLOCK{"${1}-1"})g;
54 $INTERNAL{code} =~ s(<\[/(.*?)\]>)($BLOCK{"${1}-2"})g;
57 $INTERNAL{code} =~ s(<{[ \08\09]*)($INTERNAL{q};print qq$INTERNAL{qq})g;
58 $INTERNAL{code} =~ s([ \08\09]*}>)($INTERNAL{qq};print q$INTERNAL{q})g;
59 $INTERNAL{code} = "print q$INTERNAL{q}$INTERNAL{code}$INTERNAL{q};";
61 $INTERNAL{code} =~ s{print qq$INTERNAL{qq}$INTERNAL{qq};}[]g;
62 $INTERNAL{code} =~ s{print q$INTERNAL{q}$INTERNAL{q};}[]g;
65 while ($INTERNAL{code} =~ s/<_(.*?)_>//s){
71 print "\nDebug:\n $@";
76 print "\n\n" if $DEBUG == 2;
80 for (sort keys %header){ # Sort, so lowercase and underscores come first)
83 s/\b(\w)(\w*)/\U$1\E\L$2\E/g;
84 $HEADER{$_} = $header{$copy};
87 print "$_: $HEADER{$_}\n";
96 print "<hr><b>Debug</b><br>", Entity($@);