- 在线时间
- 69 小时
- 专家
- 0
- UID
- 226505
- 注册时间
- 2005-12-17
- 帖子
- 36
- 精华
- 0
- 积分
- 197
- 离线
- 88 天
专长: 前端制作,PHP,ASP
- 帖子
- 36
- 体力
- 195
- 威望
- 2
|
发表于 2007-11-19 16:45:17
|显示全部楼层
最近经常看到RSS这几个字,不是很理解
于是在网上找了一大堆资料,了解了一下基本概念
但是没有找到一个方便的asp生成rss的类
索性自己今天写了一个
已经测试过了
加了使用方法的注释
在此和大家分享一下
我的blog同步发布的地址:http://www.ffasp.com/content.asp?newsid=637
- <%
- Dim Rs,Newrss
- Class Rss
- '========参数调用说明==================
- '作者 : 飞飞
- '网站 : [url=http://www.ffasp.com]www.ffasp.com[/url]
- 'QQ : 276230416
- '邮箱 : [url=mailto:huanmie913@163.com]huanmie913@163.com[/url]
- '注:您可以更改和使用本程序,但请保留作者和出处
- '*******************输入参数********************
- '***********************************************
- 'SetConn 必填 网站使用的Connection对象
- 'SetSql 必填 Sql查询语句。强烈建议使用在Sql语句中使用Top关键字
- ' Sql语句中包含的字段[新闻Id,标题,内容,时间,静态页名称]
- ' 注:不要颠倒顺序
- ' 如果新闻不是生成的静态页,则无最后一项,SetPageType的值则为1
- 'SetWebName 必填 网站名称
- 'SetWebUrl 必填 网站的地址
- 'SetWebDes 非必填 网站的描述信息
- 'SetPageType 必填 信息显示页的链接类型 1 为动态页面Id 0为静态页面
- 'SetMaxInfo 非必填 强制显示信息的数目,若取数据>SetMaxInfo 则显示SetMaxInfo条数据。强烈建议使用在Sql语句中使用Top关键字
- 'setContentShow 非必填 信息简介设置。注意:该参数为数组(ShowContentType,ShowContentLen)
- ' ShowContentType [数字类型] 为内容显示方式[参数(0,1)0为按百分比就算显示信息,1为按字数]
- ' ShowContentLen 内容显示的长度 由ShowContentType 决定实际长度
- '*****************输出参数********************
- 'ShowRss 显示Rss
- '======================================================
- '例如
- 'Set NewRss=New Rss
- ' Set NewRss.SetConn=article_conn
- ' NewRss.SetSql="select top 30 newsid,title,content,dateandtime,N_fname from article where typeid=1 order by newsid Desc"
- ' NewRss.SetWebName="测试中"
- ' NewRss.SetWebUrl="[url=http://www.ffasp.com/rss/rss.asp]http://www.ffasp.com/rss/rss.asp[/url]"
- ' NewRss.SetMaxInfo=10
- ' NewRss.SetInfourl="[url=http://www.ffasp.com]http://www.ffasp.com[/url]"
- ' NewRss.SetPageType="0"
- ' NewRss.setContentShow="1,200"
- ' NewRss.ShowRss()
- 'Set NewRss=Nothing
- '======================================================
- Private Conn,Sql,WebName,WebUrl,WebDes,Er,MaxInfo,i,Infourl,PageType
- Private ShowContentType,ShowContentLen
- Private AllContent,AllContentLen
- Private Sub Class_initialize()
- MaxInfo=20
- 'PageType=1
- ShowContentType=0
- ShowContentLen=20
- Er=false
- End Sub
- Private Sub Class_terminate()
- If isObject(Rs) then Set Rs=Nothing
- End Sub
- Public Property Let Errmsg(msg)
- If Er then
- Response.Clear()
- Response.Write(msg)
- Response.End()
- End If
- End Property
- Public Property Let SetWebName(WebName_)
- WebName=WebName_
- End Property
- Public Property Let SetWebUrl(WebUrl_)
- WebUrl=WebUrl_
- End Property
- Public Property Let SetWebDes(webDes_)
- WebDes=WebDes_
- End Property
- Public Property Let SetInfoUrl(Infourl_)
- Infourl=Infourl_
- End Property
- Public Property Let SetPageType(PageType_)
- PageType=PageType_
- End Property
- Public Property Let SetMaxInfo(MaxInfo_)
- MaxInfo=MaxInfo_
- End Property
- Public Property Let setContentShow(ContentShow_)
- Dim ArrContentShow
- ArrContentShow=Split(ContentShow_,",")
- If Ubound(ArrContentShow)<>1 Then Er=True:Errmsg="信息显示参数设置有误!!"
- ShowContentType=ArrContentShow(0)
- ShowContentLen=ArrContentShow(1)
- If Not isnumeric(ShowContentType) or ShowContentType="" Then ShowContentType=0
- If Not isnumeric(ShowContentLen) or ShowContentLen="" Then
- If ShowContentType=0 Then ShowContentLen=20 Else ShowContentLen=200
- Else
- If ShowContentType=0 and (ShowContentLen>100 or ShowContentLen<10) Then ShowContentLen=20
- End If
- End Property
- Public Property Set SetConn(Conn_)
- If TypeName(Conn_)="Connection" Then
- Set Conn=Conn_
- Else
- Er=true
- Errmsg="数据库连接错误"
- Exit property
- End If
- End Property
- Public Property Let SetSql(sql_)
- Sql=Sql_
- End Property
- Public Property Get RssHead()
- RssHead="<?xml version=""1.0"" encoding=""gb2312"" ?> "
- RssHead=RssHead&"<rss>"
- RssHead=RssHead&"<channel>"
- RssHead=RssHead&"<title>"&WebName&"</title>"
- RssHead=RssHead&"<link>"&WebUrl&"</link>"
- RssHead=RssHead&"<description>"&WebDes&"</description>"
- End Property
- Private Property Get RssBottom()
- RssBottom="</channel>"
- RssBottom=RssBottom&"</rss>"
- End Property
- Public Sub ShowRss()
- On Error resume Next
- Dim Rs
- Dim ShowInfoUrl,ShowContent,Content
- If TypeName(Conn)<>"Connection" Then Er=True:Errmsg="Connection对象有误"
- If Sql="" or isnull(Sql)="" or isempty(Sql)="" Then Er=True:Errmsg="没有可执行的Sql语句"
- If WebName="" or isnull(WebName)="" or isempty(WebName)="" Then Er=True:Errmsg="请设置RSS标题"
- If WebUrl="" or isnull(WebUrl)="" or isempty(WebUrl)="" Then Er=True:Errmsg="请设置网站的链接"
- If InfoUrl="" or isnull(InfoUrl)="" or isempty(InfoUrl)="" Then Er=True:Errmsg="请设置链接信息"
- If PageType="" or isnull(PageType)="" or isempty(PageType)="" Then Er=True:Errmsg="请设置链接类型"
- Set Rs=Server.CreateObject("ADODB.RecordSet")
- Rs.Open Sql,Conn,1,1
- If Err Then
- Er=true
- Errmsg="数据库未能打开<br />请检查您的Sql语句是否正确"
- Exit Sub
- End If
-
- Response.Charset = "gb2312"
- Response.ContentType="text/xml"
- Response.Write(RssHead)
- For i =1 to MaxInfo
- '*****************************
- ShowInfoUrl=InfoUrl
- If ShowInfoUrl="" or isnull(ShowInfoUrl) or isempty(ShowInfoUrl) Then
- ShowInfoUrl="#"
- Else
- If PageType Then ShowInfoUrl=ShowInfoUrl&Rs(0) Else ShowInfoUrl=ShowInfoUrl&Rs(4)
- End If
- '*****************************
- AllContent=LoseHtml(Rs(2))
- AllContentLen=byteLen(AllContent)
- ShowContent=int(ShowContentLen)
- If ShowContentType=0 Then ShowContent=AllContentLen*ShowContent/100
- Content=Server.HTMLEncode(titleb(AllContent,ShowContent))
- Response.Write("<item>")
- Response.Write("<title>")
- Response.Write(Rs(1))
- Response.Write("</title>")
- Response.Write("<link>")
- Response.Write(ShowInfoUrl)
- Response.Write("</link>")
- Response.Write("<description>")
- Response.Write(Content)
- Response.Write("</description>")
- Response.Write("<pubDate>")
- Response.Write(return_RFC822_Date(Rs(3),"GMT"))
- Response.Write("</pubDate>")
- Response.Write("</item>")
- If Rs.Eof or i>cint(MaxInfo) Then Exit For
- Rs.MoveNext
- Next
- Response.Write(RssBottom)
- End Sub
- Function LoseHtml(ContentStr)
- Dim ClsTempLoseStr,regEx
- ClsTempLoseStr = Cstr(ContentStr)
- Set regEx = New RegExp
- regEx.Pattern = "<\/*[^<>]*>"
- regEx.IgnoreCase = True
- regEx.Global = True
- ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
- LoseHtml = ClsTempLoseStr
- End function
- Function return_RFC822_Date(byVal myDate, byVal TimeZone)
- Dim myDay, myDays, myMonth, myYear
- Dim myHours, myMinutes, mySeconds
-
- myDate = CDate(myDate)
- myDay = EnWeekDayName(myDate)
- myDays = Right("00" & Day(myDate),2)
- myMonth = EnMonthName(myDate)
- myYear = Year(myDate)
- myHours = Right("00" & Hour(myDate),2)
- myMinutes = Right("00" & Minute(myDate),2)
- mySeconds = Right("00" & Second(myDate),2)
-
-
- return_RFC822_Date = myDay&", "& _
- myDays&" "& _
- myMonth&" "& _
- myYear&" "& _
- myHours&":"& _
- myMinutes&":"& _
- mySeconds&" "& _
- " " & TimeZone
- End Function
- Function EnWeekDayName(InputDate)
- Dim Result
- Select Case WeekDay(InputDate,1)
- Case 1:Result="Sun"
- Case 2:Result="Mon"
- Case 3:Result="Tue"
- Case 4:Result="Wed"
- Case 5:Result="Thu"
- Case 6:Result="Fri"
- Case 7:Result="Sat"
- End Select
- EnWeekDayName = Result
- End Function
- Function EnMonthName(InputDate)
- Dim Result
- Select Case Month(InputDate)
- Case 1:Result="Jan"
- Case 2:Result="Feb"
- Case 3:Result="Mar"
- Case 4:Result="Apr"
- Case 5:Result="May"
- Case 6:Result="Jun"
- Case 7:Result="Jul"
- Case 8:Result="Aug"
- Case 9:Result="Sep"
- Case 10:Result="Oct"
- Case 11:Result="Nov"
- Case 12:Result="Dec"
- End Select
- EnMonthName = Result
- End Function
- function titleb(str,strlen)
- Dim Bstrlen
- bstrlen=strlen
- If isempty(str) or isnull(str) or str="" Then
- titleb=str
- exit function
- Else
- dim l,t,c,i
- l=len(str)
- t=0
-
- for i=1 to l
- c=Abs(Asc(Mid(str,i,1)))
- if c>255 then
- t=t+2
- else
- t=t+1
- end if
-
- if t>=bstrlen then
- titleb=left(str,i)
- exit for
- else
- titleb=str&""
- end if
- next
- End If
- end function
- function byteLen(str)
- dim lenStr,lenTemp,i
- lenStr=0
- lenTemp=len(str)
- dim strTemp
- for i=1 to lenTemp
- strTemp=asc(mid(str,i,1))
- if strTemp>255 or strTemp<=0 then
- lenStr=lenStr+2
- else
- lenStr=lenStr+1
- end if
- next
- byteLen=lenStr
- end function
- End Class
- %>
复制代码 |
-
总评分: 威望 + 2
查看全部评分
|