Changeset 274

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

Add MTHatenaKeyworkLink container.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • HatenaKeywordLink/trunk/plugins/HatenaKeywordLink/HatenaKeywordLink.pl

    r270 r274  
    1313use base 'MT::Plugin'; 
    1414use vars qw($VERSION); 
    15 $VERSION = '0.01'; 
     15$VERSION = '0.02'; 
    1616 
    1717my $plugin = __PACKAGE__->new({ 
    1818    name => 'HatenaKeywordLink', 
    1919    description => 'This plugin enables MT to set "Hatena Diary Keyword" links to the entry body.', 
    20     doc_link => 'http://code.as-is.net/wiki/HatenaKeywordLink', 
     20    doc_link => 'http://code.as-is.net/wiki/HatenaKeywordLink_Plugin', 
    2121    author_name => 'Hirotaka Ogawa', 
    2222    author_link => 'http://profile.typekey.com/ogawa/', 
     
    2929MT->add_plugin($plugin); 
    3030 
    31 # global filter 
     31# global filter and container 
    3232MT::Template::Context->add_global_filter('hatena_keyword_link', \&flt_link); 
     33MT::Template::Context->add_container_tag(HatenaKeywordLink => \&ctr_link); 
    3334 
    3435# pre_save handler 
     
    4243    my ($str, $val, $ctx) = @_; 
    4344    return $str unless $str && $val; 
     45 
     46    my $enc = MT::ConfigMgr->instance->PublishCharset; 
     47    my $text = rpc_setKeywordLink(encode_text($str, $enc, 'utf-8')); 
     48    return encode_text($text, 'utf-8', $enc) if $text; 
     49    $str; 
     50} 
     51 
     52sub ctr_link { 
     53    my ($ctx, $args, $cond) = @_; 
     54    my $builder = $ctx->stash('builder'); 
     55    my $tokens = $ctx->stash('tokens'); 
     56    defined(my $str = $builder->build($ctx, $tokens)) 
     57        or return $ctx->error($builder->errstr); 
    4458 
    4559    my $enc = MT::ConfigMgr->instance->PublishCharset;