/// <summary> /// Adds a widget of the specified type. /// </summary> /// <param name="type">The type of widget.</param> /// <param name="zone">The zone a widget is being added to.</param> private void AddWidget(string type, string zone) { WidgetBase widget = (WidgetBase)LoadControl(Utils.RelativeWebRoot + "widgets/" + type + "/widget.ascx"); widget.WidgetID = Guid.NewGuid(); widget.ID = widget.WidgetID.ToString().Replace("-", string.Empty); widget.Title = type; widget.Zone = zone; widget.ShowTitle = widget.DisplayHeader; widget.LoadWidget(); Response.Clear(); try { using (StringWriter sw = new StringWriter()) { widget.RenderControl(new HtmlTextWriter(sw)); // Using ? as a delimiter. ? is a safe delimiter because it cannot appear in a // zonename because ? is one of the characters removed by Utils.RemoveIllegalCharacters(). Response.Write(zone + "?" + sw); } } catch (System.Web.HttpException) { Response.Write("reload"); } SaveNewWidget(widget, zone); WidgetEditBase.OnSaved(); Response.End(); }
/// <summary> /// Removes the widget from the XML file. /// </summary> /// <param name="id"> /// The id of the widget to remove. /// </param> /// <param name="zone"> /// The zone a widget is being removed from. /// </param> private void RemoveWidget(string id, string zone) { var doc = this.GetXmlDocument(zone); var node = doc.SelectSingleNode(string.Format("//widget[@id=\"{0}\"]", id)); if (node == null) { return; } // remove widget reference in the widget zone if (node.ParentNode != null) { node.ParentNode.RemoveChild(node); } this.SaveXmlDocument(doc, zone); // remove widget itself BlogService.RemoveFromDataStore(ExtensionType.Widget, id); this.Cache.Remove(string.Format("be_widget_{0}", id)); WidgetEditBase.OnSaved(); this.Response.Clear(); this.Response.Write(id + zone); this.Response.End(); }
/// <summary> /// Adds a widget of the specified type. /// </summary> /// <param name="type">The type of widget.</param> private void AddWidget(string type) { WidgetBase widget = (WidgetBase)LoadControl(Utils.RelativeWebRoot + "widgets/" + type + "/widget.ascx"); widget.WidgetID = Guid.NewGuid(); widget.ID = widget.WidgetID.ToString().Replace("-", string.Empty); widget.Title = type; widget.ShowTitle = widget.DisplayHeader; widget.LoadWidget(); Response.Clear(); try { using (StringWriter sw = new StringWriter()) { widget.RenderControl(new HtmlTextWriter(sw)); Response.Write(sw); } } catch (System.Web.HttpException) { Response.Write("reload"); } SaveNewWidget(widget); WidgetEditBase.OnSaved(); Response.End(); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender"> /// The source of the event. /// </param> /// <param name="e"> /// The <see cref="System.EventArgs"/> instance containing the event data. /// </param> private void BtnSaveClick(object sender, EventArgs e) { var widget = (WidgetEditBase)this.FindControl("widget"); var zone = this.Request.QueryString["zone"]; if (widget != null) { widget.Save(); } var doc = this.GetXmlDocument(zone); var node = doc.SelectSingleNode(string.Format("//widget[@id=\"{0}\"]", this.Request.QueryString["id"])); var changed = false; if (node != null && node.Attributes != null) { if (node.Attributes["title"].InnerText != this.txtTitle.Text.Trim()) { node.Attributes["title"].InnerText = this.txtTitle.Text.Trim(); changed = true; } if (node.Attributes["showTitle"].InnerText != this.cbShowTitle.Checked.ToString()) { node.Attributes["showTitle"].InnerText = this.cbShowTitle.Checked.ToString(); changed = true; } } if (changed) { this.SaveXmlDocument(doc, zone); } WidgetEditBase.OnSaved(); this.Cache.Remove(string.Format("widget_{0}", this.Request.QueryString["id"])); // To avoid JS errors with TextBox widget loading tinyMce scripts while // the edit window is closing, don't output phEdit. this.phEdit.Visible = false; const string Script = "PostEdit();"; this.Page.ClientScript.RegisterStartupScript(this.GetType(), "closeWindow", Script, true); }
/// <summary> /// Removes the widget from the XML file. /// </summary> /// <param name="id">The id of the widget to remove.</param> private void RemoveWidget(string id) { XmlDocument doc = GetXmlDocument(); XmlNode node = doc.SelectSingleNode("//widget[@id=\"" + id + "\"]"); if (node != null) { // remove widget reference in the widget zone node.ParentNode.RemoveChild(node); SaveXmlDocument(doc); // remove widget itself BlogEngine.Core.Providers.BlogService.RemoveFromDataStore(ExtensionType.Widget, id); Cache.Remove("be_widget_" + id); WidgetEditBase.OnSaved(); } }
/// <summary> /// Adds a widget of the specified type. /// </summary> /// <param name="type"> /// The type of widget. /// </param> /// <param name="zone"> /// The zone a widget is being added to. /// </param> private void AddWidget(string type, string zone) { var widget = (WidgetBase)LoadControl(string.Format("{0}widgets/{1}/widget.ascx", Utils.ApplicationRelativeWebRoot, type)); widget.WidgetId = Guid.NewGuid(); widget.ID = widget.WidgetId.ToString().Replace("-", string.Empty); widget.Title = type; widget.Zone = zone; widget.ShowTitle = widget.DisplayHeader; widget.LoadWidget(); // Load a widget container for this new widget. This will return the WidgetContainer // with the new widget in it. var widgetContainer = WidgetContainer.GetWidgetContainer(widget); widgetContainer.RenderContainer(); // need to manually invoke the loading process, since the Loading process for this Http Request // page lifecycle has already fired. widgetContainer.ProcessLoad(); Response.Clear(); try { using (var sw = new StringWriter()) { widgetContainer.RenderControl(new HtmlTextWriter(sw)); // Using ? as a delimiter. ? is a safe delimiter because it cannot appear in a // zonename because ? is one of the characters removed by Utils.RemoveIllegalCharacters(). Response.Write(string.Format("{0}?{1}", zone, sw)); } } catch (HttpException) { Response.Write("reload"); } SaveNewWidget(widget, zone); WidgetEditBase.OnSaved(); Response.End(); }
/// <summary> /// Moves the widgets as specified while dragging and dropping. /// </summary> /// <param name="move">The move string.</param> private void MoveWidgets(string move) { XmlDocument doc = GetXmlDocument(); string[] ids = move.Split(';'); for (int i = 0; i < ids.Length; i++) { string id = ids[i]; XmlNode node = doc.SelectSingleNode("//widget[@id=\"" + id + "\"]"); XmlNode parent = node.ParentNode; parent.RemoveChild(node); parent.AppendChild(node); } SaveXmlDocument(doc); WidgetEditBase.OnSaved(); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnSave_Click(object sender, EventArgs e) { WidgetEditBase widget = (WidgetEditBase)FindControl("widget"); string zone = Request.QueryString["zone"]; if (widget != null) { widget.Save(); } XmlDocument doc = GetXmlDocument(zone); XmlNode node = doc.SelectSingleNode("//widget[@id=\"" + Request.QueryString["id"] + "\"]"); bool isChanged = false; if (node.Attributes["title"].InnerText != txtTitle.Text.Trim()) { node.Attributes["title"].InnerText = txtTitle.Text.Trim(); isChanged = true; } if (node.Attributes["showTitle"].InnerText != cbShowTitle.Checked.ToString()) { node.Attributes["showTitle"].InnerText = cbShowTitle.Checked.ToString(); isChanged = true; } if (isChanged) { SaveXmlDocument(doc, zone); } WidgetEditBase.OnSaved(); Cache.Remove("widget_" + Request.QueryString["id"]); // To avoid JS errors with TextBox widget loading tinyMce scripts while // the edit window is closing, don't output phEdit. phEdit.Visible = false; string script = "PostEdit();"; Page.ClientScript.RegisterStartupScript(this.GetType(), "closeWindow", script, true); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnSave_Click(object sender, EventArgs e) { WidgetEditBase widget = (WidgetEditBase)FindControl("widget"); if (widget != null) { widget.Save(); } XmlDocument doc = GetXmlDocument(); XmlNode node = doc.SelectSingleNode("//widget[@id=\"" + Request.QueryString["id"] + "\"]"); bool isChanged = false; if (node.Attributes["title"].InnerText != txtTitle.Text.Trim()) { node.Attributes["title"].InnerText = txtTitle.Text.Trim(); isChanged = true; } if (node.Attributes["showTitle"].InnerText != cbShowTitle.Checked.ToString()) { node.Attributes["showTitle"].InnerText = cbShowTitle.Checked.ToString(); isChanged = true; } if (isChanged) { SaveXmlDocument(doc); } WidgetEditBase.OnSaved(); Cache.Remove("widget_" + Request.QueryString["id"]); string script = "top.location.reload(false);"; Page.ClientScript.RegisterStartupScript(this.GetType(), "closeWindow", script, true); }
/// <summary> /// Moves the widgets as specified while dragging and dropping. /// </summary> /// <param name="moveData"> /// Data containing which widget is moving, where it's moving from and where it's moving to. /// </param> private void MoveWidgets(string moveData) { var responseData = string.Empty; var data = moveData.Split(','); if (data.Length == 4) { var oldZone = data[0]; var widgetToMoveId = data[1]; var newZone = data[2]; var moveBeforeWidgetId = data[3]; // Ensure widgetToMoveId and moveBeforeWidgetId are not the same. if (!widgetToMoveId.Equals(moveBeforeWidgetId)) { var oldZoneDoc = this.GetXmlDocument(oldZone); var newZoneDoc = this.GetXmlDocument(newZone); // If a widget is moving within its own widget, oldZoneDoc and newZoneDoc will // be referencing the same XmlDocument. This is okay. if (oldZoneDoc != null && newZoneDoc != null) { // Make sure we can find all required elements before moving anything. var widgetToMove = oldZoneDoc.SelectSingleNode(string.Format("//widget[@id=\"{0}\"]", widgetToMoveId)); // If a Zone was selected from the dropdown box (rather than a Widget), moveBeforeWidgetId // will be null. In this case, the widget is moved to the bottom of the new zone. XmlNode moveBeforeWidget = null; if (!string.IsNullOrEmpty(moveBeforeWidgetId)) { moveBeforeWidget = newZoneDoc.SelectSingleNode(string.Format("//widget[@id=\"{0}\"]", moveBeforeWidgetId)); } if (widgetToMove != null) { // If the XmlNode is moving into a different XmlDocument, need to ImportNode() to // create a copy of the XmlNode that is compatible with the new XmlDocument. var widgetToMoveIntoNewDoc = newZoneDoc.ImportNode(widgetToMove, true); if (widgetToMove.ParentNode != null) { widgetToMove.ParentNode.RemoveChild(widgetToMove); if (moveBeforeWidget == null) { var widgets = newZoneDoc.SelectSingleNode("widgets"); if (widgets != null) { widgets.AppendChild(widgetToMoveIntoNewDoc); } } else { if (moveBeforeWidget.ParentNode != null) { moveBeforeWidget.ParentNode.InsertBefore( widgetToMoveIntoNewDoc, moveBeforeWidget); } } } this.SaveXmlDocument(oldZoneDoc, oldZone); if (!oldZone.Equals(newZone)) { this.SaveXmlDocument(newZoneDoc, newZone); } WidgetEditBase.OnSaved(); // Pass back the same data that was sent in to indicate success. responseData = moveData; } } } } this.Response.Clear(); this.Response.Write(responseData); this.Response.End(); }