PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Trunk/Modules/HTML/HtmlModule.ascx.cs

#
C# | 384 lines | 251 code | 34 blank | 99 comment | 38 complexity | 3fa4a77b8c29ce245528cae5417b0aa3 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0
  1. #region Copyright
  2. //
  3. // DotNetNukeŽ - http://www.dotnetnuke.com
  4. // Copyright (c) 2002-2012
  5. // by DotNetNuke Corporation
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  8. // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  10. // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all copies or substantial portions
  13. // of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  18. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #endregion
  21. #region Usings
  22. using System;
  23. using System.Web.UI;
  24. using DotNetNuke.Common;
  25. using DotNetNuke.Entities.Modules;
  26. using DotNetNuke.Entities.Modules.Actions;
  27. using DotNetNuke.Entities.Portals;
  28. using DotNetNuke.Security;
  29. using DotNetNuke.Security.Permissions;
  30. using DotNetNuke.Services.Exceptions;
  31. using DotNetNuke.Services.Localization;
  32. using DotNetNuke.UI.WebControls;
  33. #endregion
  34. namespace DotNetNuke.Modules.Html
  35. {
  36. /// -----------------------------------------------------------------------------
  37. /// <summary>
  38. /// The HtmlModule Class provides the UI for displaying the Html
  39. /// </summary>
  40. /// <remarks>
  41. /// </remarks>
  42. /// <history>
  43. /// </history>
  44. /// -----------------------------------------------------------------------------
  45. public partial class HtmlModule : PortalModuleBase, IActionable
  46. {
  47. private bool EditorEnabled;
  48. private int WorkflowID;
  49. #region "Private Methods"
  50. #endregion
  51. #region "Event Handlers"
  52. /// -----------------------------------------------------------------------------
  53. /// <summary>
  54. /// Page_Init runs when the control is initialized
  55. /// </summary>
  56. /// <remarks>
  57. /// </remarks>
  58. /// <history>
  59. /// </history>
  60. /// -----------------------------------------------------------------------------
  61. protected override void OnInit(EventArgs e)
  62. {
  63. base.OnInit(e);
  64. lblContent.UpdateLabel += lblContent_UpdateLabel;
  65. EditorEnabled = PortalSettings.InlineEditorEnabled;
  66. try
  67. {
  68. WorkflowID = new HtmlTextController().GetWorkflow(ModuleId, TabId, PortalId).Value;
  69. //Add an Action Event Handler to the Skin
  70. AddActionHandler(ModuleAction_Click);
  71. }
  72. catch (Exception exc)
  73. {
  74. Exceptions.ProcessModuleLoadException(this, exc);
  75. }
  76. }
  77. /// -----------------------------------------------------------------------------
  78. /// <summary>
  79. /// Page_Load runs when the control is loaded
  80. /// </summary>
  81. /// <remarks>
  82. /// </remarks>
  83. /// <history>
  84. /// </history>
  85. /// -----------------------------------------------------------------------------
  86. protected override void OnLoad(EventArgs e)
  87. {
  88. base.OnLoad(e);
  89. try
  90. {
  91. var objHTML = new HtmlTextController();
  92. // edit in place
  93. if (EditorEnabled && IsEditable && PortalSettings.UserMode == PortalSettings.Mode.Edit)
  94. {
  95. EditorEnabled = true;
  96. }
  97. else
  98. {
  99. EditorEnabled = false;
  100. }
  101. // get content
  102. HtmlTextInfo htmlTextInfo = null;
  103. string contentString = "";
  104. htmlTextInfo = objHTML.GetTopHtmlText(ModuleId, !IsEditable, WorkflowID);
  105. if ((htmlTextInfo != null))
  106. {
  107. //don't decode yet (this is done in FormatHtmlText)
  108. contentString = htmlTextInfo.Content;
  109. }
  110. else
  111. {
  112. // get default content from resource file
  113. if (!IsPostBack)
  114. {
  115. if (PortalSettings.UserMode == PortalSettings.Mode.Edit)
  116. {
  117. if (EditorEnabled)
  118. {
  119. contentString = Localization.GetString("AddContentFromToolBar.Text", LocalResourceFile);
  120. }
  121. else
  122. {
  123. contentString = Localization.GetString("AddContentFromActionMenu.Text", LocalResourceFile);
  124. }
  125. }
  126. else
  127. {
  128. // hide the module if no content and in view mode
  129. ContainerControl.Visible = false;
  130. }
  131. }
  132. }
  133. // token replace
  134. if (EditorEnabled && Settings["HtmlText_ReplaceTokens"] != null)
  135. {
  136. EditorEnabled = !Convert.ToBoolean(Settings["HtmlText_ReplaceTokens"]);
  137. }
  138. // localize toolbar
  139. if (!IsPostBack)
  140. {
  141. if (EditorEnabled)
  142. {
  143. foreach (DNNToolBarButton button in editorDnnToobar.Buttons)
  144. {
  145. button.ToolTip = Localization.GetString(button.ToolTip + ".ToolTip", LocalResourceFile);
  146. }
  147. }
  148. else
  149. {
  150. editorDnnToobar.Visible = false;
  151. }
  152. }
  153. lblContent.EditEnabled = EditorEnabled;
  154. // add content to module
  155. lblContent.Controls.Add(new LiteralControl(HtmlTextController.FormatHtmlText(ModuleId, contentString, Settings)));
  156. }
  157. catch (Exception exc)
  158. {
  159. Exceptions.ProcessModuleLoadException(this, exc);
  160. }
  161. }
  162. /// -----------------------------------------------------------------------------
  163. /// <summary>
  164. /// lblContent_UpdateLabel allows for inline editing of content
  165. /// </summary>
  166. /// <remarks>
  167. /// </remarks>
  168. /// <history>
  169. /// </history>
  170. /// -----------------------------------------------------------------------------
  171. private void lblContent_UpdateLabel(object source, DNNLabelEditEventArgs e)
  172. {
  173. try
  174. {
  175. // verify security
  176. if ((!new PortalSecurity().InputFilter(e.Text, PortalSecurity.FilterFlag.NoScripting).Equals(e.Text)))
  177. {
  178. throw new SecurityException();
  179. }
  180. else if (EditorEnabled && IsEditable && PortalSettings.UserMode == PortalSettings.Mode.Edit)
  181. {
  182. // get content
  183. var objHTML = new HtmlTextController();
  184. var objWorkflow = new WorkflowStateController();
  185. HtmlTextInfo objContent = objHTML.GetTopHtmlText(ModuleId, false, WorkflowID);
  186. if (objContent == null)
  187. {
  188. objContent = new HtmlTextInfo();
  189. objContent.ItemID = -1;
  190. }
  191. // set content attributes
  192. objContent.ModuleID = ModuleId;
  193. objContent.Content = Server.HtmlEncode(e.Text);
  194. objContent.WorkflowID = WorkflowID;
  195. objContent.StateID = objWorkflow.GetFirstWorkflowStateID(WorkflowID);
  196. // save the content
  197. objHTML.UpdateHtmlText(objContent, objHTML.GetMaximumVersionHistory(PortalId));
  198. }
  199. else
  200. {
  201. throw new SecurityException();
  202. }
  203. }
  204. catch (Exception exc)
  205. {
  206. Exceptions.ProcessModuleLoadException(this, exc);
  207. }
  208. }
  209. /// -----------------------------------------------------------------------------
  210. /// <summary>
  211. /// ModuleAction_Click handles all ModuleAction events raised from the action menu
  212. /// </summary>
  213. /// <remarks>
  214. /// </remarks>
  215. /// <history>
  216. /// </history>
  217. /// -----------------------------------------------------------------------------
  218. private void ModuleAction_Click(object sender, ActionEventArgs e)
  219. {
  220. try
  221. {
  222. if (e.Action.CommandArgument == "publish")
  223. {
  224. // verify security
  225. if (IsEditable && PortalSettings.UserMode == PortalSettings.Mode.Edit)
  226. {
  227. // get content
  228. var objHTML = new HtmlTextController();
  229. HtmlTextInfo objContent = objHTML.GetTopHtmlText(ModuleId, false, WorkflowID);
  230. var objWorkflow = new WorkflowStateController();
  231. if (objContent.StateID == objWorkflow.GetFirstWorkflowStateID(WorkflowID))
  232. {
  233. // publish content
  234. objContent.StateID = objWorkflow.GetNextWorkflowStateID(objContent.WorkflowID, objContent.StateID);
  235. // save the content
  236. objHTML.UpdateHtmlText(objContent, objHTML.GetMaximumVersionHistory(PortalId));
  237. // refresh page
  238. Response.Redirect(Globals.NavigateURL(), true);
  239. }
  240. }
  241. }
  242. }
  243. catch (Exception exc)
  244. {
  245. Exceptions.ProcessModuleLoadException(this, exc);
  246. }
  247. }
  248. #endregion
  249. #region "Optional Interfaces"
  250. /// -----------------------------------------------------------------------------
  251. /// <summary>
  252. /// ModuleActions is an interface property that returns the module actions collection for the module
  253. /// </summary>
  254. /// <remarks>
  255. /// </remarks>
  256. /// <history>
  257. /// </history>
  258. /// -----------------------------------------------------------------------------
  259. public ModuleActionCollection ModuleActions
  260. {
  261. get
  262. {
  263. // add the Edit Text action
  264. var Actions = new ModuleActionCollection();
  265. Actions.Add(GetNextActionID(),
  266. Localization.GetString(ModuleActionType.AddContent, LocalResourceFile),
  267. ModuleActionType.AddContent,
  268. "",
  269. "",
  270. EditUrl(),
  271. false,
  272. SecurityAccessLevel.Edit,
  273. true,
  274. false);
  275. // get the content
  276. var objHTML = new HtmlTextController();
  277. var objWorkflow = new WorkflowStateController();
  278. WorkflowID = objHTML.GetWorkflow(ModuleId, TabId, PortalId).Value;
  279. HtmlTextInfo objContent = objHTML.GetTopHtmlText(ModuleId, false, WorkflowID);
  280. if ((objContent != null))
  281. {
  282. // if content is in the first state
  283. if (objContent.StateID == objWorkflow.GetFirstWorkflowStateID(WorkflowID))
  284. {
  285. // if not direct publish workflow
  286. if (objWorkflow.GetWorkflowStates(WorkflowID).Count > 1)
  287. {
  288. // add publish action
  289. Actions.Add(GetNextActionID(),
  290. Localization.GetString("PublishContent.Action", LocalResourceFile),
  291. ModuleActionType.AddContent,
  292. "publish",
  293. "grant.gif",
  294. "",
  295. true,
  296. SecurityAccessLevel.Edit,
  297. true,
  298. false);
  299. }
  300. }
  301. else
  302. {
  303. // if the content is not in the last state of the workflow then review is required
  304. if (objContent.StateID != objWorkflow.GetLastWorkflowStateID(WorkflowID))
  305. {
  306. // if the user has permissions to review the content
  307. if (WorkflowStatePermissionController.HasWorkflowStatePermission(WorkflowStatePermissionController.GetWorkflowStatePermissions(objContent.StateID), "REVIEW"))
  308. {
  309. // add approve and reject actions
  310. Actions.Add(GetNextActionID(),
  311. Localization.GetString("ApproveContent.Action", LocalResourceFile),
  312. ModuleActionType.AddContent,
  313. "",
  314. "grant.gif",
  315. EditUrl("action", "approve", "Review"),
  316. false,
  317. SecurityAccessLevel.Edit,
  318. true,
  319. false);
  320. Actions.Add(GetNextActionID(),
  321. Localization.GetString("RejectContent.Action", LocalResourceFile),
  322. ModuleActionType.AddContent,
  323. "",
  324. "deny.gif",
  325. EditUrl("action", "reject", "Review"),
  326. false,
  327. SecurityAccessLevel.Edit,
  328. true,
  329. false);
  330. }
  331. }
  332. }
  333. }
  334. // add mywork to action menu
  335. Actions.Add(GetNextActionID(),
  336. Localization.GetString("MyWork.Action", LocalResourceFile),
  337. "MyWork.Action",
  338. "",
  339. "view.gif",
  340. EditUrl("MyWork"),
  341. false,
  342. SecurityAccessLevel.Edit,
  343. true,
  344. false);
  345. return Actions;
  346. }
  347. }
  348. #endregion
  349. }
  350. }