因为多说将于近期住手效劳,一切有部份运用多说的 emlog用户想要将在多说导出的json批评数据倒进本身的 博客中,运用本剧本能够完成这个功用。细致代码以下,假如你运用的是 emlog 博客程序,即能够运用这个剧本举行导入。注重,导入后会丧失批评的父子关系。文章的ID是经由过程 thread_key 参数指定的,假如你没有开启 thread_key 设置,不要运用这个剧本。本剧本会将批评数据添加到指定文章下。且会自动更新对应文章的批评数。
以下为悉数代码,将其保存为php文件上传到效劳器实行即可。
<?phperror_reporting(0); header("Content-type:text/html;charset=utf-8");date_default_timezone_set('Etc/GMT-8');?><form action="?ok=post" method="get"><input type="hidden" name="ok" value="post"><div style="margin:30px 0px;height:16px;line-height:16px;"> 数据库地点:<input id="host" name="host" type="text">平常为localhost</div><div style="margin:30px 0px;height:16px;line-height:16px;"> 数据库名:<input id="name" name="name" type="text">填写emlog博客地点的数据库</div><div style="margin:30px 0px;height:16px;line-height:16px;"> 数据库账号:<input id="user" name="user" type="text"></div><div style="margin:30px 0px;height:16px;line-height:16px;"> 数据库暗码:<input id="pass" name="pass" type="text"></div><div style="margin:30px 0px;height:16px;line-height:16px;"> 数据库前缀:<input id="prefix" name="prefix" type="text">一定要准确,如 emlog_</div><input style="border:1px solid #ccc;width:112px;height:30px;line-height:30px;background:#fff;" type="submit" value="肯定">确认无误后点击肯定即可。</form><?phpif($_GET['ok'] == 'post'){$host = $_GET['host'] ? $_GET['host'] : '';$name = $_GET['name'] ? $_GET['name'] : '';$user = $_GET['user'] ? $_GET['user'] : '';$pass = $_GET['pass'] ? $_GET['pass'] : '';$prefix = $_GET['prefix'] ? $_GET['prefix'] : '';if($host == '' or $name == '' or $user == '' or $pass == '' or $prefix == ''){echo '参数不完全,请填写完全参数<br>';exit;}else{$con = mysql_connect($host,$user,$pass); //衔接数据库if(!$con){die('不能衔接数据库效劳器:'.mysql_error());}mysql_select_db($name,$con);//挑选数据库mysql_query("set names 'utf8'");echo '衔接数据库胜利<br>';}//推断数据表是不是存在$sql="show tables like '".$prefix."comment'";$result = mysql_query($sql,$con);if(mysql_num_rows($result)){echo '批评数据表找到<br>';}else{echo '<span style="color:#f00;">批评数据表不存在,多是前缀填写毛病</span><br>';exit;}$sql="show tables like '".$prefix."blog'";$result = mysql_query($sql,$con);if(mysql_num_rows($result)){echo '文章数据表找到<br>';}else{echo '<span style="color:#f00;">文章数据表不存在,多是前缀填写毛病</span><br>';exit;}echo '入手下手写入批评数据<br>';//唯一须要修正的处所,将在多说导出的json数据悉数复制到‘’中心$json = '{"generator":"duoshuo","version":"0.1","threads":[{"site_id":1176228,"thread_id":12...}';$unjson = json_decode($json,true);$jishu = 0;$number = count($unjson['posts']);while($jishu < $number){$gid = $unjson['posts'][$jishu]['thread_key'] ? $unjson['posts'][$jishu]['thread_key'] : -1;$pid = 0;$date = mktime(substr($unjson['posts'][$jishu]['created_at'],11,2),substr($unjson['posts'][$jishu]['created_at'],14,2),substr($unjson['posts'][$jishu]['created_at'],17,2),substr($unjson['posts'][$jishu]['created_at'],5,2),substr($unjson['posts'][$jishu]['created_at'],8,2),substr($unjson['posts'][$jishu]['created_at'],0,4));if($date == ''){$date = time();}$poster = $unjson['posts'][$jishu]['author_name'] ? $unjson['posts'][$jishu]['author_name'] : '匿名';$comment = $unjson['posts'][$jishu]['message'] ? $unjson['posts'][$jishu]['message'] : '';$mail = $unjson['posts'][$jishu]['author_email'] ? $unjson['posts'][$jishu]['author_email'] : '';$url = $unjson['posts'][$jishu]['author_url'] ? $unjson['posts'][$jishu]['author_url'] : '';$ip = $unjson['posts'][$jishu]['ip'] ? $unjson['posts'][$jishu]['ip'] : '';$hide = 'n'; $sql="INSERT INTO ".$prefix."comment (gid,pid,date,poster ,comment,mail,url,ip,hide) VALUES ({$gid},{$pid},{$date},'{$poster}','{$comment}','{$mail}','{$url}','{$ip}','n')";mysql_query($sql,$con);//写入批评$sql="UPDATE ".$prefix."blog SET comnum=comnum+1 WHERE gid = {$gid}";mysql_query($sql,$con);//更新文章批评数//echo $jishu.' 更新胜利<br>';$jishu++;}echo $jishu.'条批评数据已写入数据库,如今你能够封闭本页面了。<br>';}?>
评论列表