Movable Typeでエントリーを保存するとメールが送信されるプラグイン
MTでエントリーを保存するとメールが送信されるプラグインを作ってみた。
つくりは、いろいろなプラグインを見ながら。もっとスマートな方法ありそうだなあ。
package MT::Plugin::PostAndMail; use strict; use MT; use MT::Plugin; use MT::Template::Context; use MT::Mail; @MT::Plugin::PostAndMail::ISA = qw(MT::Plugin); use vars qw($PLUGIN_NAME $VERSION); $PLUGIN_NAME = 'PostAndMail'; $VERSION = '0.1'; my $plugin = new MT::Plugin::PostAndMail({ name => $PLUGIN_NAME, version => $VERSION, author_name => 'd4-1977', author_link => 'http://d.hatena.ne.jp/d4-1977/', blog_config_template => \&template, settings => new MT::PluginSettings([ ['adminmailaddress'], ]), }); # MT->add_plugin($plugin); MT->add_callback('CMSPostSave.entry', 9, $plugin, \&post_save_entry); # sub instance { $plugin; } # sub template { my $tmpl = <<'TMPL'; <div class="setting"> <label>Admin Mail Address</label> <input type="text" name="adminmailaddress" value="<TMPL_VAR NAME=ADMINMAILADDRESS ESCAPE=HTML>" /> </div> TMPL } # sub adminmailaddress { my $plugin = shift; my ($blog_id) = @_; my %param; $plugin->load_config(\%param, 'blog:'.$blog_id); $param{adminmailaddress}; } sub post_save_entry { my ( $eh, $app, $obj, $original ) = @_; require MT::Entry; $obj->status == MT::Entry::RELEASE(); $original = $obj->status; my $status; if( $original == 1 ){ $status = '未公開'; }elsif( $original == 2 ){ $status = '公開'; }else{ $status = '不明'; } my $blog_id = $obj->blog_id; my $title = MT::I18N::encode_text($obj->title, undef, 'utf-8'); my $url = $obj->permalink; my $created = $obj->created_on; my $modified = $obj->modified_on; my $author = $obj->author; my $category = $obj->category; my $excerpt = $obj->excerpt; my $subject = '「' . $title . '」' . $status; my $sendmailaddress = $plugin->adminmailaddress($blog_id); my $frommailaddress = $plugin->adminmailaddress($blog_id); my $body = <<MAIL; 公開状態:$status ------------------------------------------------------------------------------------------------- 作成日 :$created 修正日 :$modified URL :$url タイトル:$title カテゴリ:$category 概要 : $excerpt ------------------------------------------------------------------------------------------------ MAIL my %head = ( To => $sendmailaddress, Subject => $subject, FROM => $frommailaddress ); MT::Mail->send(\%head, $body); } 1;