public override StatusType SetValues(System.Web.HttpContext context, NameValueCollection nvc) { base.SetValues(context, nvc); LinkData = nvc["LinkData"]; string[] lines = string.IsNullOrEmpty(LinkData) ? new string[0] : LinkData.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); List<Link> links = new List<Link>(); foreach (string line in lines) { string[] linkInfo = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (linkInfo != null && linkInfo.Length > 1) { Link link = new Link(); link.Text = linkInfo[0].Trim(); link.Href = linkInfo[1].Trim(); links.Add(link); } } Links = links.ToArray(); return StatusType.Success; }
/// <summary> /// Creates a list of links which can be used to build custom sub category navigation. /// </summary> /// <param name="usePostsIfNoChildCategories">If the current top-level category does not have any child categories, should posts from that category be returned as links instead?</param> /// <returns></returns> public List<Link> NavigationSubLinks(bool usePostsIfNoChildCategories) { List<Link> links = new List<Link>(); Category currentCategory = null; TemplatedThemePage ttp = HttpContext.Current.Handler as TemplatedThemePage; CategoryCollection categories = new CategoryCollection(); if (ttp != null) { // Is this page a category? // Note: Post pages expose their categories and do not require a seperate lookup if (ttp.CategoryID > 0) { // This could be a subcategory. Since we do not expose subcategories via NavBar(), // we should mark the parent (if it exists) as selected item currentCategory = new CategoryController().GetCachedCategory(ttp.CategoryID, true); if (currentCategory != null) { // If the current category has a parent, we have to assume it's a child category. // In which case, we need to list out all the children of the parent. if (currentCategory.ParentId > 0) { Category parentCategory = new CategoryController().GetCachedCategory(currentCategory.ParentId, true); categories = parentCategory.Children; } else { categories = currentCategory.Children; } if (categories != null && categories.Count > 0) { foreach (Category category in categories) { Link link = new Link(); link.IsSelected = (currentCategory.Id == category.Id); link.Text = category.Name; link.CategoryId = category.Id; link.NavigationType = DynamicNavigationType.Category; link.Url = category.Url; links.Add(link); } } else if (usePostsIfNoChildCategories && currentCategory.PostCount > 0) { PostCollection posts = new Data().PostsByCategory(currentCategory, 10); foreach (Post post in posts) { Link link = new Link(); link.IsSelected = (ttp.PostId == post.Id); link.Text = post.Title; link.CategoryId = post.Id; link.PostId = post.Id; link.NavigationType = DynamicNavigationType.Post; link.Url = post.Url; links.Add(link); } } } } } return links; }
/// <summary> /// Creates a list of links which can be used to build custom navigation. /// </summary> /// <returns></returns> public List<Link> NavigationLinks() { int current_PostID = -1; int current_Parent_CategoryID = -1; int current_CategoryID = -1; List<DynamicNavigationItem> items = NavigationSettings.Get().SafeItems(); List<Link> links = new List<Link>(); // Will hold a reference to the selected item DynamicNavigationItem selectedItem = null; // We can only do this on a graffit page that exposes the post/category/etc properties TemplatedThemePage ttp = HttpContext.Current.Handler as TemplatedThemePage; if (ttp != null) { // Is this page a post? if (ttp.PostId > 0) current_PostID = ttp.PostId; // Is this page a category? // Note: Post pages expose their categories and do not require a seperate lookup if (ttp.CategoryID > 0) { // This could be a subcategory. Since we do not expose subcategories via NavBar(), // we should mark the parent (if it exists) as selected item current_CategoryID = ttp.CategoryID; Category the_Category = new CategoryController().GetCachedCategory(current_CategoryID, true); if (the_Category != null) { current_Parent_CategoryID = the_Category.ParentId; } } // If we are a post, see if it has a DynamicNavigationItem if (current_PostID > 0) { foreach (DynamicNavigationItem item in items) { if (item.NavigationType == DynamicNavigationType.Post) { if (item.PostId == current_PostID) { selectedItem = item; break; } } } } // We default to post first, but if that has not been selected, try to find a category if (selectedItem == null && (current_CategoryID > 0 || current_Parent_CategoryID > 0)) { foreach (DynamicNavigationItem item in items) { if (item.NavigationType == DynamicNavigationType.Category) { if (item.CategoryId == current_CategoryID || item.CategoryId == current_Parent_CategoryID) { selectedItem = item; break; } } } } // Graffiti has two pages which could end up in the NavBar (home and search). // If still no item exists, lets see if this was added. // Note: Tags are not yet part of this if (selectedItem == null) { bool isHomePage = ttp.GetType().ToString().IndexOf("GraffitiHomePage") > -1; bool isSearchPage = ttp.GetType().ToString().IndexOf("GraffitiSearchPage") > -1; if (isHomePage || isSearchPage) { foreach (DynamicNavigationItem item in items) { if (item.NavigationType == DynamicNavigationType.Link) { if (item.Text.ToLower().IndexOf("search") > -1) { selectedItem = item; break; } if (item.Text.ToLower().IndexOf("home") > -1 || item.Href == "~/" || item.Href == "/") { selectedItem = item; break; } } } } } } foreach (DynamicNavigationItem item in items) { Link the_Link = new Link(); the_Link.IsSelected = (selectedItem == item); the_Link.Text = item.Name; the_Link.CategoryId = item.CategoryId; the_Link.PostId = item.PostId; the_Link.NavigationType = item.NavigationType; switch (item.NavigationType) { case DynamicNavigationType.Post: Post p = Post.GetCachedPost(item.PostId); if (!p.IsNew && p.IsLoaded) { the_Link.Url = p.Url; } break; case DynamicNavigationType.Category: Category category = new CategoryController().GetCachedCategory(item.CategoryId, true); if (category != null) { the_Link.Url = category.Url; } break; case DynamicNavigationType.Link: if (!string.IsNullOrEmpty(item.Href)) { the_Link.Url = item.Href.StartsWith("~/") ? VirtualPathUtility.ToAbsolute(item.Href) : item.Href; } break; } if (!string.IsNullOrEmpty(the_Link.Url) && !string.IsNullOrEmpty(the_Link.Text)) links.Add(the_Link); } List<Link> permissionsFiltered = new List<Link>(); permissionsFiltered.AddRange(links); foreach (Link link in links) { if (!RolePermissionManager.GetPermissions(link.CategoryId, GraffitiUsers.Current).Read && link.CategoryId != 0) permissionsFiltered.Remove(link); } return permissionsFiltered; }