1
# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2
# This program is distributed under the terms of the
3
# GNU General Public License, version 2.
7
package MT::ArchiveType::AuthorDaily;
10
use base qw( MT::ArchiveType::Author MT::ArchiveType::Daily );
11
use MT::Util qw( dirify start_end_day );
14
return 'Author-Daily';
18
return MT->translate('AUTHOR-DAILY_ADV');
21
sub default_archive_templates {
24
label => 'author/author-display-name/yyyy/mm/dd/index.html',
25
template => 'author/%-a/%y/%m/%d/%f',
29
label => 'author/author_display_name/yyyy/mm/dd/index.html',
30
template => 'author/%a/%y/%m/%d/%f'
35
sub dynamic_template {
36
return 'author/<$MTEntryAuthorID$>/<$MTArchiveDate format="%Y%m%d"$>';
41
archive_class => "author-daily-archive",
42
author_daily_archive => 1,
43
archive_template => 1,
50
my ( $ctx, $entry_or_ts ) = @_;
51
my $stamp = ref $entry_or_ts ? $entry_or_ts->authored_on : $entry_or_ts;
52
my $start = start_end_day($stamp);
54
MT::Template::Context::_hdlr_date( $ctx,
55
{ ts => $start, 'format' => "%x" } );
56
my $author = $obj->display_name($ctx);
57
sprintf( "%s%s", $author, $date );
62
my ( $ctx, %param ) = @_;
63
my $timestamp = $param{Timestamp};
64
my $file_tmpl = $param{Template};
65
my $author = $ctx->{__stash}{author};
66
my $entry = $ctx->{__stash}{entry};
68
my $this_author = $author ? $author : ( $entry ? $entry->author : undef );
69
return "" unless $this_author;
70
my $name = dirify( $this_author->nickname );
72
if ( $name eq '' || !$file_tmpl ) {
73
return "" unless $this_author;
74
$name = "author" . $this_author->id if $name !~ /\w/;
75
my $start = start_end_day($timestamp);
76
my ( $year, $month, $day ) = unpack 'A4A2A2', $start;
78
sprintf( "%s/%04d/%02d/%02d/index", $name, $year, $month, $day );
81
( $ctx->{current_timestamp}, $ctx->{current_timestamp_end} ) =
82
start_end_day($timestamp);
87
sub archive_group_iter {
89
my ( $ctx, $args ) = @_;
90
my $blog = $ctx->stash('blog');
92
( $args->{sort_order} || '' ) eq 'ascend' ? 'ascend' : 'descend';
93
my $auth_order = $args->{sort_order} ? $args->{sort_order} : 'ascend';
94
my $order = ( $sort_order eq 'ascend' ) ? 'asc' : 'desc';
95
my $limit = exists $args->{lastn} ? delete $args->{lastn} : undef;
97
my $tmpl = $ctx->stash('template');
101
my $ts = $ctx->{current_timestamp};
102
my $tsend = $ctx->{current_timestamp_end};
104
my $at = $ctx->{archive_type};
105
my $archiver = MT->publisher->archiver($at);
108
# if (($tmpl && $tmpl->type ne 'index') &&
109
# ($archiver && $archiver->author_based))
111
$author = $ctx->stash('author');
118
my $count_iter = MT::Entry->count_group_by(
120
blog_id => $blog->id,
121
author_id => $auth->id,
122
status => MT::Entry::RELEASE(),
123
( $ts && $tsend ? ( authored_on => [ $ts, $tsend ] ) : () ),
126
( $ts && $tsend ? ( range_incl => { authored_on => 1 } ) : () ),
128
"extract(year from authored_on)",
129
"extract(month from authored_on)",
130
"extract(day from authored_on)"
133
{ column => 'extract(year from authored_on)', desc => $order },
134
{ column => 'extract(month from authored_on)', desc => $order },
135
{ column => 'extract(day from authored_on)', desc => $order }
138
) or return $ctx->error("Couldn't get monthly archive list");
140
while ( my @row = $count_iter->() ) {
148
push( @data, $hash );
150
if ( defined($limit) && ( $count + 1 ) == $limit );
156
# Count entry by author
158
$loop_sub->($author);
165
$iter = MT::Author->load_iter(
169
direction => $auth_order,
171
'MT::Entry', 'author_id',
172
{ status => MT::Entry::RELEASE(), blog_id => $blog->id },
178
while ( my $a = $iter->() ) {
180
last if ( defined($limit) && $count == $limit );
188
if ( $curr < $loop ) {
190
"%04d%02d%02d000000",
191
$data[$curr]->{year},
192
$data[$curr]->{month},
195
my ( $start, $end ) = start_end_day($date);
196
my $count = $data[$curr]->{count};
198
author => $data[$curr]->{author},
199
year => $data[$curr]->{year},
200
month => $data[$curr]->{month},
201
day => $data[$curr]->{day},
206
return ( $count, %hash );
212
sub archive_group_entries {
214
my ( $ctx, %param ) = @_;
217
? sprintf( "%04d%02d%02d000000", $param{year}, $param{month},
219
: $ctx->stash('current_timestamp');
220
my $author = $param{author} || $ctx->stash('author');
221
my $limit = $param{limit};
222
$obj->dated_author_entries( $ctx, 'Author-Daily', $author, $ts, $limit );
225
sub archive_entries_count {
227
my ( $blog, $at, $entry ) = @_;
228
my $auth = $entry->author;
229
return $obj->SUPER::archive_entries_count(
233
Timestamp => $entry->authored_on,
239
*date_range = \&MT::ArchiveType::Daily::date_range;
240
*next_archive_entry = \&MT::ArchiveType::Date::next_archive_entry;
241
*previous_archive_entry = \&MT::ArchiveType::Date::previous_archive_entry;