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
|
# 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;
use strict;
use MT::WeblogPublisher;
sub new {
my $pkg = shift;
my $self = {@_};
bless $self, $pkg;
}
sub _getset {
my $self = shift;
my $name = shift;
@_ ? $self->{$name} = $_[0] : $self->{$name};
}
sub _getset_coderef {
my ( $obj, $key, @param ) = @_;
# We only do this weird thing for MT::ArchiveType, which for MT 4
# allowed assignment of a coderef to the base MT::ArchiveType class.
# With MT 4.2 and later, this routine should be overridden by a
# subclass, and therefore, shouldn't do anything by itself.
if ( ref($obj) eq __PACKAGE__ ) {
if ( @param && ref( $param[0] ) eq 'CODE' ) {
$obj->_getset( $key, @param );
return;
}
if ( my $code = $obj->_getset($key) ) {
return $code->(@param);
}
}
return;
}
sub name { shift->_getset( 'name', @_ ) }
# The base class routine should handle coderef assignment
# calling date_range with other parameters invokes this routine
# and returns the result
sub archive_group_iter {
shift->_getset_coderef( 'archive_group_iter', @_ );
}
sub archive_group_entries {
shift->_getset_coderef( 'archive_group_entries', @_ );
}
sub archive_file {
shift->_getset_coderef( 'archive_file', @_ );
}
sub archive_title {
shift->_getset_coderef( 'archive_title', @_ );
}
sub archive_label {
shift->_getset_coderef( 'archive_label', @_ );
}
sub group_based {
my $obj = shift;
if ( ref($obj) eq __PACKAGE__ ) {
return $obj->_getset('archive_group_entries') ? 1 : 0;
}
return 0;
}
sub default_archive_templates {
shift->_getset( 'default_archive_templates', @_ );
}
sub dynamic_template { shift->_getset( 'dynamic_template', @_ ) }
sub entry_class { shift->_getset( 'entry_class', @_ ) || 'entry' }
sub category_class { shift->_getset( 'category_class', @_ ) || 'category' }
sub template_params { shift->_getset('template_params') }
sub dynamic_support {
my $obj = shift;
if ( ref $obj ne __PACKAGE__ ) {
return 1; # assume support unless overridden
}
$obj->_getset( 'dynamic_support', @_ );
}
sub category_based {
my $obj = shift;
if ( ref $obj ne __PACKAGE__ ) {
return $obj->isa('MT::ArchiveType::Category');
}
return $obj->_getset( 'category_based', @_ );
}
sub entry_based {
my $obj = shift;
if ( ref $obj ne __PACKAGE__ ) {
return $obj->isa('MT::ArchiveType::Individual');
}
return $obj->_getset( 'entry_based', @_ );
}
sub date_based {
my $obj = shift;
if ( ref $obj ne __PACKAGE__ ) {
return $obj->isa('MT::ArchiveType::Date');
}
return $obj->_getset( 'date_based', @_ );
}
sub author_based {
my $obj = shift;
if ( ref $obj ne __PACKAGE__ ) {
return $obj->isa('MT::ArchiveType::Author');
}
return $obj->_getset( 'author_based', @_ );
}
sub archive_entries_count {
my $self = shift;
return $self->_getset_coderef( 'archive_entries_count', @_ )
if ref($self) eq __PACKAGE__;
my ($params) = @_;
my $blog = $params->{Blog};
my $at = $params->{ArchiveType};
my $ts = $params->{Timestamp};
my $cat = $params->{Category};
my $auth = $params->{Author};
my ( $start, $end );
if ($ts) {
my $archiver = MT->publisher->archiver($at);
( $start, $end ) = $archiver->date_range($ts) if $archiver;
}
my $count = MT->model('entry')->count(
{ blog_id => $blog->id,
status => MT::Entry::RELEASE(),
( $ts ? ( authored_on => [ $start, $end ] ) : () ),
( $auth ? ( author_id => $auth->id ) : () ),
},
{ ( $ts ? ( range_incl => { authored_on => 1 } ) : () ),
( $cat
? ( 'join' => [
'MT::Placement', 'entry_id',
{ category_id => $cat->id }
]
)
: ()
),
}
);
return $count;
}
# For user-defined date-based archive types
sub date_range {
shift->_getset_coderef( 'date_range', @_ );
}
sub next_archive_entry {
shift->_getset_coderef( 'next_archive_entry', @_ );
}
sub previous_archive_entry {
shift->_getset_coderef( 'previous_archive_entry', @_ );
}
1;
|