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