I was looking for a way to permit random people to submit entries to Movable Type, and there’s not really any way to do it out of the box, so I wrote this CGI. It is not entirely polished; in particular, it ought to use a config file and of course the HTML is gonna need to be changed. It also ought to display a success page. However, I realized last night that I was going to wind up modifying it substantially to meet my specific needs and that it wouldn’t be so generally useful post-modification, so here you go.
Note that unless you add NoPublishMeansDraft 1
to your mt.cfg file, submissions will be not be posted as drafts. More details on that here.
Edit: Mmm. Yeah. Sorry about that; I stuck the CGI off in the extended entry bit.
#!/usr/bin/perl -w use Net::Blogger; use CGI::Pretty; use strict; #### #### #### Initialize everything #### #### Set up Net::Blogger & CGI objects my $mt = Net::Blogger->new(engine => 'movabletype'); my $query = new CGI; #### Set up some variables my %cathash; my $categories; #### Set appropriate params $mt->Proxy("http://popone.innocence.com/mt/mt-xmlrpc.cgi"); $mt->Username("XXXXX"); $mt->Password("XXXXX"); $mt->BlogId("X"); #### Get category list my $categories = $mt->mt()->getCategoryList(); foreach my $cat (@$categories) { $cathash{$cat->{'categoryName'}} = $cat->{'categoryId'}; } #### #### #### Display the HTML page #### print $query->header; print $query->start_html; print $query->h1("Submit an Entry"); print $query->start_p; print $query->start_form; print $query->strong("Title: "); print $query->textfield('title'); print $query->strong("Category: "); print $query->popup_menu('category', [ keys(%cathash) ]); print $query->br; print $query->textarea('body','',20,80); print $query->br; print $query->submit; print $query->end_form; print $query->end_p; print $query->end_html; #### #### #### Do the actual post #### if ($query->param('title')) { post($query); } #### #### #### Subroutine: post #### Takes: CGI object #### Does: makes a post to MT #### Returns: error string if any, otherwise true #### sub post { my $query = shift; my $post = $mt->metaWeblog->newPost( title => $query->param('title'), description => $query->param('body'), publish => "0", ) || return $mt->LastError, exit; $mt->mt->setPostCategories( postid => $post, categories => [{categoryId => $cathash{$query->param('category')}}], ) || return $mt->LastError, exit; }
Be First to Comment