#region Using using System; using System.Web.UI.WebControls; using System.Threading; using System.Xml; using System.Web; using System.Web.Hosting; using BlogEngine.Core; using BlogEngine.Core.DataStore; using System.IO; #endregion namespace Controls { public class WidgetZone : PlaceHolder { public WidgetZone() { WidgetEditBase.Saved += delegate { XML_DOCUMENT = RetrieveXml(); }; } private XmlDocument XML_DOCUMENT; // For backwards compatibility or if a ZoneName is omitted, provide a default ZoneName. private string _ZoneName = "be_WIDGET_ZONE"; /// /// Gets or sets the name of the data-container used by this instance /// public string ZoneName { get { return _ZoneName; } set { _ZoneName = Utils.RemoveIllegalCharacters(value); } } protected override void OnInit(EventArgs e) { if (XML_DOCUMENT == null) XML_DOCUMENT = RetrieveXml(); base.OnInit(e); } private XmlDocument RetrieveXml() { WidgetSettings ws = new WidgetSettings(_ZoneName); ws.SettingsBehavior = new XMLDocumentBehavior(); XmlDocument doc = (XmlDocument)ws.GetSettings(); return doc; } /// /// Raises the event. /// /// The object that contains the event data. protected override void OnLoad(EventArgs e) { base.OnLoad(e); XmlNodeList zone = XML_DOCUMENT.SelectNodes("//widget"); foreach (XmlNode widget in zone) { string fileName = Utils.RelativeWebRoot + "widgets/" + widget.InnerText + "/widget.ascx"; try { WidgetBase control = (WidgetBase)Page.LoadControl(fileName); control.WidgetID = new Guid(widget.Attributes["id"].InnerText); control.ID = control.WidgetID.ToString().Replace("-", string.Empty); control.Title = widget.Attributes["title"].InnerText; control.Zone = _ZoneName; if (control.IsEditable) control.ShowTitle = bool.Parse(widget.Attributes["showTitle"].InnerText); else control.ShowTitle = control.DisplayHeader; control.LoadWidget(); this.Controls.Add(control); } catch (Exception ex) { Literal lit = new Literal(); lit.Text = "

Widget " + widget.InnerText + " not found.

"; lit.Text += ex.Message; lit.Text += "X"; this.Controls.Add(lit); } } } ///

/// Sends server control content to a provided /// object, which writes the content to be rendered on the client. /// /// /// The object /// that receives the server control content. /// protected override void Render(System.Web.UI.HtmlTextWriter writer) { writer.Write("
"); base.Render(writer); writer.Write("
"); if (Thread.CurrentPrincipal.IsInRole(BlogSettings.Instance.AdministratorRole)) { string selectorId = "widgetselector_" + _ZoneName; writer.Write("  "); writer.Write(""); writer.Write("
 
"); } } } }