5. Example Apps
• Atom ‐ Atom Publishing Protocol
• CMS ‐ the Main MT ApplicaBon
• XML‐RPC ‐ RESTian interfaces
• Feeds ‐ AcBvity Feeds
• Search ‐ Blog Side Searching
• Comments ‐ Comment Processing
• More..
Page
6. Apps in the Registry
name: Example Plugin for Movable Type
id: Example
key: Example
description: This plugin is an example plugin for Movable Type.
version: 1.0
applications:
my_app:
cgi_base:
handler:
methods:
page_actions:
list_actions:
list_filters:
search_apis:
menus:
widgets:
blog_stats_tab:
tags:
import_formats:
Page
9. Adding Menus
name: Example Plugin for Movable Type
id: Example
key: Example
description: This plugin is an example plugin.
version: 1.0
applications:
cms:
menus:
create:video:
label: 'Upload Video'
mode: 'video_upload'
order: 301
args:
'_type': quot;blogquot;
permission: 'manage_assets,publish_post'
view: blog
Page
10. Menu ProperBes
• label
• mode
• dialog
• order
• permission
• args
• view
Page
12. CreaBng a New Screen in the App
• Extending different apps
• Registering a “mode”
• ImplemenBng a Handler
• CreaBng a template
• Working with Templates
Page
13. Registering a Mode
name: Example Plugin for Movable Type
id: Example
key: Example
description: This plugin is an example plugin.
version: 1.0
applications:
cms:
methods:
do_something: $Example::Example::Plugin::do_something
Page
14. Mode Handlers
package Example::Plugin;
use strict;
sub plugin {
return MT->component('Example');
}
sub some_mode {
my $app = shift;
my $input = $app->{query}->param('some_form_parameter');
my $plugin = plugin();
my $tmpl = $plugin->load_tmpl('some_template.tmpl');
return $app->build_page( $tmpl );}
}
Page
18. Working with Variables
<mt:setvarblock name=quot;page_titlequot;>This is a page title</mt:setvarblock>
<mt:include name=quot;include/header.tmplquot;>
<p>Hello <mt:var name=quot;personquot;>!</p>
<mt:include name=quot;include/footer.tmplquot;>
sub some_mode {
my $app = shift;
my $input = $app->{query}->param('some_form_parameter');
my $plugin = plugin();
my $param = {};
$param->{person} = quot;Byrne”;
my $tmpl = $plugin->load_tmpl('some_template.tmpl');
return $app->build_page( $tmpl, $param );
}
Page
27. LisBng Handler
sub list_profileevent {
my $app = shift;
my %param = @_;
# Send the user to the dashboard if no blog ID has been provided.
$app->return_to_dashboard( redirect => 1 ) if $app->param('blog_id');
my %service_styles;
my @service_styles_loop;
# This anonymous subroutine will process each row of data. It takes
# as input the object associated with the current row, and an empty
# hash for the row that should be populated with content from the
# $obj passed to it.
my $code = sub {
my ($obj, $row) = @_;
$row->{'column1'} = $obj->some_property;
$row->{'column2'} = $obj->another_property;
my $ts = $row->{created_on};
$row->{date} = relative_date($ts, time);
};
# %terms is used in case you want to filter the contents of the
# table in someway
my %terms = (
author_id => $app->user->id,
);
Page
28. LisBng Handler
# %args is used in case you want to sort or otherwise modify the
# query arguments of the table
my %args = (
sort => 'created_on',
direction => 'descend',
);
# %params is an addition hash of input parameters into the template
# and can be used to hold an arbitrary set of name/value pairs that
# can be displayed in your template.
my %params = (
some_variable => 'You can do ANYTHING in Movable Type',
);
# Fetch an instance of the current plugin using the plugin's key
my $plugin = MT->component('Example');
# The main work horse of your handler. This will actually conduct
# the query to the database for you, populate all that is necessary
# for the pagination controls and more. The query is filtered and
# controlled using the %terms and %args parameters.
$app->listing({
type => 'myobject', # the ID of the object in the registry
terms => %terms,
args => %args,
listing_screen => 1,
code => $code,
template => $plugin->load_tmpl('my_table.tmpl'),
params => %params,
});
}
Page
31. Callback Types
• Transform the template’s source:
– MT::App::CMS::template_source
• Transform the template’s DOM:
– MT::App::CMS::template_param
• Transform the template’s output:
– MT::App::CMS::template_output
Page
32. Registering the Callback
name: Example Plugin for Movable Type
id: Example
key: Example
description: This plugin is an example.
version: 1.0
callbacks:
MT::App::CMS::template_source.edit_entry:
$Example::Example::Plugin::xfrm
Page
33. Regular Express Callback
sub my_xfrm_callback {
my ($cb, $app, $tmpl) = @_;
my $slug = <<END_TMPL;
A whole bunch of HTML here
END_TMPL
$$tmpl =~ s/(<li>Utilitiesn<ul class=quot;subquot;>)/$1$slug/;
}
Page