Post Exporting and Importing

I’m planning on being on holiday later in the year (see  Liverpool in the Autumn for more details ) and I’m planning on doing some blogging whilst we’re underway.

So I want to be able to write my posts on my laptop when I’m disconnected from the internet and then connect and push the post and its images up onto my live blog.

Normally you’d use an offline client of one form or another but I’m using my WordPress Plugin for Canalplan to easily add links to Canalplan places into my blog. So that means that I have to use a local copy of WordPress on my laptop and then move the post when its complete, and that is where the problems start.

There are lots of plugins for WordPress that allow you to do things like export whole blog or a post but many of them (including the Official WordPress ones) expect the source blog to be visible to the internet so they can pull the images over. or they rely on you exporting the whole database and re-importing it which would mean having a whole multi-site install on my laptop which is a bit OTT.

So I sat down yesterday and started coding and I’ve got something working pretty well already.

So I can export a post (along with all its attached media) from one blog into a zip file.
You then move that zip file to the new server
Then you import the zip file either into an existing post (so we overwrite the contents) or into a new post.

Its all working OK so far but there are a few issues to work through. As I have to do search and replace on the image urls then both blogs must have the same image sizes set up because WordPress appends the image sizes when it creates the different sizes:

-rw-rw-r-- 1 www-data www-data 7623937 May 8 14:31 IMG_1032.jpg
-rw-rw-r-- 1 www-data www-data 4483 May 8 14:31 IMG_1032-150x100.jpg
-rw-rw-r-- 1 www-data www-data 15115 May 8 14:31 IMG_1032-300x200.jpg
-rw-rw-r-- 1 www-data www-data 149647 May 8 14:31 IMG_1032-1024x683.jpg
-rw-rw-r-- 1 www-data www-data 59728 May 8 14:31 IMG_1032-619x413.jpg

So if those image sizes are different then the replaced strings in the new content don’t match the files that were created when we loaded the exported media files into the blog.

Also the exporter assumes that filenames are unique – its possible to have two files with the same name in two different upload directories on the source. But on the target system it puts all the files in the current upload directory. So what would happen here is the two original image urls would end up pointing at the single new object.

I’ve not tested it on anything but image files so far but its looking pretty good.

Ready To Export A Post

Ready To Export A Post

Post Exported and Ready to Dowload

Post Exported and Ready to Dowload

Zip file loaded up to new Server and ready to load into new post

Zip file loaded up to new Server and ready to load into new post

File imported into new post

File imported into new post

If I like it I might submit it to the WordPress Plugin Repository.

This entry was posted in Canalplan, Computing and tagged , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.