-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.ascx.cs
230 lines (206 loc) · 9.49 KB
/
View.ascx.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
' Copyright (c) 2015 bitboxx solutions
' All rights reserved.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
*/
using System.Collections;
using System.Linq;
using System.Resources;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework.JavaScriptLibraries;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Web.Client.ClientResourceManagement;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.ServiceModel.Syndication;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Bitboxx.DNNModules.BBNews.Components;
using Bitboxx.DNNModules.BBNews.Models;
using DotNetNuke.Application;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Utilities;
using Newtonsoft.Json;
using Globals = DotNetNuke.Common.Globals;
namespace Bitboxx.DNNModules.BBNews
{
[DNNtc.PackageProperties("Bitboxx.BBNews", 1, "Bitboxx BBNews", "A flexible RSS/News reader, provider and aggregator", "bbnews.png", "Torsten Weggen", "bitboxx solutions", "http://www.bitboxx.net", "info@bitboxx.net", true)]
[DNNtc.ModuleProperties("Bitboxx.BBNews", "Bitboxx BBNews", -1)]
[DNNtc.ModuleDependencies(DNNtc.ModuleDependency.CoreVersion, "08.00.00")]
[DNNtc.ModuleControlProperties("", "Bitboxx.BBNews", DNNtc.ControlType.View, "", true, false)]
public partial class View : PortalModuleBase, IActionable
{
protected string ModuleProperties
{
get
{
UserInfo currentUser = UserController.GetCurrentUserInfo();
Dictionary<string, string> resources;
using (var rsxr = new ResXResourceReader(MapPath(LocalResourceFile + ".ascx.resx")))
{
resources = rsxr.OfType<DictionaryEntry>()
.ToDictionary(
entry => entry.Key.ToString().Replace(".", "_"),
entry => LocalizeString(entry.Key.ToString()));
}
List<string> languages = new List<string>();
LocaleController lc = new LocaleController();
Dictionary<string, Locale> loc = lc.GetLocales(PortalId);
foreach (KeyValuePair<string, Locale> item in loc)
{
string cultureCode = item.Value.Culture.Name;
languages.Add(cultureCode);
}
dynamic properties = new ExpandoObject();
properties.Resources = resources;
properties.Settings = Settings;
properties.ApplicationPath = Globals.ApplicationPath;
properties.IsEditable = IsEditable;
properties.EditMode = EditMode;
properties.IsAdmin = currentUser == null ? false : currentUser.IsInRole(PortalSettings.AdministratorRoleName);
properties.ModuleId = ModuleId;
properties.PortalId = PortalId;
properties.UserId = UserId;
properties.HomeDirectory = PortalSettings.HomeDirectory.Substring(1);
properties.ModuleDirectory = this.ControlPath;
properties.PortalLanguages = languages;
properties.CurrentLanguage = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
return ClientAPI.GetSafeJSString(JsonConvert.SerializeObject(properties));
}
}
protected string ModuleDirectory
{
get
{
string moduleDirectory = "/" + this.ControlPath;
return moduleDirectory.Substring(0, moduleDirectory.LastIndexOf('/') + 1);
}
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
DotNetNuke.Framework.ServicesFramework.Instance.RequestAjaxScriptSupport();
DotNetNuke.Framework.ServicesFramework.Instance.RequestAjaxAntiForgerySupport();
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void Page_Prerender(object sender, EventArgs e)
{
if (Request["feed"] != null)
{
string format = Request["feed"].ToLower().Trim();
string feedUrl = Globals.NavigateURL(TabId, "", "feed=" + Request["feed"]);
string alternateUrl = Globals.NavigateURL(TabId);
string appUrl = string.Format("{0}://{1}{2}{3}",
Request.Url.Scheme,
Request.Url.Host,
Request.Url.Port == 80
? string.Empty
: ":" + Request.Url.Port,
Request.ApplicationPath);
string newsPage = (string) Settings["NewsPage"];
int categoryId = Convert.ToInt32(Settings["CategoryID"] ?? "0");
SyndicationFeed feed = new BBNewsController().CreateFeed(categoryId, feedUrl,alternateUrl,appUrl,newsPage);
Response.Clear();
Response.ContentType = "text/xml";
Response.Charset = "utf-8";
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(Response.OutputStream, settings))
{
switch (format)
{
case "atom":
Atom10FeedFormatter atom10Formatter = new Atom10FeedFormatter(feed);
atom10Formatter.WriteTo(writer);
break;
case "rss":
default:
Rss20FeedFormatter rss20Formatter = new Rss20FeedFormatter(feed);
rss20Formatter.WriteTo(writer);
break;
}
writer.Flush();
}
Response.Flush();
Response.End();
}
else
{
string titleLabelName = DotNetNukeContext.Current.Application.Version.Major < 6 ? "lblTitle" : "titleLabel";
Control ctl = Globals.FindControlRecursiveDown(this.ContainerControl, titleLabelName);
if ((ctl != null))
{
int newsId = Convert.ToInt32(Request["newsid"] ?? "-1");
NewsInfo news = DbController.Instance.GetNews(newsId);
if (Settings["ShowTitle"] != null && Convert.ToBoolean((string) Settings["ShowTitle"]) && news != null)
{
// We can set the title of our module
((Label) ctl).Text = news.Title;
}
if (Settings["ShowRss"] != null)
{
int position = Convert.ToInt32(Settings["ShowRss"]);
Control rssIconCtrl = ParseControl("<a href=\"" + Globals.NavigateURL(TabId, "", "feed=rss") +
"\"><img src=\"" + Page.ResolveUrl("~/images/action_rss.gif") + "\" style=\"vertical-align:middle; padding-right:5px;\" /></a>");
switch (position)
{
case 1:
ctl.Parent.Controls.AddAt(0, rssIconCtrl);
break;
case 2:
ctl.Parent.Controls.Add(rssIconCtrl);
break;
}
}
}
}
}
#region Implementation of IActionable
/// -----------------------------------------------------------------------------
/// <summary>
/// Registers the module actions required for interfacing with the portal framework
/// </summary>
/// <value></value>
/// <returns></returns>
/// <remarks></remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public ModuleActionCollection ModuleActions
{
get
{
ModuleActionCollection Actions = new ModuleActionCollection();
Actions.Add(
GetNextActionID(),
Localization.GetString(ModuleActionType.EditContent, this.LocalResourceFile),
ModuleActionType.EditContent,
"",
"Edit.gif",
EditUrl(),
false,
DotNetNuke.Security.SecurityAccessLevel.Edit,
true,
false);
return Actions;
}
}
#endregion
}
}