6k visitas
Script to export Wordpress posts to Tumblr
Tumblr does not provide a way to import posts from Wordpress. To solve that, I fixed some code I found on the internet and it seems to work. Here it is:
PHP
- <?php
- // wp-tumblr.php
- // originally by miguel santirso, http://miguelsantirso.es
- // updated for wp 1.1 xml export format by christopher j. pilkington, http://0x1.net, 2011 oct 27
- //
- // Use at your own risk, you may want to test this with a throw-away tumblr account first.
- //
- // The full path to the XML file you exported from Wordpress
- $xmlFile = 'MYEXPORTFILE.xml';
- // Your tumblr log in details
- $tumblr_email = 'EMAIL';
- $tumblr_password = 'PASSWORD';
- // Tumblr URL (e.g. http://yourname.tumblr.com)
- $tumblrUrl = 'http://MYTUMBLRID.tumblr.com';
- // If WordPress post is a draft, true to upload as private, false to not upload it.
- $publishDraftAsPrivate = true;
- // A writeable logfile, to keep track of the new URLs.
- $logFile = 'log.txt';
- } else {
- echo "ERROR: no such file\n\n";
- }
- $nodes = $xml->xpath('/rss/channel/item');
- $count = 0;
- $post_type = 'regular';
- $post_title = $node->title;
- $content = $node->children("http://purl.org/rss/1.0/modules/content/");
- $post_body = (string)$content->encoded;
- $wp = $node->children("http://wordpress.org/export/1.1/");
- $date = $node->pubDate;
- echo $date . "\n";
- $private = 0;
- if ($wp->status != "publish" && $wp->status != "inherit") {
- if (!$publishDraftAsPrivate) {
- continue;
- }
- $private = 1;
- }
- if ($wp->post_type == "attachment")
- continue;
- $count++;
- 'email' => $tumblr_email,
- 'password' => $tumblr_password,
- 'type' => $post_type,
- 'title' => $post_title,
- 'date' => $date,
- '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 ($status == 201) {
- echo "Success! Post ID: $result\n";
- $res = file_put_contents($logFile, $node->link . " : " . $tumblrUrl . "/post/" . $result, FILE_APPEND);
- } else if ($status == 403) {
- echo 'ERROR: Bad email and/or password.';
- } else {
- echo "Error: $result\n"; // This might not be fatal.
- }
- }
- }
- ?>
If you find some bug on this code or you have some suggestion, you can email me: miguel.santirso at gmail.com.
Enviado por miguelSantirso hace about 1 year — modificado por última vez hace less than a minute