PageRenderTime 86ms CodeModel.GetById 24ms RepoModel.GetById 2ms app.codeStats 0ms

/web/studio/ASC.Web.Studio/Products/Community/Controls/NavigationSidePanel.ascx.cs

https://gitlab.com/rekby-archive/onlyoffice-CommunityServer
C# | 292 lines | 248 code | 29 blank | 15 comment | 55 complexity | 29f39170f30ecf6d7eb729a8f97654fc MD5 | raw file
  1. /*
  2. *
  3. * (c) Copyright Ascensio System Limited 2010-2021
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. *
  15. */
  16. using System;
  17. using System.Text;
  18. using System.Web;
  19. using ASC.Core;
  20. using ASC.Core.Users;
  21. using ASC.Web.Community.Modules.Wiki.Resources;
  22. using ASC.Web.Community.Product;
  23. using ASC.Web.Core;
  24. using ASC.Web.Studio.Core;
  25. using ASC.Web.Studio.UserControls.Common.HelpCenter;
  26. using ASC.Web.Studio.UserControls.Common.InviteLink;
  27. using ASC.Web.Studio.UserControls.Common.Support;
  28. using ASC.Web.Studio.UserControls.Common.UserForum;
  29. using Newtonsoft.Json.Linq;
  30. namespace ASC.Web.Community.Controls
  31. {
  32. public partial class NavigationSidePanel : System.Web.UI.UserControl
  33. {
  34. public static String Location = VirtualPathUtility.ToAbsolute("~/Products/Community/Controls/NavigationSidePanel.ascx");
  35. protected string CurrentPage { get; set; }
  36. protected bool IsInBlogs { get; set; }
  37. protected bool IsInEvents { get; set; }
  38. protected bool IsInSettings { get; set; }
  39. protected bool IsInBookmarks { get; set; }
  40. protected bool IsInWiki { get; set; }
  41. protected bool IsBlogsAvailable { get; set; }
  42. protected bool IsEventsAvailable { get; set; }
  43. protected bool IsForumsAvailable { get; set; }
  44. protected bool IsBookmarksAvailable { get; set; }
  45. protected bool IsWikiAvailable { get; set; }
  46. protected bool IsAdmin { get; set; }
  47. protected bool IsVisitor { get; set; }
  48. protected bool IsFullAdministrator { get; set; }
  49. protected int TopicID
  50. {
  51. get
  52. {
  53. int result;
  54. return int.TryParse(Request["t"], out result) ? result : 0;
  55. }
  56. }
  57. protected int ForumID
  58. {
  59. get
  60. {
  61. int result;
  62. return int.TryParse(Request["f"], out result) ? result : 0;
  63. }
  64. }
  65. protected bool InAParticularTopic { get; set; }
  66. protected bool MakeCreateNewTopic { get; set; }
  67. protected bool ForumsHasThreadCategories { get; set; }
  68. protected void Page_Load(object sender, EventArgs e)
  69. {
  70. IsAdmin = WebItemSecurity.IsProductAdministrator(CommunityProduct.ID, SecurityContext.CurrentAccount.ID);
  71. IsVisitor = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor();
  72. IsFullAdministrator = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsAdmin();
  73. InitCurrentPage();
  74. InitPermission();
  75. InitModulesState();
  76. var help = (HelpCenter)LoadControl(HelpCenter.Location);
  77. help.IsSideBar = true;
  78. HelpHolder.Controls.Add(help);
  79. SupportHolder.Controls.Add(LoadControl(Support.Location));
  80. UserForumHolder.Controls.Add(LoadControl(UserForum.Location));
  81. InviteUserHolder.Controls.Add(LoadControl(InviteLink.Location));
  82. }
  83. private void InitPermission()
  84. {
  85. foreach (var module in WebItemManager.Instance.GetSubItems(CommunityProduct.ID))
  86. {
  87. switch (module.GetSysName())
  88. {
  89. case "community-blogs":
  90. IsBlogsAvailable = true;
  91. break;
  92. case "community-news":
  93. IsEventsAvailable = true;
  94. break;
  95. case "community-forum":
  96. InitForumsData();
  97. break;
  98. case "community-bookmarking":
  99. IsBookmarksAvailable = true;
  100. break;
  101. case "community-wiki":
  102. IsWikiAvailable = true;
  103. break;
  104. }
  105. }
  106. }
  107. private void InitCurrentPage()
  108. {
  109. var currentPath = HttpContext.Current.Request.Path;
  110. if (currentPath.IndexOf("Modules/Blogs", StringComparison.OrdinalIgnoreCase) > 0)
  111. {
  112. CurrentPage = "blogs";
  113. if (currentPath.IndexOf("AllBlogs.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  114. {
  115. CurrentPage = "allblogs";
  116. }
  117. }
  118. else if (currentPath.IndexOf("Modules/News", StringComparison.OrdinalIgnoreCase) > 0)
  119. {
  120. CurrentPage = "events";
  121. if (currentPath.IndexOf("EditPoll.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  122. {
  123. }
  124. else if (currentPath.IndexOf("EditNews.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  125. {
  126. }
  127. else
  128. {
  129. var type = Request["type"];
  130. if (!string.IsNullOrEmpty(type))
  131. {
  132. switch (type)
  133. {
  134. case "News":
  135. CurrentPage = "news";
  136. break;
  137. case "Order":
  138. CurrentPage = "order";
  139. break;
  140. case "Advert":
  141. CurrentPage = "advert";
  142. break;
  143. case "Poll":
  144. CurrentPage = "poll";
  145. break;
  146. }
  147. }
  148. }
  149. }
  150. else if (currentPath.IndexOf("Modules/Forum", StringComparison.OrdinalIgnoreCase) > 0)
  151. {
  152. CurrentPage = "forum";
  153. if (currentPath.IndexOf("ManagementCenter.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  154. {
  155. CurrentPage = "forumeditor";
  156. }
  157. if (currentPath.IndexOf("Posts.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  158. {
  159. InAParticularTopic = true;
  160. MakeCreateNewTopic = true;
  161. }
  162. }
  163. else if (currentPath.IndexOf("Modules/Bookmarking", StringComparison.OrdinalIgnoreCase) > 0)
  164. {
  165. CurrentPage = "bookmarking";
  166. if (currentPath.IndexOf("FavouriteBookmarks.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  167. {
  168. CurrentPage = "bookmarkingfavourite";
  169. }
  170. }
  171. else if (currentPath.IndexOf("Modules/Wiki", StringComparison.OrdinalIgnoreCase) > 0)
  172. {
  173. CurrentPage = "wiki";
  174. if (currentPath.IndexOf("ListCategories.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  175. {
  176. CurrentPage = "wikicategories";
  177. }
  178. if (currentPath.IndexOf("ListPages.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  179. {
  180. CurrentPage = "wikiindex";
  181. var type = Request["n"];
  182. if (type != null)
  183. {
  184. CurrentPage = "wikinew";
  185. }
  186. type = Request["f"];
  187. if (type != null)
  188. {
  189. CurrentPage = "wikirecently";
  190. }
  191. }
  192. if (currentPath.IndexOf("ListFiles.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  193. {
  194. CurrentPage = "wikifiles";
  195. }
  196. var page = Request["page"];
  197. if (!string.IsNullOrEmpty(page))
  198. {
  199. if (page.StartsWith("Category:"))
  200. CurrentPage = "wikicategories";
  201. if (page == WikiUCResource.HelpPageCaption)
  202. CurrentPage = "wikihelp";
  203. }
  204. }
  205. else if (currentPath.IndexOf("Help.aspx", StringComparison.OrdinalIgnoreCase) > 0)
  206. {
  207. CurrentPage = "help";
  208. }
  209. else
  210. {
  211. CurrentPage = "blogs";
  212. }
  213. }
  214. private void InitModulesState()
  215. {
  216. IsInBlogs = CurrentPage == "allblogs";
  217. IsInEvents = CurrentPage == "news" ||
  218. CurrentPage == "order" ||
  219. CurrentPage == "advert" ||
  220. CurrentPage == "poll";
  221. IsInSettings = CurrentPage == "forumeditor";
  222. IsInBookmarks = CurrentPage == "bookmarkingfavourite";
  223. IsInWiki = CurrentPage == "wikicategories" ||
  224. CurrentPage == "wikiindex" ||
  225. CurrentPage == "wikinew" ||
  226. CurrentPage == "wikirecently" ||
  227. CurrentPage == "wikifiles" ||
  228. CurrentPage == "wikihelp";
  229. }
  230. private void InitForumsData()
  231. {
  232. IsForumsAvailable = true;
  233. var apiServer = new Api.ApiServer();
  234. var apiResponse = apiServer.GetApiResponse(String.Format("{0}community/forum/count.json", SetupInfo.WebApiBaseUrl), "GET");
  235. var obj = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiResponse)));
  236. var count = 0;
  237. if (Int32.TryParse(obj["response"].ToString(), out count))
  238. ForumsHasThreadCategories = count > 0;
  239. if (InAParticularTopic && TopicID > 0)
  240. {
  241. apiServer = new Api.ApiServer();
  242. apiResponse = apiServer.GetApiResponse(String.Format("{0}community/forum/topic/{1}.json", SetupInfo.WebApiBaseUrl, TopicID), "GET");
  243. obj = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiResponse)));
  244. if (obj["response"] != null)
  245. {
  246. obj = JObject.Parse(obj["response"].ToString());
  247. var status = 0;
  248. if (Int32.TryParse(obj["status"].ToString(), out status))
  249. MakeCreateNewTopic = status != 1 && status != 3;
  250. }
  251. }
  252. }
  253. protected string GetDefaultSettingsPageUrl()
  254. {
  255. var defaultUrl = VirtualPathUtility.ToAbsolute("~/Management.aspx") + "?type=" + (int)ASC.Web.Studio.Utility.ManagementType.AccessRights + "#community";
  256. if (IsForumsAvailable)
  257. {
  258. defaultUrl = VirtualPathUtility.ToAbsolute("~/Products/Community/Modules/Forum/ManagementCenter.aspx");
  259. }
  260. return defaultUrl;
  261. }
  262. }
  263. }