PHP 将Wordpress迁移到Tumblr
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 将Wordpress迁移到Tumblr相关的知识,希望对你有一定的参考价值。
<?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 = '';
if (file_exists($xmlFile)) {
$xml = simplexml_load_file($xmlFile);
} else {
echo "no such file";
}
if (isset($xml)) {
$nodes = $xml->xpath('/rss/channel/item');
$count = 0;
while(list( , $node) = each($nodes)) {
$post_type = 'regular';
$post_title = rawurlencode($node->title);
$post_title = str_replace("%20"," ",$post_title);
$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++;
$request = array(
'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 .= "&";
}
$request_data .= urlencode($key) . "=";
if ($key == "body") {
$request_data .= urldecode($value);
} else {
$request_data .= urlencode($value);
}
}
$c = curl_init('http://www.tumblr.com/api/write');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $request_data);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($c);
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
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";
}
}
}
?>
以上是关于PHP 将Wordpress迁移到Tumblr的主要内容,如果未能解决你的问题,请参考以下文章
使用 php 和 Tumblr API 发布到 Tumblr
迁移后 Wordpress 不断重定向到 install-php
使用脚本一键将织梦cms迁移到 WordPress的方法
将 wordpress 电子商务迁移到自定义 Web 应用程序
如何将 wordpress 博客迁移到 AWS 弹性 beantalk
Wordpress网站 - php版本迁移(5.2 - 7.x) - 它会导致问题吗?