Changeset 233

Show
Ignore:
Timestamp:
08/11/06 15:58:57 (2 years ago)
Author:
ogawa
Message:

Add encode_urlplus filter, MTTagLastUpdated tag, MTSearchTags tag.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • TagSupplementals/trunk/TagSupplementals.pl

    r226 r233  
    2222 
    2323BEGIN { 
    24     our $VERSION = '0.02'; 
     24    our $VERSION = '0.03'; 
    2525    $plugin = __PACKAGE__->new({ 
    2626        name => 'TagSupplementals Plugin', 
    2727        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', 
    2929        author_name => 'Hirotaka Ogawa', 
    3030        author_link => 'http://profile.typekey.com/ogawa/', 
     
    3333    MT->add_plugin($plugin); 
    3434    MT::Template::Context->add_tag(EntryTagsCount => \&entry_tags_count); 
     35    MT::Template::Context->add_tag(TagLastUpdated => \&tag_last_updated); 
    3536    MT::Template::Context->add_container_tag(RelatedEntries => \&related_entries); 
    3637    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); 
    3740 
    3841    eval { require MT::XSearch; $HAVE_MT_XSEARCH = 1 }; 
     
    5558    my @tags = $entry->get_tags; 
    5659    scalar @tags; 
     60} 
     61 
     62sub 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); 
    5782} 
    5883 
     
    180205} 
    181206 
     207sub encode_urlplus { 
     208    my $s = $_[0]; 
     209    return $s unless $_[1]; 
     210    $s =~ tr/ /+/; 
     211    MT::Util::encode_url($s); 
     212} 
     213 
     214sub 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 
    182239sub tag_xsearch_link { 
    183240    my ($ctx, $args, $cond) = @_;