2. Developing for Movable Type in 2 Days
• Day 1: The Basics
– Plugin Structure
– The Registry
– ConfiguraEon DirecEves
– Template Tags
– Objects
– Callbacks
• Day 2: Building User Interfaces
– Menus
– New ApplicaEon Screens
– Dialogs
– LisEng Screens
2
Page
3. Course Prerequisites
• This course requires that you have access to a
working Movable Type installa:on.
• This course also assumes that you are familiar
with basic system administra:on tasks, such
as copying and ediEng files.
• Finally, this course requires knowledge of the
Perl programming language.
Page
5. Developing for Movable Type in 2 Days
• Day 1: The Basics
➡ Plugin Structure
– The Registry
– ConfiguraEon DirecEves
– Template Tags
– Objects
– Callbacks
• Day 2: Building User Interfaces
– Menus
– New ApplicaEon Screens
– Dialogs
– LisEng Screens
5
Page
6. Plugin Structure
• Your config file
– plugins/MyPlugin/config.yaml
• Your library files
– plugins/MyPlugin/lib/*
• Your templates
– plugins/MyPlugin/tmpl/*
• Your staEc images, javascript and CSS files
– mt-static/plugins/MyPlugin/*
Page
12. Developing for Movable Type in 2 Days
• Day 1: The Basics
– Plugin Structure
➡ The Registry
– ConfiguraEon DirecEves
– Template Tags
– Objects
– Callbacks
• Day 2: Building User Interfaces
– Menus
– New ApplicaEon Screens
– Dialogs
– LisEng Screens
12
Page
18. XML vs. YAML
address:
first_name: Byrne
last_name: Reese
email: byrne@majordojo.com
company:
name: Six Apart, Ltd.
street_address: 548 4th Street,
San Francisco, CA 94107
Page
19. Your First Plugin
Place this in: plugins/Good4Nothing/config.yaml
name: Good for Nothing Plugin for Movable Type
id: Good4Nothing
key: Good4Nothing
author_link: http://www.yourwebsite.com/
author_name: Your Name Here
description: This plugin is an example plugin.
version: 1.0
Page
20. Developing for Movable Type in 2 Days
• Day 1: The Basics
– Plugin Structure
– The Registry
➡ Configura:on Direc:ves
– Template Tags
– Objects
– Callbacks
• Day 2: Building User Interfaces
– Menus
– New ApplicaEon Screens
– Dialogs
– LisEng Screens
20
Page
22. Adding a Config DirecEve
name: Good for Nothing Plugin for Movable Type
id: Good4Nothing
key: Good4Nothing
author_link: http://www.yourwebsite.com/
author_name: Your Name Here
description: This plugin is an example plugin.
version: 1.0
config_settings:
MyImageURL:
default: http://path.com/images/foo.jpg
Page
24. Developing for Movable Type in 2 Days
• Day 1: The Basics
– Plugin Structure
– The Registry
– ConfiguraEon DirecEves
➡ Template Tags
– Objects
– Callbacks
• Day 2: Building User Interfaces
– Menus
– New ApplicaEon Screens
– Dialogs
– LisEng Screens
24
Page
26. Adding a Template Tag ‐ config.yaml
name: Good for Nothing Plugin for Movable Type
id: Good4Nothing
key: Good4Nothing
author_link: http://www.yourwebsite.com/
author_name: Your Name Here
description: This plugin is an example plugin.
version: 1.0
config_settings:
MyImageURL:
default: http://path.com/images/foo.jpg
tags:
function:
MyImageURL: $Good4Nothing::Good4Nothing::Plugin::tag
Page
27. Adding a Template Tag ‐ Handler
# Good for Nothing Plugin for Movable Type
# Author: Your Name Here, your.email@address.com
# Copyright (C) 2008 Your Name Here
# This file is licensed under the Artistic License,
# or the same terms as Perl itself.
package Good4Nothing::Plugin;
use strict;
sub tag {
my ($ctx) = @_;
my $cfg = $ctx->{config};
return $cfg->MyImageURL;
}
1; # Every module must return true
Page
29. More about Template Tags
tags:
function:
'SaySomething': $Example::Example::Plugin::SaySomething
'SayWhatever': $Example::Example::Plugin::SayWhatever
block:
'LoopTenTimes': $Example::Example::Plugin::LoopTenTimes
'IfOdd?': $Example::Example::Plugin::IfOdd
Page
30. More about Template Tags
# Example: <mt:SaySomething>
sub SaySomething {
my ($ctx, $args) = @_;
return quot;Somethingquot;quot;;
}
# Example: <mt:SayWhatever say=”Hello”>
sub SayWhatever {
my ($ctx, $args) = @_;
# What the person passed in through the
# argument 'say'
my $input = $args->{'say'};
return $input;
}
Page
31. More about Template Tags
# Example: <mt:LoopTenTimes>...</mt:LoopTenTimes>
sub LoopTenTimes {
my ($ctx, $args, $cond) = @_;
my $out = quot;quot;;
my $builder = $ctx->stash('builder');
my $tokens = $ctx->stash('tokens');
for (my $i = 1; $i <= 10; $i++) {
$ctx->stash(quot;current_loop_numberquot;,$i);
$out .= quot;$i * quot; . $builder->build($ctx,$tokens,$cond);
}
return $out;
}
# Example: <mt:IfOdd>do this</mt:IfOdd>
sub IfOdd {
my ($ctx, $args, $cond) = @_;
my $num = $ctx->stash('current_loop_number');
if ($num % 2 == 0) {
return 0;
} else {
return 1;
}
}
Page
33. Adding a Template Tag ‐ config.yaml
name: Good for Nothing Plugin for Movable Type
id: Good4Nothing
key: Good4Nothing
author_link: http://www.yourwebsite.com/
author_name: Your Name Here
description: This plugin is an example plugin.
version: 1.0
config_settings:
MyImageURL:
default: http://path.com/images/foo.jpg
tags:
modifier:
lolcats: $Good4Nothing::Good4Nothing::Plugin::lolcats
Page
34. Adding a Modifier ‐ Handler
# Good for Nothing Plugin for Movable Type
# Author: Your Name Here, your.email@address.com
# Copyright (C) 2008 Your Name Here
# This file is licensed under the Artistic License,
# or the same terms as Perl itself.
package Good4Nothing::Plugin;
use strict;
sub lolcats {
my ($str, $val, $ctx) = @_;
return quot;CAN I HAZ “. uc($str);
}
1; # Every module must return true
Page
35. Developing for Movable Type in 2 Days
• Day 1: The Basics
– Plugin Structure
– The Registry
– ConfiguraEon DirecEves
– Template Tags
➡ Objects
– Callbacks
• Day 2: Building User Interfaces
– Menus
– New ApplicaEon Screens
– Dialogs
– LisEng Screens
35
Page
39. new() and save()
my $foo = MT::Foo->new;
$foo->first_name(’Byrne');
$foo->last_name(‘Reese’);
$foo->save()
or die quot;Saving foo failed: quot;, $foo->errstr;
Page
40. load()
my @objects = MT::Foo->load(
{
title => quot;Hello Worldquot;,
foo => quot;barquot;,
}, {
sort => 'created_on',
direction => 'ascend',
}
);
foreach my $obj (@objects) {
print $obj->baz();
# do something
}
Page
41. load_iter()
my $iter = MT::Foo->load_iter(
{
title => quot;Hello Worldquot;,
foo => quot;barquot;,
}, {
sort => 'created_on',
direction => 'ascend',
}
);
while (my $obj = $iter->()) {
print $obj->baz();
# do something
}
Page
47. Extending ExisEng Objects
name: Example Plugin for Movable Type
id: Example
key: Example
description: This plugin is an example plugin
version: 1.0
schema_version: 2
object_types:
entry:
is_featured: smallint
Page
49. Developing for Movable Type in 2 Days
• Day 1: The Basics
– Plugin Structure
– The Registry
– ConfiguraEon DirecEves
– Template Tags
– Objects
➡ Callbacks
• Day 2: Building User Interfaces
– Menus
– New ApplicaEon Screens
– Dialogs
– LisEng Screens
49
Page
52. Adding a Callback ‐ config.yaml
name: Good for Nothing Plugin for Movable Type
id: Good4Nothing
key: Good4Nothing
author_link: http://www.yourwebsite.com/
author_name: Your Name Here
description: This plugin is an example plugin.
version: 1.0
callbacks:
MT::Entry::pre_save: $Example::Example::Plugin::pre_save
Page
53. Adding a Callback ‐ Handler
package Example::Plugin;
use strict;
sub pre_save {
my ($cb, $obj) = @_;
# $cb - holds a reference to the callback object
# $obj - holds a reference to the object about
# to be saved
# do your thing
if ($error) {
return $cb->error(“Error Message”);
}
}
Page