Changeset 233 for TagSupplementals/trunk/TagSupplementals.pl
- Timestamp:
- 08/11/06 15:58:57 (2 years ago)
- Files:
-
- 1 modified
-
TagSupplementals/trunk/TagSupplementals.pl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
TagSupplementals/trunk/TagSupplementals.pl
r226 r233 22 22 23 23 BEGIN { 24 our $VERSION = '0.0 2';24 our $VERSION = '0.03'; 25 25 $plugin = __PACKAGE__->new({ 26 26 name => 'TagSupplementals Plugin', 27 27 description => 'A plugin for providing supplemental features for MT 3.3 tags.', 28 doc_link => 'http:// as-is.net/wiki/TagSupplementals_Plugin',28 doc_link => 'http://code.as-is.net/wiki/TagSupplementals_Plugin', 29 29 author_name => 'Hirotaka Ogawa', 30 30 author_link => 'http://profile.typekey.com/ogawa/', … … 33 33 MT->add_plugin($plugin); 34 34 MT::Template::Context->add_tag(EntryTagsCount => \&entry_tags_count); 35 MT::Template::Context->add_tag(TagLastUpdated => \&tag_last_updated); 35 36 MT::Template::Context->add_container_tag(RelatedEntries => \&related_entries); 36 37 MT::Template::Context->add_container_tag(RelatedTags => \&related_tags); 38 MT::Template::Context->add_global_filter(encode_urlplus => \&encode_urlplus); 39 MT::Template::Context->add_container_tag(SearchTags => \&search_tags); 37 40 38 41 eval { require MT::XSearch; $HAVE_MT_XSEARCH = 1 }; … … 55 58 my @tags = $entry->get_tags; 56 59 scalar @tags; 60 } 61 62 sub tag_last_updated { 63 my ($ctx, $args) = @_; 64 my $tag = $ctx->stash('Tag') or return ''; 65 my $blog_id = $ctx->stash('blog_id') or return ''; 66 67 my ($e) = MT::Entry->load(undef, { 68 sort => 'created_on', 69 direction => 'descend', 70 limit => 1, 71 join => [ 'MT::ObjectTag', 'object_id', { 72 tag_id => $tag->id, 73 blog_id => $blog_id, 74 object_datasource => MT::Entry->datasource, 75 }, { 76 unique => 1, 77 } ] }) 78 or return ''; 79 80 $args->{ts} = $e->created_on; 81 MT::Template::Context::_hdlr_date($ctx, $args); 57 82 } 58 83 … … 180 205 } 181 206 207 sub encode_urlplus { 208 my $s = $_[0]; 209 return $s unless $_[1]; 210 $s =~ tr/ /+/; 211 MT::Util::encode_url($s); 212 } 213 214 sub search_tags { 215 my ($ctx, $args, $cond) = @_; 216 217 return '' unless $ctx->stash('search_string') =~ /\S/; 218 my $tags = $ctx->stash('search_string'); 219 my @tag_names = MT::Tag->split(',', $tags); 220 # my %tags = map { $_ => 1, MT::Tag->normalize($_) => 1 } @tag_names; 221 # my @tags = MT::Tag->load({ name => [ keys %tags ] }); 222 my @tags = MT::Tag->load({ name => @tag_names }); 223 return '' unless scalar @tags; 224 225 my @res; 226 my $builder = $ctx->stash('builder'); 227 my $tokens = $ctx->stash('tokens'); 228 foreach (@tags) { 229 local $ctx->{__stash}{'Tag'} = $_; 230 local $ctx->{__stash}{tag_count} = undef; 231 defined(my $out = $builder->build($ctx, $tokens, $cond)) 232 or return $ctx->error($ctx->errstr); 233 push @res, $out; 234 } 235 my $glue = $args->{glue} || ''; 236 join $glue, @res; 237 } 238 182 239 sub tag_xsearch_link { 183 240 my ($ctx, $args, $cond) = @_;
![(please configure the [header_logo] section in trac.ini)](/public/chrome/common/trac_banner.png)