advertisement

Hacking Movable Type

67 %
33 %
advertisement
Information about Hacking Movable Type

Published on August 31, 2007

Author: larsen

Source: slideshare.net

Description

An introduction to plugin development for Movable Type
advertisement

Hacking Movable Type Italian Perl Workshop 2006 Stefano Rodighiero - stefano.rodighiero@dada.net

“Movable Type 3.2 is the premier weblog publishing platform for businesses, organizations, developers, and web designers”

Le funzioni di MT MT ________ ________ Articoli, ________ template

Le funzioni di MT <MTEntries> <$MTEntryTrackbackData$> ... <a id=quot;a<$MTEntryID pad=quot;1quot;$>quot;></a> <div class=quot;entryquot; id=quot;entry-<$MTEntryID$>quot;> <h3 class=quot;entry-headerquot;><$MTEntryTitle$></h3> <div class=quot;entry-contentquot;> <div class=quot;entry-bodyquot;> <$MTEntryBody$> <MTEntryIfExtended> ... </div> </div> </div> </MTEntries>

Le caratteristiche di MT • Interfaccia web completa ma affidabile • Sistema di gestione degli autori (con abbozzo di gestione di ruoli e permessi) • Sistema potente per la gestione dei template

Inoltre...

MT dal punto di vista del programmatore • Espone una API sofisticata e documentata • Incoraggia lo sviluppo di plug-in per estenderne le funzionalità • È scritto in Perl :-)

Estendere MT MT ________ ________ Articoli, ________ template Plugin

Esempi di realizzazioni

Esempi di realizzazioni

maketitle.pl my $plugin; require MT::Plugin; $plugin = MT::Plugin->new( { name => 'Maketitle', description => q{Costruisce titoli grafici}, doc_link => '', } ); MT->add_plugin($plugin);

maketitle.pl /2 # ... continua MT::Template::Context->add_tag( MakeGraphicTitle => &make_graphic_title );

maketitle.pl /2 nel template... ... <center> <$MTMakeGraphicTitle$> </center> ...

maketitle.pl /2 sub make_graphic_title { my $context = shift; my $params = shift; my $entry = $context->stash('entry'); my $title = $entry->title(); my $dirified_title = dirify( $title ); ... return qq{<img src=quot;$imageurlquot;>}; }

maketitle.pl /2 nel file HTML risultante... ... <center> <img src=”...”> </center> ...

statwatch

statwatch schemas mysql.dump list.tmpl statwatch swfooter.tmpl tmpl swheader.tmpl view.tmpl

statwatch Stats.pm lib StatWatch Visit.pm statvisit.cgi StatWatch.pm statwatch statwatch.cgi StatWatchConfig.pm statwatch.pl

statwatch.pl ... MT::Template::Context->add_tag('Stats' => sub{&staturl}); sub staturl { my $ctx = shift; my $blog = $ctx->stash('blog'); my $cfg = MT::ConfigMgr->instance; my $script = '<script type=quot;text/javascriptquot;> '.'<!-- '. qq|document.write('<img src=quot;| . $cfg->CGIPath . quot;plugins/statwatch/statvisit.cgi?blog_id=quot; . $blog->id ... |.'// -->'.' </script>'; return $script; } 1;

statwatch Stats.pm lib StatWatch Visit.pm statvisit.cgi StatWatch.pm statwatch statwatch.cgi StatWatchConfig.pm statwatch.pl

Visit.pm # StatWatch - lib/StatWatch/Visit.pm # Nick O'Neill (http://www.raquo.net/statwatch/) package StatWatch::Visit; use strict; use MT::App; @StatWatch::Visit::ISA = qw( MT::App ); use Stats; my $VERSION = '1.2'; my $DEBUG = 0;

MT::ErrorHandler MT::Plugin MT MT::App MT::App::CMS MT::App::Comments MT::App::Search

Visit.pm /2 sub init { my $app = shift; $app->SUPER::init(@_) or return; $app->add_methods( visit => &visit, ); $app->{default_mode} = 'visit'; $app->{user_class} = 'MT::Author'; $app->{charset} = $app->{cfg}->PublishCharset; my $q = $app->{query}; $app; }

Visit.pm /2 sub visit { my $app = shift; my $q = $app->{query}; my $blog_id; if ($blog_id = $q->param('blog_id')) { require MT::Blog; my $blog = MT::Blog->load({ id => $blog_id }) or die quot;Error loading blog from blog_id $blog_idquot;; my $stats = Stats->new; # ...

statwatch Stats.pm lib StatWatch Visit.pm statvisit.cgi StatWatch.pm statwatch statwatch.cgi StatWatchConfig.pm statwatch.pl

Visit.pm /2 package Stats; use strict; use MT::Object; @Stats::ISA = qw( MT::Object ); __PACKAGE__->install_properties({ columns => [ 'id', 'blog_id', 'url', 'referrer', 'ip', ], indexes => { ip => 1, blog_id => 1, created_on => 1, }, audit => 1, datasource => 'stats', primary_key => 'id', }); 1;

MT::ErrorHandler MT::Object MT::ObjectDriver MT::ObjectDriver::DBI MT::ObjectDriver::DBM MT::Entry MT::Author MT::Config

Visit.pm /2 # ... $stats->ip($app->remote_ip); $stats->referrer($referrer); $stats->blog_id($blog_id); $stats->url($url); &compileStats($blog_id,$app->remote_ip); $stats->save or die quot;Saving stats failed: quot;, $stats->errstr; } else { die quot;No blog idquot;; } }

statwatch Stats.pm lib StatWatch Visit.pm statvisit.cgi StatWatch.pm statwatch statwatch.cgi StatWatchConfig.pm statwatch.pl

Visit.pm /2 sub init { my $app = shift; $app->SUPER::init(@_) or return; $app->add_methods( list => &list, view => &view, ); $app->{default_mode} = 'list'; $app->{user_class} = 'MT::Author'; $app->{requires_login} = 1; $app->{charset} = $app->{cfg}->PublishCharset; my $q = $app->{query}; $app; }

Visit.pm /2 sub list { my $app = shift; my %param; my $q = $app->{query}; $param{debug} = ($DEBUG || $q->param('debug')); $param{setup} = $q->param('setup'); ( $param{script_url} , $param{statwatch_base_url} , $param{statwatch_url} , my $static_uri) = parse_cfg(); require MT::PluginData; unless (MT::PluginData->load({ plugin => 'statwatch', key => 'setup_'.$VERSION })) { &setup; $app->redirect($param{statwatch_url}.quot;?setup=1quot;); } require MT::Blog; my @blogs = MT::Blog->load; my $data = []; ...

Visit.pm /2 ... ### Listing the blogs on the main page ### for my $blog (@blogs) { if (Stats->count({ blog_id => $blog->id })) { # [... colleziona i dati da mostrare ...] # Row it my $row = { ... }; push @$data, $row; } } $param{blog_loop} = $data; $param{gen_time} = quot; | quot;.$now.quot; secondsquot;; $param{version} = $VERSION; $app->build_page('tmpl/list.tmpl', %param); }

Riepilogo? • Inserire nuovi tag speciale all’interno dei template • Aggiungere pannelli (applicazioni) • ...

BigPAPI • Big Plugin API • Permette di agganciarsi all’interfaccia esistente di MT, estendendo le funzionalità dei pannelli esistenti

Perchè?

RightFields MT->add_callback( 'bigpapi::template::edit_entry::top', 9, $rightfields, &edit_entry_template ); MT->add_callback( 'bigpapi::param::edit_entry', 9, $rightfields, &edit_entry_param ); MT->add_callback( 'bigpapi::param::preview_entry', 9, $rightfields, &preview_entry_param);

RightFields

Approfondimenti • Six Apart Developer Wiki http://www.lifewiki.net/sixapart/ • Seedmagazine.com — Lookin’ Good http://o2b.net/archives/seedmagazine • Beyond the blog http://a.wholelottanothing.org/features/2003/07/beyond_the_blog • http://del.icio.us/slr/movabletype :-)

Grazie :) Stefano Rodighiero stefano.rodighiero@dada.net

Add a comment

Related pages

Hacking Movable Type (ExtremeTech): Jay Allen, Brad Choate ...

Hacking Movable Type (ExtremeTech) [Jay Allen, Brad Choate, Ben Hammersley, Matthew Haughey, Ben Trott, Mena Trott, David Raynes] on Amazon.com. *FREE ...
Read more

MovableType.org – News: Category Archives: Hacks

November 10, 2008. Hacking the UI to make Movable Type better By Byrne Reese and posted in Hacks. One of the great things about Movable Type is the ...
Read more

Movable Type Developer Guide - MovableType.org ...

Movable Type Developer Guide Movable Type Developer Guide. Welcome to the Movable Type Developer Guide. This guide will provide those wishing to extend ...
Read more

Hacking Movable Type by Jay Allen · OverDrive: eBooks ...

Ready to push Movable Type to the max? Movable Type, that amazingly powerful personal publishing application, is the superhero of the Internet age. But ...
Read more

Hacking Movable Type - Now Shipping | Announcements ...

Hacking Movable Type, the long awaited book by MT experts Jay Allen, Brad Choate, Ben Hammersley, David Raynes and Matt Haughey, is now in print, shipping ...
Read more

Hacking Movable Type | Movalog Blog: Making Movable Type ...

I finally got my copy of Hacking Movable Type and finished reading it last night. Written by the biggest names in the Movable Type community, the 300 pages ...
Read more

Hacking Movable Type - Graphic Design

Hacking Movable Type, by Jay Allen, Brad Choate, Ben Hammersley, Matthew Haughey, David Raynes reviewed for the Design Bookshelf, in DTG magazine for ...
Read more

Hacking Movable Type - Technology - documents

1. Hacking Movable Type Italian Perl Workshop 2006 Stefano Rodighiero - stefano.rodighiero@dada.net . 2. “Movable Type 3.2 is the premier weblog ...
Read more

Hacking movable type (Book, 2005) [WorldCat.org]

Get this from a library! Hacking movable type. [Jay Allen;]
Read more