1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$
package MT::ArchiveType::Author;
use strict;
use base qw( MT::ArchiveType );
use MT::Util qw( remove_html encode_html );
sub name {
return 'Author';
}
sub archive_label {
return MT->translate('AUTHOR_ADV');
}
sub default_archive_templates {
return [
{ label => 'author/author-basename/index.html',
template => 'author/%-a/%f',
default => 1
},
{ label => 'author/author_basename/index.html',
template => 'author/%a/%f'
},
];
}
sub dynamic_template {
return 'author/<$MTEntryAuthorID$>/<$MTEntryID$>';
}
sub template_params {
return {
archive_class => "author-archive",
'module_author-monthly_archives' => 1,
author_archive => 1,
archive_template => 1,
archive_listing => 1,
};
}
sub archive_title {
my $obj = shift;
my ($ctx) = @_;
my $a = $ctx->stash('author');
encode_html(
remove_html(
$a ? $a->nickname || MT->translate('(Display Name not set)') : ''
)
);
}
sub archive_file {
my $obj = shift;
my ( $ctx, %param ) = @_;
my $file_tmpl = $param{Template};
my $author = $ctx->{__stash}{author};
my $entry = $ctx->{__stash}{entry};
my $file;
my $this_author = $author ? $author : ( $entry ? $entry->author : undef );
return "" unless $this_author;
if ( !$file_tmpl ) {
$file = sprintf( "%s/index", $this_author->basename );
}
$file;
}
sub archive_group_iter {
my $obj = shift;
my ( $ctx, $args ) = @_;
my $blog = $ctx->stash('blog');
my $sort_order
= ( $args->{sort_order} || '' ) eq 'ascend' ? 'ascend' : 'descend';
my $auth_order = $args->{sort_order} ? $args->{sort_order} : 'ascend';
my $order = ( $sort_order eq 'ascend' ) ? 'asc' : 'desc';
my $limit = exists $args->{lastn} ? delete $args->{lastn} : undef;
require MT::Entry;
require MT::Author;
my $auth_iter = MT::Author->load_iter(
undef,
{ sort => 'name',
direction => $auth_order,
join => [
'MT::Entry', 'author_id',
{ status => MT::Entry::RELEASE(), blog_id => $blog->id },
{ unique => 1 }
]
}
);
my $i = 0;
return sub {
while ( my $a = $auth_iter->() ) {
last if defined($limit) && $i == $limit;
my $count = MT::Entry->count(
{ blog_id => $blog->id,
status => MT::Entry::RELEASE(),
author_id => $a->id
}
);
next if $count == 0 && !$args->{show_empty};
$i++;
return ( $count, author => $a );
}
undef;
};
}
sub archive_group_entries {
my $obj = shift;
my ( $ctx, %param ) = @_;
my $blog = $ctx->stash('blog');
my $a = $param{author} || $ctx->stash('author');
my $limit = $param{limit};
if ( $limit && ( $limit eq 'auto' ) ) {
my $blog = $ctx->stash('blog');
$limit = $blog->entries_on_index if $blog;
}
return [] unless $a;
require MT::Entry;
my @entries = MT::Entry->load(
{ blog_id => $blog->id,
author_id => $a->id,
status => MT::Entry::RELEASE()
},
{ 'sort' => 'authored_on',
'direction' => 'descend',
( $limit ? ( 'limit' => $limit ) : () ),
}
);
\@entries;
}
sub archive_entries_count {
my $obj = shift;
my ( $blog, $at, $entry ) = @_;
return $obj->SUPER::archive_entries_count(@_) unless $entry;
my $auth = $entry->author;
return $obj->SUPER::archive_entries_count(
{ Blog => $blog,
ArchiveType => $at,
Author => $auth
}
);
}
sub display_name {
my $obj = shift;
my ($ctx) = shift;
my $tmpl = $ctx->stash('template');
my $at = $ctx->{archive_type};
my $author = '';
if ( ( $tmpl && ( $tmpl->type eq 'index' || $tmpl->type eq 'widget' ) )
|| !$obj
|| ( $obj && !$obj->author_based )
|| !$ctx->{inside_archive_list} )
{
$author = $ctx->stash('author');
$author
= $author
? $author->nickname
? $author->nickname . ": "
: MT->translate('(Display Name not set)')
: '';
}
return $author;
}
sub author_based {
return 1;
}
sub group_based {
return 1;
}
1;
|