整合嘀咕数据到wordpress中
首先使用去年写的嘀咕备份工具(现有出现了乱码的问题,空了再解决)下载所有嘀咕数据(消息,图片),然后导入到本地的mysql数据中,把数据库中的status表导入到你wordpress数据库中:
然后将以下代码保存为php文件,放在网站上运行一次:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
$img_new_path = 'http://tunps.com/wp-content/myuploads/2011/01/';
$link_id = mysql_connect("localhost", "user", "pass") or
die("Could not connect: " . mysql_error());
mysql_select_db('wp');
mysql_query("set names utf8");
$result = mysql_query("select * from status");
while ($row = mysql_fetch_assoc($result)) {
if ($row['in_reply_to_status_id'] == '0')
{
$title = substr($row['text'], 0, 60);
if ($row['text'] == '') {
$title = '无标题';
}
$sql = "INSERT INTO `jq_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`,
`post_category`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`,
`pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`,
`post_mime_type`, `comment_count`)
VALUES (NULL, '1', '$row[created_at]', CONVERT_TZ('$row[created_at]','+08:00','+00:00'), '$row1', '$title', '0', '', 'publish', 'open', 'open', '', unix_timestamp('$row[created_at]'), '', '',
'$row[created_at]',CONVERT_TZ('$row[created_at]','+08:00','+00:00') , '', '0', unix_timestamp('$row[created_at]'), '0', 'post', '', '0');";
mysql_query($sql);
$insert_id = mysql_insert_id($link_id);
mysql_query("insert into wp_term_relationships values ($insert_id,770,0) "); //将770改为对应的term_taxonomy_id
mysql_query("update wp_term_taxonomy set count=count+1 where term_taxonomy_id=770 ");//将770改为对应的term_taxonomy_id
//如果不含图片/插入一行记录post
if ($row['picPath'] == '') {
} else
{
//http://pic.minicloud.com.cn:80/file/10/02/58/10/201003/7868626c6629a84bbe60828fbaeac0d3_100x75.jpg
$url = $row['picPath'];
$filename = substr($url, strrpos($url, '/') + 1, strlen($url));
$filename = str_replace('100x75', '640x480', $filename);
$url = $img_new_path . $filename;
$sql = "INSERT INTO `jq_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`,
`post_category`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`,
`pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`,
`post_mime_type`, `comment_count`)
VALUES (NULL, '1', '$row[created_at]', CONVERT_TZ('$row[created_at]','+08:00','+00:00'), '', '$filename', '0', '', 'inherit', 'open', 'open', '', '$filename', '', '',
'$row[created_at]',CONVERT_TZ('$row[created_at]','+08:00','+00:00') , '', '$insert_id', '$url', '0', 'attachment', 'image/jpeg', '0');";
mysql_query($sql);
$img_id = mysql_insert_id($link_id);
//文章插入图片
$img_tag = '<br /><a href="' . $url . '"><img class="alignleft size-full wp-image-' . $img_id . '" title="' . $filename . '" src="' . $url . '" alt="" /></a>';
$img_tag = addslashes($img_tag);
$sql = "update wp_posts set post_content=concat(post_content,'$img_tag') where ID=$insert_id";
mysql_query($sql);
}
}
}
echo 'ok';
?>
完成!