Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sub filter_blogs {
    my ( $ctx, $args ) = @_;
    my $local_blog_id = $ctx->stash('local_blog_id');
    my (%terms, %args, %blog_can_access, $disallowed);

    $ctx->set_blog_load_context($args, \%terms, \%args)
        or return $ctx->error($ctx->errstr);

    # Create access lookup map of specified blogs
    require MT::Blog;
    my $iter = MT::Blog->load_iter(\%terms, \%args);
    while (my $blog = $iter->()) {
        $blog_can_access{$blog->id} = _can_access( $local_blog_id
                                                 ,  $blog->id    );
        $blog_can_access{$blog->id} or $disallowed++;                                                  
    }
    # If the number of disallowed is smaller than allowed
    # return the disallowed blogs with a flag instead of the 
    # allowed blogs