-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsarss.aspx.cs
139 lines (110 loc) · 4.79 KB
/
sarss.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using Christoc.Modules.dnnsimplearticle.Components;
using DotNetNuke.Entities.Portals;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
namespace Christoc.Modules.dnnsimplearticle
{
public partial class sarss : System.Web.UI.Page
{
//Grabbed this logic (MIT LICENSE) from the RSS page I built with Engage Publish YEARS ago. See the Publish code at https://github.com/chrishammond/Engage-Publish
public int NumberOfItems
{
get
{
string i = Request.Params["numberOfItems"];
if (i != null)
{
return Convert.ToInt32(i, CultureInfo.InvariantCulture);
}
return -1;
}
}
public int PortalId
{
get
{
string i = Request.Params["portalId"];
if (i != null)
{
return Convert.ToInt32(i, CultureInfo.InvariantCulture);
}
return -1;
}
}
public int ModuleId
{
get
{
string i = Request.Params["moduleId"];
if (i != null)
{
return Convert.ToInt32(i, CultureInfo.InvariantCulture);
}
return -1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
var ps = new PortalSettings(PortalId);
Response.ContentType = "text/xml";
Response.ContentEncoding = Encoding.UTF8;
var sw = new StringWriter(CultureInfo.InvariantCulture);
var wr = new XmlTextWriter(sw);
wr.WriteStartElement("rss");
wr.WriteAttributeString("version", "2.0");
wr.WriteAttributeString("xmlns:wfw", "http://wellformedweb.org/CommentAPI/");
wr.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");
wr.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
wr.WriteAttributeString("xmlns:trackback", "http://madskills.com/public/xml/rss/module/trackback/");
wr.WriteStartElement("channel");
wr.WriteElementString("title", ps.PortalName);
//Get aliases
var portalAliases = PortalAliasController.Instance.GetPortalAliasesByPortalId(PortalId);//.GetPortalAliasesByPortalId(portalId);
var pa = (portalAliases != null && portalAliases.Count<PortalAliasInfo>() > 0 ? portalAliases.ElementAt<PortalAliasInfo>(0) : null);
if (pa.HTTPAlias.IndexOf("//", StringComparison.OrdinalIgnoreCase) == -1)
{
wr.WriteElementString("link", "//" + pa.HTTPAlias);
}
else
{
wr.WriteElementString("link", pa.HTTPAlias);
}
wr.WriteElementString("description", "RSS Feed for " + ps.PortalName);
wr.WriteElementString("ttl", "120");
var dt = new DataTable { Locale = CultureInfo.InvariantCulture };
//dt = ItemId == -1 ? DataProvider.Instance().GetMostRecent(ItemTypeId, NumberOfItems, PortalId) : DataProvider.Instance().GetMostRecentByCategoryId(ItemId, ItemTypeId, NumberOfItems, PortalId);
var al = ArticleController.GetArticles(ModuleId);
if (al != null)
{
foreach (var a in al)
{
wr.WriteStartElement("item");
DateTime startDate = DateTime.MinValue;
wr.WriteElementString("title", a.Title);
wr.WriteElementString("link", ArticleController.GetArticleLink(a.TabID, a.ArticleId));
wr.WriteElementString("description", Server.HtmlDecode(a.Description));
wr.WriteElementString("thumbnail", a.ThumbImg);
wr.WriteElementString("dc:creator", a.CreatedByUser);
wr.WriteElementString("pubDate", a.CreatedOnDate.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture));
wr.WriteStartElement("guid");
wr.WriteAttributeString("isPermaLink", "true");
wr.WriteString(ArticleController.GetArticleLink(a.TabID, a.ArticleId));
wr.WriteEndElement();
wr.WriteEndElement();
}
}
wr.WriteEndElement();
wr.WriteEndElement();
Response.Write(sw.ToString());
}
}
}