2 # The shebang is only there for mcedit syntax highlights, as I'm too lazy to
3 # change the configfile. It won't hurt performance
13 print qq{<input type=hidden name="$_" value="$hash->{$_}">}
14 unless exists $saves{$_};
21 if (defined wantarray){
34 s/\t/ /g;
37 if ($@){ return defined wantarray ? @_ : undef }
39 return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
42 # Browsers do s/ /+/ - I don't care about RFC's, but I do care about real-life
48 my $dec = uri_unescape($_);
49 if (defined wantarray){
53 return undef if $@; # ;DecodeURI("foo");
56 return defined wantarray ? (wantarray ? @r : "@r") : undef;
61 my $esc = uri_escape($_, '^;\/?:@&=\$,A-Za-z0-9\-_.!~*\'()');
62 if (defined wantarray){
66 return undef if $@; # ;EncodeURI("foo");
69 return defined wantarray ? (wantarray ? @r : "@r") : undef;
73 if ($header{'set-cookie'}){
74 $header{'set-cookie'} .= "\nset-cookie: $_[0]";
76 $header{'set-cookie'} = $_[0];
82 open (READFILE, $_[0]);
90 open (WRITEFILE, ">$_[0]");
92 print WRITEFILE $_[1];
98 open COUNTER, "+<$_[0]";
101 my $counter = <COUNTER>;
104 print COUNTER ++$counter;
111 # This sub assumes your string does not match /(["<>])\cC\1/
113 if (defined wantarray){
114 $ref = \(my $copy = $_[0]);
119 $$ref =~ s/"/"\cC"/g; # Single characters are easier to match :)
120 $$ref =~ s/>/>\cC>/g; # so we can just use a character class []
121 $$ref =~ s/</<\cC</g;
123 # Now this is a big, ugly regex! But hey - it works :)
124 $$ref =~ s{((\w+://|www\.|WWW\.)[a-zA-Z0-9\.\@:-]+[^\"\'>< \r\t\n]*)}{
127 s/// if (my $trailing) = /([\.,!\?\(\)\[\]]+$)/;
128 s/&(?!\x23?\w+;)/&/g;
130 my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
131 qq{<a href="$href" target="_blank">$_</a>$trailing};
134 $$ref =~ s/"\cC"/"/g;
135 $$ref =~ s/>\cC>/>/g;
136 $$ref =~ s/<\cC</</g;
138 if ($@){ return defined wantarray ? @_ : undef }
139 return defined wantarray ? $$ref : undef;