>设为首页
>收藏本站
>最新电影
> 子栏目 Asp | Jsp | XML | XSL | Div+Css | 自定义函数 | 数据库 | 脚本特效
您现在的位置: 首页=>后台技术=>自定义函数 订阅本栏目  
Asp生成RSS的类
时间: 2007-11-13 17:19:03 阅读次数:6878



<%
Dim Rs,Newrss
Class Rss
'========参数调用说明==================
'作者 : 飞飞
'网站 : www.ffasp.com
'QQ : 276230416
'邮箱 : huanmie913@163.com
'注:您可以更改和使用本程序,但请保留作者和出处
'*******************输入参数********************
'***********************************************
'SetConn 必填 网站使用的Connection对象
'SetSql 必填 Sql查询语句。强烈建议使用在Sql语句中使用Top关键字
' Sql语句中包含的字段[新闻Id,标题,内容,时间,静态页名称]
' 注:不要颠倒顺序
' 如果新闻不是生成的静态页,则无最后一项,SetPageType的值则为1
'SetWebName 必填 网站名称
'SetWebUrl 必填 网站的地址
'SetWebDes 非必填 网站的描述信息
'SetPageType 必填 信息显示页的链接类型 1 为动态页面Id 0为静态页面
'SetMaxInfo 非必填 强制显示信息的数目,若取数据>SetMaxInfo 则显示SetMaxInfo条数据。飞飞Asp技术乐园强烈建议使用在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="http://www.ffasp.com/rss/rss.asp"
' NewRss.SetMaxInfo=10
' NewRss.SetInfourl="http://www.ffasp.com"
' 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
%>



本站下载资源全部放在fs2you共享空间上,若不能正常下载以上资源,请下载修复补丁
下载"Asp生成RSS的类"Word版
点击下载
站内搜索:    

下一篇检测空间支持组件 是否支持fso

上一篇获取字符串实际占用字节数(如何取特定的长)(len)

本栏目最新 栏目最新列表
解决asp使用xmlhttp生成静态页有延时的方法
Asp按照指定目录使用fso创建文件夹
使用aspjpeg组件给指定图片添加文字水印
使用aspjpeg组件给指定图片添加图片水印
使用aspjpeg组件生成缩略图
网站优化策划 栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
站点最新 站点最新列表
微博推广的一些技巧
xhEditor v1.1.7 发布,
收集的一些轻量级非常实
50个新鲜兼容最新版本的
javascript中cookie的设
Excel中出现#VALUE!、#D
jquery插件:飞飞表情插件
十个使用HTML5开发的精彩
支持HTML5的浏览器有哪些
飞妮莫属:漫画:如何写出
历史最热10条信息  
AWStats安装QQ传真IP插件
MIME介绍 及 [1] [2] [3]
巧用Google和迅雷来下载
Transact SQL 常 [1] [2]
VIA Rhine II Fast Ethe
电脑常用端 [1] [2] [3]
Do you get a kick out
十道羊皮卷 欣赏+mp3版+
经典__悟透JavaScript
每日一句:A friend and
相关文章
Fireworks画Rss ico
Asp生成RSS的类
RSS 2.0 规范
 
相关专题 相关专题列表
RSS 2.0 规范
Asp生成RSS的类
 width= 
伟哥博客 西安房产 123最新电影 三四六四