sub count {
my $self = shift;
+ my $params = {@_};
+
my $join = 'LEFT JOIN firehose ON (comments.cid = firehose.srcid AND firehose.type = "comment")';
- my $where = 'firehose.public != "no"';
+
+ my @clauses;
+ if ($params->{hide_future}) {
+ push @clauses, 'comments.ts < NOW()';
+ }
+ if ($params->{public_only}) {
+ push @clauses, 'firehose.public != "no"';
+ }
+ my $where = join " AND ", @clauses;
+
return $self->generic_count(table => "comments",
target => "cid",
timestamp => "date",
sub count {
my $self = shift;
+ my $params = {@_};
my $join = 'LEFT JOIN firehose ON (journals.id = firehose.srcid AND firehose.type = "journal")';
- my $where = 'firehose.public != "no"';
+
+ my @clauses;
+ if ($params->{hide_future}) {
+ push @clauses, 'journals.date < NOW()';
+ }
+ if ($params->{public_only}) {
+ push @clauses, 'firehose.public != "no"';
+ }
+ my $where = join " AND ", @clauses;
+
return $self->generic_count(table => "journals",
target => "id",
timestamp => "date",
sub count {
my $self = shift;
+ my $params = {@_};
+
my $join = 'LEFT JOIN firehose ON (stories.stoid = firehose.srcid AND firehose.type = "story")';
- my $where = 'firehose.public != "no"';
- return $self->generic_count(table => "stories",
+
+ my @clauses;
+ if ($params->{hide_future}) {
+ push @clauses, 'stories.time < NOW()';
+ }
+ if ($params->{public_only}) {
+ push @clauses, 'firehose.public != "no"';
+ }
+ my $where = join " AND ", @clauses;
+
+ return $self->generic_count(table => "stories",
target => "stoid",
timestamp => "time",
join => $join,
sub count {
my $self = shift;
+ my $params = {@_};
my $join = 'LEFT JOIN firehose ON (submissions.subid = firehose.srcid AND firehose.type = "submission")';
- my $where = 'firehose.public != "no"';
+
+ my @clauses;
+ if ($params->{hide_future}) {
+ push @clauses, 'submission.time < NOW()';
+ }
+ if ($params->{public_only}) {
+ push @clauses, 'firehose.public != "no"';
+ }
+ my $where = join " AND ", @clauses;
+
return $self->generic_count(table => "submissions",
target => "subid",
timestamp => "time",
$next = Newslash::Util::Items->get_date_string_from_item($next_items->[0], $offset_sec, $unit);
}
+
+ # get prev month
+ $dt = DateTime->new(year => $year,
+ month => $month,
+ day => 1);
+ my ($prev_month, $prev_month_date);
+ $dt->add(days => -1);
+ $prev_items = $model->select(until => $dt,
+ offset_sec => $offset_sec,
+ order_by => {create_time => "DESC"},
+ hide_future => $user->{author} ? 0 : 1,
+ public_only => $user->{author} ? 0 : 1,
+ limit => 1
+ );
+ if ($prev_items && @$prev_items) {
+ $dt = $c->format_timestamp(mysql => $prev_items->[0]->{create_time},
+ format => "datetime",
+ offset_sec => 0,
+ );
+ $dt->set(day => 1, hour => 0, minute => 0, second => 0);
+ $prev_items = $model->select(since => $dt,
+ offset_sec => $offset_sec,
+ order_by => {create_time => "ASC"},
+ hide_future => $user->{author} ? 0 : 1,
+ public_only => $user->{author} ? 0 : 1,
+ limit => 1
+ );
+ if ($prev_items && @$prev_items) {
+ $prev_month_date = Newslash::Util::Items->get_date_string_from_item($prev_items->[0], $offset_sec, "day");
+ $prev_month_date =~ m/^\d+\/0?(\d+)/;
+ $prev_month = $1;
+ }
+ }
+
+ # get next month
+ $dt = DateTime->new(year => $year,
+ month => $month,
+ day => 1);
+ my ($next_month, $next_month_date);
+ $dt->add(months => 1);
+ $next_items = $model->select(since => $dt,
+ offset_sec => $offset_sec,
+ order_by => {create_time => "ASC"},
+ hide_future => $user->{author} ? 0 : 1,
+ public_only => $user->{author} ? 0 : 1,
+ limit => 1
+ );
+ if ($next_items && @$next_items) {
+ $next_month_date = Newslash::Util::Items->get_date_string_from_item($next_items->[0], $offset_sec, "day");
+ $next_month_date =~ m/^\d+\/0?(\d+)/;
+ $next_month = $1;
+ }
+
my $page = { content_type => $type,
type => "archive",
year => $year,
page => $page,
prev => $prev,
next => $next,
+ prev_month => $prev_month,
+ next_month => $next_month,
+ prev_month_date => $prev_month_date,
+ next_month_date => $next_month_date,
);
if (@$items == 0) {
[%- IF ctype == "poll" -%]
<div class="prev">
<a href="/[% ctype %]/[% p_yy %]/[% p_mm %]/">
- [% p_mm + 0 %]月
+ 前
</a>
</div>
<div class="next">
<a href="/[% ctype %]/[% n_yy %]/[% n_mm %]/">
- [% n_mm + 0 %]月
+ 次
</a>
</div>
<div class="current">[% yyyy %]年[% m %]月</div>
- </div>
- [%- ELSE -%]
+ [%- ELSE -%]
<div class="prev">
- <a href="/[% ctype %]/[% p_yy %]/[% p_mm %]/01/">
- [% p_mm + 0 %]月
- </a>
+ [% IF prev_month %]
+ <a href="/[% ctype %]/[% prev_month_date %]">[% prev_month %]月</a>
+ [% END %]
</div>
<div class="next">
- <a href="/[% ctype %]/[% n_yy %]/[% n_mm %]/01/">
- [% n_mm + 0 %]月
- </a>
+ [% IF next_month %]
+ <a href="/[% ctype %]/[% next_month_date %]">[% next_month %]月</a>
+ [% END %]
</div>
<div class="current">[% yyyy %]年[% m %]月[% d %]日</div>
</div>