--- /dev/null
+package Newslash::Plugin::DiscussionHelper;
+use Mojo::Base 'Mojolicious::Plugin';
+use Data::Dumper;
+sub register {
+ my ($self, $app, $conf) = @_;
+
+ $app->hook(before_render => sub {
+ my ($c, $args) = @_;
+ my $discus = $args->{discussion} || $c->stash('discussion');
+ return if !$discus;
+
+ my $user = $c->stash('user');
+ my $discussions = $c->model('discussions');
+ my $comment_allowed = $discussions->is_comment_allowed(discussion => $discus,
+ uid => $user->{uid});
+ $c->stash(comment_allowed => $comment_allowed);
+
+ });
+}
+
+
+
+1;
# set canocal (for test.srad.jp)
$app->plugin('Newslash::Plugin::Canonical');
+ # DiscussionHelper
+ $app->plugin('Newslash::Plugin::DiscussionHelper');
+
# use HSTS
$app->plugin('Newslash::Plugin::Hsts');
}
my $parent_item;
- my $comment_allowed;
if ($discuss) {
my $d_id = $discuss->{discussion_id};
if ($discuss->{kind} eq "story"
elsif ($discuss->{kind} eq "submission") {
$parent_item = $c->model('submissions')->select(discussion_id => $d_id);
}
-
- $comment_allowed = $discussions->is_comment_allowed(discussion => $discuss,
- uid => $user->{uid});
}
my $page = { content_type => "comment",
$c->render(item => $comment,
parent => $parent,
discussion => $discuss,
- comment_allowed => $comment_allowed,
parent_item => $parent_item,
page => $page,
);
my $comments = [];
my $discuss;
- my $comment_allowed = 0;
if ($d_id) {
my $discussions = $c->model('discussions');
$discuss = $discussions->select(id => $d_id);
$comments = $c->model('comments')->select(discussion_id => $d_id);
- $comment_allowed = $discussions->is_comment_allowed(discussion => $discuss,
- uid => $user->{uid});
-
}
my $page = { content_type => "journal",
the_user => $the_user,
page => $page,
use_captcha => 1,
- comment_allowed => $comment_allowed,
);
}
my $discussions = $c->model('discussions');
my $discussion_id = $poll->{discussion_id};
my $discuss = $discussions->select(discussion_id => $discussion_id);
- my $comment_allowed = 0;
my $comments = [];
if ($discussion_id) {
$comments = $c->model('comments')->select(discussion_id => $discussion_id);
- $comment_allowed = $discussions->is_comment_allowed(discussion => $discuss,
- uid => $user->{uid});
}
page => $page,
comments => $comments,
use_captcha => 1,
- comment_allowed => $comment_allowed,
discussion => $discuss,
related => $related_polls,
);
my $discuss = $discussions->select(sid => $sid);
my $d_id = $discuss->{id};
my $comments = [];
- my $comment_allowed = 0;
if ($d_id) {
$comments = $c->model('comments')->select(discussion_id => $d_id);
- $comment_allowed = $discussions->is_comment_allowed(discussion => $discuss,
- uid => $user->{uid});
}
my $related = $stories->get_related_items(stoid => $story->{stoid});
authors => $authors,
use_captcha => 1,
page => $page,
- comment_allowed => $comment_allowed,
);
}
my $d_id = $submission->{discussion_id};
my $comments = [];
my $discuss = {};
- my $comment_allowed => 0;
if ($d_id) {
my $discussions = $c->model('discussions');
$discuss = $discussions->select(id => $d_id);
$comments = $c->model('comments')->select(discussion_id => $d_id);
- $comment_allowed = $discussions->is_comment_allowed(discussion => $discuss,
- uid => $user->{uid});
}
my $page = { content_type => "submission",
comments => $comments,
page => $page,
use_captcha => 1,
- comment_allowed => $comment_allowed,
);
}