Class.asp
上传用户:rblchem
上传日期:2022-04-27
资源大小:1941k
文件大小:22k
- <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>
- <%
- Class TCategory
- Public ID
- Public Name
- Public Intro
- Public Order
- Public Count
- Public ParentID
- Public sortPath
- Public Function Post()
- Call CheckParameter(ID,"int",0)
- Call CheckParameter(Order,"int",0)
- 'ID可以为0
- Name=FilterSQL(Name)
- Intro=FilterSQL(Intro)
- If Len(Name)=0 Then Post=False:Exit Function
- If ID=0 Then
- '这句话很有用捉摸一下
- conn.Execute("INSERT INTO [Category]([Category_Name],[Category_Order],[Category_Intro],[Category_ParentID],[Category_sortPath]) VALUES ('"&Name&"',"&Order&",'"&Intro&"','"&ParentID&"','"&sortPath&"')")
- Else
- conn.Execute("UPDATE [Category] set [Category_Name]='"&Name&"',[Category_Order]="&Order&",[Category_Intro]='"&Intro&"',[Category_ParentID]='"&ParentID&"',[Category_sortPath]='"&sortPath&"' WHERE [Category_ID] =" & ID)
- End If
- Post=True
- End Function
- Public Function LoadInfoByID(cate_ID)
- Call CheckParameter(cate_ID,"int",0)
-
- Set rs=conn.Execute("SELECT * FROM [Category] WHERE [Category_ID]=" & cate_ID)
- If (Not rs.bof) And (Not rs.eof) Then
- ID=rs("Category_ID")
- Name=rs("Category_Name")
- Intro=rs("Category_Intro")
- Order=rs("Category_Order")
- Count=rs("Category_Count")
- ParentID=rs("Category_parentID")
- sortPath=rs("Category_sortPath")
- Else
- Exit Function
- End If
- rs.Close
- Set rs=Nothing
- LoadInfoByID=True
- End Function
- Public Function Del()
- Call CheckParameter(ID,"int",0)
- If (ID=0) Then Del=False:Exit Function
- set rs=conn.execute ("select * from [Category] WHERE [Category_ParentID] =" & ID)
- If rs.bof Then
- conn.Execute("DELETE FROM [LinkXML] WHERE [Category_id]=" & ID)
- Conn.Execute("DELETE FROM [Article] WHERE [Category_id]=" & ID)
- Conn.Execute("DELETE FROM [Category] WHERE [Category_ParentID] =" & ID)
- Conn.Execute("DELETE FROM [Category] WHERE [Category_ID] =" & ID)
- Del=True
- Else
- Del=False
- End If
- End Function
- End Class
- Class TWebSite
- Public ID,Name,CateID,Intro,Url,XML,XmlUrl,Interval,AggregateNumber,Cate,ShenHe,strXmlFile,objXmlFile,Regexp_Description,DescriptionNumber,Regexp_Title,Regexp_Author,ViewOther
- Public documentElement,item,title,AuthorType,Author,AuthorText,AuthorText2,pubDate,pubDateTextOriginal,pubDateText,linka,Description,pubDateType,RegExpPattern,RegExpReplace,RegExpText,Elements,Report
- Public Function Post()
- If not isobject(conn) then set conn=connectdb
- On Error Resume Next
- 'ID可以为0
- Call CheckParameter(ID,"int",0)
- '这句话必须,如果ID空则插入
- Call CheckParameter(CateID,"int",0)
- Call CheckParameter(Interval,"int",0)
- Name=FilterSQL2(Name)
- Intro=FilterSQL2(Intro)
- Url=FilterSQL2(Url)
- XmlUrl=FilterSQL2(XmlUrl)
- Elements=Elements
- If Len(Name)=0 Then Post=False:Exit Function
- If ID=0 Then
- Conn.Execute("INSERT INTO [LinkXML]([title],[Category_id],[Description],[htmlUrl],[linkxml],[shenhe],[Inteval],[AggregateNumber],[Elements],[Other]) VALUES ('"&Name&"',"&CateID&",'"&Intro&"','"&Url&"','"&XmlUrl&"','"&ShenHe&"',"&Interval&","&AggregateNumber&",'"&Elements&"','"&ViewOther&"')")
- Else
- Conn.Execute("UPDATE [LinkXML] set [title]='"&Name&"',[Category_id]="&CateID&",[Description]='"&Intro&"',[htmlUrl]='"&Url&"',[linkxml]='"&XmlUrl&"',[shenhe]='"&shenhe&"',[Inteval]="&Interval&",[AggregateNumber]="&AggregateNumber&",[Elements]='"&Elements&"',[Other]='"&ViewOther&"' WHERE [id] =" & ID)
- Conn.Execute("UPDATE [Article] set [Category_id]="&CateID&" WHERE [xmlid]="&ID)
- End If
- If Err Then
- If err.number=-2147467259 Then
- call Showerr_already
- err.clear
- Else
- call Showerr_unknown(err.number,err.description)
- err.clear
- End IF
- Post=False
- Else
- Post=True
- End IF
- End Function
- Public Function LoadSiteInfoByID(site_ID)
- If Not IsObject(Conn) Then set conn=connectdb()
- Call CheckParameter(site_ID,"int",0)
- Dim objRS
- Set objRS=conn.Execute("SELECT * FROM [LinkXML] WHERE [id]=" & site_ID)
- If (Not objRS.bof) And (Not objRS.eof) Then
- ID=objRS("id")
- Name=objRS("title")
- CateID=objRS("Category_id")
- Intro=objRS("Description")
- Url=objRS("htmlUrl")
- XmlUrl=objRS("linkxml")
- AggregateNumber=objRS("AggregateNumber")
- Interval=objRS("Inteval")
- ShenHe=objRS("ShenHe")
- ViewOther=objRS("Other")
- If trim(objRS("Elements"))="" or isnull(objRS("Elements")) or Ubound(Split(objRS("Elements"),"|||"))<>14 then
- Elements=Split("||||||||||||||||||||||||||||||||||||||||||","|||")
- else
- Elements=Split(objRS("Elements"),"|||")
- End IF
- documentElement=Elements(0)
- title=Elements(1)
- AuthorType=Elements(2)
- Author=Elements(3)
- AuthorText=Elements(4)
- pubDate=Elements(5)
- pubDateType=Elements(6)
- RegExpPattern=Elements(7)
- RegExpReplace=Elements(8)
- linka=Elements(9)
- Description=Elements(10)
- Regexp_Description=Elements(11)
- DescriptionNumber=Elements(12)
- Regexp_Title=Elements(13)
- Regexp_Author=Elements(14)
-
-
- Else
-
- Exit Function
- End If
- objRS.Close
- Set objRS=Nothing
- LoadSiteInfoByID=True
- End Function
- Public Function Del()
- Call CheckParameter(ID,"int",0)
- If (ID=0) Then Del=False:Exit Function
- Conn.Execute("DELETE FROM [Article] WHERE [xmlid] =" & ID)
- Conn.Execute("DELETE FROM [LinkXML] WHERE [id] =" & ID)
- Del=True
- End Function
- Public Function IsViewN()
- Call CheckParameter(ID,"int",0)
- If (ID=0) Then IsViewN=False:Exit Function
- Conn.Execute("UPDATE [LinkXML] set [Other]='N' WHERE [id]="&ID)
- IsViewN=True
- End Function
- Public Function IsViewY()
- Call CheckParameter(ID,"int",0)
- If (ID=0) Then IsViewY=False:Exit Function
- Conn.Execute("UPDATE [LinkXML] set [Other]='Y' WHERE [id]="&ID)
- IsViewY=True
- End Function
- Private 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
- Private Function Showerr_http(XmlUrl,httpStatus)
- Report=Report& "<tr><td width=""80%"">"&XmlUrl&"</td><td width=""20%"">下载失败,描述如下</td></tr><tr><td colspan=""2"">"&Showerr_Desciption(httpStatus)&"</td></tr>"
- End Function
- Private 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
- Private Function Showerr_unknown(err_number,err_description)
- Report=Report& "<tr><td width=""80%"">发生未知错误,请向<a href=""http://www.sxna.cn"" target=_blank>www.sxna.cn</a>报告此错误</td><td width=""20%"">描述如下</td></tr><tr><td colspan=""2"">错误代码:"&err_number&",错误描述:"&err_description&"</td></tr>"
- End Function
- Private Function Showerr_already()
- Report=Report& "<tr><td width=""80%"">这个地址您已经加入了</td><td width=""20%"">地址重复</td></tr><tr><td colspan=""2""><span style=""cursor:hand;color:#FF6600;""><a href=""admin_xml.asp"">按这里请重新输入</a></span></td></tr>"
- End Function
- Private Function Showerr_NOTXML(XmlUrl,xml_parseError_errorCode)
- Report=Report& "<tr><td width=""80%"">"&XmlUrl&"解析失败,不是标准XML文件</td><td width=""20%""></td></tr><tr><td colspan=""2"">错误代码:"&xml_parseError_errorCode&"<span style=""cursor:hand;color:#FF6600;"" onclick=""javascript:history.go(-1);"">请重新输入</span>,若仍失败请向<a href=""http://www.sxna.cn"" target=_blank>www.sxna.cn</a>报告</td></tr>"
- End Function
- Private Function ShowErr2(XmlUrl,Name)
- Report=Report& "<tr><td width=""80%"">"&XmlUrl&"</td><td width=""20%"">加入失败</td></tr><tr><td colspan=""2"">该文件<b>"&Name&"</b>部分有错误。<span style=""cursor:hand;color:#FF6600;"" onclick=""javascript:history.go(-1);"">请重新输入</span>,若仍失败请向<a href=""http://www.sxna.cn"" target=_blank>www.sxna.cn</a>报告</td></tr>"
- End Function
- Public Function GetXml
- on error resume next
- Dim objXMLHTTP
- Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
-
- objXMLHTTP.setTimeouts lResolve*1000,lConnect*1000,lSend*1000,lReceive*1000
- objXMLHTTP.Open "GET",XmlUrl,False
- objXMLHTTP.Send
- Select Case ObjXMLHTTP.readyState
- Case 0
- call Showerr("对象初始化失败,估计你输入了一堆无效的字符....","请检查一下~","错误参数:"&Err.Number&Err.Description)
- GetXml=False
- Case 1
- call Showerr(XmlUrl&"域名分析超时/连接站点超时!也许是这个网站有问题,或许是超时设定太短,或许机器没有联网","请检查","错误参数:"&Err.Number&Err.Description)
- GetXml=False
- Case 2
- call Showerr(XmlUrl&"发送数据请求超时,是不是服务器出故障了?","请检查","错误参数:"&Err.Number&Err.Description)
- GetXml=False
- Case 3
- ContentLength=objXMLHTTP.GetResponseHeader("Content-Length")
- If err.number=-2147012746 then
- Call Showerr(XmlUrl&"数据下载超时/等待反馈时间超时","原因如下","没有获得文件大小的信息,估计网站有问题,可能是你的等待反馈时间超时设定太短")
- Else
- Call Showerr(RSSLINK_S&"数据下载超时/等待反馈时间超时","原因如下","该文件大小"&Formatnumber(ContentLength/1000,2)&"KB,下载过程中超过你设定的等待反馈时间超时时间,可能是你的等待反馈时间超时设定太短了,或许这个网站他就是慢...")
- End If
- Err.clear
- GetXml=False
- Case 4
- ContentLength=objXMLHTTP.GetResponseHeader("Content-Length")
- If err.number=-2147012746 then
- If objXMLHTTP.Status=200 Then
- call Showerr(XmlUrl&"没有找到文件长度信息,估计是这个网站的rss设计有问题","","操作继续..附加头信息供调试"&objXMLHTTP.GetAllResponseHeaders)
- strXmlFile=objXMLHTTP.responseBody
- GetXml=True
- Else
- call Showerr_http(XmlUrl,objXMLHTTP.status)
- GetXml=False
- End If
- err.clear
- ElseIf err.number<>0 then
- call Showerr(XmlUrl&"有未知错误发生","有错误","错误参数:"&Err.Number&Err.Description)
- GetXml=False
- err.clear
- Else
- If objXMLHTTP.Status=200 Then
- strXmlFile=objXMLHTTP.responseBody
- GetXml=True
- Else
- call Showerr_http(XmlUrl,objXMLHTTP.status)
- GetXml=False
- End If
- End If
- End Select
- End Function
- Public Function GetXml2
- ON ERROR RESUME NEXT
- Set objXMLHTTP=Server.CreateObject("Microsoft.XMLHTTP")
- objXMLHTTP.Open "GET",XmlUrl,False
- objXMLHTTP.Send
- If objXMLHTTP.Status="200" Then
- strXmlFile=objXMLHTTP.responseBody
- GetXml2=True
- Else
- call Showerr_http(XmlUrl,objXMLHTTP.status)
- GetXml2=False
- Exit Function
- End If
-
- If Err Then
- call Showerr(Err.description,"","")
- Err.clear
- GetXml2=False
- Exit Function
- End IF
- End Function
- Private 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
- Public Function ParseXml()
- Set xml=Server.CreateObject("Microsoft.XMLDOM")
- xml.Async=False
- xml.ValidateOnParse=False
- xml.Load(strXmlFile)
- If xml.ReadyState=4 Then
- If xml.parseError.errorCode <> 0 Then
- call Showerr_NOTXML(XmlUrl,xml.parseError.errorCode)
- ParseXml=False
- set xml=nothing
- Exit Function
- Else
- Set Gen=xml.documentElement
- If Gen is Nothing Then
- call Showerr_NOTXML(XmlUrl,xml.parseError.errorCode)
- ParseXml=False
- set xml=nothing
- Exit Function
- End If
-
- Set channel=xml.documentElement.selectSingleNode("channel")
- If channel is Nothing then
- Set feed=xml.getElementsByTagName("feed")
- set feed=feed(0)
- 'ATom
- If feed is Nothing then
- Report=Report&"<tr><td width=""80%"">"&XmlUrl&"不是RSS/ATOM文件</td><td width=""20%""></td></tr><tr><td colspan=""2"">请察看原因</td></tr>"
- ParseXml=False
- set xml=nothing
- Exit Function
-
- Else
- 'FEED分析
- On error resume next
- documentElement="ATOM"
- Url=feed.selectSingleNode("link").getAttributeNode("href").value
- Name=feed.selectSingleNode("title").text
- If Name="" Then Name="未知"
- Intro=feed.selectSingleNode("subtitle").text
-
- set item=xml.getElementsByTagName("entry")
- Set objtitle=item(0).selectSingleNode("title")
- If objtitle is Nothing then
- title=""
- Else
- title="title"
- End If
- Redim NodeAuthor(2)
- NodeAuthor(1)="author|item|Multi"
- NodeAuthor(2)="author|feed|Single"
- For i=1 to Ubound(NodeAuthor)
- If split(NodeAuthor(i),"|")(1)="item" then Set objAuthor=item(0).selectSingleNode(split(NodeAuthor(i),"|")(0))
- If split(NodeAuthor(i),"|")(1)="feed" then Set objAuthor=feed.selectSingleNode(split(NodeAuthor(i),"|")(0))
- If objAuthor is Nothing then
- If i=Ubound(NodeAuthor) then
- AuthorType="Single"
- Author=""
- AuthorText=feed.selectSingleNode("title").text
- Exit for
- Else
- End If
- Else
- Set objname=objAuthor.selectSingleNode("name")
- If objname is Nothing then
- AuthorType="Single"
- Author=""
- AuthorText=feed.selectSingleNode("title").text
- Else
- AuthorType=split(NodeAuthor(i),"|")(2)
- Author="name"
- AuthorText=objname.text
- End If
- Exit For
- End If
- Next
- AuthorText2=AuthorText
- AuthorText=PickUpTrueAuthor(AuthorText)
- Redim NodepubDate(2)
- NodepubDate(1)="updated"
- NodepubDate(2)="modified"
- For i=1 to Ubound(NodepubDate)
- Set objpubDate=item(0).selectSingleNode(NodepubDate(i))
- If objpubDate is Nothing then
- If i=Ubound(NodepubDate) then
- pubDate="No"
- Exit for
- Else
- End If
- Else
- pubDate=NodepubDate(i)
- RegexpDate(objpubDate)
- pubDateTextOriginal= objpubDate.text
- RegExpPattern=""
- RegExpReplace=""
- Exit For
- End If
- Next
- If NOT ISDATE(pubDateText) Then
- pubDateType="Type3"
- End IF
- Set objlink=item(0).selectSingleNode("link")
- If objlink is Nothing then
- linka=""
- Else
- linka="link"
- End If
-
- Set objDescription=item(0).selectSingleNode("summary")
- If objDescription is Nothing then
- set objDescription=item(0).selectSingleNode("content")
- If objDescription is Nothing then
- Description="title"
- Else
- Description="content"
- End If
- Else
- Description="summary"
- End If
- AggregateNumber=item.Length
- Regexp_Description="0"
- Regexp_Author="0"
- Regexp_Title="0"
- DescriptionNumber=""
- ParseXml=True
- End IF'ATOM分析结束
- Else
- 'RSS分析开始
- On error resume next
-
- documentElement="RSS"
- Url=channel.selectSingleNode("link").text
- Name=channel.selectSingleNode("title").text
- If Name="" Then Name="未知"
- Intro=channel.selectSingleNode("description").text
-
- Set item=xml.getElementsByTagName("item")
- Set item=item(0)
- Set objtitle=item.selectSingleNode("title")
- If objtitle is Nothing then
- title=""
- Else
- title="title"
- End If
- Redim NodeAuthor(4)
- NodeAuthor(1)="author|item|Multi"
- NodeAuthor(2)="dc:creator|item|Multi"
- NodeAuthor(3)="dc:creator|channel|Single"
- NodeAuthor(4)="source|channel|Single"
- For i=1 to Ubound(NodeAuthor)
- SplitedNodeAuthor=split(NodeAuthor(i),"|")
- If SplitedNodeAuthor(1)="item" then Set objAuthor=item.selectSingleNode(SplitedNodeAuthor(0))
- If SplitedNodeAuthor(1)="channel" then Set objAuthor=channel.selectSingleNode(SplitedNodeAuthor(0))
- If objAuthor is Nothing then
- If i=Ubound(NodeAuthor) then
- IF RegExpTest("msn.com",XmlUrl) then
- AuthorType="Single"
- Author=""
- AuthorText=split(XmlUrl,"/")(4)
- ElseIf RegExpTest("yculblog.com",XmlUrl) then
- AuthorType="Single"
- Author=""
- AuthorText=split(split(XmlUrl,"/")(2),".")(0)
- Else
- Set objAuthor=channel.selectSingleNode("webMaster")
- If objAuthor is Nothing then
- AuthorType="Single"
- Author=""
- AuthorText=xml.documentElement.selectSingleNode("channel").selectSingleNode("title").text
- Else
- AuthorType="Single"
- Author=""
- AuthorText=objAuthor.text
- End IF
- Exit for
-
- End If
- End If
- Else
- AuthorType=SplitedNodeAuthor(2)
- Author=SplitedNodeAuthor(0)
- AuthorText=objAuthor.text
- Exit For
- End If
- Next
- AuthorText2=AuthorText
- AuthorText=PickUpTrueAuthor(AuthorText)
-
- Redim NodepubDate(5)
- NodepubDate(1)="pubDate"
- NodepubDate(2)="dc:date"
- NodepubDate(3)="PubDate"
- NodepubDate(4)="pubdate"
- NodepubDate(5)="Pubdate"
- For i=1 to Ubound(NodepubDate)
- Set objpubDate=item.selectSingleNode(NodepubDate(i))
- If objpubDate is Nothing then
- If i=Ubound(NodepubDate) then
- pubDate="No"
- Exit for
- Else
- End If
- Else
- pubDate=NodepubDate(i)
- RegexpDate(objpubDate)
- pubDateTextOriginal= objpubDate.text
- RegExpPattern=""
- RegExpReplace=""
- Exit For
- End If
- Next
- If NOT ISDATE(pubDateText) Then
- pubDateType="Type3"
- If RegExpTest("pconline.com.cn",XmlUrl) Then
- pubDate="pubDate"
- RegExpPattern=".0"
- RegExpReplace=""
- End If
- If RegExpTest("tianyablog.com",XmlUrl) Then
- pubDate="comments"
- pubDateType="Type1"
- pubDateTextOriginal=item.selectSingleNode(pubDate).text
- pubDateText=StrangeTOISO(pubDateTextOriginal)
- RegExpPattern=""
- RegExpReplace=""
- End If
- End IF
- Set objlink=item.selectSingleNode("link")
- If objlink is Nothing then
- linka=""
- Else
- linka="link"
- End If
- Set objDescription=item.selectSingleNode("description")
- If objDescription is Nothing then
- Description="title"
- Else
- Description="description"
- End If
- Set Objitemnodes=Xml.Getelementsbytagname("item")
- Aggregatenumber=Objitemnodes.Length
- Regexp_Description="0"
- Regexp_Author="0"
- Regexp_Title="0"
- DescriptionNumber=""
- ParseXml=True
- End IF
-
- End IF 'xml.parseError.errorCode <> 0
- End If'xml.ReadyState=4
- End Function
- Private Function PickUpTrueAuthor(Text)
- IF RegExpTest("(.+)",Text) then
- Set SRegExp=New RegExp
- SRegExp.IgnoreCase =True
- SRegExp.Global=True
- SRegExp.Pattern="(.+)"
- Set Match = SRegExp.Execute(Text)
- IF MATCH.COUNT<>0 THEN
- PickUpTrueAuthor=Match(0).value
- PickUpTrueAuthor=Replace(PickUpTrueAuthor,CHR(40),"")
- PickUpTrueAuthor=Replace(PickUpTrueAuthor,CHR(41),"")
- Else
- PickUpTrueAuthor=Text
- End IF
- Set SRegExp=Nothing
- Else
- PickUpTrueAuthor=Text
- End IF
- End Function
- Private Function RegexpDate(objpubDate)
- IF RegExpTest("(?:D*)(d+)D(d+)D(d+)D(d+)D(d+)D(d+)(?:.*)",objpubDate.text) then
- pubDateText=StrangeTOISO(objpubDate.text)
- If ISDATE(pubDateText) then pubDateType="Type1"
- Else
- pubDateText=rfc_to_iso(objpubDate.text)
- If ISDATE(pubDateText) then pubDateType="Type2"
- End IF
- End Function
- Public Function Add_xml()
-
- If IsUseXmlHttp=0 then
- If GetXml Then
- If ParseXml Then
- Add_xml=True
- Else
- Add_xml=False
- End If
- Else
- Add_xml=False
- End If
- Else
- If GetXml2 Then
- If ParseXml Then
- Add_xml=True
- Else
- Add_xml=False
- End If
- Else
- Add_xml=False
- End If
- End If
- If trim(Report)<>"" then
- response.write Report
- Else
- response.write "<tr><td>下载成功</td></tr>"
- End If
- session(SessionStr&"ReloadXMLReport")= session(SessionStr&"ReloadXMLReport") & Report
- End Function
- Private Sub Class_Initialize()
- End Sub
- End Class
- %>