private static void AddChildrenToMenu(StringBuilder stringBuilder, CmsPage nodePage, CmsPage page, PageCollection pagePath, string itemClassName, string selectedItemClassName, string linkClassName, string listClass) { foreach (CmsPage child in nodePage.Children) { if (!child.VisibleInMenu) { continue; } stringBuilder.Append("<li"); if (child.PageId == page.PageId && !string.IsNullOrEmpty(selectedItemClassName)) { AddClassName(selectedItemClassName, stringBuilder); } else { AddOptionalClassName(itemClassName, stringBuilder); } stringBuilder.AppendFormat("><a href=\"{0}\"", child.PageUrl); AddOptionalClassName(linkClassName, stringBuilder); stringBuilder.AppendFormat(">{0}</a>", child.PageName); if (child.HasChildren && pagePath.Contains(child.PageId)) { stringBuilder.Append("<ul"); AddOptionalClassName(listClass, stringBuilder); stringBuilder.Append(">"); AddChildrenToMenu(stringBuilder, child, page, pagePath, itemClassName, selectedItemClassName, linkClassName, listClass); stringBuilder.Append("</ul>"); } stringBuilder.Append("</li>"); } }
/* ----------------------------------------------------------------- */ /// /// Recover /// /// <summary> /// データが格納されているフォルダから PageCollection オブジェクトを /// 再構築します。 /// </summary> /// /// <remarks> /// NOTE: 現在の方法ではタグ情報を復旧することはできない。 /// </remarks> /// /* ----------------------------------------------------------------- */ public static void Recover(this PageCollection pages, string direcotry, int maxLength) { if (!IoEx.Directory.Exists(direcotry)) { return; } foreach (var path in IoEx.Directory.GetFiles(direcotry)) { var filename = IoEx.Path.GetFileName(path).ToLower(); var exp = new Regex("^[0-9a-z]{32}$"); if (!exp.IsMatch(filename) || pages.Contains(filename)) { continue; } pages.NewPage(pages.Tags.Everyone, 0, (page) => { var document = DocumentHandler.Create(path); page.FileName = filename; page.Document = document; page.UpdateAbstract(maxLength); }); } }
internal PageCollection GetPageTreeFromPage(Guid rootPageId, Guid leafPageId, PublishState pageState) { var pageCollection = new PageCollection(); Predicate <PageIndexItem> match = GetPublishStatePredicate(pageState); var stack = new Stack(); int currentId; int index = 0; PageCollection pagePath = GetPagePath(leafPageId); if (rootPageId == Guid.Empty) { currentId = 0; } else { PageIndexItem firstPage = GetPageIndexItem(rootPageId); if (firstPage == null) { throw new ArgumentException("Page with id " + rootPageId + " not found!"); } currentId = firstPage.FirstChild; } while (currentId > -1) { PageIndexItem item = _pageIndex[currentId]; if (match(item)) { pageCollection.Add(item.PageId); if (item.NextPage > -1) { stack.Push(item.NextPage); } if (pagePath.Contains(item.PageId)) { currentId = item.FirstChild; } else { currentId = -1; } } else { currentId = item.NextPage; } if ((currentId == -1) && (stack.Count > 0)) { currentId = (int)stack.Pop(); } if (index > _pageIndex.Count) { // TODO: This should never happen, to be removed.. throw new Exception("Unending whileloop detected"); } index++; } return(pageCollection); }
protected override void CreateControlHierarchy() { var pageCollection = GetCacheablePageSource(); PageCollection pathway = PageFactory.GetPagePath(((PageTemplate)Page).CurrentPage.PageId); var pageList = GetFilteredPageList(pageCollection); Controls.Clear(); Count = pageList.Count; if (pageList.Count == 0 && !DisplayIfNoHits) { return; } Index = 0; int currentLevel = -1; int openedItems = 0; // TODO: Fixa till så att ordningen på templates blir rätt!!!! TemplateItem templateItem; foreach (CmsPage page in pageList) { if (page.VisibleInMenu) { if (currentLevel == page.TreeLevel) { CreateItem(Index, page.PageId, EndItemTemplate); openedItems--; } //new lv? if (NewLevelTemplate != null && currentLevel < page.TreeLevel) { currentLevel = page.TreeLevel; templateItem = new TemplateItem(); NewLevelTemplate.InstantiateIn(templateItem); Controls.Add(templateItem); } //up a lv? if (EndLevelTemplate != null && currentLevel > page.TreeLevel) { int lvups = currentLevel - page.TreeLevel; currentLevel = page.TreeLevel; for (int moi = 0; moi < lvups; moi++) { openedItems--; CreateItem(Index, page.PageId, EndItemTemplate); templateItem = new TemplateItem(); EndLevelTemplate.InstantiateIn(templateItem); Controls.Add(templateItem); CreateItem(Index, page.PageId, EndItemTemplate); openedItems--; } } if (pathway.Contains(page.PageId)) { CreateItem(Index, page.PageId, StartItemTemplate); openedItems++; if (SelectedItemTemplate != null) { CreateItem(Index, page.PageId, SelectedItemTemplate); } else { CreateItem(Index, page.PageId, ItemTemplate); } } else { CreateItem(Index, page.PageId, StartItemTemplate); openedItems++; CreateItem(Index, page.PageId, ItemTemplate); } Index++; } } for (int i = 0; i < openedItems; i++) { templateItem = new TemplateItem(); EndItemTemplate.InstantiateIn(templateItem); Controls.Add(templateItem); templateItem = new TemplateItem(); EndLevelTemplate.InstantiateIn(templateItem); Controls.Add(templateItem); } }