updateFunction.asp
上传用户:rblchem
上传日期:2022-04-27
资源大小:1941k
文件大小:20k
- <script language="JavaScript" runat="server">
- function rfc_to_iso(DataRCC){
- var dateTimeObject = new Date(DataRCC);
- if(isNaN(dateTimeObject)){
- var dateTimeObject2 = new Date(DataRCC.substring(0,DataRCC.lastIndexOf(" ")));
- if (isNaN(dateTimeObject2)){
- return DataRCC;
- }
- else{
- return dateTimeObject2.toLocaleString();
- }
- }
- else{
- return dateTimeObject.toLocaleString();
- }
- }
- </script>
- <%
- Public ISUserUpdate,BLOGURL
- db="../data/"&dbname
- %>
- <!-- #include file="conn.asp" -->
- <!-- #include file="RegExpFunction.asp" -->
- <%
- IF ISServerScriptTimeout=1 Then
- Server.ScriptTimeout=Server_ScriptTimeout
- End IF
- Function FilterSQL(strSQL)
- FilterSQL=CStr(Replace(strSQL,chr(39),chr(39)&chr(39)))
- End Function
- Function StrangeTOISO(DataRCC)
- StrangeTOISO=ReplaceStr(DataRCC,"(?:D*)(d+)D(d+)D(d+)D(d+)D(d+)D(d+)(?:.*)","$1-$2-$3 $4:$5:$6")
- End function
- Function RegExpTest(patrn, strng)
- Dim regEx, retVal
- Set regEx = New RegExp
- regEx.Pattern = patrn
- regEx.IgnoreCase = False
- RegExpTest = regEx.Test(strng)
- End Function
- Function GetList(ID)
- SET conn=connectDB()
- set rs=server.createobject("adodb.recordset")
- If ID=1 Then
- sql="select * from [linkxml] where Category_id="&Request.QueryString("id")&" and Shenhe=1"
- End IF
- If ID=2 Then
- sql="select * from [linkxml] where Shenhe=1"
- End IF
- rs.open sql,conn,1,3
- for i=1 to rs.recordcount
- List=List&rs(0)&"|"
- rs.movenext
- Next
- rs.close:set rs=nothing
- closedb(conn)
- GetList=List
- End Function
- Function ListReport(ID)
- List=GetList(ID)
- If trim(list)="" then exit function
- session(SessionStr&"UpDateListByCategory")=List
- List2=split(List,"|")
- session(SessionStr&"ListTotalNumber")=Ubound(List2)
- session(SessionStr&"UpdatePercentage")=0
- session(SessionStr&"report")=""
- Response.redirect "update_xml.asp?action=UpdateBySession"
- End Function
- Function ReplaceStr(source,para,str)
- Set objRegExp=New RegExp
- objRegExp.IgnoreCase =True
- objRegExp.Global=True
- objRegExp.Pattern=para
- ReplaceStr= objRegExp.Replace(source,str)
- Set objRegExp=Nothing
- End Function
- Function Showerr_Desciption(ErrorID)
- Set conn=ConnectDB()
- Set RS=conn.execute ("select * from [ErrHandle] where [ErrorID]=" & ErrorID )
- If not rs.eof Then
- Showerr_Desciption=" 错误代码:"&RS(0)&",错误描述:"&RS(1)&" "&RS(2)
- Else
- Showerr_Desciption="错误库中没有关于代码为"&ErrorID&"的描述,请向<a href=""http://www.sxna.cn"" target=_blank>www.sxna.cn</a>报告此问题"
- End IF
- rs.close:set rs=nothing
- CloseDB(conn)
- End Function
- Function Shengcheng(UpdateCatId,XmlId)
- Set conn=ConnectDB()
- APPLICATION.LOCK
- application(SessionStr&"SXNA_NOWTIME") = now()
- APPLICATION.UNLOCK
- If UpdateCatId<>"" and XmlId="" Then
- sql="select * from [linkxml] where Category_id="&UpdateCatId&" and Shenhe=1"
- Else
- If UpdateCatId="" and XmlId<>"" Then
- sql="select * from [linkxml] where id="&XmlId&" and Shenhe=1"
- Else
- sql="select * from [linkxml] where Shenhe=1"
- End If
- End If
- set rs=server.createobject("adodb.recordset")
- rs.open sql,conn,1,3
- DBcount=rs.recordcount
- Redim XMLLINK(DBcount)
- Redim XMLLINKID(DBcount)
- Redim XMLLINKLastUpdateTime(DBcount)
- Redim XMLLINKInteval(DBcount)
- Redim XMLLINKAggregateNumber(DBcount)
- Redim XMLLINKcategory_id(DBcount)
- Redim XMLLINKlastupdatetime(DBcount)
- Redim XMLLINKElements(DBcount)
- Redim XMLLINKHtmlURL(DBcount)
- for i = 1 to DBcount
- if rs.EOF then
- Exit For
- end if
- XMLLINK(i)=rs("linkxml")
- XMLLINKID(i)=rs("id")
- XMLLINKcategory_id(i)=rs("category_id")
- XMLLINKInteval(i)=rs("Inteval")
- XMLLINKAggregateNumber(i)=rs("AggregateNumber")
- XMLLINKlastupdatetime(i)=rs("lastupdatetime")
- XMLLINKElements(i)=rs("Elements")
- XMLLINKHtmlURL(i)=rs("htmlUrl")
- rs.MoveNext
- Next
- rs.close:set rs=nothing
- CloseDB(conn)
- for j=1 to DBcount
- call InputXML(XMLLINKcategory_id(j),XMLLINK(j),XMLLINKID(j),XMLLINKInteval(j),XMLLINKAggregateNumber(j),XMLLINKlastupdatetime(j),XMLLINKElements(j),XMLLINKHtmlURL(j))
- next
- ShengCheng=True
- End Function
- Function Showerr(msg1,msg2,msg3)
- Report=Report& "<tr><td width=""80%"">"&msg1&"</td><td width=""20%"">"&msg2&"</td></tr><tr><td colspan=""2"">"&msg3&"</td></tr>"
- End Function
- Function InputXML(XLC_ID,RSSLINK_S,RSSLINKID_S,XMLLINKInteval,XMLLINKAggregateNumber,XMLLINKlastupdatetime,XMLLINKElements,XMLLINKHtmlURL)
- On Error Resume Next
- IF CheckRights2=False then
- If DateDiff("n",XMLLINKlastupdatetime,now())<XMLLINKInteval then
- Report=Report& "<tr><td width=""80%"">"&RSSLINK_S&"</td><td width=""20%"">未下载</td></tr><tr><td colspan=""2"">允许更新时间未到,上次更新时间是"&XMLLINKlastupdatetime&",允许前台更新时间为"&XMLLINKInteval&"分钟,现在过了"&DateDiff("n",XMLLINKlastupdatetime,now())&"分钟</td></tr>"
- Exit Function
- End IF
- End IF
- If isnull(XMLLINKElements) or trim(XMLLINKElements)="" then
- Report=Report&"<tr><td width=""80%"">"&RSSLINK_S&"</td><td width=""20%"">未设置元素</td></tr><tr><td colspan=""2"">请进行[重载]或[站点重载],设置提取元素.</td>"
- Exit Function
- Else
- elements=split(XMLLINKElements,"|||")
- End if
- If IsUseXmlHttp=1 then
- On Error Resume Next
- Set http=Server.CreateObject("Microsoft.XMLHTTP")
- http.Open "GET",RSSLINK_S,False
- If Err Then
- Report=Report&"<tr><td colspan=""2"">您的地址有错误.请检查"&Err.Number&Err.description&"</td><tr>"
- Err.Clear
- set http=nothing
- Exit Function
- End If
- http.send
- Else
- on error resume next
- Dim http
- Set http = Server.CreateObject("Msxml2.ServerXMLHTTP")
-
- http.setTimeouts lResolve*1000,lConnect*1000,lSend*1000,lReceive*1000
- http.Open "GET",RSSLINK_S,False
- http.Send
- 'response.write Err.Number&Err.Description&http.readyState
- 'response.end
- Select Case http.readyState
- Case 0
- call Showerr("对象初始化失败,估计你输入了一堆无效的字符....","请检查一下~","错误参数:"&Err.Number&Err.Description)
- Err.Clear
- set http=nothing
- Exit Function
- Case 1
- call Showerr(RSSLINK_S&"域名分析超时/连接站点超时!也许是这个网站有问题,或许是超时设定太短,或许机器没有联网","请检查","错误参数:"&Err.Number&Err.Description)
- Err.Clear
- set http=nothing
- Exit Function
- Case 2
- call Showerr(RSSLINK_S&"发送数据请求超时,是不是服务器出故障了?","请检查","错误参数:"&Err.Number&Err.Description)
- Err.Clear
- set http=nothing
- Exit Function
- Case 3
- ContentLength=http.GetResponseHeader("Content-Length")
- If err.number=-2147012746 then
- Call Showerr(RSSLINK_S&"数据下载超时/等待反馈时间超时","原因如下","没有获得文件大小的信息,估计网站有问题,可能是你的等待反馈时间超时设定太短")
- Else
- Call Showerr(RSSLINK_S&"数据下载超时/等待反馈时间超时","原因如下","该文件大小"&Formatnumber(ContentLength/1000,2)&"KB,下载过程中超过你设定的等待反馈时间超时时间,可能是你的等待反馈时间超时设定太短了,或许这个网站他就是慢...")
- End If
- Err.Clear
- set http=nothing
- Exit Function
- Case 4
- ErrContentLength=0
- ContentLength=http.GetResponseHeader("Content-Length")
- If err.number=-2147012746 then
- If http.Status=200 Then
- ErrContentLength=1
- End If
- Err.clear
- ElseIf err.number<>0 then
- call Showerr(RSSLINK_S&"有未知错误发生","有错误","错误参数:"&Err.Number&Err.Description)
- Err.Clear
- set http=nothing
- Exit Function
- Else
-
- End If
- End Select
- End If
- If http.status<>200 then
- Report=Report& "<tr><td width=""80%"">"&RSSLINK_S&"</td><td width=""20%"">下载失败,描述如下</td></tr><tr><td colspan=""2"">"&Showerr_Desciption(http.status)&"</td></tr>"
- Err.Clear
- set http=nothing
- Exit Function
- END IF
- If http.status="200" then'1
- If ErrContentLength=1 then
- Report=Report& "<tr><td width=""80%"">"&RSSLINK_S&"(没找到文件长度信息)</td><td width=""20%"">下载成功</td></tr>"
- Else
- Report=Report& "<tr><td width=""80%"">"&RSSLINK_S&"</td><td width=""20%"">下载成功</td></tr>"
- End If
- Set xml=Server.CreateObject("Microsoft.XMLDOM")
- xml.Async=False
- xml.ValidateOnParse=False
- xml.Load(http.ResponseBody)
- Set http=Nothing
- If xml.ReadyState=4 Then'2
- If xml.parseError.errorCode <> 0 Then'3
- Report=Report& "<tr><td colspan=""2"">解析失败,此文件不是XML文件</td></tr>"
- set xml=nothing
- Exit Function
- Else
- '获取链接
- If elements(0)="RSS" then
- Set channel=xml.documentElement.selectSingleNode("channel")
- Set item=xml.getElementsByTagName("item")
- Else' elements(0)="Atom" then
- Set channel=xml.getElementsByTagName("feed")
- set channel=channel(0)
- Set item=xml.getElementsByTagName("entry")
- End if'If elements(0)="rss"
- Rs_link2=XMLLINKHtmlURL
- BLOGURL=XMLLINKHtmlURL
- If ((XMLLINKAggregateNumber)>(item.Length)) then
- ItemNum=item.Length
- Else
- ItemNum=XMLLINKAggregateNumber
- End if
- redim RS_title(ItemNum)
- redim RS_Author(ItemNum)
- redim RS_pubDate(ItemNum)
- redim RS_link(ItemNum)
- redim RS_Description(ItemNum)
- For i=0 To ItemNum-1
- If elements(0)="RSS" then
- '链接获取
- RS_link(i)=item(i).selectSingleNode(elements(9)).text
- '作者获取
- If elements(2)="Multi" then
- RS_Author(i)=item(i).selectSingleNode(elements(3)).text
- If elements(14)="0" Then
- RS_Author(i)=RegExpHtml(RS_Author(i),RegExpType_Author)
- Else
- RS_Author(i)=RegExpHtml(RS_Author(i),elements(14))
- End IF
- Else
- RS_Author(i)=elements(4)
- End if
- Else
- '链接获取
- RS_link(i)=item(i).selectSingleNode(elements(9)).getAttributeNode("href").value
- '作者获取
- If elements(2)="Multi" then
- RS_Author(i)=item(i).selectSingleNode("author").selectSingleNode(elements(3)).text
- If elements(14)="0" Then
- RS_Author(i)=RegExpHtml(RS_Author(i),RegExpType_Author)
- Else
- RS_Author(i)=RegExpHtml(RS_Author(i),elements(14))
- End IF
- Else
- RS_Author(i)=elements(4)
- End if
- End IF
-
- '标题获取
-
- RS_title(i)=item(i).selectSingleNode(elements(1)).text
- If elements(13)="0" Then
- RS_title(i)=RegExpHtml(RS_title(i),RegExpType_Title)
- Else
- RS_title(i)=RegExpHtml(RS_title(i),elements(13))
- End If
- If isIntercept_title=1 then
- RS_title(i)=Left(RS_title(i),InterceptTitle)
- Else
- RS_title(i)=RS_title(i)
- End If
-
- '时间获取
- set pubDate=item(i).selectSingleNode(elements(5))
- If pubdate is nothing then
- Report=Report& "<tr><td colspan=""2"">时间设置有错误,老兄若实在搞不定,请提交"&RSSLINK_S&"到<A HREF=""http://www.sxna.cn"" target=""_blank"">SXNA交流论坛</A></tr></td>"
- Exit function
- set xml=nothing
- Else
- If elements(6)="Type1" then
- RS_pubDate(i)=StrangeTOISO(pubdate.text)
- End IF
- If elements(6)="Type2" then
- RS_pubDate(i)=rfc_to_iso(pubdate.text)
- End IF
- If elements(6)="Type3" then
- RS_pubDate(i)=ReplaceStr(pubdate.text,elements(7),elements(8))
- End IF
- End IF
- RS_Description(i)=item(i).selectSingleNode(elements(10)).text
- If DisplayDescriptionType=1 then
- RS_Description(i)=RS_Description(i)
- Else
- '先判断转化模式
- If Elements(11)="0" Then
- '应用全局设定转化模式
- RS_Description(i)=RegExpHtml(RS_Description(i),RegExpType_Discription)
- Else
- '应用特定转化模式
- RS_Description(i)=RegExpHtml(RS_Description(i),Elements(11))
- End If
- '截取字符
- If Elements(12)="" Then
- '应用全局设定截取字符
- IF isIntercept_description=0 then
- RS_Description(i)=RS_Description(i)
- Else
- RS_Description(i)=Left(RS_Description(i),cint(InterceptDescriptin))
- End If
- Else
- '应用特定截取字符
- RS_Description(i)=Left(RS_Description(i),cint(Elements(12)))
- End If
- End IF
- RS_title(i)=EncodeJP(RS_title(i))
- RS_Description(i)=EncodeJP(RS_Description(i))
- Next
- SuccessFlag=1
- End If ' 3 parseError.errorCode <> 0
- Else'2
- Report=Report&"文档还未准备就绪。状态:"& xml.ReadyState &"<br>"
- End If '2 xml ReadyState2
- End if '1 下载成功
- Set xml=Nothing
- If SuccessFlag=1 Then
- 'on error resume next
-
- Report=Report& "<tr><td colspan=""2"">解析完成,"
- Set CONN=ConnectDB()
-
- If IsStoreArticle=0 then
- CONN.execute "delete * from Article where xmlid="&RSSLINKID_S
- End If
- '初始化计数器
- SuccessNumber=0
- '成功存入的数目
- BadFilterNumber=0
- '过滤掉的数目
- BadFilterNumberButIn=0
- '过滤掉字符但是入库了的数目
- OverlapNumber=0
- '重复的文章/更新的文章数目
- UnKnownErrNumber=0
- '未知错误条数
- TimeExceed=0
- '超前的文章时间
- TimeErrNumber=0
- '时间错误的文章数(...累死我了)
-
- For i=0 To ItemNum-1
-
- If ISDate(RS_pubDate(i)) Then
- '如果时间条件满足,则放入相应的目录
- IF DateDiff("n",RS_pubDate(i),now())>0 THEN
- '不储存利用时间调大的置顶文章
- RS_pubDate(i)=formatdatetime(RS_pubDate(i),2)&" "&formatdatetime(RS_pubDate(i),4)
-
- If badfilter=0 then
- CONN.EXECUTE("INSERT INTO [Article] ([title],[author],[link],[pubDate],[description],[xmlid],[Category_id],[site]) VALUES ('"&FilterSQL(RS_title(i))&"','"&FilterSQL(RS_Author(i))&"','"&RS_link(i)&"','"&RS_pubDate(i)&"','"&FilterSQL(RS_Description(i))&"',"&RSSLINKID_S&","&XLC_ID&",'"&Rs_link2&"')")
- Else
- If RegExpTest(badfilterWord, RS_title(i)) or RegExpTest(badfilterWord, RS_Description(i)) then
- '满足过滤
- If badfilterMode="DeleteWord" then
- '入库
- RS_Description(i)=RegExpHtml(RS_Description(i),"[BadFilter]")
- RS_title(i)=RegExpHtml(RS_title(i),"[BadFilter]")
- BadFilterNumberButIn=BadFilterNumberButIn+1
- '过滤掉字符但是入库了的数目
- CONN.EXECUTE("INSERT INTO [Article] ([title],[author],[link],[pubDate],[description],[xmlid],[Category_id],[site]) VALUES ('"&FilterSQL(RS_title(i))&"','"&FilterSQL(RS_Author(i))&"','"&RS_link(i)&"','"&RS_pubDate(i)&"','"&FilterSQL(RS_Description(i))&"',"&RSSLINKID_S&","&XLC_ID&",'"&Rs_link2&"')")
- Report=Report&"已过滤字符(已入库):<a href="""&RS_link(i)&"""><b><font color=""#FF0000"">"&RS_title(i)&"</font></b></a><br />"
- Else
- '不入库
- Report=Report&"已过滤(未入库):<a href="""&RS_link(i)&"""><b><font color=""#FF0000"">"&RS_title(i)&"</font></b></a><br />"
- BadFilterNumber=BadFilterNumber+1
- End If
- Else
- '不满足过滤
- CONN.EXECUTE("INSERT INTO [Article] ([title],[author],[link],[pubDate],[description],[xmlid],[Category_id],[site]) VALUES ('"&FilterSQL(RS_title(i))&"','"&FilterSQL(RS_Author(i))&"','"&RS_link(i)&"','"&RS_pubDate(i)&"','"&FilterSQL(RS_Description(i))&"',"&RSSLINKID_S&","&XLC_ID&",'"&Rs_link2&"')")
- End If
- End If
-
- If Err.number=-2147467259 Then
- 'Report=Report& "<a href="""&RS_link(i)&""" target=""_blank"" style=""color:red;"">"&RS_title(i)&"</a> 有重复,未被记入<br>"
- err.clear
- CONN.EXECUTE("UPDATE [Article] set [title]='"&FilterSQL(RS_title(i))&"',[author]='"&FilterSQL(RS_Author(i))&"',[link]='"&RS_link(i)&"',[pubDate]='"&RS_pubDate(i)&"',[description]='"&FilterSQL(RS_Description(i))&"',[xmlid]="&RSSLINKID_S&",[Category_id]="&XLC_ID&",[site]='"&Rs_link2&"' WHERE [link]='"&RS_link(i)&"' ")
- If Err.number<>0 Then
- Report=Report& "错误!"&RS_link(i)&Err.number&err.description
- err.clear
- UnKnownErrNumber=UnKnownErrNumber+1
- Else
- OverlapNumber=OverlapNumber+1
- End If
- Else
- If Err.number<>0 Then
- Report=Report& "产生未知错误:"&RS_link(i)&Err.number&err.description&"请向www.sxna.cn报告"
- err.clear
- UnKnownErrNumber=UnKnownErrNumber+1
- End IF
- End IF
- Else
- '由于时间制定而导致未被计入的不进行提示
- 'Report=Report&RS_title(i)&"的时间大于当前时间未被计入"
- TimeExceed=TimeExceed+1
- END IF 'IF RS_pubDate(i)<NOW() THEN 不储存利用时间调大的置顶文章
- Else
- '如果时间条件不满足
- TimeErrNumber=TimeErrNumber+1
- 'call ShowErr1(RS_title(i)&"时间"&RS_pubDate(i))
- End If 'If ISDate(RS_pubDate(i)) Then'如果时间条件不满足
-
- NEXT
- Report=Report& "要求存取"&ItemNum&"条记录"
-
- If badfilter=1 then
- If BadFilterNumber<>0 then Report=Report&",过滤掉"&BadFilterNumber&"条"
- If BadFilterNumberButIn<>0 then Report=Report&",有"&BadFilterNumberButIn&"条中的字符被过滤掉"
- End If
-
- If IsStoreArticle=1 then
- If (ItemNum-OverlapNumber-BadFilterNumber)<>0 then Report=Report&",有"&(ItemNum-OverlapNumber-BadFilterNumber)&"条新信息"
- Else
- If OverlapNumber<>0 then Report=Report&",有"&OverlapNumber&"条重复未计入"
- End If
- If TimeErrNumber<>0 then Report=Report&",有"&TimeErrNumber&"条时间错误未计入"
- If TimeExceed<>0 then Report=Report&",有"&TimeExceed&"条时间超前未计入"
-
- If IsStoreArticle=1 then
- If (ItemNum-BadFilterNumber-OverlapNumber-TimeExceed-TimeErrNumber)=0 then
- Report=Report& ",成功更新"&OverlapNumber&"条,没有新信息。"
- Else
- Report=Report& ",成功更新"&OverlapNumber&"条,成功存入"&(ItemNum-BadFilterNumber-OverlapNumber-TimeExceed-TimeErrNumber)&"条新信息"
- End If
- Else
- Report=Report& ",成功存入"&(ItemNum-BadFilterNumber-OverlapNumber-TimeExceed-TimeErrNumber)&"条。"
- End If
- Report=Report& "</td></tr>"
-
- conn.Execute("UPDATE [linkxml] SET [lastupdatetime] = Now() WHERE [id] ="&RSSLINKID_S)
-
- CloseDB(conn)
- Application.Lock
- Application(SessionStr&"Catelog")=empty
- Application(SessionStr&"Statistics")=empty
- Application(SessionStr&"SXNAindex")=empty
- Application(SessionStr&"SXNAintPageCount")=empty
- Application.unlock
- End if
- End Function
- Public Function EncodeJP(StrHTML)
- If StrHTML<>"" Then
- StrHTML=Replace(StrHTML,"ガ","ガ")
- StrHTML=Replace(StrHTML,"ギ","ギ")
- StrHTML=Replace(StrHTML,"ア","ア")
- StrHTML=Replace(StrHTML,"ゲ","ゲ")
- StrHTML=Replace(StrHTML,"ゴ","ゴ")
- StrHTML=Replace(StrHTML,"ザ","ザ")
- StrHTML=Replace(StrHTML,"ジ","ジ")
- StrHTML=Replace(StrHTML,"ズ","ズ")
- StrHTML=Replace(StrHTML,"ゼ","ゼ")
- StrHTML=Replace(StrHTML,"ゾ","ゾ")
- StrHTML=Replace(StrHTML,"ダ","ダ")
- StrHTML=Replace(StrHTML,"ヂ","ヂ")
- StrHTML=Replace(StrHTML,"ヅ","ヅ")
- StrHTML=Replace(StrHTML,"デ","デ")
- StrHTML=Replace(StrHTML,"ド","ド")
- StrHTML=Replace(StrHTML,"バ","バ")
- StrHTML=Replace(StrHTML,"パ","パ")
- StrHTML=Replace(StrHTML,"ビ","ビ")
- StrHTML=Replace(StrHTML,"ピ","ピ")
- StrHTML=Replace(StrHTML,"ブ","ブ")
- StrHTML=Replace(StrHTML,"ブ","ブ")
- StrHTML=Replace(StrHTML,"プ","プ")
- StrHTML=Replace(StrHTML,"ベ","ベ")
- StrHTML=Replace(StrHTML,"ペ","ペ")
- StrHTML=Replace(StrHTML,"ボ","ボ")
- StrHTML=Replace(StrHTML,"ポ","ポ")
- StrHTML=Replace(StrHTML,"ヴ","ヴ")
- End If
- EncodeJP=StrHTML
- End Function
- %>