| | 31 | MT::Template::Context->add_container_tag(IPBanList => \&ipbanlist); |
| | 32 | MT::Template::Context->add_tag(IPBanListIP => \&ipbanlist_ip); |
| | 33 | } |
| | 34 | |
| | 35 | sub init_app { |
| | 36 | my ($plugin, $app) = @_; |
| | 37 | return unless $app->isa('MT::App::CMS'); |
| | 38 | $app->add_itemset_action({ |
| | 39 | type => 'ping', |
| | 40 | key => 'add_to_ipbanlist_ping', |
| | 41 | label => 'Add To IPBanList', |
| | 42 | code => \&add_to_ipbanlist_ping |
| | 43 | }); |
| | 44 | $app->add_itemset_action({ |
| | 45 | type => 'comment', |
| | 46 | key => 'add_to_ipbanlist_comment', |
| | 47 | label => 'Add To IPBanList', |
| | 48 | code => \&add_to_ipbanlist_comment |
| | 49 | }); |
| 68 | | sub _add_ipbanlist { |
| | 88 | sub add_to_ipbanlist_ping { |
| | 89 | my ($app) = @_; |
| | 90 | my @ids = $app->param('id') |
| | 91 | or return $app->error("Need pings to add to IPBanList"); |
| | 92 | for my $id (@ids) { |
| | 93 | my $ping = MT::TBPing->load($id, { cache_ok => 1 }); |
| | 94 | _add_to_ipbanlist($ping->blog_id, $ping->ip); |
| | 95 | } |
| | 96 | $app->call_return; |
| | 97 | } |
| | 98 | |
| | 99 | sub add_to_ipbanlist_comment { |
| | 100 | my ($app) = @_; |
| | 101 | my @ids = $app->param('id') |
| | 102 | or return $app->error("Need comments to add to IPBanList"); |
| | 103 | for my $id (@ids) { |
| | 104 | my $comment = MT::Comment->load($id, { cache_ok => 1 }); |
| | 105 | _add_to_ipbanlist($comment->blog_id, $comment->ip); |
| | 106 | } |
| | 107 | $app->call_return; |
| | 108 | } |
| | 109 | |
| | 110 | sub _add_to_ipbanlist { |
| | 120 | sub ipbanlist { |
| | 121 | my ($ctx, $args) = @_; |
| | 122 | my @blog_ids = defined $args->{blog_id} ? |
| | 123 | split /\s*,\s*/, $args->{blog_id} : [ $ctx->stash('blog_id') ]; |
| | 124 | my %ips; |
| | 125 | for my $blog_id (@blog_ids) { |
| | 126 | my @list = MT::IPBanList->load({ blog_id => $blog_id }); |
| | 127 | %ips = map { $_->ip => 1 } @list; |
| | 128 | } |
| | 129 | my @res; |
| | 130 | my $builder = $ctx->stash('builder'); |
| | 131 | my $tokens = $ctx->stash('tokens'); |
| | 132 | for my $ip (keys %ips) { |
| | 133 | local $ctx->{__stash}{'ipbanlist_ip'} = $ip; |
| | 134 | defined(my $out = $builder->build($ctx, $tokens)) |
| | 135 | or return $ctx->error($ctx->errstr); |
| | 136 | push @res, $out; |
| | 137 | } |
| | 138 | my $glue = $args->{glue} || ''; |
| | 139 | join $glue, @res; |
| | 140 | } |
| | 141 | |
| | 142 | sub ipbanlist_ip { |
| | 143 | $_[0]->stash('ipbanlist_ip') || ''; |
| | 144 | } |
| | 145 | |