PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/widgets/LinkList/widget.ascx.cs

#
C# | 112 lines | 72 code | 17 blank | 23 comment | 14 complexity | 2ab06adc7a9097d1857d30561548b96f MD5 | raw file
  1// --------------------------------------------------------------------------------------------------------------------
  2// <summary>
  3//   The widgets link list_widget.
  4// </summary>
  5// --------------------------------------------------------------------------------------------------------------------
  6
  7namespace Widgets.LinkList
  8{
  9    using System;
 10    using System.Web.UI.HtmlControls;
 11    using System.Xml;
 12
 13    using App_Code.Controls;
 14
 15    /// <summary>
 16    /// The widgets link list_widget.
 17    /// </summary>
 18    public partial class Widget : WidgetBase
 19    {
 20        #region Properties
 21
 22        /// <summary>
 23        /// Gets a value indicating whether or not the widget can be edited.
 24        /// <remarks>
 25        /// The only way a widget can be editable is by adding a edit.ascx file to the widget folder.
 26        /// </remarks>
 27        /// </summary>
 28        /// <value></value>
 29        public override bool IsEditable
 30        {
 31            get
 32            {
 33                return true;
 34            }
 35        }
 36
 37        /// <summary>
 38        /// Gets the name. It must be exactly the same as the folder that contains the widget.
 39        /// </summary>
 40        /// <value></value>
 41        public override string Name
 42        {
 43            get
 44            {
 45                return "LinkList";
 46            }
 47        }
 48
 49        #endregion
 50
 51        #region Public Methods
 52
 53        /// <summary>
 54        /// This method works as a substitute for Page_Load. You should use this method for
 55        /// data binding etc. instead of Page_Load.
 56        /// </summary>
 57        public override void LoadWidget()
 58        {
 59            var settings = this.GetSettings();
 60            var doc = new XmlDocument();
 61
 62            if (settings["content"] != null)
 63            {
 64                doc.InnerXml = settings["content"];
 65            }
 66
 67            var links = doc.SelectNodes("//link");
 68
 69            if (links == null)
 70            {
 71                return;
 72            }
 73
 74            if (links.Count == 0)
 75            {
 76                this.ulLinks.Visible = false;
 77            }
 78            else
 79            {
 80                foreach (XmlNode node in links)
 81                {
 82                    var a = new HtmlAnchor();
 83
 84                    if (node.Attributes != null)
 85                    {
 86                        if (node.Attributes["url"] != null)
 87                        {
 88                            a.HRef = node.Attributes["url"].InnerText;
 89                        }
 90
 91                        if (node.Attributes["title"] != null)
 92                        {
 93                            a.InnerText = node.Attributes["title"].InnerText;
 94                        }
 95
 96                        if (node.Attributes["newwindow"] != null &&
 97                            node.Attributes["newwindow"].InnerText.Equals("true", StringComparison.OrdinalIgnoreCase))
 98                        {
 99                            a.Target = "_blank";
100                        }
101                    }
102
103                    var li = new HtmlGenericControl("li");
104                    li.Controls.Add(a);
105                    this.ulLinks.Controls.Add(li);
106                }
107            }
108        }
109
110        #endregion
111    }
112}