advertisement

Hacking Movable Type Training - Day 1

56 %
44 %
advertisement
Information about Hacking Movable Type Training - Day 1
Technology

Published on October 14, 2008

Author: byrnereese

Source: slideshare.net

Description

A series of slides presented to developers wishing to learn how to build plugins using Movable Type.
advertisement

Hacking
Movable
Type A
guide
for
developers Six
Apart
Ltd. Page


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


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


About
Hacking • What
makes
a
good
programmer? • Use
the
source
Luke. • Copy
and
paste
is
your
friend. Page


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


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


Plugin
Structure • Other
important
files
and
directories – MyPlugin-README.txt – MyPlugin-LICENSE.txt – plugins/MyPlugin/t/* – plugins/MyPlugin/extlib/* – plugins/MyPlugin/php/* Page


Plugin
Packaging • Files
that
really
help
with
the
packaging
and
 distribuEon
of
an
enEre
plugin: – Makefile.PL – MANIFEST.SKIP Page


Makefile.PL use ExtUtils::MakeMaker; WriteMakefile( NAME => quot;My Plugin's Display Namequot;, VERSION => '1.1', DISTNAME => 'MyPlugin', ); Page


MANIFEST.SKIP # version control bCVS (^|/). # CPAN chain files ^MANIFEST ^Makefile ^META.yml$ ^blib/ ~$ # packages .zip$ .tar.gz$ Page


CreaEng
a
Plugin
Zip
File These
simple
sequence
of
commands: > perl Makefile.PL > make manifest > make zipdist Will
produce
the
perfect
MT
Plugin
zip
file: • MyPlugin‐1.1.zip Page


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


The
Movable
Type
Registry • Movable
Type
is
a
config‐driven
applicaEon. • The
“registry”
is
where
Movable
Type
stores
its
 configuraEon. • Each
plugin
provides
a
mini‐registry
file,
config.yaml,
 that
defines
its
feature
set. • The
config.yaml
file
is
then
merged
into
Movable
 Type’s
main
registry. • Every
plugin
therefore
is
50%
configuraEon
and
50%
 code. Page


config.yaml name: Fluid App id: FluidApp author_link: http://www.majordojo.com/ author_name: Byrne Reese description: This plugin provides enhanced support for Fluid. version: 0.90 plugin_link: http://www.majordojo.com/projects/mt-fluid-app.php applications: cms: methods: fluid_update: $FluidApp::FluidApp::Plugin::cms_update callbacks: MT::App::CMS::template_source.header: $FluidApp::…::Plugin::xfrm Page


Yikes What
is
all
that? Page


A
YAML
Primer • YAML
==
“Yet
Another
Markup
Language” • XML
AlternaEve • Less
verbose • Human
readable
and
writable Page


XML
vs.
YAML <?xml version=quot;1.0quot;> <address> <first_name>Byrne</first_name> <last_name>Reese</last_name> <email>byrne@majordojo.com</email> <company> <name>Six Apart, Ltd.</name> <street_address> 548 4th Street, San Francisco, CA 94107 </street_address> </company> </address> Page


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


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


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


Adding
a
Config
DirecEve • What
is
a
configuraEon
direcEve? • When
should
you
use
a
config
direcEve? • What
are
the
alternaEves? Page


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


Config
DirecEve
ProperEes • Registry
properEes: – path – handler – alias Page


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


Adding
a
Template
Tag • What
is
a
template
tag? • Where
are
template
tags
used? • What
are
the
various
types
of
template
tags? Page


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


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


More
about
Template
Tags • Types
of
Tags – funcEon – block – modifiers • CondiEonal
Tags • Loops • Template
Context Page


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


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


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


Adding
a
Tag
Modifier • What
is
a
tag
modifier? • Example
modifiers: – <mt:block capitalize=“1”>abc</block> – <mt:block ltrim=“1”> foo</mt:block> – <mt:block regex_replace=“/foo/gi”,”bar”> foo </mt:block> – <mt:block count_words=“1”>Hello World</mt:block> Page


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


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


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


Objects
and
Data
Persistence • An
overview
of
Movable
Type
Objects – MT::Entry – MT::Comment – Etc. • Before
and
afer
a
record
is
modified
in
the
 Movable
Type
database,
an
event
is
fired. • Plugins
can
register
callbacks
for
those
events. Page


About
MT
Objects • Movable
Type’s
Data
AbstracEon
Layer – Data::ObjectDriver – MT::ObjectDriver – MT::Object • Memcached
Support • Event
PropagaEon • Gegers/Segers Page


InteracEng
with
MT::Objects • MT::MyObject‐>new() • $obj‐>save() • MT::MyObject‐>load($terms,
$arguments) • MT::MyObject‐>load_iter($terms,
$arguments) • $obj‐>remove($terms,
$arguments) • MT::MyObject‐>remove_all • MT::MyObject‐>count($terms) • MT::MyObject‐>exists($terms) • $obj‐>clone() Page


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


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


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


load
and
load_iter
OpEons • sort • direcEon • limit • lastn • offset • start_val • range • range_incl • join
 • unique Page


CreaEng
Your
Own
Object • Schema
definiEon • Registering
database
indexes • Record
audiEng • Primary
keys • Meta
Data Page


MT::MyObject package Example::MyObject; use strict; use base qw( MT::Object ); __PACKAGE__->install_properties({ column_defs => { 'id' => 'integer not null auto_increment', 'blog_id' => 'integer', 'some_property' => 'string(100) not null', }, audit => 1, indexes => { id => 1, }, datasource => 'myplugin_myobject', primary_key => 'id', }); Page


MT::Object
Database
Data
Types • string • integer • boolean • smallint • dateEme • blob • text • float Page


Extending
ExisEng
Objects • Extending
exisEng
objects • schema_version
registry
property Page


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


Extending
ExisEng
Objects • Which
then
let’s
you
do
this: use MT::Entry; my $entry = MT::Entry->load($id); $entry->is_featured(1); $entry->save; Page


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


Movable
Type
Callbacks • Nomenclature: – Event,
Callback,
Fire,
Listening • Event
Types – Object
Level – ApplicaEon
Level – TransformaEon Page


Object‐Level
Callbacks • Events: – MT::ObjectName::pre_save – MT::ObjectName::post_save – MT::ObjectName::pre_load – MT::ObjectName::post_load – MT::ObjectName::pre_remove – MT::ObjectName::pre_remove_all – MT::ObjectName::post_remove_all Page


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


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


Exercise:
Add
a
Callback • Your
Mission:
Add
a
record
to
the
Movable
 Type
AcEvity
Log,
just
afer
an
entry
is
saved. • About
Logging: MT->log({ message => quot;DemoPlugin: an object was saved.quot;, class => 'system', level => MT::Log::INFO() }); }); Page


End
Day
1 Byrne
Reese byrne@sixapart.com Page


Add a comment

Comments

WilliamOn | 25/03/15
Nice blog ) http://anmdcf7i.com my blog

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Introducing Movable Type 5.1 - Technology

Introducing Movable Type 5.1 Dec 05, 2014 Technology six-apart-kk. of 46 ... Hacking Movable Type Training - Day 1. Login or Join. Processing Login successful.
Read more

Movable Type

Movable Type for iOS v1.1 is out By Yuji Takayama and posted in News. We are pleased to inform you that Movable Type for iOS Ver. 1.1 is out now. Read More.
Read more

Movable Type Developer Guide - MovableType.org ...

Movable Type Developer Guide ... you will never succeed in your Jedi training. ... This plugin is an example plugin for Movable Type. version: 1.0 ...
Read more

Movable Type 5.1 : What's New - Technology

Movable Type 5.1 で新しく追加 ... Hacking Movable Type Training - Day 2 Comments. RECOMMENDED. Introducing Movable Type 5.1. Movable Type 6 Overview ...
Read more

Hacking Movable Type to Create and Integrate Advertising ...

Hacking Movable Type to Create and Integrate Advertising Posts. Apr 28th. by Aaron Wall. ... We offer the #1 SEO training program.
Read more

YouTube

Made My Day Movie Empfohlener Kanal. Abonnieren Abonniert Abo beenden 397.403 999+ ... 1.377.810.594 Aufrufe; vor 6 Monaten; 3:55. Nächstes Video; Jetzt ...
Read more

HACKER TRAINING ONLINE - INFOSEC INSTITUTE ONLINE TRAINING

Hacker Training Online ... Pass the exam with the best type of hacking training for you! ... Hacker Training Course Overview CERTIFICATIONS: 1: ...
Read more

Monster Hunter Portable 3rd Ps3 Vers. Training Day 1 ...

Monster Hunter Portable 3rd Ps3 Vers. Training Day 1: First weapon Types and practice ... Gundam Breaker Part 1: ...
Read more