Guest User

Untitled

a guest
Apr 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.42 KB | None | 0 0
  1. Index: lib/MT/Page.pm
  2. ===================================================================
  3. --- lib/MT/Page.pm (revision 1587)
  4. +++ lib/MT/Page.pm (working copy)
  5. @@ -64,10 +64,4 @@
  6. return ($page->permalink(@_));
  7. }
  8.  
  9. -# This routine is declared to avoid building 'previous'/'next' pages
  10. -# by MT's rebuild process.
  11. -sub get_entry {
  12. - return undef;
  13. -}
  14. -
  15. 1;
  16. Index: lib/MT/ArchiveType/Date.pm
  17. ===================================================================
  18. --- lib/MT/ArchiveType/Date.pm (revision 1587)
  19. +++ lib/MT/ArchiveType/Date.pm (working copy)
  20. @@ -79,7 +79,7 @@
  21. my $archiver = MT->publisher->archiver($at);
  22. my ( $start, $end );
  23. if ($ts) {
  24. - ( $start, $end ) = $archiver->date_range->($ts);
  25. + ( $start, $end ) = $archiver->date_range($ts);
  26. }
  27. else {
  28. $start = $ctx->{current_timestamp};
  29. @@ -101,4 +101,44 @@
  30. \@entries;
  31. }
  32.  
  33. +# get an entry in the next or previous archive for dated-based ArchiveType
  34. +
  35. +sub next_archive_entry { $_[0]->adjacent_archive_entry({ %{$_[1]}, order => 'next' }) }
  36. +sub previous_archive_entry { $_[0]->adjacent_archive_entry({ %{$_[1]}, order => 'previous' }) }
  37. +
  38. +sub adjacent_archive_entry {
  39. + my $obj = shift;
  40. + my ( $param ) = @_;
  41. +
  42. + my $order = ( $param->{order} eq 'previous' ) ? 'descend' : 'ascend';
  43. + my $cat = $param->{category} if $obj->category_based;
  44. + my $author = $param->{author} if $obj->author_based;
  45. +
  46. + my $ts = $param->{ts};
  47. + my $blog_id = $param->{blog_id} || ($param->{blog} ? $param->{blog}->id : undef);
  48. +
  49. + # if $param->{entry} given, override $ts and $blog_id.
  50. + if (my $e = $param->{entry}) {
  51. + $ts = $e->authored_on;
  52. + $blog_id = $e->blog_id;
  53. + }
  54. + my ( $start, $end ) = $obj->date_range($ts);
  55. + $ts = ( $order eq 'descend' ) ? $start : $end;
  56. +
  57. + require MT::Entry;
  58. + require MT::Placement;
  59. + my $entry = MT::Entry->load({
  60. + status => MT::Entry::RELEASE(),
  61. + $blog_id ? ( blog_id => $blog_id ) : (),
  62. + $author ? ( author_id => $author->id ) : (),
  63. + }, {
  64. + limit => 1,
  65. + 'sort' => 'authored_on',
  66. + direction => $order,
  67. + start_val => $ts,
  68. + $cat ? ( 'join' => [ 'MT::Placement', 'entry_id', { category_id => $cat->id } ] ) : (),
  69. + });
  70. + $entry;
  71. +}
  72. +
  73. 1;
  74. Index: lib/MT/ArchiveType.pm
  75. ===================================================================
  76. --- lib/MT/ArchiveType.pm (revision 1587)
  77. +++ lib/MT/ArchiveType.pm (working copy)
  78. @@ -9,11 +9,6 @@
  79. use strict;
  80. use MT::WeblogPublisher;
  81.  
  82. -our %ArchiveTypes;
  83. -BEGIN {
  84. - *ArchiveTypes = *MT::WeblogPublisher::ArchiveTypes;
  85. -}
  86. -
  87. sub new {
  88. my $pkg = shift;
  89. my $self = {@_};
  90. @@ -138,8 +133,7 @@
  91. my $auth = $params->{Author};
  92. my ( $start, $end );
  93. if ($ts) {
  94. - MT::WeblogPublisher::init_archive_types() unless %ArchiveTypes;
  95. - my $archiver = $ArchiveTypes{$at};
  96. + my $archiver = MT->publisher->archiver($at);
  97. ( $start, $end ) = $archiver->date_range($ts) if $archiver;
  98. }
  99.  
  100. Index: lib/MT/Template/ContextHandlers.pm
  101. ===================================================================
  102. --- lib/MT/Template/ContextHandlers.pm (revision 1587)
  103. +++ lib/MT/Template/ContextHandlers.pm (working copy)
  104. @@ -5568,46 +5565,6 @@
  105. $fb ? $fb->junk_score || 0 : '';
  106. }
  107.  
  108. -## Archives
  109. -sub _get_adjacent_category_entry {
  110. - my($ts, $cat, $order) = @_;
  111. - if ($order eq 'previous') {
  112. - $order = 'descend';
  113. - } else {
  114. - $order = 'ascend';
  115. - }
  116. - require MT::Entry;
  117. - require MT::Placement;
  118. - my $entry = MT::Entry->load(
  119. - { status => MT::Entry::RELEASE() },
  120. - { limit => 1,
  121. - 'sort' => 'authored_on',
  122. - direction => $order,
  123. - start_val => $ts,
  124. - 'join' => [ 'MT::Placement', 'entry_id',
  125. - { category_id => $cat->id } ] });
  126. - $entry;
  127. -}
  128. -
  129. -sub _get_adjacent_author_entry {
  130. - my($ts, $blog_id, $author, $order) = @_;
  131. - if ($order eq 'previous') {
  132. - $order = 'descend';
  133. - } else {
  134. - $order = 'ascend';
  135. - }
  136. - require MT::Entry;
  137. - my $entry = MT::Entry->load(
  138. - { status => MT::Entry::RELEASE(),
  139. - author_id => $author->id,
  140. - blog_id => $blog_id },
  141. - { limit => 1,
  142. - 'sort' => 'authored_on',
  143. - direction => $order,
  144. - start_val => $ts});
  145. - $entry;
  146. -}
  147. -
  148. sub _hdlr_archive_prev_next {
  149. my($ctx, $args, $cond) = @_;
  150. my $tag = lc $ctx->stash('tag');
  151. @@ -5617,26 +5574,21 @@
  152. my $arctype = MT->publisher->archiver($at);
  153. return '' unless $arctype;
  154.  
  155. - my ($start, $end, $entry);
  156. + my $entry;
  157. if ($arctype->date_based && $arctype->category_based) {
  158. - my $cat = $ctx->stash('archive_category');
  159. - $start = $ctx->{current_timestamp};
  160. - $end = $ctx->{current_timestamp_end};
  161. - if ($is_prev) {
  162. - $entry = _get_adjacent_category_entry( $start, $cat, 'previous' );
  163. - } else {
  164. - $entry = _get_adjacent_category_entry( $end, $cat, 'next' );
  165. - }
  166. + my $param = {
  167. + ts => $ctx->{current_timestamp},
  168. + blog_id => $ctx->stash('blog_id'),
  169. + category => $ctx->stash('archive_category'),
  170. + };
  171. + $entry = $is_prev ? $arctype->previous_archive_entry($param) : $arctype->previous_archive_entry($param);
  172. } elsif ($arctype->date_based && $arctype->author_based) {
  173. - my $author = $ctx->stash('author');
  174. - my $blog = $ctx->stash('blog');
  175. - $start = $ctx->{current_timestamp};
  176. - $end = $ctx->{current_timestamp_end};
  177. - if ($is_prev) {
  178. - $entry = _get_adjacent_author_entry( $start, $blog->id, $author, 'previous' );
  179. - } else {
  180. - $entry = _get_adjacent_author_entry( $end, $blog->id, $author, 'next' );
  181. - }
  182. + my $param = {
  183. + ts => $ctx->{current_timestamp},
  184. + blog_id => $ctx->stash('blog_id'),
  185. + author => $ctx->stash('author'),
  186. + };
  187. + $entry = $is_prev ? $arctype->previous_archive_entry($param) : $arctype->previous_archive_entry($param);
  188. } elsif ($arctype->category_based) {
  189. return _hdlr_category_prevnext(@_);
  190. } elsif ($arctype->author_based) {
  191. @@ -5661,9 +5613,11 @@
  192. "[_1] can be used only with Daily, Weekly, or Monthly archives.",
  193. "<MT$tag>" ))
  194. unless $arctype->date_based;
  195. - my @arg = ($ts, $ctx->stash('blog_id'), $at);
  196. - push @arg, $is_prev ? 'previous' : 'next';
  197. - $entry = get_entry(@arg);
  198. + my $param = {
  199. + ts => $ts,
  200. + blog_id => $ctx->stash('blog_id'),
  201. + };
  202. + $entry = $is_prev ? $arctype->previous_archive_entry($param) : $arctype->previous_archive_entry($param);
  203. }
  204. if ($entry) {
  205. my $builder = $ctx->stash('builder');
  206. Index: lib/MT/WeblogPublisher.pm
  207. ===================================================================
  208. --- lib/MT/WeblogPublisher.pm (revision 1587)
  209. +++ lib/MT/WeblogPublisher.pm (working copy)
  210. @@ -377,7 +377,7 @@
  211. }
  212. return 1 if $blog->is_dynamic;
  213.  
  214. - my $at = $blog->archive_type;
  215. + my $at = $param{PreferredArchiveOnly} ? $blog->archive_type_preferred : $blog->archive_type;
  216. if ( $at && $at ne 'None' ) {
  217. my @at = split /,/, $at;
  218. for my $at (@at) {
  219. @@ -430,22 +430,24 @@
  220. if ( $param{BuildDependencies} ) {
  221. ## Rebuild previous and next entry archive pages.
  222. if ( my $prev = $entry->previous(1) ) {
  223. - $mt->rebuild_entry( Entry => $prev ) or return;
  224. + $mt->rebuild_entry( Entry => $prev, PreferredArchiveOnly => 1 ) or return;
  225.  
  226. ## Rebuild the old previous and next entries, if we have some.
  227. if ( $param{OldPrevious}
  228. + && ( $param{OldPrevious} != $prev->id )
  229. && ( my $old_prev = MT::Entry->load( $param{OldPrevious} ) ) )
  230. {
  231. - $mt->rebuild_entry( Entry => $old_prev ) or return;
  232. + $mt->rebuild_entry( Entry => $old_prev, PreferredArchiveOnly => 1 ) or return;
  233. }
  234. }
  235. if ( my $next = $entry->next(1) ) {
  236. - $mt->rebuild_entry( Entry => $next ) or return;
  237. + $mt->rebuild_entry( Entry => $next, PreferredArchiveOnly => 1 ) or return;
  238.  
  239. if ( $param{OldNext}
  240. + && ( $param{OldNext} != $next->id )
  241. && ( my $old_next = MT::Entry->load( $param{OldNext} ) ) )
  242. {
  243. - $mt->rebuild_entry( Entry => $old_next ) or return;
  244. + $mt->rebuild_entry( Entry => $old_next, PreferredArchiveOnly => 1 ) or return;
  245. }
  246. }
  247. }
  248. @@ -465,12 +467,14 @@
  249. my @db_at = grep { my $archiver = $mt->archiver($_); $archiver && $archiver->date_based } $mt->archive_types;
  250. for my $at (@db_at) {
  251. if ( $at{$at} ) {
  252. - my @arg = ( $entry->authored_on, $entry->blog_id, $at );
  253. my $archiver = $mt->archiver($at);
  254. - if ( my $prev_arch = $mt->get_entry( @arg, 'previous' ) ) {
  255. - if ( $archiver->category_based ) {
  256. - my $cats = $prev_arch->categories;
  257. - for my $cat (@$cats) {
  258. + if ( $archiver->category_based ) {
  259. + my $cats = $entry->categories;
  260. + for my $cat (@$cats) {
  261. + if ( my $prev_arch = $archiver->previous_archive_entry({
  262. + entry => $entry,
  263. + category => $cat,
  264. + }) ) {
  265. $mt->_rebuild_entry_archive_type(
  266. NoStatic => $param{NoStatic},
  267. Entry => $prev_arch,
  268. @@ -482,24 +486,10 @@
  269. ArchiveType => $at
  270. ) or return;
  271. }
  272. - }
  273. - else {
  274. - $mt->_rebuild_entry_archive_type(
  275. - NoStatic => $param{NoStatic},
  276. - Entry => $prev_arch,
  277. - Blog => $blog,
  278. - ArchiveType => $at,
  279. - $param{TemplateMap}
  280. - ? ( TemplateMap => $param{TemplateMap} )
  281. - : (),
  282. - Author => $prev_arch->author
  283. - ) or return;
  284. - }
  285. - }
  286. - if ( my $next_arch = $mt->get_entry( @arg, 'next' ) ) {
  287. - if ( $archiver->category_based ) {
  288. - my $cats = $next_arch->categories;
  289. - for my $cat (@$cats) {
  290. + if ( my $next_arch = $archiver->next_archive_entry({
  291. + entry => $entry,
  292. + category => $cat,
  293. + }) ) {
  294. $mt->_rebuild_entry_archive_type(
  295. NoStatic => $param{NoStatic},
  296. Entry => $next_arch,
  297. @@ -512,16 +502,35 @@
  298. ) or return;
  299. }
  300. }
  301. - else {
  302. + } else {
  303. + if ( my $prev_arch = $archiver->previous_archive_entry({
  304. + entry => $entry,
  305. + $archiver->author_based ? (author => $entry->author) : (),
  306. + }) ) {
  307. $mt->_rebuild_entry_archive_type(
  308. NoStatic => $param{NoStatic},
  309. + Entry => $prev_arch,
  310. + Blog => $blog,
  311. + ArchiveType => $at,
  312. + $param{TemplateMap}
  313. + ? ( TemplateMap => $param{TemplateMap} )
  314. + : (),
  315. + $archiver->author_based ? (Author => $entry->author) : (),
  316. + ) or return;
  317. + }
  318. + if ( my $next_arch = $archiver->next_archive_entry({
  319. + entry => $entry,
  320. + $archiver->author_based ? (author => $entry->author) : (),
  321. + }) ) {
  322. + $mt->_rebuild_entry_archive_type(
  323. + NoStatic => $param{NoStatic},
  324. Entry => $next_arch,
  325. Blog => $blog,
  326. ArchiveType => $at,
  327. $param{TemplateMap}
  328. ? ( TemplateMap => $param{TemplateMap} )
  329. : (),
  330. - Author => $next_arch->author
  331. + $archiver->author_based ? (Author => $entry->author) : (),
  332. ) or return;
  333. }
  334. }
  335. @@ -740,8 +749,6 @@
  336. my $archiver = $mt->archiver($at);
  337. return unless $archiver;
  338.  
  339. - my $fmgr = $blog->file_mgr;
  340. -
  341. # Special handling for pages-- they are always published to the
  342. # 'site' path instead of the 'archive' path, which is reserved for blog
  343. # content.
Add Comment
Please, Sign In to add comment