PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/Web/DesignTools/CssEditor.aspx.cs

#
C# | 167 lines | 113 code | 43 blank | 11 comment | 7 complexity | 80de0bd03f9c231b0aca40cf6ea70609 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-03-21
  3. // Last Modified: 2011-03-22
  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.Collections.Generic;
  15. using System.Configuration;
  16. using System.Data;
  17. using System.Globalization;
  18. using System.IO;
  19. using System.Text;
  20. using System.Web;
  21. using System.Web.Security;
  22. using System.Web.UI;
  23. using System.Web.UI.WebControls;
  24. using System.Web.UI.WebControls.WebParts;
  25. using System.Web.UI.HtmlControls;
  26. using mojoPortal.Web;
  27. using mojoPortal.Web.Framework;
  28. using mojoPortal.Web.UI;
  29. using log4net;
  30. using mojoPortal.Business;
  31. using mojoPortal.Business.WebHelpers;
  32. using Resources;
  33. namespace mojoPortal.Web.AdminUI
  34. {
  35. public partial class CssEditorPage : NonCmsBasePage
  36. {
  37. protected string skinName = string.Empty;
  38. protected string cssFile = string.Empty;
  39. private string skinBasePath = string.Empty;
  40. private bool allowEditing = false;
  41. protected void Page_Load(object sender, EventArgs e)
  42. {
  43. if ((!WebUser.IsInRoles(siteSettings.RolesThatCanManageSkins)))
  44. {
  45. SiteUtils.RedirectToAccessDeniedPage(this);
  46. return;
  47. }
  48. LoadSettings();
  49. if (!allowEditing)
  50. {
  51. WebUtils.SetupRedirect(this, SiteRoot + "/DesignTools/SkinList.aspx");
  52. return;
  53. }
  54. if (!Directory.Exists(Server.MapPath(skinBasePath + skinName)))
  55. { //skin doesn't exist go back to skin list
  56. WebUtils.SetupRedirect(this, SiteRoot + "/DesignTools/SkinList.aspx");
  57. return;
  58. }
  59. if (!File.Exists(Server.MapPath(skinBasePath + skinName + "/" + cssFile)))
  60. { //css file doesn't exist go back to skin manager
  61. WebUtils.SetupRedirect(this, SiteRoot + "/DesignTools/ManageSkin.aspx?s=" + skinName);
  62. return;
  63. }
  64. PopulateLabels();
  65. PopulateControls();
  66. }
  67. private void PopulateControls()
  68. {
  69. if (!IsPostBack)
  70. {
  71. BindCss();
  72. }
  73. }
  74. private void BindCss()
  75. {
  76. txtCss.Text = File.ReadAllText(Server.MapPath(skinBasePath + skinName + "/" + cssFile), Encoding.UTF8); //should this be ascii?
  77. }
  78. void btnSave_Click(object sender, EventArgs e)
  79. {
  80. using (StreamWriter writer = File.CreateText(Server.MapPath(skinBasePath + skinName + "/" + cssFile)))
  81. {
  82. writer.Write(txtCss.Text);
  83. }
  84. WebUtils.SetupRedirect(this, Request.RawUrl);
  85. }
  86. private void PopulateLabels()
  87. {
  88. string title = string.Format(CultureInfo.InvariantCulture, Resource.ManageSkinFormat, skinName);
  89. Title = SiteUtils.FormatPageTitle(siteSettings, title);
  90. lnkAdminMenu.Text = Resource.AdminMenuLink;
  91. lnkAdminMenu.NavigateUrl = SiteRoot + "/Admin/AdminMenu.aspx";
  92. lnkAdvancedTools.Text = Resource.AdvancedToolsLink;
  93. lnkAdvancedTools.NavigateUrl = SiteRoot + "/Admin/AdvancedTools.aspx";
  94. lnkDesignerTools.Text = DevTools.DesignTools;
  95. lnkDesignerTools.NavigateUrl = SiteRoot + "/DesignTools/Default.aspx";
  96. lnkSkinList.Text = DevTools.SkinManagement;
  97. lnkSkinList.NavigateUrl = SiteRoot + "/DesignTools/SkinList.aspx";
  98. lnkSkin.Text = skinName;
  99. lnkSkin.NavigateUrl = SiteRoot + "/DesignTools/ManageSkin.aspx?s=" + skinName;
  100. lnkThisPage.Text = cssFile;
  101. lnkThisPage.NavigateUrl = Request.RawUrl;
  102. btnSave.Text = Resource.SaveButton;
  103. }
  104. private void LoadSettings()
  105. {
  106. skinBasePath = "~/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/skins/";
  107. skinName = WebUtils.ParseStringFromQueryString("s", string.Empty);
  108. cssFile = WebUtils.ParseStringFromQueryString("f", string.Empty);
  109. allowEditing = WebConfigSettings.AllowEditingSkins && (WebConfigSettings.AllowEditingSkinsInChildSites || siteSettings.IsServerAdminSite);
  110. AddClassToBody("administration");
  111. AddClassToBody("designtools");
  112. }
  113. #region OnInit
  114. override protected void OnInit(EventArgs e)
  115. {
  116. base.OnInit(e);
  117. this.Load += new EventHandler(this.Page_Load);
  118. btnSave.Click += new EventHandler(btnSave_Click);
  119. SuppressMenuSelection();
  120. SuppressPageMenu();
  121. }
  122. #endregion
  123. }
  124. }