请选择 进入手机版 | 继续访问电脑版
收藏本站腾讯微博新浪微博
点点网模板设计大赛 phpchina

经典论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

蓝色理想 最新研发动态 用悬赏 三天解决问题 解决访问速度慢 论坛支持农历生日 - 给官方提建议

论坛活动及任务 归纳网站最新活动 地图任务 邮件更新任务:保护帐号安全

积分换实物,来参加蓝色理想积分兑换吧! 联系招聘客服 蓝色理想帮你找工作! 万元奖励等你拿——点点网模板设计大赛

查看: 2595|回复: 3

[asp] Asp生成RSS的类 [复制链接]

feijie913 楼主

飞妮莫属

初级会员 手机认证 

帖子
36
体力
195
威望
2
发表于 2007-11-19 16:45:17 |显示全部楼层
最近经常看到RSS这几个字,不是很理解
于是在网上找了一大堆资料,了解了一下基本概念
但是没有找到一个方便的asp生成rss的类
索性自己今天写了一个
已经测试过了
加了使用方法的注释
在此和大家分享一下

我的blog同步发布的地址:http://www.ffasp.com/content.asp?newsid=637


  1. <%
  2. Dim Rs,Newrss
  3. Class Rss
  4. '========参数调用说明==================
  5. '作者 : 飞飞
  6. '网站 :  [url=http://www.ffasp.com]www.ffasp.com[/url]
  7. 'QQ  :  276230416
  8. '邮箱 :  [url=mailto:huanmie913@163.com]huanmie913@163.com[/url]
  9. '注:您可以更改和使用本程序,但请保留作者和出处
  10. '*******************输入参数********************
  11. '***********************************************
  12. 'SetConn          必填      网站使用的Connection对象
  13. 'SetSql          必填      Sql查询语句。强烈建议使用在Sql语句中使用Top关键字
  14. '        Sql语句中包含的字段[新闻Id,标题,内容,时间,静态页名称]
  15. '                            注:不要颠倒顺序      
  16. '                            如果新闻不是生成的静态页,则无最后一项,SetPageType的值则为1
  17. 'SetWebName      必填      网站名称         
  18. 'SetWebUrl        必填      网站的地址
  19. 'SetWebDes        非必填    网站的描述信息
  20. 'SetPageType      必填      信息显示页的链接类型 1 为动态页面Id  0为静态页面
  21. 'SetMaxInfo      非必填    强制显示信息的数目,若取数据>SetMaxInfo 则显示SetMaxInfo条数据。强烈建议使用在Sql语句中使用Top关键字
  22. 'setContentShow  非必填    信息简介设置。注意:该参数为数组(ShowContentType,ShowContentLen)
  23. '                                    ShowContentType  [数字类型]    为内容显示方式[参数(0,1)0为按百分比就算显示信息,1为按字数]   
  24. '                                    ShowContentLen  内容显示的长度 由ShowContentType 决定实际长度
  25. '*****************输出参数********************
  26. 'ShowRss  显示Rss
  27. '======================================================
  28. '例如
  29. 'Set NewRss=New Rss
  30. ' Set NewRss.SetConn=article_conn
  31. ' NewRss.SetSql="select top 30 newsid,title,content,dateandtime,N_fname from article where typeid=1 order by newsid Desc"
  32. ' NewRss.SetWebName="测试中"
  33. ' NewRss.SetWebUrl="[url=http://www.ffasp.com/rss/rss.asp]http://www.ffasp.com/rss/rss.asp[/url]"
  34. ' NewRss.SetMaxInfo=10
  35. ' NewRss.SetInfourl="[url=http://www.ffasp.com]http://www.ffasp.com[/url]"
  36. ' NewRss.SetPageType="0"
  37. ' NewRss.setContentShow="1,200"
  38. ' NewRss.ShowRss()
  39. 'Set NewRss=Nothing
  40. '======================================================

  41. Private Conn,Sql,WebName,WebUrl,WebDes,Er,MaxInfo,i,Infourl,PageType
  42. Private ShowContentType,ShowContentLen
  43. Private AllContent,AllContentLen

  44. Private Sub Class_initialize()
  45.   MaxInfo=20
  46.   'PageType=1
  47.   ShowContentType=0
  48.   ShowContentLen=20
  49.   Er=false
  50. End Sub

  51.   Private Sub Class_terminate()
  52.   If isObject(Rs) then Set Rs=Nothing
  53. End Sub

  54. Public Property Let Errmsg(msg)
  55.   If Er then
  56.   Response.Clear()
  57.   Response.Write(msg)
  58.   Response.End()
  59.   End If
  60. End Property

  61. Public Property Let SetWebName(WebName_)
  62.   WebName=WebName_
  63. End Property

  64. Public Property Let SetWebUrl(WebUrl_)
  65.   WebUrl=WebUrl_
  66. End Property

  67. Public Property Let SetWebDes(webDes_)
  68.   WebDes=WebDes_
  69. End Property

  70. Public Property Let SetInfoUrl(Infourl_)
  71.   Infourl=Infourl_
  72. End Property

  73. Public Property Let SetPageType(PageType_)
  74.   PageType=PageType_
  75. End Property

  76. Public Property Let SetMaxInfo(MaxInfo_)
  77.   MaxInfo=MaxInfo_
  78. End Property

  79. Public Property Let setContentShow(ContentShow_)
  80.   Dim ArrContentShow
  81.   ArrContentShow=Split(ContentShow_,",")
  82.   If Ubound(ArrContentShow)<>1 Then Er=True:Errmsg="信息显示参数设置有误!!"
  83.   ShowContentType=ArrContentShow(0)
  84.   ShowContentLen=ArrContentShow(1)
  85.   If Not isnumeric(ShowContentType) or ShowContentType="" Then ShowContentType=0
  86.   If Not isnumeric(ShowContentLen) or ShowContentLen="" Then
  87.   If ShowContentType=0  Then ShowContentLen=20 Else ShowContentLen=200
  88.   Else
  89.   If ShowContentType=0 and (ShowContentLen>100 or ShowContentLen<10) Then ShowContentLen=20
  90.   End If
  91. End Property

  92. Public Property Set SetConn(Conn_)
  93.   If TypeName(Conn_)="Connection"  Then
  94.   Set Conn=Conn_
  95.   Else
  96.   Er=true
  97.   Errmsg="数据库连接错误"
  98.   Exit property
  99.   End If
  100. End Property

  101. Public Property Let SetSql(sql_)
  102.   Sql=Sql_
  103. End Property

  104. Public Property Get RssHead()
  105.   RssHead="<?xml version=""1.0"" encoding=""gb2312"" ?> "
  106.   RssHead=RssHead&"<rss>"
  107.   RssHead=RssHead&"<channel>"
  108.   RssHead=RssHead&"<title>"&WebName&"</title>"
  109.   RssHead=RssHead&"<link>"&WebUrl&"</link>"
  110.   RssHead=RssHead&"<description>"&WebDes&"</description>"
  111. End Property

  112. Private Property Get RssBottom()
  113.   RssBottom="</channel>"
  114.   RssBottom=RssBottom&"</rss>"
  115. End Property

  116. Public Sub ShowRss()
  117.   On Error resume Next
  118.   Dim Rs
  119.   Dim ShowInfoUrl,ShowContent,Content
  120.   If TypeName(Conn)<>"Connection" Then Er=True:Errmsg="Connection对象有误"
  121.   If Sql="" or isnull(Sql)="" or isempty(Sql)="" Then Er=True:Errmsg="没有可执行的Sql语句"
  122.   If WebName="" or isnull(WebName)="" or isempty(WebName)="" Then Er=True:Errmsg="请设置RSS标题"
  123.   If WebUrl="" or isnull(WebUrl)="" or isempty(WebUrl)="" Then Er=True:Errmsg="请设置网站的链接"
  124.   If InfoUrl="" or isnull(InfoUrl)="" or isempty(InfoUrl)="" Then Er=True:Errmsg="请设置链接信息"
  125.   If PageType="" or isnull(PageType)="" or isempty(PageType)="" Then Er=True:Errmsg="请设置链接类型"
  126.   Set Rs=Server.CreateObject("ADODB.RecordSet")
  127.   Rs.Open Sql,Conn,1,1
  128.   If Err Then
  129.     Er=true
  130.     Errmsg="数据库未能打开<br />请检查您的Sql语句是否正确"
  131.     Exit Sub
  132.   End If
  133.   
  134.   Response.Charset = "gb2312"
  135.   Response.ContentType="text/xml"
  136.   Response.Write(RssHead)
  137.   For i =1 to MaxInfo
  138.     '*****************************
  139.     ShowInfoUrl=InfoUrl
  140.     If ShowInfoUrl="" or isnull(ShowInfoUrl) or isempty(ShowInfoUrl) Then
  141.     ShowInfoUrl="#"
  142.     Else
  143.     If PageType Then ShowInfoUrl=ShowInfoUrl&Rs(0) Else ShowInfoUrl=ShowInfoUrl&Rs(4)
  144.     End If
  145.     '*****************************
  146.     AllContent=LoseHtml(Rs(2))
  147.     AllContentLen=byteLen(AllContent)
  148.     ShowContent=int(ShowContentLen)
  149.     If ShowContentType=0 Then ShowContent=AllContentLen*ShowContent/100
  150.     Content=Server.HTMLEncode(titleb(AllContent,ShowContent))
  151.     Response.Write("<item>")
  152.     Response.Write("<title>")
  153.     Response.Write(Rs(1))
  154.     Response.Write("</title>")
  155.     Response.Write("<link>")
  156.     Response.Write(ShowInfoUrl)
  157.     Response.Write("</link>")
  158.     Response.Write("<description>")
  159.     Response.Write(Content)
  160.     Response.Write("</description>")
  161.     Response.Write("<pubDate>")
  162.     Response.Write(return_RFC822_Date(Rs(3),"GMT"))
  163.     Response.Write("</pubDate>")
  164.     Response.Write("</item>")
  165.     If Rs.Eof or i>cint(MaxInfo) Then Exit For
  166.     Rs.MoveNext
  167.   Next
  168.   Response.Write(RssBottom)
  169. End Sub

  170. Function LoseHtml(ContentStr)
  171.   Dim ClsTempLoseStr,regEx
  172.   ClsTempLoseStr = Cstr(ContentStr)
  173.   Set regEx = New RegExp
  174.   regEx.Pattern = "<\/*[^<>]*>"
  175.   regEx.IgnoreCase = True
  176.   regEx.Global = True
  177.   ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
  178.   LoseHtml = ClsTempLoseStr
  179. End function

  180. Function return_RFC822_Date(byVal myDate, byVal TimeZone)
  181.   Dim myDay, myDays, myMonth, myYear
  182.   Dim myHours, myMinutes, mySeconds
  183.   
  184.   myDate = CDate(myDate)
  185.   myDay = EnWeekDayName(myDate)
  186.   myDays = Right("00" & Day(myDate),2)
  187.   myMonth = EnMonthName(myDate)
  188.   myYear = Year(myDate)
  189.   myHours = Right("00" & Hour(myDate),2)
  190.   myMinutes = Right("00" & Minute(myDate),2)
  191.   mySeconds = Right("00" & Second(myDate),2)
  192.   
  193.   
  194.   return_RFC822_Date = myDay&", "& _
  195.   myDays&" "& _
  196.   myMonth&" "& _
  197.   myYear&" "& _
  198.   myHours&":"& _
  199.   myMinutes&":"& _
  200.   mySeconds&" "& _
  201.   " " & TimeZone
  202. End Function
  203. Function EnWeekDayName(InputDate)
  204.   Dim Result
  205.   Select Case WeekDay(InputDate,1)
  206.   Case 1:Result="Sun"
  207.   Case 2:Result="Mon"
  208.   Case 3:Result="Tue"
  209.   Case 4:Result="Wed"
  210.   Case 5:Result="Thu"
  211.   Case 6:Result="Fri"
  212.   Case 7:Result="Sat"
  213.   End Select
  214.   EnWeekDayName = Result
  215. End Function

  216. Function EnMonthName(InputDate)
  217.   Dim Result
  218.   Select Case Month(InputDate)
  219.   Case 1:Result="Jan"
  220.   Case 2:Result="Feb"
  221.   Case 3:Result="Mar"
  222.   Case 4:Result="Apr"
  223.   Case 5:Result="May"
  224.   Case 6:Result="Jun"
  225.   Case 7:Result="Jul"
  226.   Case 8:Result="Aug"
  227.   Case 9:Result="Sep"
  228.   Case 10:Result="Oct"
  229.   Case 11:Result="Nov"
  230.   Case 12:Result="Dec"
  231.   End Select
  232.   EnMonthName = Result
  233. End Function

  234. function titleb(str,strlen)
  235.   Dim Bstrlen
  236.   bstrlen=strlen
  237.   If isempty(str) or isnull(str) or str="" Then
  238.   titleb=str
  239.   exit function
  240.   Else
  241.   dim l,t,c,i
  242.   l=len(str)
  243.   t=0
  244.   
  245.   for i=1 to l
  246.   c=Abs(Asc(Mid(str,i,1)))
  247.   if c>255 then
  248.   t=t+2
  249.   else
  250.   t=t+1
  251.   end if
  252.   
  253.   if t>=bstrlen then
  254.   titleb=left(str,i)
  255.   exit for
  256.   else
  257.   titleb=str&""
  258.   end if
  259.   next
  260.   End If
  261. end function

  262. function byteLen(str)
  263.   dim lenStr,lenTemp,i
  264.   lenStr=0
  265.   lenTemp=len(str)
  266.   dim strTemp
  267.   for i=1 to lenTemp
  268.   strTemp=asc(mid(str,i,1))
  269.   if strTemp>255 or strTemp<=0 then
  270.   lenStr=lenStr+2
  271.   else
  272.   lenStr=lenStr+1
  273.   end if
  274.   next
  275.   byteLen=lenStr
  276. end function
  277. End Class
  278. %>
复制代码
已有 1 人评分威望 收起 理由
帅青蛙 + 2 原创内容

总评分: 威望 + 2   查看全部评分

西部数码顶级域名注册商39元抢注!
帖子
596
体力
2221
威望
0
居住地
江苏省 苏州市
发表于 2007-11-19 17:22:49 |显示全部楼层
好东东,还解决了我另外一个问题~
租服务器,上51IDC | [长沙]招聘:PHP经理10K/WEB前端6K/PHP开发6K

使用道具 举报

苦寒竹

管理员

帖子
19732
体力
18027
威望
23
居住地
浙江省 金华市
发表于 2007-11-19 18:37:49 |显示全部楼层
楼上的解决了你的什么问题?
楼主的类,感觉使原先生成rss文件的方法给复杂化了~
RSS生成其实重点不应该放在代码书写和套用上,而是文章察看权限上,比如blog的,私有的blog就得判断后不能显示。
论坛中需要回复或者斑竹讨论区的帖子也不能用Rss看到(动网7.1的可以看到~
搞IT的穷秀才。

使用道具 举报

feijie913 楼主

飞妮莫属

初级会员 手机认证 

帖子
36
体力
195
威望
2
发表于 2007-11-20 07:48:41 |显示全部楼层
能否看到
以及权限的问题
全在你的Sql语句哦

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

Archiver|手机版|安久科技提供CDN|blueidea.com ( 京ICP备05002321号 )  

GMT+8, 2012-2-4 15:25 , Processed in 0.135658 second(s), 11 queries , Gzip On, Memcache On.

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部