RSS Feed

Posted By BORNXenon Thu 12 Jun 2014
Add to Favorites0
Author Message
BORNXenon
 Posted Thu 12 Jun 2014
Supreme Being

Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)

Group: Forum Members
Last Active: Mon 23 Apr 2018
Posts: 59, Visits: 291
While configuration of my Kartris installation continues, I was quite surprised to find that there is no RSS feed generation. After checking the Kartris website's feed, I realised that it appears to be generated by a 3rd Party tool and doesn't seem to be updated automatically as it is way out of date.

I have spent the afternoon writing my own feed generator which pulls the Kartris news items and generates an RSS feed which can be read either by visiting the page or by a RSS Reader. Any new news items will automatically be added to the feed.

Code is below, feel free to borrow it!

Create a new aspx page in the root of your Kartris installation and call it rss.aspx

rss.aspx

<%@ Page Language="VB" ContentType="text/xml" AutoEventWireup="false" CodeFile="rss.aspx.vb" Inherits="rss" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><%# Server.HtmlEncode(GetGlobalResourceObject("Kartris", "Config_Webshopname"))%> RSS Feed</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>


rss.aspx.vb

Imports System.Xml
Imports System.Text
Imports CkartrisDisplayFunctions

Partial Class rss
Inherits System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

Dim intSizeOfFeed As Integer = 25
Dim strWebshopURL As String = CkartrisBLL.WebShopURLhttp
Dim strWebshopName As String = Server.HtmlEncode(GetGlobalResourceObject("Kartris", "Config_Webshopname"))
Dim intLanguageID As Integer = CkartrisBLL.GetLanguageIDfromSession
Dim strSkinFolder As String = LanguagesBLL.GetTheme(intLanguageID)
Dim intLanguage As Integer = Session("LANG")

'If Session is empty, get default language
If intLanguage = 0 Then
intLanguage = KartSettingsManager.GetKartConfig("frontend.languages.default")
End If

'Check for Empty Skin Folder
If String.IsNullOrEmpty(strSkinFolder) Then
strSkinFolder = "Kartris"
End If

' Clear any previous output from the buffer
Response.Clear()
Response.ContentType = "application/xml"

' XML Declaration Tag
Using xml As XmlTextWriter = New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
xml.WriteStartDocument()

' RSS Tag
xml.WriteStartElement("rss")
xml.WriteAttributeString("version", "2.0")
xml.WriteAttributeString("xmlns:atom", "http://www.w3.org/2005/Atom")

' The Channel Tag - RSS Feed Details
xml.WriteStartElement("channel")
xml.WriteElementString("title", strWebshopName & " RSS Feed")
xml.WriteElementString("link", strWebshopURL)
xml.WriteElementString("description", "All the latest news, marketing and promotions from " & strWebshopName)
xml.WriteElementString("copyright", "Copyright 2014. All rights reserved.")

' Image
xml.WriteStartElement("image")
xml.WriteElementString("url", strWebshopURL & "Skins/" & strSkinFolder & "/Images/logo.png")
xml.WriteElementString("title", strWebshopName & " RSS Feed")
xml.WriteElementString("link", strWebshopURL)
xml.WriteElementString("width", "130")
xml.WriteElementString("height", "90")
xml.WriteEndElement()

' Atom Tag
xml.WriteStartElement("atom:link")
xml.WriteAttributeString("href", strWebshopURL & "rss.aspx")
xml.WriteAttributeString("rel", "self")
xml.WriteAttributeString("type", "application/rss+xml")
xml.WriteEndElement()

'Pull news records into a DataTable
Dim tblLatestNews As DataTable = NewsBLL.GetLatestNews(intLanguage, intSizeOfFeed)

'Loop through DataTable and write news items to xml output
For Each row As DataRow In tblLatestNews.Rows
xml.WriteStartElement("item")
xml.WriteElementString("title", row("N_Name").ToString())
xml.WriteElementString("description", CkartrisDisplayFunctions.TruncateDescription(Server.HtmlDecode(row("N_Text").ToString()), KartSettingsManager.GetKartConfig("frontend.news.display.truncatestory")) & " <a href=""" & strWebshopURL & "News.aspx?NewsID=" & row("N_ID").ToString() & """>[more]</a>")
xml.WriteElementString("link", strWebshopURL & "News.aspx?NewsID=" & row("N_ID").ToString())
xml.WriteElementString("guid", strWebshopURL & "News.aspx?NewsID=" & row("N_ID").ToString())
xml.WriteElementString("pubDate", dateRFC822(row("N_DateCreated")))
xml.WriteEndElement()
Next

xml.WriteEndElement()
xml.WriteEndElement()
xml.WriteEndDocument()
xml.Flush()
xml.Close()
Response.End()

End Using
End Sub

Public Function dateRFC822([date] As DateTime) As String
'Function converts date string to RFC822 format
Dim offset As Integer = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours
Dim timeZone__1 As String = "+" & offset.ToString().PadLeft(2, "0"c)
If offset < 0 Then
Dim i As Integer = offset * -1
timeZone__1 = "-" & i.ToString().PadLeft(2, "0"c)
End If
Return [date].ToString("ddd, dd MMM yyy HH:mm:ss " & timeZone__1.PadRight(5, "0"c))
End Function

End Class


Cheers

Chris
Fri 13 Jun 2014 by BORNXenon
Paul
 Posted Wed 2 Jul 2014
große Käse

große Käse - (500,178 reputation)große Käse - (500,178 reputation)große Käse - (500,178 reputation)große Käse - (500,178 reputation)große Käse - (500,178 reputation)große Käse - (500,178 reputation)große Käse - (500,178 reputation)große Käse - (500,178 reputation)große Käse - (500,178 reputation)

Group: Administrators
Last Active: Tue 10 Sep 2024
Posts: 807, Visits: 2,748
Nice bit of code... I have added this in to our site, works great. Would you mind if I zip this up and list it on the site as an add-on? Could you PM with any copyright details you want to add in (I am assuming keep it GPL v2 though, same as rest of code).

--
If my post solves your issue, can you 'Mark as Answer' so it's easier for other users to find in future.

If you would like to be informed of new features, new releases, developments and occasional special bonuses, please sign up to our mailing list: http://bit.ly/19sKMZb
BORNXenon
 Posted Wed 9 Jul 2014
Supreme Being

Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)Supreme Being - (33,325 reputation)

Group: Forum Members
Last Active: Mon 23 Apr 2018
Posts: 59, Visits: 291
Hi Paul,

nope, feel free.
Listing it as an add-on will help other users who may not be familiar with writing code, creating pages, etc. so I'm all for it.

PM sent with credit details.

Cheers

Chris

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top