手工将多说评论迁回本地
编辑:佚名 2021-06-06 16:05:56 来源于:魔法系统之家下载
<html>
<meta charset="utf8">
<title>多说评论转回typecho</title>
<?php
include_once("config.inc.php");
$db = Typecho_Db::get();
if (isset($_FILES["file1"])&&isset($_FILES["file2"])) {
$postid=json_decode(file_get_contents($_FILES["file1"]["tmp_name"]),1);
$comments=file_get_contents($_FILES["file2"]["tmp_name"]);
for ($i=0; $i < count($postid["threads"]); $i++) {
$comments=str_replace($postid["threads"][$i]["thread_id"], $postid["threads"][$i]["thread_key"], $comments);
}
$comments=json_decode($comments,1);
for ($i=0; $i < count($comments["posts"]); $i++) {
$name=$comments["posts"][$i]["author_name"];
$cid=$comments["posts"][$i]["thread_id"];
$email=$comments["posts"][$i]["author_email"];
$url=$comments["posts"][$i]["author_url"];
$time=strtotime($comments["posts"][$i]["created_at"]);
$ip=$comments["posts"][$i]["ip"];
$content=$comments["posts"][$i]["message"];
$insert = $db->insert('typecho_comments')
->rows(array('cid' => $cid, 'created' => $time,'author'=>$name,'authorId'=>0,'ownerId'=>1,'mail'=>$email,'url'=>$url,'ip'=>$ip,'text'=>$content,'type'=>'comment','status'=>'approved','parent'=>0));
$db->query($insert);
}
die("<h1>OK</h1>");
}
?>
<body>
<style>
.updata{
width: 400px;
border: 1px;
border-style: solid;
margin-left: auto;
margin-right: auto;
}
</style>
<div class="updata">
<form style="margin:5px;" action="duoshuo.php" method="post" enctype="multipart/form-data">
文章数据<input type="file" name="file1" id="file1" />
<br>
评论数据<input type="file" name="file2" id="file2" />
<input type="submit" name="submit" value="Submit" />
</form>
</div>
</body>
</html>
结束
步骤比较繁琐,慢慢来吧 如果仅需要迁回本地而不在前台显示,仅需要执行3-6步即可。
步骤
第一步,修改模板文件中的comments.php
文件,去掉多说评论代码,添加系统自带评论代码
第二步,文章信息处将多说评论数调用函数改为系统评论数调用函数,输出文章评论次数,现在文章评论数都为0
第三步,进入多说后台,使用评论导出功能,将文章数据和评论数据分别导出为两个文件
第四步,使用下文代码,保存为duoshuo.php
文件,并上传至博客根目录
第五步,访问blog.sinsle.com/duoshuo.php
(域名部分替换为你自己的域名),将刚刚导出的两个文件上传,然后提交,成功后界面出现OK即可
第六步,登陆数据库管理后台,选择typecho_comments
数据表,可以看到所有的评论都在数据库中,但是现在博客文章中不会显示评论,不知道之前会不会有这个问题,或许是typecho版本更新导致现在这个工具不好使了,不过没关系,接着往下
第七步,对照多说后台评论,修改数据库中所有评论的cid字段为评论对应文章的cid,文章cid在多说评论后台为thread_key
第八步,修改完成后可以发现文章中已经正常显示评论内容,但是文章评论次数还是为0,在文章中发布新的评论,文章评论数便会显示为正常评论条数
第九步,这一步我还没有做,太麻烦了,打算慢慢来,如果你是一个完美主义者,那么你需要去数据库中的typecho_comments表中修改parent字段,该字段的意思为该条评论回复的上一条评论的coid,假如评论内容“你好”的coid为1,那么我回复“你也好”,“你也好”的coid为2,“你也好”的parent字段值为1,因为“你也好”是为了回复“你好”而回复的,他的父级评论就是“你好”。
第十步,如果你是一个最最完美主义者,那么剩下的就是研究研究评论样式了,让你的评论更加美观!
Ok,整个多说评论迁移回typecho数据库的步骤就结束了,如果在评论的过程中出现了问题,可以在文章下方留言,我可以帮忙尝试解决!
相关信息