<?php
/*
[Zaqi!] (C)2009-2010 zaqi.net
从supsite采集机器人导入数据
QQ:findallove@qq.com
tel:13430875919
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
//supsites数据库连接设置
$dbhost1 = 'localhost'; // 数据库服务器
$dbuser1 = 'root'; // 数据库用户名
$dbpw1 = xxx; // 数据库密码
$dbname1 = xxx; // 数据库名
$pconnect1 = 0; // 数据库持久连接 0=关闭, 1=打开
$tablepre1 = 'supe_';
$first=1;
$db1 = new dbstuff;
$db1->connect($dbhost1, $dbuser1, $dbpw1, $dbname1, $pconnect1);
$dbuser1 = $dbpw1 = $dbname1 = $pconnect1 = NULL;
//运行机器人
/*
$sql="select robotid from {$tablepre1}robots";
$query = $db1->query($sql);
$url="http://www.168mobi.com/blog/admincp.php?action=robots&op=robot&clearcache=1&robotid=";
echo "<script language=javascript>";
while($rs= $db1->fetch_array($query)) {
$url1=$url.$rs['robotid'];
echo "open(\"$url1\");";
}
echo "</script>";
$db1->free_result($query);
*/
//设置发帖人
$author="findallove";
$authorid="1";
//$d1=round(time()/(3600*24))*3600*24;
//$sql="update {$tablepre}posts set message=replace(replace(message,'<','<'),'>','>') where dateline>$d1";
//$query = $db->query($sql);
//$db->query($sql);
if(!empty($_POST["author"])){
$author=$_POST["author"];
$sql="select uid from {$tablepre}members where username='$author'";
$rs=$db->getin($sql);
$authorid=$rs['uid'];
unset($rs);
}else{
echo "设置发帖人";
cjupdateforum();
//echo strftime("%Y-%m-%d",strtotime("1 day"))."<br>";
//echo microtime(strftime("%Y-%m-%d",strtotime("1 day")))."<br>";
//echo time()."<br>";
echo "<form method=post>";
echo "<input type=\"text\" name=\"author\"> ";
echo "<input type=\"submit\" value=\"开始采集\"></form><br>";
echo "技术支持:<a href=http://www.zaqi.net target=_blank>杂器网</a>";
echo "<a href=\"http://wpa.qq.com/msgrd?V=1&Uin=64816414&Site=杂器网&Menu=yes\" target=\"_blank\"> <img src=http://wpa.qq.com/pa?p=1:46133092:4 height=\"16\" border=\"0\" alt=\"QQ\" > 64816414</a><br><br>";
die("如果为空,则不会进行数据采集");
}
//读取机器人数据
$sql="select a.username,a.uid,a.subject,a.robotid,a.robottime,b.message,c.name from {$tablepre1}robotitems a left join {$tablepre1}robotmessages b on a.itemid=b.itemid left join {$tablepre1}robots c on c.robotid=b.robotid";
$query1 = $db1->query($sql);
while($rs1= $db1->fetch_array($query1)) {
//获取论坛分类
$sql="select fid from {$tablepre}forums where name='".$rs1['name']."'";
$rs=$db->getin($sql);
$fid=$rs['fid'];
if($fid!=''){
$subject=$rs1['subject'];
$dateline=$rs1['robottime'];
$views=rand(50,200);
//$subject=str_replace("\'","\"",$subject);
$subject=dhtml($subject);
//监测是否重复
$sql="select tid from {$tablepre}threads where subject like '$subject'";
unset($rs);
$rs=$db->getin($sql);
$sb=$rs['tid'];
if($sb==''){
//1.添加主题
$sql="insert into {$tablepre}threads(fid,subject,author,authorid,dateline,lastpost,lastposter,supe_pushstatus,views)values($fid,'$subject','$author',$authorid,'$dateline','$dateline','$author',1,$views)";
$db->query($sql);
$tid =$db->insert_id();
$db->free_result($query);
//2.添加内容
if($tid!=''){
echo $tid."subject<br>";
$message=$rs1['message'];
//$message=str_replace("\'","\"",$message);
$message=dhtml($message);
$sql="insert into {$tablepre}posts(tid,first,message,fid,subject,author,authorid,usesig,htmlon,bbcodeoff,smileyoff,parseurloff,dateline)values($tid,$first,'$message',$fid,'$subject','$author',$authorid,'0','1','0','-1','0',$dateline)";
$db->query($sql);
}
$db->free_result($query);
$lastpost = addslashes("$tid\t$subject\t$dateline\t$author");
mysql_query("UPDATE {$tablepre}forums SET lastpost='$lastpost', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'");
}
}
}
$db1->free_result($query1);
cjupdateforum();
//删除机器人采集的数据
$sql="DELETE FROM {$tablepre1}robotitems";
$db1->query($sql);
$db1->free_result($query);
$sql="DELETE FROM {$tablepre1}robotmessages";
$db1->query($sql);
$db1->free_result($query);
function cjupdateforum()
{
global $tablepre,$db;
$queryf = $db->query("SELECT fid FROM {$tablepre}forums WHERE type<>'group'");
while($forum=$db->fetch_array($queryf)) {
$rs = $db->getin("SELECT tid, subject, lastpost, lastposter FROM {$tablepre}threads WHERE fid='$forum[fid]' AND displayorder>='0' ORDER BY lastpost DESC LIMIT 1");
$lastpost = addslashes("$rs[tid]\t$rs[subject]\t$rs[lastpost]\t$rs[lastposter]");
$sql="SELECT COUNT(*) AS threads, SUM(replies)+COUNT(*) AS posts FROM {$tablepre}threads WHERE fid='$forum[fid]' AND displayorder>='0'";
$rs=$db->getin($sql);
$threads=$rs['threads'];
$posts=$rs['posts'];
$d1=round(time()/(3600*24))*3600*24;
$sql="SELECT COUNT(*) AS todayposts FROM {$tablepre}threads WHERE fid='$forum[fid]' AND displayorder>='0' and dateline>$d1";
$rs=$db->getin($sql);
$todayposts=$rs['todayposts'];
$query=$db->query("UPDATE {$tablepre}forums SET threads='$threads', posts='$posts', lastpost='$lastpost',todayposts='$todayposts' WHERE fid='$forum[fid]'");
$db->free_result($query);
}
$db->free_result($queryf);
}
function dhtml($s){
if($s!='') {
$s=str_replace("'","'",$s);
$s=str_replace(",",",",$s);
$s=str_replace("\"",""",$s);
$s=str_replace("|","I",$s);
$s=str_replace("\t","",$s);
// $s=str_replace("<","<",$s);
// $s=str_replace(">",">",$s);
$s=str_replace(" "," ",$s);
}
return $s;
}
?>
这是最终版代码 |