summaryrefslogtreecommitdiff
path: root/index.cgi
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-10-05 16:10:22 +0200
committerYorhel <git@yorhel.nl>2010-10-05 16:10:22 +0200
commit5e9f6e92c8ac9715c8cfb7bc60e1ba49b141c2a8 (patch)
treef4c8b4657d51e5f60d9335ec19a9e7d9bceb41ff /index.cgi
parent8bbde44a03d1d86e4cd347ea19761e52c5ed213e (diff)
added clickable url feature
Diffstat (limited to 'index.cgi')
-rwxr-xr-xindex.cgi12
1 files changed, 8 insertions, 4 deletions
diff --git a/index.cgi b/index.cgi
index 0dee61f..2869865 100755
--- a/index.cgi
+++ b/index.cgi
@@ -11,7 +11,8 @@
# html text,
# date timestamp with time zone NOT NULL DEFAULT now(),
# lastvisit timestamp with time zone NOT NULL DEFAULT now(),
-# ip inet
+# ip inet,
+# parse_urls boolean NOT NULL DEFAULT false
# );
@@ -80,6 +81,7 @@ sub upload {
my $code = join '', map $chars[rand @chars], 1..5;
my $s = $cgi->param('s') || 'nosyntax';
my $w = $cgi->param('w') ? 1 : 0;
+ my $c = $cgi->param('c') ? 1 : 0;
plain("Unknown syntax code.") if !grep $s eq $_, @syntax;
my $dat = $cgi->param('u') || $cgi->param('f') || '';
$dat =~ s/\x0D\x0A?/\n/g;
@@ -90,8 +92,8 @@ sub upload {
my $html = $s eq 'nosyntax' ? undef
: decode_utf8(Text::VimColor->new(string => encode_utf8($dat), filetype => $s)->html());
- $db->do('INSERT INTO pastes (code, syntax, wrap, raw, html, ip) VALUES(?,?,?,?,?,?)',
- undef, $code, $s, $w, $dat, $html, $ENV{REMOTE_ADDR});
+ $db->do('INSERT INTO pastes (code, syntax, wrap, raw, html, ip, parse_urls) VALUES(?,?,?,?,?,?,?)',
+ undef, $code, $s, $w, $dat, $html, $ENV{REMOTE_ADDR}, $c);
print "Status: 303\nLocation: http://$ENV{HTTP_HOST}/$code\nContent-type: text/plain\n\nRedirecting...\n";
exit;
@@ -114,7 +116,7 @@ sub get {
sub view {
my $code = shift;
- my $r = get $code, 'syntax, wrap, raw, html, ip';
+ my $r = get $code, 'wrap, raw, html, ip, parse_urls';
my $cnt = ($r->{raw} =~ y/\n/\n/);
$cnt += 1 if $r->{raw} !~ /\n$/;
@@ -123,6 +125,7 @@ sub view {
} else {
$r->{html} =~ s/\n/<br \/>/g;
}
+ $r->{html} =~ s/(http|https):\/\/([^< ]+[0-9a-zA-Z=\/-])/<a href="$1:\/\/$2" rel="nofollow">$1:\/\/$2<\/a>/g if $r->{parse_urls};
html(sprintf q|
<div id="toplinks">
%s
@@ -178,6 +181,7 @@ sub form {
<fieldset>
<legend>▾ Formatting</legend>
<input type="checkbox" id="w" name="w" value="1" /> <label for="w">allow line wrapping</label><br />
+ <input type="checkbox" id="c" name="c" value="1" checked="checked" /> <label for="c">make URLs clickable</label><br />
<i>Syntax highlighting:</i> <input type="text" name="s" id="s" size="10" value="nosyntax" /> <i><a href="#" onclick="return showall()">Show options &raquo;</a></i>
<div id="syntax" style="display: none">%s</div>
</fieldset>