use strict; package MT::Plugin::LinkedEntriesLimit; use base qw(MT::Plugin); use vars qw( $VERSION ); $VERSION = '1.1'; require MT::Plugin; require MT; use MT::Util qw( ts2epoch ); my $days = 2; my $plugin = MT::Plugin::LinkedEntriesLimit->new({ name => "LinkedEntriesLimit", description => 'Limit and sort the entries displayed in RightFields Linked Entry menus.', author_name => 'Kevin Shay', author_link => 'http://www.staggernation.com/', version => $VERSION, }); MT->add_plugin($plugin); MT->add_callback('MT::App::CMS::AppTemplateParam.edit_entry', 10, $plugin, \&edit_entry_param); my $list_cache = {}; sub edit_entry_param { my ($cb, $app, $param) = @_; my $cutoff = time() - ($days * 24 * 60 * 60); for my $row (@{$param->{'rf_loop'}}) { next unless (my $entries = $row->{'entries'}); my $new_entries = []; my $blog_id = $entries->[0]->{'blog_id'}; if ($list_cache->{$blog_id}) { $row->{'entries'} = $list_cache->{$blog_id}; next; } my $blog = MT::Blog->load($blog_id); for my $entry_row (@$entries) { my $e = MT::Entry->load($entry_row->{'id'}); my $e_date = ts2epoch($blog, $e->created_on); next if ($e_date < $cutoff); $entry_row->{'created_on'} = $e->created_on; push(@$new_entries, $entry_row); } @$new_entries = sort { $b->{'created_on'} cmp $a->{'created_on'} } @$new_entries; $row->{'entries'} = $new_entries; $list_cache->{$blog_id} = $new_entries; } } 1;