PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/mojoPortal.Features.UI/Forums/Controls/ThreadList.ascx.cs

#
C# | 288 lines | 210 code | 62 blank | 16 comment | 17 complexity | 0535664bfae2ae4a3d884a557d26f91c 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
  2. // Created: 2011-06-13
  3. // Last Modified: 2011-06-14
  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. //
  13. using System;
  14. using System.Data;
  15. using System.Web.UI;
  16. using mojoPortal.Business;
  17. using mojoPortal.Business.WebHelpers;
  18. using mojoPortal.Web.Framework;
  19. using Resources;
  20. namespace mojoPortal.Web.ForumUI
  21. {
  22. public partial class ThreadList : UserControl
  23. {
  24. #region Properties
  25. private ForumConfiguration config = null;
  26. protected Double TimeOffset = 0;
  27. private TimeZoneInfo timeZone = null;
  28. private SiteSettings siteSettings = null;
  29. private string notificationUrl = string.Empty;
  30. private Forum forum = null;
  31. protected bool isSubscribedToForum = false;
  32. private SiteUser currentUser = null;
  33. private int pageNumber = 1;
  34. public Forum Forum
  35. {
  36. get { return forum; }
  37. set { forum = value; }
  38. }
  39. private int pageId = -1;
  40. public int PageId
  41. {
  42. get { return pageId; }
  43. set { pageId = value; }
  44. }
  45. private int moduleId = -1;
  46. public int ModuleId
  47. {
  48. get { return moduleId; }
  49. set { moduleId = value; }
  50. }
  51. private int itemId = -1;
  52. public int ItemId
  53. {
  54. get { return itemId; }
  55. set { itemId = value; }
  56. }
  57. public int PageNumber
  58. {
  59. get { return pageNumber; }
  60. set { pageNumber = value; }
  61. }
  62. private bool isEditable = false;
  63. public bool IsEditable
  64. {
  65. get { return isEditable; }
  66. set { isEditable = value; }
  67. }
  68. public ForumConfiguration Config
  69. {
  70. get { return config; }
  71. set { config = value; }
  72. }
  73. private string siteRoot = string.Empty;
  74. public string SiteRoot
  75. {
  76. get { return siteRoot; }
  77. set { siteRoot = value; }
  78. }
  79. private string imageSiteRoot = string.Empty;
  80. public string ImageSiteRoot
  81. {
  82. get { return imageSiteRoot; }
  83. set { imageSiteRoot = value; }
  84. }
  85. #endregion
  86. protected void Page_Load(object sender, EventArgs e)
  87. {
  88. if (!Visible) { return; }
  89. LoadSettings();
  90. PopulateLabels();
  91. PopulateControls();
  92. }
  93. private void PopulateControls()
  94. {
  95. if (forum == null) { return; }
  96. //TODO: need to look into this:
  97. // http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
  98. //http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#sequential-link-types
  99. string pageUrl = SiteRoot
  100. + "/Forums/ForumView.aspx?"
  101. + "ItemID=" + forum.ItemId.ToInvariantString()
  102. + "&mid=" + ModuleId.ToInvariantString()
  103. + "&pageid=" + PageId.ToInvariantString()
  104. + "&pagenumber={0}";
  105. pgrTop.PageURLFormat = pageUrl;
  106. pgrTop.ShowFirstLast = true;
  107. pgrTop.CurrentIndex = pageNumber;
  108. pgrTop.PageSize = forum.ThreadsPerPage;
  109. pgrTop.PageCount = forum.TotalPages;
  110. pgrTop.Visible = (pgrTop.PageCount > 1);
  111. pgrBottom.PageURLFormat = pageUrl;
  112. pgrBottom.ShowFirstLast = true;
  113. pgrBottom.CurrentIndex = pageNumber;
  114. pgrBottom.PageSize = forum.ThreadsPerPage;
  115. pgrBottom.PageCount = forum.TotalPages;
  116. pgrBottom.Visible = (pgrBottom.PageCount > 1);
  117. if ((Request.IsAuthenticated) || (forum.AllowAnonymousPosts))
  118. {
  119. lnkNewThread.HRef = SiteRoot
  120. + "/Forums/EditPost.aspx?forumid=" + ItemId.ToInvariantString()
  121. + "&pageid=" + PageId.ToInvariantString()
  122. + "&mid=" + ModuleId.ToInvariantString();
  123. lnkNewThreadBottom.HRef = lnkNewThread.HRef;
  124. lnkLogin.Visible = false;
  125. }
  126. else
  127. {
  128. lnkNewThread.Visible = false;
  129. lnkNewThreadBottom.Visible = false;
  130. }
  131. using (IDataReader reader = forum.GetThreads(pageNumber))
  132. {
  133. rptForums.DataSource = reader;
  134. #if MONO
  135. this.rptForums.DataBind();
  136. #else
  137. this.DataBind();
  138. #endif
  139. }
  140. }
  141. private void PopulateLabels()
  142. {
  143. lnkNewThread.InnerHtml = ForumResources.ForumViewNewThreadLabel;
  144. lnkNewThread.Title = ForumResources.ForumViewNewThreadLabel;
  145. lnkNewThreadBottom.InnerHtml = ForumResources.ForumViewNewThreadLabel;
  146. lnkNewThreadBottom.Title = ForumResources.ForumViewNewThreadLabel;
  147. lnkLogin.Text = ForumResources.ForumsLoginRequiredLink;
  148. pgrTop.NavigateToPageText = ForumResources.CutePagerNavigateToPageText;
  149. pgrTop.BackToFirstClause = ForumResources.CutePagerBackToFirstClause;
  150. pgrTop.GoToLastClause = ForumResources.CutePagerGoToLastClause;
  151. pgrTop.BackToPageClause = ForumResources.CutePagerBackToPageClause;
  152. pgrTop.NextToPageClause = ForumResources.CutePagerNextToPageClause;
  153. pgrTop.PageClause = ForumResources.CutePagerPageClause;
  154. pgrTop.OfClause = ForumResources.CutePagerOfClause;
  155. pgrBottom.NavigateToPageText = ForumResources.CutePagerNavigateToPageText;
  156. pgrBottom.BackToFirstClause = ForumResources.CutePagerBackToFirstClause;
  157. pgrBottom.GoToLastClause = ForumResources.CutePagerGoToLastClause;
  158. pgrBottom.BackToPageClause = ForumResources.CutePagerBackToPageClause;
  159. pgrBottom.NextToPageClause = ForumResources.CutePagerNextToPageClause;
  160. pgrBottom.PageClause = ForumResources.CutePagerPageClause;
  161. pgrBottom.OfClause = ForumResources.CutePagerOfClause;
  162. lnkNotify.ToolTip = ForumResources.SubscribeLink;
  163. lnkNotify2.Text = ForumResources.SubscribeLongLink;
  164. }
  165. private void LoadSettings()
  166. {
  167. siteSettings = CacheHelper.GetCurrentSiteSettings();
  168. TimeOffset = SiteUtils.GetUserTimeOffset();
  169. timeZone = SiteUtils.GetUserTimeZone();
  170. pageNumber = WebUtils.ParseInt32FromQueryString("pagenumber", 1);
  171. notificationUrl = SiteRoot + "/Forums/EditSubscriptions.aspx?mid="
  172. + ModuleId.ToInvariantString()
  173. + "&pageid=" + PageId.ToInvariantString() +"#forum" + ItemId.ToInvariantString();
  174. lnkNotify.ImageUrl = ImageSiteRoot + "/Data/SiteImages/FeatureIcons/email.png";
  175. lnkNotify.NavigateUrl = notificationUrl;
  176. lnkNotify2.NavigateUrl = notificationUrl;
  177. if (WebConfigSettings.LoginPageRelativeUrl.Length > 0)
  178. {
  179. lnkLogin.NavigateUrl = SiteRoot + WebConfigSettings.LoginPageRelativeUrl + "?returnurl=" + Server.UrlEncode(Request.RawUrl);
  180. }
  181. else
  182. {
  183. lnkLogin.NavigateUrl = SiteRoot + "/Secure/Login.aspx?returnurl=" + Server.UrlEncode(Request.RawUrl);
  184. }
  185. if (Request.IsAuthenticated)
  186. {
  187. currentUser = SiteUtils.GetCurrentSiteUser();
  188. if ((currentUser != null) && (ItemId > -1))
  189. {
  190. isSubscribedToForum = Forum.IsSubscribed(ItemId, currentUser.UserId);
  191. }
  192. if (!isSubscribedToForum) { pnlNotify.Visible = true; }
  193. }
  194. }
  195. protected string GetRowCssClass(int stickySort, bool isLocked)
  196. {
  197. if (isLocked) { return "lockedthreadrow"; }
  198. if (stickySort < Forum.NormalThreadSort) { return "stickythreadrow"; }
  199. return "normalthreadrow";
  200. }
  201. protected string GetFolderCssClass(int stickySort, bool isLocked)
  202. {
  203. if (isLocked) { return "lockedthread"; }
  204. if (stickySort < Forum.NormalThreadSort) { return "stickythread"; }
  205. return "normalthread";
  206. }
  207. protected string FormatDate(DateTime startDate)
  208. {
  209. if (timeZone != null)
  210. {
  211. return TimeZoneInfo.ConvertTimeFromUtc(startDate, timeZone).ToString();
  212. }
  213. return startDate.AddHours(TimeOffset).ToString();
  214. }
  215. public bool GetPermission(object startedByUser)
  216. {
  217. // TODO: allow the user who started the thread to edit it?
  218. return IsEditable;
  219. }
  220. protected override void OnInit(EventArgs e)
  221. {
  222. base.OnInit(e);
  223. this.Load += new EventHandler(Page_Load);
  224. }
  225. }
  226. }