Web制作会社アークウェブのスタッフが、システム開発のTips・ノウハウをまとめているWikiです
Movable Type/第9回MTプラグイン勉強会 - registryのリファレンスを精読する(2)
第9回は第8回に続いてMovable Type Registry Referenceの精読の続きを行います。元のドキュメントが未完状態が多いため、各機能の具体的な指定方法といったことより、だいたいにどういったことができるのかといったことを確認することに主眼をおきます。
勉強会の模様をアップしました。 今回は確信をもっていえる内容に乏しいです(汗 勉強会の中でも言っていますが、使い方がよくわからないものは、ちょっとづつ実際につかって試してみていこうと思います(ドキュメントに書かれていないものを使っていいのかという疑問は常にありますが^^;)
Ustreamのチャンネルはこちら。 http://www.ustream.tv/channel/mt%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E5%8B%89%E5%BC%B7%E4%BC%9A
ご感想、ご質問などあればお気軽にどうぞ。頂けるととても励みになります。
registryで指定できるkeyとその解説。
※ 追加したカスタムパーミッションは自動的に管理画面のUIで指定できるようにはならない。当分の間、指定できるようにするためにはTransformerコールバックを用意する必要がある。
例)
$registry = { permissions => { 'system.create_blog' => { label => trans("Create Blogs"), group => 'sys_admin', order => 100, }, }, };
text_filters => { 'my_filter' => { # key label => 'Transform this Text', handler => 'MT::Foo::text_transform', }, }
Application Properties
applications => { 'ack' => { handler => 'MyApp::Ack', cgi_base => 'ack', list_actions => { 'entry' => { 'do_something' => { label => "Batch Do Something", order => 100, code => \&do_something, permission => 'edit_all_posts,publish_post', }, }, menus => { 'foo' => { label => "Create", order => 100, }, 'foo:bar' => { label => "Do Something", order => 100, mode => 'hdlr_bar', args => { _type => 'entry' }, permission => 'create_post', requires_blog => 1, }, }, methods => sub { MT->app->core_methods() }, }, };
How to Add a Mode to the CMS Component
$registry = { applications => { 'cms' => { methods => { myapp_new-mode => sub { // my handler // }, }, }, }, };,
※ コアや他のプラグイン等と重複を避けるために独自モード名の頭には固有の接頭辞をつけるようにすべき。
CMS Application Specific Stuff
import_formats => { 'import_mt_format' => { # key label => 'Another system (Movable Type format)', code => \&MT::ImportExport::import, options => [ 'title_start', 'title_end', 'default_status' ], options_template => 'import_others.tmpl', }, }, },
ドキュメントなし
一覧の絞込み(フィルタ)の定義か可能ということだと思います。
entry => { published => { label => 'Published entries', order => 100, handler => sub { my ( $terms, $args ) = @_; $terms->{status} = 2; }, }, received_comments_in_last_7_days => { label => 'Entries with comments in the last 7 days', order => 500, handler => sub { my ( $terms, $args ) = @_; my $ts = time - 10 * 24 * 60 * 60; $ts = MT::Util::epoch2ts( MT->app->blog, $ts ); $args->{join} = MT::Comment->join_on( 'entry_id', { created_on => [ $ts, undef ], }, { range_incl => { created_on => 1 }, } ); $args->{sort} = \'comment_created_on'; $args->{direction} = 'descend'; }, }, },
独自のアップグレード処理を定義できる??
upgrade_functions => { 'core_create_placements' => { version_limit => 2.0, priority => 9.1, updater => { type => 'entry', label => 'Creating entry category placements...', condition => sub { $_[0]->category_id }, code => sub { require MT::Placement; my $entry = shift; my $existing = MT::Placement->load({ entry_id => $entry->id, category_id => $entry->category_id }); if (!$existing) { my $place = MT::Placement->new; $place->entry_id($entry->id); $place->blog_id($entry->blog_id); $place->category_id($entry->category_id); $place->is_primary(1); $place->save; } $entry->category_id(0); }, }, }, }
独自テンプレートタグ、モディファイア(=global filter)の定義
tags => { block => { TagNameFoo => &foo_handler, }, function => { TagNameFoo => &foo_handler, }, modifier => { # attribute only, not a tag name - this is for global filters TagNameFoo => &foo_handler, }, }
Archive Type Properties
archive_types => { 'Weekly' => ArchiveType( name => 'Weekly', archive_label => \&weekly_archive_label, archive_file => \&weekly_archive_file, archive_title => \&weekly_archive_title, date_range => \&weekly_date_range, archive_group_iter => \&weekly_group_iter, archive_group_entries => \&weekly_group_entries, dynamic_template => 'archives/week/<$MTArchiveDate format="%Y%m%d"$>', default_archive_templates => [ ArchiveFileTemplate( label => MT->translate('yyyy/mm/day-week/index.html'), template => '%y/%m/%d-week/%i', default => 1 ), ], dynamic_support => 1, date_based => 1, ), }
コメントの独自の認証を定義できる??
commenter_authenticators => { 'OpenID' => { class => 'MT::Auth::OpenID', label => 'OpenID', login_form => <<OpenID, <form method="post" action="<mt:var name="script_url">"> <input type="hidden" name="__mode" value="login_external" /> <input type="hidden" name="blog_id" value="<mt:var name="blog_id">" /> <input type="hidden" name="entry_id" value="<mt:var name="entry_id">" /> <input type="hidden" name="static" value="<mt:var name="static" escape="html">" /> <fieldset> <mtapp:setting id="openid_display" label="<__trans phrase="OpenID URL">"> <input type="hidden" name="key" value="OpenID" /> <input name="openid_url" /> </mtapp:setting> <input type="submit" name="submit" value="<__trans phrase="Sign In">" /> </fieldset> </form> OpenID login_form_params => \&_commenter_auth_params, }, }
キャプチャを定義できる?
captcha_providers => { 'mt_default' => { label => 'Movable Type default', class => 'MT::Util::Captcha', } }
ドキュメントなし*3
次回はMT::App、MT::App::CMSのリファレンスの精読を予定します。
投稿者進地 | パーマリンク | コメント(0)
tag: Movable Type、MT、MT、MTPlugin、勉強会、A-Form