|
|
@ -5,7 +5,8 @@ use warnings; |
|
|
|
use utf8; |
|
|
|
use utf8; |
|
|
|
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
|
use Mojo::Util qw(b64_encode); |
|
|
|
use Mojo::Util qw(b64_encode md5_sum); |
|
|
|
|
|
|
|
use Mojo::URL; |
|
|
|
|
|
|
|
|
|
|
|
sub register { |
|
|
|
sub register { |
|
|
|
my ($self, $app) = @_; |
|
|
|
my ($self, $app) = @_; |
|
|
@ -14,13 +15,7 @@ sub register { |
|
|
|
my ($c) = @_; |
|
|
|
my ($c) = @_; |
|
|
|
my $url = $c->req->headers->referrer || |
|
|
|
my $url = $c->req->headers->referrer || |
|
|
|
$c->req->param('url'); |
|
|
|
$c->req->param('url'); |
|
|
|
return $url; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$app->helper(pageid => sub { |
|
|
|
|
|
|
|
my ($c, $url) = @_; |
|
|
|
|
|
|
|
return unless $url; |
|
|
|
return unless $url; |
|
|
|
|
|
|
|
|
|
|
|
my $u = Mojo::URL->new($url); |
|
|
|
my $u = Mojo::URL->new($url); |
|
|
|
my $site = $u->host; |
|
|
|
my $site = $u->host; |
|
|
|
my $path = $u->path; |
|
|
|
my $path = $u->path; |
|
|
@ -30,7 +25,7 @@ sub register { |
|
|
|
$path =~ s<\.[a-z0-9]{2,4}$><>io; |
|
|
|
$path =~ s<\.[a-z0-9]{2,4}$><>io; |
|
|
|
my $md5 = md5_sum($path); |
|
|
|
my $md5 = md5_sum($path); |
|
|
|
|
|
|
|
|
|
|
|
return {site => $site, pid => $md5, path => $path}; |
|
|
|
return {site => $site, hash => $md5, path => $path}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$app->helper(maintenance => sub { |
|
|
|
$app->helper(maintenance => sub { |
|
|
@ -63,29 +58,30 @@ sub register { |
|
|
|
my ($c, $code, $msg) = @_; |
|
|
|
my ($c, $code, $msg) = @_; |
|
|
|
$c->res->code($code); |
|
|
|
$c->res->code($code); |
|
|
|
$c->render(text => "$msg\n"); |
|
|
|
$c->render(text => "$msg\n"); |
|
|
|
|
|
|
|
$c->rendered; |
|
|
|
return; |
|
|
|
return; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$app->helper(site_by_name => sub { |
|
|
|
$app->helper(site_by_name => sub { |
|
|
|
my ($c, $site) = @_; |
|
|
|
my ($c, $site) = @_; |
|
|
|
return $self->app->db->select('sites', '*', {site => $site})->hash; |
|
|
|
return $c->app->db->select('sites', '*', {site => $site})->hash; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$app->helper(pid_by_hash => sub { |
|
|
|
$app->helper(pid_by_hash => sub { |
|
|
|
my ($c, $sid, $hash) = @_; |
|
|
|
my ($c, $sid, $hash) = @_; |
|
|
|
return $self->app->db->select('pages', 'id', {sid => $sid, hash => $hash})->list; |
|
|
|
return $c->app->db->select('pages', 'id', {sid => $sid, hash => $hash})->list; |
|
|
|
}); |
|
|
|
}); |
|
|
|
$app->helper(comments_by_pid => sub { |
|
|
|
$app->helper(comments_by_pid => sub { |
|
|
|
my ($c, $pid) = @_; |
|
|
|
my ($c, $pid) = @_; |
|
|
|
return $self->app->db->select('comments', '*', {pid => $pid}, 'seq')->hashes; |
|
|
|
return $c->app->db->select('comments', '*', {pid => $pid}, 'seq')->hashes; |
|
|
|
}); |
|
|
|
}); |
|
|
|
$app->helper(captcha_by_id => sub { |
|
|
|
$app->helper(captcha_by_id => sub { |
|
|
|
my ($c, $cid) = @_; |
|
|
|
my ($c, $cid) = @_; |
|
|
|
return $self->app->db->select('captcha', '*', {cid => $cid})->hash; |
|
|
|
return $c->app->db->select('captcha', '*', {cid => $cid})->hash; |
|
|
|
}); |
|
|
|
}); |
|
|
|
$app->helper(captcha_solve => sub { |
|
|
|
$app->helper(captcha_solve => sub { |
|
|
|
my ($c, $id, $input) = @_; |
|
|
|
my ($c, $id, $input) = @_; |
|
|
|
my $cap = $self->app->db->select('captcha', '*', {cid => $id})->hash; |
|
|
|
my $cap = $c->app->db->select('captcha', '*', {cid => $id})->hash; |
|
|
|
return "no captcha with this id" |
|
|
|
return "no captcha with this id" |
|
|
|
unless $cap and ref($cap) eq 'HASH'; |
|
|
|
unless $cap and ref($cap) eq 'HASH'; |
|
|
|
if ($cap->{code} ne $input) { |
|
|
|
if ($cap->{code} ne $input) { |
|
|
@ -109,7 +105,7 @@ sub register { |
|
|
|
}); |
|
|
|
}); |
|
|
|
$app->helper(add_page => sub { |
|
|
|
$app->helper(add_page => sub { |
|
|
|
my ($c, $sid, $page) = @_; |
|
|
|
my ($c, $sid, $page) = @_; |
|
|
|
$self->app->db->insert('pages', { |
|
|
|
$c->app->db->insert('pages', { |
|
|
|
sid => $sid, |
|
|
|
sid => $sid, |
|
|
|
hash => $page->{hash}, |
|
|
|
hash => $page->{hash}, |
|
|
|
path => $page->{path}, |
|
|
|
path => $page->{path}, |
|
|
@ -118,9 +114,9 @@ sub register { |
|
|
|
$app->helper(add_comment => sub { |
|
|
|
$app->helper(add_comment => sub { |
|
|
|
my ($c, $pid, $cm) = @_; |
|
|
|
my ($c, $pid, $cm) = @_; |
|
|
|
my $table = 'comments'; |
|
|
|
my $table = 'comments'; |
|
|
|
$self->app->db->begin; |
|
|
|
$c->app->db->begin; |
|
|
|
my $seq = $self->app->db->select($table, 'max(seq)', {pid => $pid})->list; |
|
|
|
my $seq = $c->app->db->select($table, 'max(seq)', {pid => $pid})->list; |
|
|
|
$self->app->db->insert($table, { |
|
|
|
$c->app->db->insert($table, { |
|
|
|
pid => $pid, |
|
|
|
pid => $pid, |
|
|
|
seq => $seq, |
|
|
|
seq => $seq, |
|
|
|
date => time(), |
|
|
|
date => time(), |
|
|
@ -129,7 +125,7 @@ sub register { |
|
|
|
email => $cm->{email}, |
|
|
|
email => $cm->{email}, |
|
|
|
text => b64_encode($cm->{text}), |
|
|
|
text => b64_encode($cm->{text}), |
|
|
|
}); |
|
|
|
}); |
|
|
|
$self->app->db->commit; |
|
|
|
$c->app->db->commit; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|