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::Author;
10
use base qw( MT::ArchiveType );
17
return MT->translate('AUTHOR_ADV');
20
sub default_archive_templates {
23
label => 'author/author-display-name/index.html',
24
template => 'author/%-a/%f',
28
label => 'author/author_display_name/index.html',
29
template => 'author/%a/%f'
34
sub dynamic_template {
35
return 'author/<$MTEntryAuthorID$>/<$MTEntryID$>';
40
archive_class => "author-archive",
41
'module_author-monthly_archives' => 1,
43
archive_template => 1,
51
my $a = $ctx->stash('author');
52
$a ? $a->nickname || MT->translate( '(Display Name not set)' ) : '';
57
my ( $ctx, %param ) = @_;
58
my $file_tmpl = $param{Template};
59
my $author = $ctx->{__stash}{author};
60
my $entry = $ctx->{__stash}{entry};
63
my $this_author = $author ? $author : ( $entry ? $entry->author : undef );
64
return "" unless $this_author;
67
$file = sprintf( "%s/index", $this_author->basename );
72
sub archive_group_iter {
74
my ( $ctx, $args ) = @_;
75
my $blog = $ctx->stash('blog');
77
( $args->{sort_order} || '' ) eq 'ascend' ? 'ascend' : 'descend';
78
my $auth_order = $args->{sort_order} ? $args->{sort_order} : 'ascend';
79
my $order = ( $sort_order eq 'ascend' ) ? 'asc' : 'desc';
80
my $limit = exists $args->{lastn} ? delete $args->{lastn} : undef;
83
my $auth_iter = MT::Author->load_iter(
87
direction => $auth_order,
89
'MT::Entry', 'author_id',
90
{ status => MT::Entry::RELEASE(), blog_id => $blog->id },
98
while ( my $a = $auth_iter->() ) {
99
last if defined($limit) && $i == $limit;
100
my $count = MT::Entry->count(
102
blog_id => $blog->id,
103
status => MT::Entry::RELEASE(),
107
next if $count == 0 && !$args->{show_empty};
109
return ( $count, author => $a );
115
sub archive_group_entries {
117
my ( $ctx, %param ) = @_;
118
my $blog = $ctx->stash('blog');
119
my $a = $param{author} || $ctx->stash('author');
120
my $limit = $param{limit};
121
if ( $limit eq 'auto' ) {
122
my $blog = $ctx->stash('blog');
123
$limit = $blog->entries_on_index if $blog;
127
my @entries = MT::Entry->load(
129
blog_id => $blog->id,
131
status => MT::Entry::RELEASE()
134
'sort' => 'authored_on',
135
'direction' => 'descend',
136
( $limit ? ( 'limit' => $limit ) : () ),
142
sub archive_entries_count {
144
my ( $blog, $at, $entry ) = @_;
145
return $obj->SUPER::archive_entries_count(@_) unless $entry;
146
my $auth = $entry->author;
147
return $obj->SUPER::archive_entries_count(
159
my $tmpl = $ctx->stash('template');
160
my $at = $ctx->{archive_type};
162
if ( ( $tmpl && $tmpl->type eq 'index' )
164
|| ( $obj && !$obj->author_based )
165
|| !$ctx->{inside_archive_list} )
167
$author = $ctx->stash('author');
171
? $author->nickname . ": "
172
: MT->translate( '(Display Name not set)' )
186
sub date_based_author_entries {
188
my ( $ctx, $at, $author, $ts ) = @_;
190
my $blog = $ctx->stash('blog');
193
( $start, $end ) = $obj->date_range($ts);
196
$start = $ctx->{current_timestamp};
197
$end = $ctx->{current_timestamp_end};
199
my @entries = MT::Entry->load(
201
blog_id => $blog->id,
202
author_id => $author->id,
203
status => MT::Entry::RELEASE(),
204
authored_on => [ $start, $end ]
207
range => { authored_on => 1 },
208
'sort' => 'authored_on',
209
'direction' => 'descend',
211
) or return $ctx->error("Couldn't get $at archive list");