Posted By

miziomon on 07/23/07


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

f0vela
gafsveno
rchk


asprss


 / Published in: ASP
 

  1. <%
  2.  
  3. ' --------------------------------------------------------------------
  4. Class asprss
  5. ' --------------------------------------------------------------------
  6. ' 23.07.2007 | maurizio
  7. ' asprss v 0.1
  8. '
  9.  
  10. Public rss_cs
  11. Public rss_sql
  12.  
  13. Public channel_title
  14. Public channel_description
  15. Public channel_link
  16. Public channel_lastBuildDate
  17.  
  18. Public item_title
  19. Public item_link
  20. Public item_pubdate
  21. Public item_description
  22.  
  23. public ItemCount
  24.  
  25. ' --------------------------------------------------------------------
  26. Private Sub Class_Initialize()
  27. ' --------------------------------------------------------------------
  28.  
  29. response.CodePage = 65001 ' -> utf-8
  30. response.CharSet = "utf-8"
  31. response.ContentType = "application/xml"
  32.  
  33. ItemCount = 0
  34.  
  35. end Sub
  36.  
  37. ' --------------------------------------------------------------------
  38. Function gmt ( ddate )
  39. ' --------------------------------------------------------------------
  40. ' 23.07.2007 | maurizio
  41. ' data in formato gmt
  42.  
  43. gmt = ""
  44. Session.LCID = 1033
  45. gmt = gmt & FormatDateTime( ddate , vbLongDate)
  46.  
  47. Session.LCID = 2057
  48. gmt = gmt & " " & time()
  49.  
  50. end function
  51.  
  52. ' --------------------------------------------------------------------
  53. Function create_item ( )
  54. ' --------------------------------------------------------------------
  55. ' 23.07.2007 | maurizio
  56. '
  57. create_item = ""
  58.  
  59. set cn_item = CreateObject("ADODB.Connection")
  60. cn_item.Open rss_cs
  61.  
  62. set rs_item = CreateObject("ADODB.recordset")
  63. rs_item.Open rss_sql , cn_item , 0 , 1 , 1
  64.  
  65. nrow = 0
  66. do while not rs_item.eof
  67.  
  68. nrow = nrow + 1
  69.  
  70. create_item = create_item & "<item>" & vbcrlf
  71. create_item = create_item & "<title>" & rs_item(item_title) & "</title>" & vbcrlf
  72. create_item = create_item & "<link>" & server.htmlencode(rs_item(item_link)) & "</link>" & vbcrlf
  73. create_item = create_item & "<guid isPermaLink=""true"">" & server.htmlencode(rs_item(item_link)) & "</guid>" & vbcrlf
  74. create_item = create_item & "<pubDate>" & gmt(rs_item(item_pubdate)) & "</pubDate>" & vbcrlf
  75. create_item = create_item & "<description>" & rs_item(item_description) &"</description>" & vbcrlf
  76. create_item = create_item & "</item>" & vbcrlf
  77.  
  78. if ItemCount > 0 and nrow => ItemCount then
  79. Exit Do
  80. else
  81. rs_item.movenext
  82. end if
  83.  
  84. loop
  85.  
  86.  
  87. rs_item.Close
  88. cn_item.Close
  89. Set rs_item = Nothing
  90. Set cn_item = Nothing
  91.  
  92. end function
  93.  
  94.  
  95. ' --------------------------------------------------------------------
  96. Function create ( )
  97. ' --------------------------------------------------------------------
  98. ' 23.07.2007 | maurizio
  99. '
  100.  
  101.  
  102. sRss = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbcrlf
  103. sRss = sRss & "<rss version=""2.0"">" & vbcrlf
  104. 'sRss = sRss & "<rss version=""2.0"" xmlns:content=""http://purl.org/rss/1.0/modules/content/"" xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:geo=""http://www.w3.org/2003/01/geo/wgs84_pos#"" xmlns:creativeCommons=""http://backend.userland.com/creativeCommonsRssModule"" >" & vbcrlf
  105. sRss = sRss & "<channel>" & vbcrlf
  106. sRss = sRss & "<title>" & channel_title & "</title>" & vbcrlf
  107. sRss = sRss & "<description>" & channel_description & "</description>" & vbcrlf
  108. sRss = sRss & "<link>" & channel_link & "</link>" & vbcrlf
  109. sRss = sRss & "<lastBuildDate>" & channel_lastBuildDate & "</lastBuildDate>" & vbcrlf
  110.  
  111. sRss = sRss & create_item()
  112.  
  113. sRss = sRss & "</channel>" & vbcrlf
  114. sRss = sRss & "</rss>" & vbcrlf
  115.  
  116. create = sRss
  117.  
  118. end function
  119.  
  120.  
  121. end class
  122.  
  123.  
  124. ' esempio utilizzo
  125. '
  126.  
  127. set orss = new asprss
  128. orss.rss_cs = connectionstring
  129. orss.rss_sql = querysql
  130.  
  131. orss.channel_title = "Video Mercurius"
  132. orss.channel_description = "il sito con i video delle scuole"
  133. orss.channel_link = "http://video.mercurius.it"
  134. orss.channel_lastBuildDate = date()
  135.  
  136. orss.item_title = "title_video"
  137. orss.item_link = "link_video"
  138. orss.item_pubdate = "dateadd_video"
  139. orss.item_description = "descrio_video"
  140.  
  141. orss.ItemCount = 5
  142. response.write orss.create
  143.  
  144.  
  145.  
  146. %>

Report this snippet  

You need to login to post a comment.