using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text.RegularExpressions; public partial class EditTextContent : WebBlockUserControl { public bool ContainedInIFrame { get { return (ViewState["ContainedInIFrame"] == DBNull.Value ? false : (bool)ViewState["ContainedInIFrame"]); } set { ViewState["ContainedInIFrame"] = value; } } private int DraftID { get { return (ViewState["DraftID"] == null ? 0 : (int)ViewState["DraftID"]); } set { ViewState["DraftID"] = value; } } private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { if (Request.UrlReferrer != null) Session["returnPath"] = Request.UrlReferrer.AbsoluteUri; if (Request.QueryString["ContentTitle"] != null) { pnlLive.Visible = true; DataRow dr = Database.TextBlock_Get(Request.QueryString["ContentTitle"]); if (dr == null) throw new Exception("Invalid Block Title."); litHeader.Text = "Edit Text Block - " + (string)dr["ContentTitle"]; litContentTitle.Text = (string)dr["ContentTitle"]; txtContent.Value = (string)dr["ContentText"]; DraftID = (dr["DraftID"] == DBNull.Value ? 0 : (int)dr["DraftID"]); if (DraftID > 0) { litHeader.Text += " (DRAFT)"; btnDraftDelete.Visible = true; } else btnDraftDelete.Visible = false; } } } private void Complete() { if (ContainedInIFrame) { Page.ClientScript.RegisterStartupScript(typeof(string), "success", "parent.window.location.reload();", true); } else { string returnPath; if (Session["returnPath"] != null) returnPath = (string)Session["returnPath"]; else returnPath = "ShowAllBlocks.aspx"; Response.Redirect(returnPath); } } protected void btnSubmit_Click1(object sender, EventArgs e) { #region crazy pixelated image replacement doohickey Regex r = new Regex(".*)\">[^\"]+)\" (.* )?height=\"(?[^\"]+)\" (.* )?src=\"(?[^\"]*)\" (.*)?/>"); Match m = r.Match(txtContent.Value); if (!m.Success) // match against an alternate criteria if this fails { r = new Regex(".*)\">[^\"]+)px; height: (?[^\"]+)px;\" (.* )?src=\"(?[^\"]*)\" (.*)?/>"); m = r.Match(txtContent.Value); } while (m.Success) { string orig = Server.MapPath(m.Groups["original"].Captures[0].Value); int width = Int32.Parse(m.Groups["width"].Captures[0].Value); int height = Int32.Parse(m.Groups["height"].Captures[0].Value); string thumb = Server.MapPath(m.Groups["thumbnail"].Captures[0].Value); if (System.IO.File.Exists(orig)) { // resize the image and save it, with the new size, into the thumbnail Graphix.GetSizedImage(orig, width, height).Save(thumb); } m = m.NextMatch(); } #endregion if (DraftID > 0) Database.TextBlock_DeleteDraft(DraftID); Database.TextBlock_Update(litContentTitle.Text, txtContent.Value); Complete(); } protected void btnSaveToDraft_Click(object sender, EventArgs e) { if (DraftID == 0) Database.TextBlock_CreateDraft(litContentTitle.Text, txtContent.Value); else Database.TextBlock_UpdateDraft(DraftID, litContentTitle.Text, txtContent.Value); Complete(); } protected void btnCancel_Click(object sender, EventArgs e) { Complete(); } protected void btnDraftDelete_Click(object sender, EventArgs e) { Database.TextBlock_DeleteDraft(DraftID); Complete(); } }