PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/mojoPortal.Features.UI/FeedManager/FeedManager.aspx.cs

#
C# | 309 lines | 219 code | 64 blank | 26 comment | 24 complexity | fdabedd68c6cf2e4c46d8cdf405ea278 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause, CPL-1.0, CC-BY-SA-3.0, GPL-2.0
  1. /// Author: Joe Audette and Walter Ferrari
  2. /// Created: 2008-09-27
  3. /// Last Modified: 2011-05-23
  4. ///
  5. /// The use and distribution terms for this software are covered by the
  6. /// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
  7. /// which can be found in the file CPL.TXT at the root of this distribution.
  8. /// By using this software in any fashion, you are agreeing to be bound by
  9. /// the terms of this license.
  10. ///
  11. /// You must not remove this notice, or any other, from this software.
  12. using System;
  13. using System.Collections;
  14. using System.Data;
  15. using System.Globalization;
  16. using System.Web.UI;
  17. using System.Web.UI.WebControls;
  18. using mojoPortal.Web.Framework;
  19. using mojoPortal.Web.UI;
  20. using mojoPortal.Business;
  21. using Resources;
  22. namespace mojoPortal.Web.FeedUI
  23. {
  24. public partial class FeedManagerPage : mojoBasePage
  25. {
  26. protected int PageId = -1;
  27. protected int ModuleId = -1;
  28. protected int ItemId = -1;
  29. private Module module = null;
  30. private Hashtable moduleSettings = null;
  31. private bool canEdit = false;
  32. private int totalPages = 1;
  33. //private string previousPubDate;
  34. protected FeedManagerConfiguration config = new FeedManagerConfiguration();
  35. protected string ConfirmImage = string.Empty;
  36. protected string allowedImageUrlRegexPattern = SecurityHelper.RegexRelativeImageUrlPatern;
  37. protected string FeedItemHeadingElement = FeedManagerConfiguration.FeedItemHeadingElement;
  38. protected Double timeZoneOffset = 0;
  39. private TimeZoneInfo timeZone = null;
  40. protected void Page_Load(object sender, EventArgs e)
  41. {
  42. LoadParams();
  43. if (!canEdit)
  44. {
  45. SiteUtils.RedirectToAccessDeniedPage(this);
  46. return;
  47. }
  48. LoadSettings();
  49. if (!config.EnableSelectivePublishing)
  50. {
  51. WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
  52. return;
  53. }
  54. SetupCss();
  55. PopulateLabels();
  56. PopulateControls();
  57. }
  58. private void PopulateControls()
  59. {
  60. if (!IsPostBack)
  61. {
  62. pgrRptEntries.CurrentIndex = 1;
  63. BindRepeater();
  64. }
  65. }
  66. private DataView GetEntriesTable()
  67. {
  68. DataTable entriesTable = null;
  69. entriesTable = FeedCache.GetRssFeedEntries(
  70. ModuleId,
  71. module.ModuleGuid,
  72. config.EntryCacheTimeout,
  73. config.MaxDaysOld,
  74. config.MaxEntriesPerFeed,
  75. config.EnableSelectivePublishing);
  76. return entriesTable.DefaultView;
  77. }
  78. private void BindRepeater()
  79. {
  80. DataView entries = GetEntriesTable();
  81. if (config.SortAscending)
  82. {
  83. entries.Sort = "PubDate ASC";
  84. }
  85. else
  86. {
  87. entries.Sort = "PubDate DESC";
  88. }
  89. PagedDataSource pagedDS = new PagedDataSource();
  90. pagedDS.DataSource = entries;
  91. pagedDS.AllowPaging = true;
  92. pagedDS.PageSize = config.PageSize;
  93. pagedDS.CurrentPageIndex = pgrRptEntries.CurrentIndex - 1;
  94. totalPages = 1;
  95. int totalRows = entries.Count;
  96. if (config.PageSize > 0) totalPages = totalRows / config.PageSize;
  97. if (totalRows <= config.PageSize)
  98. {
  99. totalPages = 1;
  100. }
  101. else
  102. {
  103. int remainder;
  104. Math.DivRem(totalRows, config.PageSize, out remainder);
  105. if (remainder > 0)
  106. {
  107. totalPages += 1;
  108. }
  109. }
  110. if (this.totalPages > 1)
  111. {
  112. pgrRptEntries.ShowFirstLast = true;
  113. pgrRptEntries.PageSize = config.PageSize;
  114. pgrRptEntries.PageCount = totalPages;
  115. }
  116. else
  117. {
  118. pgrRptEntries.Visible = false;
  119. }
  120. rptEntries.DataSource = pagedDS;
  121. rptEntries.DataBind();
  122. }
  123. protected void pgrRptEntries_Command(object sender, CommandEventArgs e)
  124. {
  125. int currentPageIndex = Convert.ToInt32(e.CommandArgument);
  126. pgrRptEntries.CurrentIndex = currentPageIndex;
  127. BindRepeater();
  128. updPnlRSSA.Update();
  129. }
  130. protected void rptEntries_ItemCommand(object source, RepeaterCommandEventArgs e)
  131. {
  132. if (e.CommandName == "Confirm")
  133. {
  134. string entryInfo = (string)e.CommandArgument;
  135. int sep = -1;
  136. sep = entryInfo.IndexOf('_');
  137. if (sep != -1)
  138. {
  139. string[] entryHash = entryInfo.Split('_');
  140. bool published = Convert.ToBoolean(entryHash[1]);
  141. if (published)
  142. {
  143. RssFeed.UnPublish(module.ModuleGuid, Convert.ToInt32(entryHash[0]));
  144. }
  145. else
  146. {
  147. RssFeed.Publish(module.ModuleGuid, Convert.ToInt32(entryHash[0]));
  148. }
  149. BindRepeater();
  150. }
  151. }
  152. }
  153. //protected string GetDateHeader(DateTime pubDate)
  154. //{
  155. // string retVal = string.Empty;
  156. // if (previousPubDate != pubDate.ToString(config.DateFormat))
  157. // {
  158. // previousPubDate = pubDate.ToString(config.DateFormat);
  159. // retVal = previousPubDate;
  160. // }
  161. // return retVal;
  162. //}
  163. protected string GetDateHeader(DateTime pubDate)
  164. {
  165. // adjust from GMT to user time zone
  166. if (timeZone == null)
  167. {
  168. return pubDate.AddHours(timeZoneOffset).ToString(config.DateFormat);
  169. }
  170. return pubDate.ToLocalTime(timeZone).ToString(config.DateFormat);
  171. }
  172. private void PopulateLabels()
  173. {
  174. Title = SiteUtils.FormatPageTitle(siteSettings, FeedResources.ManagePublishingLink);
  175. }
  176. private void LoadSettings()
  177. {
  178. timeZoneOffset = SiteUtils.GetUserTimeOffset();
  179. timeZone = SiteUtils.GetUserTimeZone();
  180. try
  181. {
  182. // this keeps the action from changing during ajax postback in folder based sites
  183. SiteUtils.SetFormAction(Page, Request.RawUrl);
  184. }
  185. catch (MissingMethodException)
  186. {
  187. //this method was introduced in .NET 3.5 SP1
  188. }
  189. if (ModuleId == -1) { return; }
  190. module = new Module(ModuleId, CurrentPage.PageId);
  191. moduleSettings = ModuleSettings.GetModuleSettings(ModuleId);
  192. if (moduleSettings == null) { return; }
  193. config = new FeedManagerConfiguration(moduleSettings);
  194. ConfirmImage = this.ImageSiteRoot + "/Data/SiteImages/confirmed";
  195. if (config.AllowExternalImages) allowedImageUrlRegexPattern = SecurityHelper.RegexAnyImageUrlPatern;
  196. heading.Text = string.Format(CultureInfo.InvariantCulture,
  197. FeedResources.PublishingHeaderFormat, module.ModuleTitle);
  198. lnkBackToPage.Text = string.Format(CultureInfo.InvariantCulture,
  199. FeedResources.BackToPageLinkFormat, CurrentPage.PageName);
  200. lnkBackToPage.NavigateUrl = SiteUtils.GetCurrentPageUrl();
  201. lnkEditFeeds.Text = FeedResources.AddButton;
  202. lnkEditFeeds.NavigateUrl = SiteRoot + "/FeedManager/FeedEdit.aspx?pageid="
  203. + PageId.ToInvariantString()
  204. + "&mid=" + ModuleId.ToInvariantString();
  205. AddClassToBody("feedmanagerpage");
  206. }
  207. private void SetupCss()
  208. {
  209. // older skins have this
  210. StyleSheet stylesheet = (StyleSheet)Page.Master.FindControl("StyleSheet");
  211. if (stylesheet != null)
  212. {
  213. if (stylesheet.FindControl("rsscss") == null)
  214. {
  215. Literal cssLink = new Literal();
  216. cssLink.ID = "rsscss";
  217. cssLink.Text = "\n<link href='"
  218. + SiteUtils.GetSkinBaseUrl()
  219. + "rssmodule.css' type='text/css' rel='stylesheet' media='screen' />";
  220. stylesheet.Controls.Add(cssLink);
  221. }
  222. }
  223. }
  224. private void LoadParams()
  225. {
  226. PageId = WebUtils.ParseInt32FromQueryString("pageid", PageId);
  227. ModuleId = WebUtils.ParseInt32FromQueryString("mid", ModuleId);
  228. canEdit = UserCanEditModule(ModuleId, RssFeed.FeatureGuid);
  229. }
  230. #region OnInit
  231. protected override void OnPreInit(EventArgs e)
  232. {
  233. AllowSkinOverride = true;
  234. base.OnPreInit(e);
  235. }
  236. override protected void OnInit(EventArgs e)
  237. {
  238. base.OnInit(e);
  239. this.Load += new EventHandler(this.Page_Load);
  240. rptEntries.ItemCommand += new RepeaterCommandEventHandler(rptEntries_ItemCommand);
  241. pgrRptEntries.Command += new CommandEventHandler(pgrRptEntries_Command);
  242. }
  243. #endregion
  244. }
  245. }