Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: lib/MT/Page.pm
- ===================================================================
- --- lib/MT/Page.pm (revision 1587)
- +++ lib/MT/Page.pm (working copy)
- @@ -64,10 +64,4 @@
- return ($page->permalink(@_));
- }
- -# This routine is declared to avoid building 'previous'/'next' pages
- -# by MT's rebuild process.
- -sub get_entry {
- - return undef;
- -}
- -
- 1;
- Index: lib/MT/ArchiveType/Date.pm
- ===================================================================
- --- lib/MT/ArchiveType/Date.pm (revision 1587)
- +++ lib/MT/ArchiveType/Date.pm (working copy)
- @@ -79,7 +79,7 @@
- my $archiver = MT->publisher->archiver($at);
- my ( $start, $end );
- if ($ts) {
- - ( $start, $end ) = $archiver->date_range->($ts);
- + ( $start, $end ) = $archiver->date_range($ts);
- }
- else {
- $start = $ctx->{current_timestamp};
- @@ -101,4 +101,44 @@
- \@entries;
- }
- +# get an entry in the next or previous archive for dated-based ArchiveType
- +
- +sub next_archive_entry { $_[0]->adjacent_archive_entry({ %{$_[1]}, order => 'next' }) }
- +sub previous_archive_entry { $_[0]->adjacent_archive_entry({ %{$_[1]}, order => 'previous' }) }
- +
- +sub adjacent_archive_entry {
- + my $obj = shift;
- + my ( $param ) = @_;
- +
- + my $order = ( $param->{order} eq 'previous' ) ? 'descend' : 'ascend';
- + my $cat = $param->{category} if $obj->category_based;
- + my $author = $param->{author} if $obj->author_based;
- +
- + my $ts = $param->{ts};
- + my $blog_id = $param->{blog_id} || ($param->{blog} ? $param->{blog}->id : undef);
- +
- + # if $param->{entry} given, override $ts and $blog_id.
- + if (my $e = $param->{entry}) {
- + $ts = $e->authored_on;
- + $blog_id = $e->blog_id;
- + }
- + my ( $start, $end ) = $obj->date_range($ts);
- + $ts = ( $order eq 'descend' ) ? $start : $end;
- +
- + require MT::Entry;
- + require MT::Placement;
- + my $entry = MT::Entry->load({
- + status => MT::Entry::RELEASE(),
- + $blog_id ? ( blog_id => $blog_id ) : (),
- + $author ? ( author_id => $author->id ) : (),
- + }, {
- + limit => 1,
- + 'sort' => 'authored_on',
- + direction => $order,
- + start_val => $ts,
- + $cat ? ( 'join' => [ 'MT::Placement', 'entry_id', { category_id => $cat->id } ] ) : (),
- + });
- + $entry;
- +}
- +
- 1;
- Index: lib/MT/ArchiveType.pm
- ===================================================================
- --- lib/MT/ArchiveType.pm (revision 1587)
- +++ lib/MT/ArchiveType.pm (working copy)
- @@ -9,11 +9,6 @@
- use strict;
- use MT::WeblogPublisher;
- -our %ArchiveTypes;
- -BEGIN {
- - *ArchiveTypes = *MT::WeblogPublisher::ArchiveTypes;
- -}
- -
- sub new {
- my $pkg = shift;
- my $self = {@_};
- @@ -138,8 +133,7 @@
- my $auth = $params->{Author};
- my ( $start, $end );
- if ($ts) {
- - MT::WeblogPublisher::init_archive_types() unless %ArchiveTypes;
- - my $archiver = $ArchiveTypes{$at};
- + my $archiver = MT->publisher->archiver($at);
- ( $start, $end ) = $archiver->date_range($ts) if $archiver;
- }
- Index: lib/MT/Template/ContextHandlers.pm
- ===================================================================
- --- lib/MT/Template/ContextHandlers.pm (revision 1587)
- +++ lib/MT/Template/ContextHandlers.pm (working copy)
- @@ -5568,46 +5565,6 @@
- $fb ? $fb->junk_score || 0 : '';
- }
- -## Archives
- -sub _get_adjacent_category_entry {
- - my($ts, $cat, $order) = @_;
- - if ($order eq 'previous') {
- - $order = 'descend';
- - } else {
- - $order = 'ascend';
- - }
- - require MT::Entry;
- - require MT::Placement;
- - my $entry = MT::Entry->load(
- - { status => MT::Entry::RELEASE() },
- - { limit => 1,
- - 'sort' => 'authored_on',
- - direction => $order,
- - start_val => $ts,
- - 'join' => [ 'MT::Placement', 'entry_id',
- - { category_id => $cat->id } ] });
- - $entry;
- -}
- -
- -sub _get_adjacent_author_entry {
- - my($ts, $blog_id, $author, $order) = @_;
- - if ($order eq 'previous') {
- - $order = 'descend';
- - } else {
- - $order = 'ascend';
- - }
- - require MT::Entry;
- - my $entry = MT::Entry->load(
- - { status => MT::Entry::RELEASE(),
- - author_id => $author->id,
- - blog_id => $blog_id },
- - { limit => 1,
- - 'sort' => 'authored_on',
- - direction => $order,
- - start_val => $ts});
- - $entry;
- -}
- -
- sub _hdlr_archive_prev_next {
- my($ctx, $args, $cond) = @_;
- my $tag = lc $ctx->stash('tag');
- @@ -5617,26 +5574,21 @@
- my $arctype = MT->publisher->archiver($at);
- return '' unless $arctype;
- - my ($start, $end, $entry);
- + my $entry;
- if ($arctype->date_based && $arctype->category_based) {
- - my $cat = $ctx->stash('archive_category');
- - $start = $ctx->{current_timestamp};
- - $end = $ctx->{current_timestamp_end};
- - if ($is_prev) {
- - $entry = _get_adjacent_category_entry( $start, $cat, 'previous' );
- - } else {
- - $entry = _get_adjacent_category_entry( $end, $cat, 'next' );
- - }
- + my $param = {
- + ts => $ctx->{current_timestamp},
- + blog_id => $ctx->stash('blog_id'),
- + category => $ctx->stash('archive_category'),
- + };
- + $entry = $is_prev ? $arctype->previous_archive_entry($param) : $arctype->previous_archive_entry($param);
- } elsif ($arctype->date_based && $arctype->author_based) {
- - my $author = $ctx->stash('author');
- - my $blog = $ctx->stash('blog');
- - $start = $ctx->{current_timestamp};
- - $end = $ctx->{current_timestamp_end};
- - if ($is_prev) {
- - $entry = _get_adjacent_author_entry( $start, $blog->id, $author, 'previous' );
- - } else {
- - $entry = _get_adjacent_author_entry( $end, $blog->id, $author, 'next' );
- - }
- + my $param = {
- + ts => $ctx->{current_timestamp},
- + blog_id => $ctx->stash('blog_id'),
- + author => $ctx->stash('author'),
- + };
- + $entry = $is_prev ? $arctype->previous_archive_entry($param) : $arctype->previous_archive_entry($param);
- } elsif ($arctype->category_based) {
- return _hdlr_category_prevnext(@_);
- } elsif ($arctype->author_based) {
- @@ -5661,9 +5613,11 @@
- "[_1] can be used only with Daily, Weekly, or Monthly archives.",
- "<MT$tag>" ))
- unless $arctype->date_based;
- - my @arg = ($ts, $ctx->stash('blog_id'), $at);
- - push @arg, $is_prev ? 'previous' : 'next';
- - $entry = get_entry(@arg);
- + my $param = {
- + ts => $ts,
- + blog_id => $ctx->stash('blog_id'),
- + };
- + $entry = $is_prev ? $arctype->previous_archive_entry($param) : $arctype->previous_archive_entry($param);
- }
- if ($entry) {
- my $builder = $ctx->stash('builder');
- Index: lib/MT/WeblogPublisher.pm
- ===================================================================
- --- lib/MT/WeblogPublisher.pm (revision 1587)
- +++ lib/MT/WeblogPublisher.pm (working copy)
- @@ -377,7 +377,7 @@
- }
- return 1 if $blog->is_dynamic;
- - my $at = $blog->archive_type;
- + my $at = $param{PreferredArchiveOnly} ? $blog->archive_type_preferred : $blog->archive_type;
- if ( $at && $at ne 'None' ) {
- my @at = split /,/, $at;
- for my $at (@at) {
- @@ -430,22 +430,24 @@
- if ( $param{BuildDependencies} ) {
- ## Rebuild previous and next entry archive pages.
- if ( my $prev = $entry->previous(1) ) {
- - $mt->rebuild_entry( Entry => $prev ) or return;
- + $mt->rebuild_entry( Entry => $prev, PreferredArchiveOnly => 1 ) or return;
- ## Rebuild the old previous and next entries, if we have some.
- if ( $param{OldPrevious}
- + && ( $param{OldPrevious} != $prev->id )
- && ( my $old_prev = MT::Entry->load( $param{OldPrevious} ) ) )
- {
- - $mt->rebuild_entry( Entry => $old_prev ) or return;
- + $mt->rebuild_entry( Entry => $old_prev, PreferredArchiveOnly => 1 ) or return;
- }
- }
- if ( my $next = $entry->next(1) ) {
- - $mt->rebuild_entry( Entry => $next ) or return;
- + $mt->rebuild_entry( Entry => $next, PreferredArchiveOnly => 1 ) or return;
- if ( $param{OldNext}
- + && ( $param{OldNext} != $next->id )
- && ( my $old_next = MT::Entry->load( $param{OldNext} ) ) )
- {
- - $mt->rebuild_entry( Entry => $old_next ) or return;
- + $mt->rebuild_entry( Entry => $old_next, PreferredArchiveOnly => 1 ) or return;
- }
- }
- }
- @@ -465,12 +467,14 @@
- my @db_at = grep { my $archiver = $mt->archiver($_); $archiver && $archiver->date_based } $mt->archive_types;
- for my $at (@db_at) {
- if ( $at{$at} ) {
- - my @arg = ( $entry->authored_on, $entry->blog_id, $at );
- my $archiver = $mt->archiver($at);
- - if ( my $prev_arch = $mt->get_entry( @arg, 'previous' ) ) {
- - if ( $archiver->category_based ) {
- - my $cats = $prev_arch->categories;
- - for my $cat (@$cats) {
- + if ( $archiver->category_based ) {
- + my $cats = $entry->categories;
- + for my $cat (@$cats) {
- + if ( my $prev_arch = $archiver->previous_archive_entry({
- + entry => $entry,
- + category => $cat,
- + }) ) {
- $mt->_rebuild_entry_archive_type(
- NoStatic => $param{NoStatic},
- Entry => $prev_arch,
- @@ -482,24 +486,10 @@
- ArchiveType => $at
- ) or return;
- }
- - }
- - else {
- - $mt->_rebuild_entry_archive_type(
- - NoStatic => $param{NoStatic},
- - Entry => $prev_arch,
- - Blog => $blog,
- - ArchiveType => $at,
- - $param{TemplateMap}
- - ? ( TemplateMap => $param{TemplateMap} )
- - : (),
- - Author => $prev_arch->author
- - ) or return;
- - }
- - }
- - if ( my $next_arch = $mt->get_entry( @arg, 'next' ) ) {
- - if ( $archiver->category_based ) {
- - my $cats = $next_arch->categories;
- - for my $cat (@$cats) {
- + if ( my $next_arch = $archiver->next_archive_entry({
- + entry => $entry,
- + category => $cat,
- + }) ) {
- $mt->_rebuild_entry_archive_type(
- NoStatic => $param{NoStatic},
- Entry => $next_arch,
- @@ -512,16 +502,35 @@
- ) or return;
- }
- }
- - else {
- + } else {
- + if ( my $prev_arch = $archiver->previous_archive_entry({
- + entry => $entry,
- + $archiver->author_based ? (author => $entry->author) : (),
- + }) ) {
- $mt->_rebuild_entry_archive_type(
- NoStatic => $param{NoStatic},
- + Entry => $prev_arch,
- + Blog => $blog,
- + ArchiveType => $at,
- + $param{TemplateMap}
- + ? ( TemplateMap => $param{TemplateMap} )
- + : (),
- + $archiver->author_based ? (Author => $entry->author) : (),
- + ) or return;
- + }
- + if ( my $next_arch = $archiver->next_archive_entry({
- + entry => $entry,
- + $archiver->author_based ? (author => $entry->author) : (),
- + }) ) {
- + $mt->_rebuild_entry_archive_type(
- + NoStatic => $param{NoStatic},
- Entry => $next_arch,
- Blog => $blog,
- ArchiveType => $at,
- $param{TemplateMap}
- ? ( TemplateMap => $param{TemplateMap} )
- : (),
- - Author => $next_arch->author
- + $archiver->author_based ? (Author => $entry->author) : (),
- ) or return;
- }
- }
- @@ -740,8 +749,6 @@
- my $archiver = $mt->archiver($at);
- return unless $archiver;
- - my $fmgr = $blog->file_mgr;
- -
- # Special handling for pages-- they are always published to the
- # 'site' path instead of the 'archive' path, which is reserved for blog
- # content.
Add Comment
Please, Sign In to add comment