/ Published in: PHP
Recently moved my Wordpress blog to a tumblr account while I was removing a hosting account, wrote this script to do the transfer for me using Wordpress' Export feature and Tumblr's API.
It's rough around the edges but gets the job done!
It's rough around the edges but gets the job done!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // The full path to the XML file you exported from Wordpress $xmlFile = ''; // Your tumblr log in details $tumblr_email = ''; $tumblr_password = ''; // Tumblr URL (e.g. http://yourname.tumblr.com) $tumblrUrl = ''; // If a post from Wordpress is a draft, do you want it posted as private so you // have it available? True if so, False to ignore drafts $publishDraftAsPrivate = true; // Full path to a file that is writable, so that a log of current URL on your // wordpress blog to new URL on your tumblr can be written (good for redirects // to preserve links, etc) $logFile = ''; } else { echo "no such file"; } $nodes = $xml->xpath('/rss/channel/item'); $count = 0; $post_type = 'regular'; $content = $node->children("http://purl.org/rss/1.0/modules/content/"); $post_body = (string)$content->encoded; $publish_status = $node->children("http://wordpress.org/export/1.0/"); $private = 0; if ($publish_status->status != "publish") { if (!$publishDraftAsPrivate) { continue; } $private = 1; } $count++; 'email' => $tumblr_email, 'password' => $tumblr_password, 'type'=> $post_type, 'title'=>$post_title, 'body'=>$post_body, 'generator'=> 'wptumblr-ds', 'private'=>$private ); $request_data = ""; $first = true; foreach ($request as $key=>$value) { if ($first) { $first = false; } else { $request_data .= "&"; } if ($key == "body") { } else { } } if ($status == 201) { echo "Success! Post ID: $result"; $res = file_put_contents($logFile,$node->link . " : " . $tumblrUrl . "/post/" . $result,FILE_APPEND); } else if ($status == 403) { echo 'Bad email/password'; } else { echo "Error: $result\n"; } } } ?>
URL: http://shakefon.tumblr.com