| | 143 | sub related_tags { |
| | 144 | my ($ctx, $args, $cond) = @_; |
| | 145 | my $tag = $ctx->stash('Tag') or return ''; |
| | 146 | my $blog_id = $ctx->stash('blog_id') or return ''; |
| | 147 | |
| | 148 | my @otags = MT::ObjectTag->load({ |
| | 149 | blog_id => $blog_id, |
| | 150 | tag_id => $tag->id, |
| | 151 | object_datasource => MT::Entry->datasource, |
| | 152 | }); |
| | 153 | my @eids = map { $_->object_id } @otags; |
| | 154 | |
| | 155 | my $iter = MT::Tag->load_iter(undef, { |
| | 156 | sort => 'name', |
| | 157 | join => ['MT::ObjectTag', 'tag_id', { |
| | 158 | blog_id => $blog_id, |
| | 159 | object_id => \@eids, |
| | 160 | object_datasource => MT::Entry->datasource, |
| | 161 | }, { |
| | 162 | unique => 1, |
| | 163 | } ] }); |
| | 164 | |
| | 165 | my @res; |
| | 166 | my $builder = $ctx->stash('builder'); |
| | 167 | my $tokens = $ctx->stash('tokens'); |
| | 168 | while (my $t = $iter->()) { |
| | 169 | next if $t->is_private || ($t->id == $tag->id); |
| | 170 | local $ctx->{__stash}{Tag} = $t; |
| | 171 | local $ctx->{__stash}{tag_count} = undef; |
| | 172 | local $ctx->{__stash}{tag_entry_count} = undef; |
| | 173 | defined(my $out = $builder->build($ctx, $tokens)) |
| | 174 | or return $ctx->error($ctx->errstr); |
| | 175 | push @res, $out; |
| | 176 | } |
| | 177 | my $glue = $args->{glue} || ''; |
| | 178 | join $glue, @res; |
| | 179 | } |
| | 180 | |