MT4.x¥×¥é¥°¥¤¥óºîÀ®/transformer¥×¥é¥°¥¤¥ó http://www.ark-web.jp/sandbox/wiki/301.html

MT4.x¥×¥é¥°¥¤¥óºîÀ®/transformer¥×¥é¥°¥¤¥ó

[edit]

Transfromer¥×¥é¥°¥¤¥ó¤È¤Ï¡©

Transformer¥×¥é¥°¥¤¥ó¤Ï´ÉÍý²èÌ̤ò³ÈÄ¥¡¢¥«¥¹¥¿¥Þ¥¤¥º¤¹¤ë¥×¥é¥°¥¤¥ó¤Ç¤¹¡£MT3.3¤«¤éÂбþ¤·¤Æ¤¤¤Þ¤¹¡£
MT3.2¤Þ¤Ç¤ÏBigAPI¥×¥é¥°¥¤¥ó¤ò»È¤Ã¤Æ´ÉÍý²èÌ̤γÈÄ¥¤ò¹Ô¤¨¤¿¡Ê¤é¤·¤¤^^;¡Ë

»²¹Í¡§MovableType3.3¤È4.0¤ÎξÊý¤ËÂбþ¤·¤¿Transformer¥×¥é¥°¥¤¥ó¤Î½ñ¤­Êý¡£

Transformer¥×¥é¥°¥¤¥ó¤ÎºîÀ®¤ÏMT4.0°ÊÁ°¤Ï

MT->add_callback('MT::App::CMS::AppTemplateSource.blog_left_nav', $priority, $plugin, \$code);

¤Î¤è¤¦¤Ê¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Î¥»¥Ã¥È¤ò¹Ô¤¤¡¢¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÃæ¤Ç´ÉÍý²èÌ̤Υƥó¥×¥ì¡¼¥È¤òÀµµ¬É½¸½¤ò»È¤Ã¤ÆÃÖ´¹¤·¤Æ¤¤¤¯¤è¤¦¤Ê¡Ú¤ï¤ê¤ÈÎϵ»¡Û¤ÎÊýË¡¤Ç¼Â¸½¤¹¤ë¤·¤«¤Ê¤«¤Ã¤¿¤è¤¦¤Ç¤¹¤¬¡¢MT4.0¤Ç¤Ï¤³¤ì¤Ë²Ã¤¨¤Æ¡¢¥Æ¥ó¥×¥ì¡¼¥È¤òDOM¥é¥¤¥¯¤ËÁàºî¤·¤Æ´ÉÍý²èÌ̤γÈÄ¥¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤é¤·¤¤¤Ç¤¹¡£

»²¹Í¡§MT4.0, CMS¤ÎÊѲ½¤ÈTransformer¥×¥é¥°¥¤¥ó¡£¡¢Movable Type v4.0 (Athena): A Developer's Perspective

[edit]

¥×¥é¥°¥¤¥ó¤Î´ðËܹ½Â¤

Transformer¥×¥é¥°¥¤¥ó¤Î´ðËܹ½Â¤¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¢¨ °Ê²¼¤ÏMT4.0°Ê¹ß¤ËÂбþ¤¹¤ëTransformer¥×¥é¥°¥¤¥ó¤Ç¡¢MT4.0̤Ëþ¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë¤ÏÂбþ¤·¤Æ¤¤¤Þ¤»¤ó¡£

# ¥×¥é¥°¥¤¥ó̾¤òMySample¤È¤¹¤ë¡£
package MT::Plugin::MySample;

use strict;
use MT;
use MT::Template::Context;

use vars qw($VERSION);
$VERSION = '0.1';

# MT::Plugin::MySample¤ÏMT::Plugin¤ò·Ñ¾µ¤¹¤ë
@MT::Plugin::MySample::ISA = qw(MT::Plugin);

# ¥×¥é¥°¥¤¥ó¤Î´ÉÍý¾ðÊó¡Ê¥á¥¿¾ðÊó¡Ë¤ò¥»¥Ã¥È
my $plugin = new MT::Plugin::MySample({
    name => 'MySample',    # ¥×¥é¥°¥¤¥ó̾
    version => $VERSION,   # ¥Ð¡¼¥¸¥ç¥ó
    description => 'My simple sample plugin', # ¥×¥é¥°¥¤¥ó¤Î´Êñ¤ÊÀâÌÀ
    author_name => 'SHINCHI, Takahiro',       # ¥×¥é¥°¥¤¥óºî¼Ô̾
    author_link => 'http://www.ark-web.jp/pluginexample/',  # ºî¼Ô¤ÎWeb¥µ¥¤¥È
    doc_link => 'http://www.ark-web.jp/pluginexample/doc/', # ¥×¥é¥°¥¤¥ó¤Î¥É¥­¥å¥á¥ó¥È¤ÎURL
});
MT->add_plugin($plugin);

# ¢¬¤³¤³¤Þ¤Ç¤Ç¡¢´ÉÍý²èÌ̤Υץ饰¥¤¥ó°ìÍ÷¤Ë¥ê¥¹¥È¤µ¤ì¤ë¥³¡¼¥É¤Ë¤Ê¤ë¡£
# ¡Ê¼ÂºÝ¤Ë¤Ï¥Õ¥¡¥¤¥ë¤ÎËöÈø¤Ë
#   1;
#   ¤È¤¤¤¦¹Ô¤òÄɲ䷤ơ¢plugins/MySample/
#   ¥Ç¥£¥ì¥¯¥È¥ê¤Ësample.pl¤Ê¤É¤ÎŬÅö¤Ê̾Á°¤ÇÊݸ¤¹¤ëɬÍפ¬¤¢¤ë¡£
#   ¥Õ¥¡¥¤¥ë̾¤ÏŬÅö¤Ç¤è¤¤¤¬¡¢¥Ç¥£¥ì¥¯¥È¥ê̾¤Ï¥×¥é¥°¥¤¥ó̾¤È°ìÃפ¹¤ëɬÍפ¬¤¢¤ë¡Ë

# ¢­°Ê²¼¤¬Transformer¥×¥é¥°¥¤¥óÆÃÍ­¤Î½èÍý

my $priority = 9;    # ¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤¬¼Â¹Ô¤µ¤ì¤ëÍ¥Àè½ç°Ì¤ò1¤«¤é10¤ÎÈϰϤοôÃͤǻØÄê
my $pagename = '';   # ¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë̾

# ¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÅÐÏ¿

# ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤¬»ØÄꤷ¤¿¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ó¤ÀºÝ¤Ë
# Æɤ߹þ¤ó¤À¥Æ¥ó¥×¥ì¡¼¥È¤ÎÆâÍƤòÊѹ¹¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÅÐÏ¿
MT->add_callback('MT::App::CMS::template_source.' . $pagename, $priority, $plugin, \&_callback_for_template_source);

# ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤¬½èÍý¤¹¤ë¡¢É½¼¨¥Ñ¥é¥á¡¼¥¿¡¼¤ÎÆâÍƤòÊѹ¹¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÅÐÏ¿
 MT->add_callback('MT::App::CMS::template_param.' . $pagename, $priority, $plugin, \&_callback_for_template_param);

# ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤¬½èÍý¤·¤¿·ë²Ì¤òÊѹ¹¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÅÐÏ¿
 MT->add_callback('MT::App::CMS::template_output.' . $pagename, $priority, $plugin, \&_callback_for_template_output);

# ¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÄêµÁ

sub _callback_for_template_source {
    my ($eh, $app, $tmpl_ref, $tmpl_filename) = @_;
    # $eh            : MT::Callback(¥³¡¼¥ë¥Ð¥Ã¥¯¥Ï¥ó¥É¥é¡¼)
    # $app           : MT::App::CMS¥ª¥Ö¥¸¥§¥¯¥È
    # $tmpl_ref      : ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤ÎÆâÍÆ¡Êʸ»úÎó¡Ë¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹
    # $tmpl_filename : ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë̾¡Ê= $pagename . '.tmpl'¡Ë
}

sub _callback_for_template_param {
    my ($eh, $app, $param_ref, $tmpl_ref) = @_;
    # $eh        : MT::Callback(¥³¡¼¥ë¥Ð¥Ã¥¯¥Ï¥ó¥É¥é¡¼)
    # $app       : MT::App::CMS¥ª¥Ö¥¸¥§¥¯¥È
    # $param_ref : ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤ËÅϤ¹¥Ñ¥é¥á¡¼¥¿¤Ø¤Î¥Ï¥Ã¥·¥å¡¦¥ê¥Õ¥¡¥ì¥ó¥¹
    # $tmpl      : MT::Template¥ª¥Ö¥¸¥§¥¯¥È
}

sub _callback_for_template_output {
    my ($eh, $app, $tmpl_str, $param_ref, $tmpl) = @_;
    # $eh        : MT::Callback(¥³¡¼¥ë¥Ð¥Ã¥¯¥Ï¥ó¥É¥é¡¼)
    # $app       : MT::App::CMS¥ª¥Ö¥¸¥§¥¯¥È
    # $tmpl_str  : ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤¬½èÍý¤·¤¿·ë²Ìʸ»úÎó¤Î»²¾È(MT::App::CMS->build_page¥á¥½¥Ã¥É¤Î·ë²Ìʸ»úÎó¤Ø¤Î»²¾È)
    # $param_ref : ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤ËÅϤ¹¥Ñ¥é¥á¡¼¥¿¤Ø¤Î¥Ï¥Ã¥·¥å¡¦¥ê¥Õ¥¡¥ì¥ó¥¹
    # $tmpl      : MT::Template¥ª¥Ö¥¸¥§¥¯¥È
}

1;

Transformer¥×¥é¥°¥¤¥ó¤ÎȯÁÛ¤Ï

  1. ¥«¥¹¥¿¥Þ¥¤¥ºÂоݤδÉÍý²èÌ̤ò·è¤á
  2. Åö³º´ÉÍý²èÌ̤Υƥó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë̾¤ò·èÄꤷ¡Ê¤È¤¤¤¦¤è¤êõ¤·¡Ë
  3. ¤½¤Î¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß»þ¡¢¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤Ë¥Ñ¥é¥á¡¼¥¿¤òÅϤ¹»þ¡¢¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤Î½èÍý·ë²Ì¤Î½ÐÎÏ»þ¤Ë¤½¤ì¤¾¤ì³ä¤ê¹þ¤à¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤òÀßÄꤷ
    ¤³¤ÎÊդκ٤«¤¤¥¿¥¤¥ß¥ó¥°¤Ë´Ø¤·¤Æ¤Ï¥½¡¼¥¹¤ò³Îǧ¤·¤Æ¤¤¤Ê¤¤¤Î¤Ç¥¦¥½¤¬¤¢¤ë¤«¤â¤Ç¤¹^^;
  4. ³Æ¡¹¤Î¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Ç¡¢¤½¤ì¤¾¤ì¾åµ­¤Î¥¿¥¤¥ß¥ó¥°¤Ç¹Ô¤¤¤¿¤¤½èÍý¤òº¹¤·¶´¤à

¤È¤¤¤¦¤â¤Î¤Ç¤¹¡£

»²¹Í¡§Transformer¥×¥é¥°¥¤¥ó¤Î³«È¯¡§µ»½Ñ¾ðÊóÄó¶¡¥Ö¥í¥°

[edit]

¥«¥¹¥¿¥Þ¥¤¥ºÂоݤδÉÍý²èÌ̤ÈÂбþ¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë̾

¥«¥¹¥¿¥Þ¥¤¥º¤·¤¿¤¤´ÉÍý²èÌ̤˥¢¥¯¥»¥¹¤·¤Æ¡¢¤½¤ÎURL¤ò³Îǧ¤·¤Þ¤¹¡£
Î㤨¤Ð¡¢¥Ö¥í¥°µ­»ö¤Î°ìÍ÷¤Î²èÌ̤Ǥ¢¤ì¤ÐURL¤Ï

http://¡Á¡¦¡¦¡¦/mt.cgi?__mode=list_entry&blog_id=1

¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£¤³¤Î¤È¤­¤Î__mode¤ÎÃÍ¡á[list_entry]¤«¤é¡¢¤³¤Î²èÌ̤Υƥó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤¬ÆÃÄê¤Ç¤­¤Þ¤¹¡£

¤¢¤ë__mode¤Î´ÉÍý²èÌ̤Υƥó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤Ï¼¡¤Ë¤Ê¤ê¤Þ¤¹¡£

[MT¤ò¥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¥Ç¥£¥ì¥¯¥È¥ê]/tmpl/cms/[__mode¤ÎÃÍ].tmpl

¾åµ­¤ÎÎã¤Ç¤¤¤¨¤Ð¡¢

[MT¤ò¥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¥Ç¥£¥ì¥¯¥È¥ê]/tmpl/cms/list_entry.tmpl

¤È¤Ê¤ê¤Þ¤¹¡£

¢¨ ¸·Ì©¤Ë__mode¤ÎÃͤ¬¾ï¤Ë¥Æ¥ó¥×¥ì¡¼¥È̾¤Ë¤Ê¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¤è¤¦¤Ç¤¹¡£Î㤨¤Ð¡¢¥Ö¥í¥°ÊÔ½¸²èÌ̤ǤÏ__mode=view¤Ç¤¹¤¬¡¢¤³¤Î¥Æ¥ó¥×¥ì¡¼¥È¤Ï/tmpl/cms/edit_entry.tmpl¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹

[edit]

¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÀßÄêÊýË¡¤È³Æ¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÍÑÅÓ

¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ÎÀßÄê¤Ë¤ÏMT¥¯¥é¥¹¤Îadd_callback¥á¥½¥Ã¥É¤ò»È¤¤¤Þ¤¹¡£

MT->add_callback('MT::App::CMS::template_source.' . $pagename, $priority, $plugin, \&_callback_for_template_source);

Âè°ì°ú¿ô¤ÎMT::App::CMS::template_{source|param|output}.[¥«¥¹¥¿¥Þ¥¤¥ºÂоݤΥƥó¥×¥ì¡¼¥È̾]¤Ç¡¢¤É¤Î¥¿¥¤¥ß¥ó¥°¤Ç¤É¤Î¥Æ¥ó¥×¥ì¡¼¥È¤ËÂФ·¤Æ¤Î¥³¡¼¥ë¥Ð¥Ã¥¯¤òÀßÄꤹ¤ë¤«¤ò»ØÄꤷ¤Þ¤¹¡£¥«¥¹¥¿¥Þ¥¤¥ºÂоݤΥƥó¥×¥ì¡¼¥È̾¤Ï[[>./#j049cf7a]]¤Î__mode¤ÎÃͤò»ØÄꤷ¤Þ¤¹¡£

Î㤨¤Ð¡¢¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Î¥¿¥¤¥ß¥ó¥°¤Ç__mode=list_entry¤Î¥Æ¥ó¥×¥ì¡¼¥È¤ò¥«¥¹¥¿¥Þ¥¤¥º¤¹¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤òÀßÄꤹ¤ë¤Ë¤Ï

MT->add_callback('MT::App::CMS::template_source.list_entry, $priority, $plugin, \&_callback_for_template_source);

¤È¤·¤Þ¤¹¡£

template_source¡¢template_param¡¢template_output¤ËÀßÄꤷ¤¿¤½¤ì¤¾¤ì¤Î¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤Ç¤Ï°Ê²¼¤Î¤è¤¦¤Ê½èÍý¤ò¹Ô¤¤¤Þ¤¹¡£

template_source¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô
Âè»°°ú¿ô¤Î$tmpl_ref¡Ê¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤ÎÆâÍÆ¡Êʸ»úÎó¡Ë¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹)¤¬»²¾È¤¹¤ë¥Æ¥ó¥×¥ì¡¼¥È¡¦¥Õ¥¡¥¤¥ë¤ÎÆâÍƤòÊѹ¹¤¹¤ë½èÍý¤òµ­½Ò¤¹¤ë¡£¢¨ °ú¿ô̾¤ÏǤ°Õ
template_param¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô
Âè»°°ú¿ô¤Î$param_ref¡Ê¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤ËÅϤ¹¥Ñ¥é¥á¡¼¥¿¤Ø¤Î¥Ï¥Ã¥·¥å¡¦¥ê¥Õ¥¡¥ì¥ó¥¹¡Ë¤¬»²¾È¤¹¤ë¥Ï¥Ã¥·¥å¤ÎÆâÍƤòÊѹ¹¤¹¤ë½èÍý¤òµ­½Ò¤¹¤ë¡£ ¢¨ °ú¿ô̾¤ÏǤ°Õ
template_output¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô
Âè»°°ú¿ô¤Î$tmpl_str¡Ê¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤¬½èÍý¤·¤¿·ë²Ìʸ»úÎó¤Î»²¾È¡Ë¤¬»²¾È¤¹¤ë¥Æ¥ó¥×¥ì¡¼¥È¡¦¥¨¥ó¥¸¥ó¤Ë¤è¤ë½èÍý·ë²Ìʸ»úÎó¤òÊѹ¹¤¹¤ë½èÍý¤òµ­½Ò¤¹¤ë¡£ ¢¨ °ú¿ô̾¤ÏǤ°Õ
[edit]

DOM ¥é¥¤¥¯¤ÊÁàºî¤Ë¤è¤ë´ÉÍý²èÌ̤γÈÄ¥

Ummm....Ä´ººÃæ^^;
¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ôÆâ¤Ç$tmpl->getElementById("meta-settings");¤Ê¤É»î¤·¤Æ¤ß¤ë¤â¡¢¾å¼ê¤¯Element¤¬¼è¤ì¤Æ¤Ê¤¤¤â¤è¤¦¡£
¥ê¥Õ¥¡¥ì¥ó¥¹¤Ë¤Î¤Ã¤Æ¤ª¤é¤º¡¢¥½¡¼¥¹Æɤष¤«¤Ê¤¤¤È¤Ï¡¦¡¦¡¦Movable Type ¥ª¥Ö¥¸¥§¥¯¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹ MT::Template

Åê¹Æ¼Ô¿ÊÃÏ | ¥Ñ¡¼¥Þ¥ê¥ó¥¯

| append.gif

¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS
Last-modified: 2007-11-08 (ÌÚ) 09:27:23 (6225d)

¥¢¡¼¥¯¥¦¥§¥Ö¤Î¥µ¡¼¥Ó¥¹¤ä¥½¥ê¥å¡¼¥·¥ç¥ó¤Ï¤³¤Á¤é