XML-RPC & forms
When I set about re-creating MovaDir, I wanted to create a form that would post directly into MT. I soon discovered that I would need to use the XML-RPC API to really streamline it. This is a tutorial that will guide you through setting up a form that will allow a user to manipulate entry fields and then rebuild the entry. Use of the mySQL database is required.
You will need to create a new index template called Incutio XML-RPC Library, set the output file as IXR_Library.inc.php and copy this file for the template body.
Next create a new index template called IP Tracking with an output file iptracking.php and copy this file into the template body.
This is a very neat script written by Rob Beckett. Basically this script restricts the number of page views from the same IP and hence prevents people abusing this xmlrpc script. Just change the value of $IPT_TF to reflect how long the interval between page views should be.
Next, you'll need to create a form as an Index Template that will be used to post into MT. Here's an example that I use (you will need the CategoryDepth and PerlScript plugins for the subcategory listing)
Finally, create a new template and call it something like XMLRPC with an output of xmlrpc.php and copy the following code into the template body
Plenty to change in this script:
- Replace DB_USRNAME with the username used to connect to the MT mySQL database (same as DBUser in mt.cfg)
- Replace DB_PASS with the password used to connect to the MT mySQL database (same as the contents of mt-db-pass.cgi)
- Replace DB_DB with the name of the database used by MT (the Database variable in mt.cfg)
- Replace BLOGID with the id of the blog you want the entry posted to
- Replace MYUSERNAME with the username used to log into Movable Type
- Replace MYPASSWORD with the password that corresponds with the above username to log into MT
- Change all three /path/to/ with the correct paths to iptracking.php, the IXR_Library and mt-xmlrpc.cgi
With PHP, the variable $_POST grabs details that have been posted to the script. Basically this is what the script does.
- Connects to the MT database and checks the iptracking table for the current IP
- If the IP isn't in the table then it runs the script, if the IP is there and the last time the page was requested from the IP is less than the value of $IPT_TF, the script fails
- The variable $content is populated with the contents of the form
- A new XMLRPC instance is called
- The metaWeblog.newPost method is called and the necessary parameters are passed. The entry has not yet been published -- if you want to publish it at this stage change the 0 to a 1
- On success, the post's ID is captured
- The post's categories are set and the post is (re)published
More parameters can be passed in $content, created the necessary <input> in the form and then simply add to the $content array using the corresponding parameter name found in the docs For example, if I wanted to also add keywords, I would create a new input perhaps called "keywords" and then my $content would look something like this:
$content = array('title' => $_POST['title'],'description' => $_POST['text'],'mt_text_more' => $_POST['text_more'],'mt_keywords' => $_POST['keywords']);

Robmonster said:
on Apr 13, 2005 2:20 PM | Reply
This is exactly what I've been looking for! I need a method for people to post into a specific category on ne of my weblogs. This looks like it will do the trick.
I'll give it a whirl tonight!
R
dwood said:
on Apr 28, 2005 7:05 AM | Reply
Arvind, Got it working like a charm, but one question. If I wanted the entry to be posted as a draft, and not published, what changes do I need to make?
This is a great little script! Thanks!
Eric winther said:
on Sep 23, 2005 6:12 AM | Reply
Hi!wonderful plugin. I've done step by step all you have said, but it does not work for me.What may the problem be? Shoud I change Chmod for the files? or what?Should I write absolute path to the files? I'm so confused, coz everything seems to be ok, but nothing happens when I use the form to post an entry
Steve said:
on Oct 18, 2005 8:35 AM | Reply
I encounterd the same problem as dwood, it gets posted but 'draft' status doesn't work. It gets published immediately. 0 or 1 parameter doesn't do anything.
eric said:
on Oct 21, 2005 1:00 AM | Reply
Hi Robmonster and Steve. That sems that you guys have been able to use this feature. Please let me know why when I use "
print " "x"".""; " No category lables show up.When I use: "
print " "x""."";
"
then I have the categories, but when I post an entry, it has no category assigned to it.Can you help me please?
Chuck05 said:
on Jan 6, 2006 1:45 PM | Reply
When I press "Submit" on the form, I get an error message:
Any idea what I'm doing wrong?
Peter Johnstone said:
on Mar 21, 2006 7:46 PM | Reply
This is an excellent set of scripts and hacks that can be incredibly useful, I'm suprised there's not a whole forum somewhere dedicated to implementing alternative MT interfaces through the browser.
Beware that the 'posting' index template above is slightly wonked in its current version - it doesn't generate a proper dropdown menu, and you need to pass along the category ID number - not the name - in order to have MT post the category. something like this should work:
My personal tragedy is that I'd love to pass along manual date-posted field along with the post. While the tutorial states that this can be done just by adding parameters to the $content array, my poor attempts to do so have only been met with:
I see that in the XMLRPC file, categories gets its own array - perhaps date needs to be similarly processed?
Woe is me. Any help's appreciated...
Peter Johnstone said:
on Mar 21, 2006 7:48 PM | Reply
well, my code for the drop down menu got stripped out above. But I'm sure you can figure it out yourself, I've heard you're really very bright.
Ro said:
on Mar 28, 2006 9:36 AM | Reply
Well I wasn't able to make it work. Someone has a full complete script working with Mt 3.2 ?
Robmonster said:
on Mar 28, 2006 12:25 PM | Reply
I do.
Email me at movalog.store@neverbox.com and I'll send you the code I use.
R
alan said:
on Apr 5, 2006 6:32 AM | Reply
Has anyone used a similar method to edit posts? i'm thinking it would be using metaweblog.editpost, but I haven't been able to get it to work by tinkering with the above code. The new post stuff works wonderfully, though...
alan said:
on Apr 5, 2006 7:35 PM | Reply
I've posted a query over at the sixapart forums, trying to make some headway on adapting this script to pass entry edits. head over there to give me a hand...
Matt Carey said:
on Oct 16, 2006 4:38 AM | Reply
I have just been trying to get this to work and the xml-rpc php file runs but no entry is added.
What is odd is that I have this working on one host, but on a different host it doesn't work. I've copied the same code across, so could it be because the one that doesn't work is using Zeus rather than Apache?
Arvind Satyanarayan said:
on Oct 16, 2006 5:35 PM | Reply
Hi Matt, that is really odd. Unfortunately I'm not very familiar with Zeus so I can't offer much help :(
Matt Carey said:
on Oct 20, 2006 3:39 AM | Reply
Does anyone know what php modules are required for this to work. i'm assuming the xml-rpc one but is there anything else? i am 100% sure my code is correct so it must be the hosting set-up and i want to tell the host people that!
Arvind Satyanarayan said:
on Oct 21, 2006 2:50 PM | Reply
Hi Matt. To my knowledge no other PHP Modules are needed, you simply need to include the Incutio XML-RPC Library. What exact problems are you experiencing? Are there any error messages/anything in the server log?
Paul Berry said:
on Dec 1, 2006 11:09 PM | Reply
Hi guys -- does anyone know if MT3.3 has a xmlrpc spec to get, update and insert Tags related to entries? I see it does getCategory but I don't find anything on getTag or somiliar