MT to moblog

Quick Links

How fast is that drive?

hunting for prime numbers

From Movatble Type to Wordpress

If you have been struck by an overwhelming urge to move from movable type to easy moblog hopefully this will help.

The entries in a MovableType blog seem to have the following format:

AUTHOR: name
TITLE: title
STATUS: Draft | Publish
CONVERT BREAKS: __default__
[CATEGORY: name]

DATE: mm/dd/yyyy hh:mm:ss AM | PM
body text here.
<Extended body text here.>

<Excerpt here>

<Why bother with keywords?>



This is just the kind of format that is easy to parse with PHP string handling functions. Before we do that let's take a look at what the table structure looks like in easy moblog. As you might guess, the result from running the desc blog_posts command has been cut and pasted.

| Field                | Type                           | Null | Key | Default    | Extra          |
| post_id              | int(10) unsigned               |      | PRI | NULL       | auto_increment |
| post_added           | int(10) unsigned               | YES  |     | NULL       |                |
| post_ctype           | enum('text/plain','text/html') |      |     | text/plain |                |
| post_images          | int(10) unsigned               | YES  |     | 0          |                |
| post_mail_from       | varchar(255)                   | YES  |     | NULL       |                |
| post_mail_date       | int(10) unsigned               | YES  |     | NULL       |                |
| post_mail_subject    | varchar(255)                   | YES  |     | NULL       |                |
| post_mail_body       | text                           | YES  |     | NULL       |                |
| post_mail_user_agent | varchar(255)                   | YES  |     | NULL       |                |
| topic_id             | int(10) unsigned               |      |     | 0          |                |

The mail_from field (post_ is a prefix) represents the author field in movable type and obviously there isn't any space to enter the excerpt. We will append the data from the extended body field in movable type to the mail_body field in easy moblog. The only field that is going to cause us any headaches is the mail_date' field, which represents the time the post was published. Also note that easymoblog does not recognize the concept of draft posts, since it expects you to store all your drafts in the drafts folder of your mail user agent.

Getting back to the post_added, we have two options when converting the formatted date and time from movable type into the numeric format that easy mobklog except. We could use the datetime functions of either PHP or mysql (or even both if we were inclined to do so). Moblog's email parser uses the strtotime php function so we will use the same. When retrieving messages from the database for display moblog uses getdate so it makes sense for us to use the same method ourselves.

        $s = fgets($fp);
        $post['author'] = addslashes(trim(str_replace("AUTHOR: ","",$s)));
        $s = fgets($fp);
        $post['title'] = addslashes(trim(str_replace("TITLE: ","",$s)));
         * The next five lines can be discarded since they do not have a
         * 1-1 mapping with moblog .
        for($i=0 ; $i < 5 && !feof($fp) ; $i++)
        $s = fgets($fp);
        if(preg_match("/DATE\: /",$s))
                $post['date'] = strtotime(trim(str_replace("DATE: ","",$s)));
                fgets($fp); // discard another line.
                $s = fgets($fp);
                $post['date'] = strtotime(trim(str_replace("DATE: ","",$s)));

The few lines of code produced above demonstrates how the headers can be grabbed. That's really the only section of the code that is worth commenting on. Some of the header fields are of no interest to us and we just discard them. Retrieving the body is a lot easier. And once we finish processing an entry we just chuck it into the databse with an sql query.

This version of the script is not compatible with mt entries that have comments, but that will follow soon.

Download the script (