My first Movable Type Plugin


Two nights ago, I put together a syntax highlighter - actually a wrapper around a set of CPAN based syntax highlighting code because I was writing something and I wanted to have highlighted syntax for it. It started out as a command line utility that I thought I'd occasionally use. An hour later, I wanted it again for an article in this blog so I made it a CGI script.

Last night I got a wild bug to try to put together one of those cool Movable Type Plugins. Wouldn't it be cool if I could trigger my syntax highlighter from within MT? It took me about an hour to get the 26 lines right - but it really was a matter of putting together 26 lines of perl to add something really cool to the interface.

At first, I just went through the sixapart documentation regarding plugins. While it does lay out things, it really is lacking a real tutorial. Maybe I should put one together.

I saw at the very bottom of the doc that you can add a link to MT by using similar code to this:



my $link = "http://somelink";
MT->add_plugin_action('entry', $link,
'My cool syntax highlighter');

After I got it working, I discovered that the link is prefixed with your plugin directory, which isn't where I had my syntax highlighter stored. I also discovered that the "Plugin Actions" section is at the very bottom of the page in the edit entry page. Not exactly what I wanted, but it's still useful for those people who haven't installed BigPapI.

BigPapi is a utility that allows you to programatically alter the movable type admin interface templates without actually going in and editing them yourself. Pretty cool, I thought. Then I got worried about how difficult it actually was going to be to accomplish.

Believe it or not, it was a piece of cake, once I got past a couple of not so obvious steps. Movable Type uses HTML::Template for outputting pages, which thank goodness I'm already very familiar with. If you are not, don't worry, it's very easy to figure out. Basically, the HTML templates are stored in the "tmpl" directory. They are all named appropriately. What I was looking for was the edit_entry template.

Once I found it, it was simply a matter of putting together a simple regular expression to insert my link:


my $old = "Upload File\"></a></li></TMPL_IF>";
my $new = "Upload File\"></a></li></TMPL_IF>>li>>a href=\"#\" onClick=\"MyWindow=window.open('','MyWindow','toolbar=no,location=no,directories=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=598,height=458');return false;\">SKSyntax</a></li>";
$$template =~ s/$old/$new/;

Badda Bing Badda Boom. I now have a link from within my MT interface that will open up my syntax highlighter.

More on how it looks, how it works, and how to install it when I release the plugin.



Join The My first Movable Type Plugin Discussion