forked from BlogEngine/BlogEngine.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.ascx.cs
More file actions
108 lines (91 loc) · 3.49 KB
/
menu.ascx.cs
File metadata and controls
108 lines (91 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
namespace Admin
{
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using BlogEngine.Core;
using Resources;
/// <summary>
/// The Menu control.
/// </summary>
public partial class Menu : UserControl
{
#region Public Methods
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="text">
/// The text string.
/// </param>
/// <param name="url">
/// The URL string.
/// </param>
public void AddItem(string text, string url)
{
var a = new HtmlAnchor { InnerHtml = string.Format("<span>{0}</span>", text), HRef = url };
System.Diagnostics.Debug.WriteLine("AddItem: " + a.HRef.ToString());
var li = new HtmlGenericControl("li");
li.Controls.Add(a);
ulMenu.Controls.Add(li);
}
#endregion
#region Methods
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
/// </summary>
/// <param name="e">
/// The <see cref="T:System.EventArgs"/> object that contains the event data.
/// </param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsCallback)
{
BindMenu();
}
}
/// <summary>
/// The bind menu.
/// </summary>
private void BindMenu()
{
var sitemap = SiteMap.Providers["SecuritySiteMap"];
if (sitemap != null)
{
string adminRootFolder = string.Format("{0}admin", Utils.RelativeWebRoot);
var root = sitemap.RootNode;
if (root != null)
{
foreach (
var adminNode in root.ChildNodes.Cast<SiteMapNode>().Where(
adminNode => adminNode.IsAccessibleToUser(HttpContext.Current)).Where(
adminNode => Security.IsAuthenticated ))
{
if (adminNode.Url.EndsWith("#/blogs") && !Blog.CurrentInstance.IsPrimary)
continue;
if (adminNode.Url.EndsWith("#/blogs") && !Security.IsAdministrator)
continue;
var a = new HtmlAnchor
{
// replace the RelativeWebRoot in adminNode.Url with the RelativeWebRoot of the current
// blog instance. So a URL like /admin/Dashboard.aspx becomes /blog/admin/Dashboard.aspx.
HRef = Utils.RelativeWebRoot + adminNode.Url.Substring(Utils.ApplicationRelativeWebRoot.Length),
InnerHtml = string.Format("<span>{0}</span>", Utils.Translate(adminNode.Title, adminNode.Title))
};
var li = new HtmlGenericControl("li");
li.Controls.Add(a);
ulMenu.Controls.Add(li);
}
}
}
if (Security.IsAuthenticated)
{
AddItem(labels.myProfile, string.Format("{0}admin/#/security/profile", Utils.RelativeWebRoot));
AddItem(labels.changePassword, string.Format("{0}Account/change-password.aspx", Utils.RelativeWebRoot));
}
}
#endregion
}
}