diff --git a/lib/CMTD/Helpers.pm b/lib/CMTD/Helpers.pm index ba0ff3e..994f25c 100644 --- a/lib/CMTD/Helpers.pm +++ b/lib/CMTD/Helpers.pm @@ -70,7 +70,31 @@ sub register { }); $app->helper(comments_by_pid => sub { my ($c, $pid) = @_; - return $self->app->db->select('comments', '*', {pid => $sid}, 'seq')->hashes; + return $self->app->db->select('comments', '*', {pid => $pid}, 'seq')->hashes; + }); + $app->helper(add_page => sub { + my ($c, $sid, $page) = @_; + $self->app->db->insert('pages', { + sid => $sid, + hash => $page->{hash}, + path => $page->{path}, + }); + }); + $app->helper(add_comment => sub { + my ($c, $pid, $cm) = @_; + my $table = 'comments'; + $self->app->db->begin; + my $seq = $self->app->db->select($table, 'max(seq)', {pid => $pid})->list; + $self->app->db->insert($table, { + pid => $pid, + seq => $seq, + date => time(), + name => $cm->{name}, + reply => $cm->{reply}, + email => $cm->{mail} || '', + text => b64_encode($cm->{text}), + }); + $self->app->db->commit; }); }