1 #-------------------------#
2 package PLP::Functions;
3 #-------------------------#
7 our @EXPORT = qw/HiddenFields Entity DecodeURI EncodeURI Entity include
8 AddCookie ReadFile WriteFile AutoURL Counter Include/;
14 eval PLP::source($file, 0);
21 sub HiddenFields ($@) {
26 print qq{<input type=hidden name="$_" value="$hash->{$_}">}
27 unless exists $saves{$_};
34 if (defined wantarray) {
47 s/\t/ /g;
50 # if ($@){ return defined wantarray ? @_ : undef }
52 return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
55 # Browsers do s/ /+/ - I don't care about RFC's, but I do care about real-life
63 $dec =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
64 if (defined wantarray) {
68 # return undef if $@; # ;DecodeURI("foo");
71 return defined wantarray ? (wantarray ? @r : "@r") : undef;
80 ([^\/?:@\$,A-Za-z0-9\-_.!~*\'()])
82 sprintf("%%%02x", ord($1))
84 if (defined wantarray) {
88 # return undef if $@; # ;EncodeURI("foo");
91 return defined wantarray ? (wantarray ? @r : "@r") : undef;
95 if ($PLP::Script::header{'Set-Cookie'}) {
96 $PLP::Script::header{'Set-Cookie'} .= "\nSet-Cookie: $_[0]";
98 $PLP::Script::header{'Set-Cookie'} = $_[0];
105 open (READFILE, '<', $_[0]);
113 open (WRITEFILE, '>', $_[0]);
115 print WRITEFILE $_[1];
122 open COUNTER, "+<$_[0]" or
123 open COUNTER, ">$_[0]" or return undef;
126 my $counter = <COUNTER>;
129 print COUNTER ++$counter;
135 # This sub assumes your string does not match /(["<>])\cC\1/
137 if (defined wantarray){
138 $ref = \(my $copy = $_[0]);
143 $$ref =~ s/"/"\cC"/g; # Single characters are easier to match :)
144 $$ref =~ s/>/>\cC>/g; # so we can just use a character class []
145 $$ref =~ s/</<\cC</g;
147 # Now this is a big, ugly regex! But hey - it works :)
148 $$ref =~ s{((\w+://|www\.|WWW\.)[a-zA-Z0-9\.\@:-]+[^\"\'>< \r\t\n]*)}{
151 s/// if (my $trailing) = /([\.,!\?\(\)\[\]]+$)/;
152 s/&(?!\x23?\w+;)/&/g;
154 my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
155 qq{<a href="$href" target="_blank">$_</a>$trailing};
158 $$ref =~ s/"\cC"/"/g;
159 $$ref =~ s/>\cC>/>/g;
160 $$ref =~ s/<\cC</</g;
162 if ($@){ return defined wantarray ? @_ : undef }
163 return defined wantarray ? $$ref : undef;