0
Brand New API


Movable Type Developers & Designers Conference
              2010.2.5 in Tokyo

            Yuji Takayama,...
r y!
 u ng
H
Whatʼs brand new?
• Website
• Theme Framework
• Revision History Framework
• User Dashboard
• Everything is UTF-8
• Permission API
• Menu Structure
• Dynamic Publishing
• User Interface
• Custom Fields
What is “Website”?
Website is ...
The root object of the
  Movable Type 5
How can I use the
 website object
use MT::Website;

my $website_id = 1;
my $website =
    MT::Website-
>load($website_id)
    or die;
$website->name(‘New We...
itʼs easy
use MT::Blog;
use MT::Website;

my $website_id = 1;
my $website =
    MT::Website->load($website_id)
        or die;
my $b...
All blogs belongs to
     the website
$website->site_url;
$website->site_path;
$website->name;
$website->description;
like a blog?

  Right.
• The website uses same table as the
  blog.

• The class of the website is “website”,
  also the class of the blog is “bl...
mysql> select blog_id, blog_class, blog_parent_id
from mt_blog;

+---------+------------+----------------+
| blog_id | blo...
new template tags
•   MTWebsites                •   MTWebsitePath

•   MTIfWebsite?              •   MTWebsiteTimezone

• ...
new template tags
•   MTWebsites                •   MTWebsitePath

•   MTIfWebsite?              •   MTWebsiteTimezone

• ...
Now, Movable Type
has a revision history
   management.
By default, only the entry
and the template use it.
But....
You can use it in your
      plug-in.
package MT::Object::MyModel
use base qw ( MT::Object
MT::Revisable );

__PACKAGE__->install_properties({
    ‘id’ => ‘inte...
package MT::Object::MyModel
use base qw ( MT::Object
MT::Revisable );

__PACKAGE__->install_properties({
    ‘id’ => ‘inte...
package MT::Object::MyModel
use base qw ( MT::Object
MT::Revisable );

__PACKAGE__->install_properties({
    ‘id’ => ‘inte...
itʼs easy
Movable Type does
 save a revision
  automatically.
If your object related
    to other object
You must override
 ʻpack_revisionʼ and
  ʻunpack_revisionʼ
method on your object.
sub pack_revision {
    my $obj = shift;
    my $values = MT::Revisable::pack_revision( $obj );

    # add category placem...
}

sub unpack_revision {                             if ( my $rev_cats = delete $packed_obj-
    my $obj = shift;         ...
See MT::Entry
perldoc MT::Revisable
Itʼs your Home to start
       all actions.
Also, you can add
your own widget here
widgets:
  FeedsWidget:
  label: Feed Aggregate
  template: tmpl/widget.tmpl
  handler:
$FeedWidget::Widget::hdlr_widget
 ...
widgets:
  FeedsWidget:
  label: Feed Aggregate
  template: tmpl/widget.tmpl
  handler:
$FeedWidget::Widget::hdlr_widget
 ...
widgets:
  FeedsWidget:
  label: Feed Aggregate
  template: tmpl/widget.tmpl
  handler:
$FeedWidget::Widget::hdlr_widget
 ...
widgets:
  FeedsWidget:
  label: Feed Aggregate
  template: tmpl/widget.tmpl
  handler:
$FeedWidget::Widget::hdlr_widget
 ...
widgets:
  FeedsWidget:
  label: Feed Aggregate
  template: tmpl/widget.tmpl
  handler:
$FeedWidget::Widget::hdlr_widget
 ...
Everything is UTF-8
Now, all strings in the
 Movable Type 5 is
   utf-8 flagged.
before
Movable Type 5
You must encode object
       by yourself
  if PublishCharset is
       not UTF-8.
sub _hdlr_my_tag {
    my ( $ctx, $args ) = @_;
    my $obj = MT::Entry->load(
        $args->{id});
    my $data = $obj->...
sub _hdlr_my_tag {
    my ( $ctx, $args ) = @_;
    my $obj = MT::Entry->load(
        $args->{id});
    my $data = $obj->...
from now,
You are freed from
obligation of Encode.
sub _hdlr_my_tag {
    my ( $ctx, $args ) = @_;
    my $obj = MT::Entry->load(
        $args->{id});
    my $data = $obj->...
You must
encode/decode
 your own data
    when...
• Communicating with an external
  network.

• File input/output without MT::FileMgr.
• Saving valuesto columns declared i...
sub _hdlr_my_tag {
    my ( $ctx, $args ) = @_;
    my $data;

    # received from web service.

    return Encode::decode...
sub _hdlr_my_tag {
    my ( $ctx, $args ) = @_;
    my $data;

    # received from web service.

    return Encode::decode...
Weʼve aimed to...


• easy to understanding
An user who has ‘manage_pages’
permission. Which actions this
user can do?
Movable Type 4...
  $app->can_manage_pages();

Movable Type 5...
  $app->can_do(
‘remove_all_trackbacks_on_webpages’
  );
...
See MT::Core
load_core_permissions
Weʼve aimed to...


• easy to understanding
• Can be extensible
permissions:
   blog.your_permission:
       group: blog_admin
       label: Your New Permission
       order: 350
       ...
Specify the role group.


• blog_admin
• auth_pub           • sys_admin
• blog_upload          (only system
              ...
label
The display name of the permission.
order
Ordering the permission in its role group
permitted_action
Hash to define a list of actions permitted for hte
use who has this permission.
inherit_from
A list of inheritance origins for this permission.
Defined by references to the list.
Of course, you can
add your menu by
      plugin.
applications:
  cms:
    menus:
       tools:my_menu:
         label: Your Menu Label
         mode: your_mode
         or...
You can display your
   menu on any
     dashboard
applications:
  cms:
    menus:
       tools:my_menu:
         label: Your Menu Label
         mode: your_mode
         or...
applications:
  cms:
    menus:
       tools:my_menu:
         label: Your Menu Label
         mode: your_mode
         or...
You can restrict your
menu by permission.
permissions:
   blog.your_permission:
       permitted_action:
           your_action: 1
applications:
 cms:
  menus:
   t...
If your plugin still
supports MT4 and MT5
menus:
 create:my_object:
  condition: >
  sub {
    MT->product_version < 5; }
 entries:create:
  condition: >
  sub {
  ...
jquery
and... jquery-ui Ready.
CSS
More detail...

http://www.slideshare.net/
   swordbreaker/plugin
Thank you for listening.
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
Upcoming SlideShare
Loading in...5
×

MTDDC 2010.2.5 Tokyo - Brand new API

3,783

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,783
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
23
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • &amp;#x30A6;&amp;#x30A7;&amp;#x30D6;&amp;#x30B5;&amp;#x30A4;&amp;#x30C8;&amp;#x95A2;&amp;#x4FC2;&amp;#x3060;&amp;#x3051;&amp;#x3067;&amp;#x3053;&amp;#x308C;&amp;#x3060;&amp;#x3051;&amp;#x306E;&amp;#x30BF;&amp;#x30B0;&amp;#x304C;&amp;#x8FFD;&amp;#x52A0;&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x307E;&amp;#x3059;&amp;#x304C;&amp;#x3001;&amp;#x30B5;&amp;#x30A4;&amp;#x30C8;&amp;#x3092;&amp;#x898B;&amp;#x3066;&amp;#x3044;&amp;#x305F;&amp;#x3060;&amp;#x3044;&amp;#x305F;&amp;#x65B9;&amp;#x304C;&amp;#x65E9;&amp;#x3044;&amp;#x304B;&amp;#x3068;&amp;#x601D;&amp;#x3044;&amp;#x307E;&amp;#x3059;
  • &amp;#x5272;&amp;#x611B;&amp;#x3057;&amp;#x307E;&amp;#x3059;
  • Transcript of "MTDDC 2010.2.5 Tokyo - Brand new API"

    1. 1. Brand New API Movable Type Developers & Designers Conference 2010.2.5 in Tokyo Yuji Takayama,Six Apart
    2. 2. r y! u ng H
    3. 3. Whatʼs brand new?
    4. 4. • Website • Theme Framework • Revision History Framework • User Dashboard
    5. 5. • Everything is UTF-8 • Permission API • Menu Structure • Dynamic Publishing • User Interface • Custom Fields
    6. 6. What is “Website”?
    7. 7. Website is ...
    8. 8. The root object of the Movable Type 5
    9. 9. How can I use the website object
    10. 10. use MT::Website; my $website_id = 1; my $website = MT::Website- >load($website_id) or die; $website->name(‘New Website’); $website->save or die;
    11. 11. itʼs easy
    12. 12. use MT::Blog; use MT::Website; my $website_id = 1; my $website = MT::Website->load($website_id) or die; my $blog = new MT::Blog; $website->add_blog($blog); my $blogs = $website->blogs;
    13. 13. All blogs belongs to the website
    14. 14. $website->site_url; $website->site_path; $website->name; $website->description;
    15. 15. like a blog? Right.
    16. 16. • The website uses same table as the blog. • The class of the website is “website”, also the class of the blog is “blog”. • The blog has parent_id that means the belonging website.
    17. 17. mysql> select blog_id, blog_class, blog_parent_id from mt_blog; +---------+------------+----------------+ | blog_id | blog_class | blog_parent_id | +---------+------------+----------------+ | 1 | website | NULL | | 2 | blog | 1 | | 3 | blog | 1 | | 4 | blog | 1 | | 5 | website | NULL | +---------+------------+----------------+ 5 rows in set (0.01 sec)
    18. 18. new template tags • MTWebsites • MTWebsitePath • MTIfWebsite? • MTWebsiteTimezone • MTWebsiteIfCCLicense • MTWebsiteCCLicenseURL • MTWebsiteHasBlog • MTWebsiteCCLicenseImage • MTBlogParentWebsite • MTWebsiteFileExtension • MTWebsiteIfCommentsOpen • MTWebsiteHost • MTWebsiteID • MTWebsiteRelativeURL • MTWebsiteName • MTWebsiteThemeID • MTWebsiteDescription • MTWebsiteCommentCount • MTWebsiteLanguage • MTWebsitePingCount • MTWebsiteURL • MTWebsitePageCount
    19. 19. new template tags • MTWebsites • MTWebsitePath • MTIfWebsite? • MTWebsiteTimezone • MTWebsiteIfCCLicense • MTWebsiteCCLicenseURL • MTWebsiteHasBlog • MTWebsiteCCLicenseImage • MTBlogParentWebsite • MTWebsiteFileExtension • MTWebsiteIfCommentsOpen • MTWebsiteHost • MTWebsiteID • MTWebsiteRelativeURL • MTWebsiteName • MTWebsiteThemeID • MTWebsiteDescription • MTWebsiteCommentCount • MTWebsiteLanguage • MTWebsitePingCount • MTWebsiteURL • MTWebsitePageCount
    20. 20. Now, Movable Type has a revision history management.
    21. 21. By default, only the entry and the template use it.
    22. 22. But....
    23. 23. You can use it in your plug-in.
    24. 24. package MT::Object::MyModel use base qw ( MT::Object MT::Revisable ); __PACKAGE__->install_properties({ ‘id’ => ‘integer not null auto_increment’, ‘text’ => ‘string(255) revisioned’ # ... }); 1;
    25. 25. package MT::Object::MyModel use base qw ( MT::Object MT::Revisable ); __PACKAGE__->install_properties({ ‘id’ => ‘integer not null auto_increment’, ‘text’ => ‘string(255) revisioned’ # ... }); 1;
    26. 26. package MT::Object::MyModel use base qw ( MT::Object MT::Revisable ); __PACKAGE__->install_properties({ ‘id’ => ‘integer not null auto_increment’, ‘text’ => ‘string(255) revisioned’ # ... }); 1;
    27. 27. itʼs easy
    28. 28. Movable Type does save a revision automatically.
    29. 29. If your object related to other object
    30. 30. You must override ʻpack_revisionʼ and ʻunpack_revisionʼ method on your object.
    31. 31. sub pack_revision { my $obj = shift; my $values = MT::Revisable::pack_revision( $obj ); # add category placements and tag associations my ( @tags, @cats ); if ( my $tags = $obj->get_tag_objects ) { @tags = map { $_->id } @$tags if @$tags; } # a revision may remove all the tags $values->{__rev_tags} = @tags; my $primary = $obj->category; if ( my $cats = $obj->categories ) { @cats = map { [ $_->id, $_->id == $primary->id ? 1 : 0 ] } @$cats if @$cats; } # a revision may remove all the categories $values->{__rev_cats} = @cats; $values; }
    32. 32. } sub unpack_revision { if ( my $rev_cats = delete $packed_obj- my $obj = shift; >{__rev_cats} ) { my ($packed_obj) = @_; $obj->clear_cache('category'); MT::Revisable::unpack_revision( $obj, $obj->clear_cache('categories'); @_ ); my ( $cat, @cats ); # restore category placements and tag if ( @$rev_cats ) { associations my ($primary) = grep { $_->[1] } if ( my $rev_tags = delete $packed_obj- @$rev_cats; >{__rev_tags} ) { $cat = MT::Category- delete $obj->{__tags}; >lookup( $primary->[0] ); delete $obj->{__tag_objects}; my $cats = MT::Category- MT::Tag->clear_cache(datasource => >lookup_multi([ map { $_->[0] } @ $obj->datasource, $rev_cats ]); ($obj->blog_id ? (blog_id => my @cats = sort { $a->label cmp $obj->blog_id) : ())); $b->label } grep { defined } @$cats; $obj->{__missing_cats_rev} = 1 require MT::Memcached; if scalar( @cats ) != MT::Memcached->instance- scalar( @$cats ); >delete( $obj->tag_cache_key ); } $obj->cache_property( 'category', if ( @$rev_tags ) { undef, $cat ); my $lookups = MT::Tag- $obj->cache_property( 'categories', >lookup_multi($rev_tags); undef, @cats ); my @tags = grep { defined } @ } $lookups; } $obj->{__tags} = [ map { $_- >name } @tags ]; $obj->{__tag_objects} = @tags; $obj->{__missing_tags_rev} = 1 if scalar( @tags ) != scalar( @$lookups ); } else { $obj->{__tags} = []; $obj->{__tag_objects} = []; }
    33. 33. See MT::Entry
    34. 34. perldoc MT::Revisable
    35. 35. Itʼs your Home to start all actions.
    36. 36. Also, you can add your own widget here
    37. 37. widgets: FeedsWidget: label: Feed Aggregate template: tmpl/widget.tmpl handler: $FeedWidget::Widget::hdlr_widget set: main singular: 1 view: blog
    38. 38. widgets: FeedsWidget: label: Feed Aggregate template: tmpl/widget.tmpl handler: $FeedWidget::Widget::hdlr_widget set: main singular: 1 view: blog
    39. 39. widgets: FeedsWidget: label: Feed Aggregate template: tmpl/widget.tmpl handler: $FeedWidget::Widget::hdlr_widget set: main singular: 1 view: blog
    40. 40. widgets: FeedsWidget: label: Feed Aggregate template: tmpl/widget.tmpl handler: $FeedWidget::Widget::hdlr_widget set: main singular: 1 view: blog
    41. 41. widgets: FeedsWidget: label: Feed Aggregate template: tmpl/widget.tmpl handler: $FeedWidget::Widget::hdlr_widget set: main singular: 1 view: blog
    42. 42. Everything is UTF-8
    43. 43. Now, all strings in the Movable Type 5 is utf-8 flagged.
    44. 44. before Movable Type 5
    45. 45. You must encode object by yourself if PublishCharset is not UTF-8.
    46. 46. sub _hdlr_my_tag { my ( $ctx, $args ) = @_; my $obj = MT::Entry->load( $args->{id}); my $data = $obj->text; # do something... return MT::I18N::encode_text( $data, ‘utf-8’ ); }
    47. 47. sub _hdlr_my_tag { my ( $ctx, $args ) = @_; my $obj = MT::Entry->load( $args->{id}); my $data = $obj->text; # do something... return MT::I18N::encode_text( $data, ‘utf-8’ ); }
    48. 48. from now,
    49. 49. You are freed from obligation of Encode.
    50. 50. sub _hdlr_my_tag { my ( $ctx, $args ) = @_; my $obj = MT::Entry->load( $args->{id}); my $data = $obj->text; # do something... return $data; }
    51. 51. You must encode/decode your own data when...
    52. 52. • Communicating with an external network. • File input/output without MT::FileMgr. • Saving valuesto columns declared in MT::Object blob format.
    53. 53. sub _hdlr_my_tag { my ( $ctx, $args ) = @_; my $data; # received from web service. return Encode::decode_utf8( $data ); }
    54. 54. sub _hdlr_my_tag { my ( $ctx, $args ) = @_; my $data; # received from web service. return Encode::decode_utf8( $data ); }
    55. 55. Weʼve aimed to... • easy to understanding
    56. 56. An user who has ‘manage_pages’ permission. Which actions this user can do?
    57. 57. Movable Type 4... $app->can_manage_pages(); Movable Type 5... $app->can_do( ‘remove_all_trackbacks_on_webpages’ ); manage_pages: permitted_action: remove_all_trackbacks_on_webpages: 1
    58. 58. See MT::Core load_core_permissions
    59. 59. Weʼve aimed to... • easy to understanding • Can be extensible
    60. 60. permissions: blog.your_permission: group: blog_admin label: Your New Permission order: 350 permitted_action: your_action: 1 your_other_action: 1
    61. 61. Specify the role group. • blog_admin • auth_pub • sys_admin • blog_upload (only system level) • blog_comment • blog_design
    62. 62. label The display name of the permission.
    63. 63. order Ordering the permission in its role group
    64. 64. permitted_action Hash to define a list of actions permitted for hte use who has this permission.
    65. 65. inherit_from A list of inheritance origins for this permission. Defined by references to the list.
    66. 66. Of course, you can add your menu by plugin.
    67. 67. applications: cms: menus: tools:my_menu: label: Your Menu Label mode: your_mode order: 150 view: blog
    68. 68. You can display your menu on any dashboard
    69. 69. applications: cms: menus: tools:my_menu: label: Your Menu Label mode: your_mode order: 150 view: blog
    70. 70. applications: cms: menus: tools:my_menu: label: Your Menu Label mode: your_mode order: 150 view: blog
    71. 71. You can restrict your menu by permission.
    72. 72. permissions: blog.your_permission: permitted_action: your_action: 1 applications: cms: menus: tools:my_menu: label: Your Menu Label mode: your_mode order: 150 view: blog permit_action: your_action
    73. 73. If your plugin still supports MT4 and MT5
    74. 74. menus: create:my_object:   condition: >   sub { MT->product_version < 5; }  entries:create:   condition: >   sub { MT->product_version >= 5; }
    75. 75. jquery
    76. 76. and... jquery-ui Ready.
    77. 77. CSS
    78. 78. More detail... http://www.slideshare.net/ swordbreaker/plugin
    79. 79. Thank you for listening.
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×