# # 2ch風のIDを表示するプラグイン # # Copyright (c) 2010 initial-t # # 使い方:<$MTCommentIP ID_2ch="1"$> # package MT::Plugin::ID_2ch; use strict; use Digest::MD5 qw(md5_hex); use MT::Template::Context; my $plugin = new MT::Plugin(); $plugin->name( 'ID_2ch' ); $plugin->description( '2ch風のIDを表示します。' ); $plugin->version( '1.00' ); $plugin->author_name( 'initial-t' ); $plugin->author_link('http://gika.s206.xrea.com/'); $plugin->plugin_link('http://gika.s206.xrea.com/reference:index'); $plugin->doc_link('http://gika.s206.xrea.com/reference:id_2ch'); MT->add_plugin ($plugin); MT::Template::Context->add_global_filter(ID_2ch => \&ID_2ch); sub ID_2ch { my ($str,$flag,$ctx) = @_; my ($str_md5, $key_md5, $id_md5, $id); if($flag){ $str_md5 = substr(md5_hex($str), 0, 30); $key_md5 = substr(md5_hex("keyword"), 0, 10); $id_md5 = md5_hex($str_md5.$key_md5); $id = substr(_base64($id_md5), 0, 8); return $id; } return $str; } sub _base64 { require MIME::Base64; return MIME::Base64::encode_base64(@_, ''); } 1;