/// <summary> /// Used to render the search result listing (virtual node) /// </summary> /// <param name="model"></param> /// <param name="term"> /// The search term /// </param> /// <param name="provider"> /// The search provider name (optional) /// </param> /// <param name="p"></param> /// <returns></returns> public ActionResult Search(RenderModel model, string term, string provider = null, int? p = null) { var tagPage = model.Content as ArticulateVirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(ArticulateVirtualPage)); } //create a blog model of the main page var rootPageModel = new MasterModel(model.Content.Parent); if (term == null) { //nothing to search, just render the view var emptyList = new ListModel(tagPage, Enumerable.Empty<IPublishedContent>(), new PagerModel(rootPageModel.PageSize, 0, 0)); return View(PathHelper.GetThemeViewPath(emptyList, "List"), emptyList); } if (p != null && p.Value == 1) { return new RedirectToUmbracoPageResult(model.Content, UmbracoContext); } if (p == null || p.Value <= 0) { p = 1; } int totalPosts; var searchResult = ArticulateSearcher.Search(term, provider, rootPageModel.BlogArchiveNode.Id, rootPageModel.PageSize, p.Value - 1, out totalPosts); var pageSize = rootPageModel.PageSize; var totalPages = totalPosts == 0 ? 1 : Convert.ToInt32(Math.Ceiling((double)totalPosts / pageSize)); //Invalid page, redirect without pages if (totalPages < p) { return new RedirectToUmbracoPageResult(model.Content.Parent, UmbracoContext); } var pager = new PagerModel( pageSize, p.Value - 1, totalPages, totalPages > p ? model.Content.Url.EnsureEndsWith('?') + "term=" + term + "&p=" + (p + 1) : null, p > 2 ? model.Content.Url.EnsureEndsWith('?') + "term=" + term + "&p=" + (p - 1) : p > 1 ? model.Content.Url.EnsureEndsWith('?') + "term=" + term : null); var listModel = new ListModel(tagPage, searchResult, pager); return View(PathHelper.GetThemeViewPath(listModel, "List"), listModel); }
private ActionResult RenderView(IRenderModel model, int? p = null) { var listNode = model.Content.Children .FirstOrDefault(x => x.DocumentTypeAlias.InvariantEquals("ArticulateArchive")); if (listNode == null) { throw new InvalidOperationException("An ArticulateArchive document must exist under the root Articulate document"); } if (p != null && p.Value == 1) { return new RedirectToUmbracoPageResult(model.Content, UmbracoContext); } if (p == null || p.Value <= 0) { p = 1; } var rootPageModel = new MasterModel(model.Content); //get the count with XPath, this will be the fastest var totalPosts = Umbraco.GetPostCount(listNode.Id); var pageSize = rootPageModel.PageSize; var totalPages = Convert.ToInt32(Math.Ceiling((double)totalPosts/pageSize)); //Invalid page, redirect without pages if (totalPages > 0 && totalPages < p) { return new RedirectToUmbracoPageResult(model.Content, UmbracoContext); } var pager = new PagerModel( pageSize, p.Value - 1, totalPages, totalPages > p ? model.Content.Url.EnsureEndsWith('?') + "p=" + (p + 1) : null, p > 2 ? model.Content.Url.EnsureEndsWith('?') + "p=" + (p - 1) : p > 1 ? model.Content.Url : null); var listItems = Umbraco.GetPostsSortedByPublishedDate(listNode.Id, pager); var listModel = new ListModel(listNode, listItems, pager); return View(PathHelper.GetThemeViewPath(listModel, "List"), listModel); }
public ActionResult RenderTagsOrCategories(RenderModel model, string tagGroup, string baseUrl) { var tagPage = model.Content as ArticulateVirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(ArticulateVirtualPage)); } //create a blog model of the main page var rootPageModel = new MasterModel(model.Content.Parent); var contentByTags = Umbraco.GetContentByTags(rootPageModel, tagGroup, baseUrl); var tagListModel = new TagListModel( rootPageModel, tagPage.Name, rootPageModel.PageSize, new PostTagCollection(contentByTags)); return View(PathHelper.GetThemeViewPath(tagListModel, "Tags"), tagListModel); }
public static PostTagCollection GetPostTagCollection(this UmbracoHelper helper, IMasterModel masterModel) { var listNode = masterModel.RootBlogNode.Children .FirstOrDefault(x => x.DocumentTypeAlias.InvariantEquals("ArticulateArchive")); if (listNode == null) { throw new InvalidOperationException("An ArticulateArchive document must exist under the root Articulate document"); } //create a blog model of the main page var rootPageModel = new MasterModel(listNode); var tagsBaseUrl = masterModel.RootBlogNode.GetPropertyValue<string>("tagsUrlName"); var contentByTags = helper.GetContentByTags(rootPageModel, "ArticulateTags", tagsBaseUrl); return new PostTagCollection(contentByTags); }
private ActionResult RenderByTagOrCategory(IRenderModel model, int? p, string tagGroup, string baseUrl) { var tagPage = model.Content as ArticulateVirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(ArticulateVirtualPage)); } //create a blog model of the main page var rootPageModel = new MasterModel(model.Content.Parent); var contentByTag = Umbraco.GetContentByTag(rootPageModel, tagPage.Name, tagGroup, baseUrl); //this is a special case in the event that a tag contains a '.', when this happens we change it to a '-' // when generating the URL. So if the above doesn't return any tags and the tag contains a '-', then we // will replace them with '.' and do the lookup again if (contentByTag == null && tagPage.Name.Contains("-")) { contentByTag = Umbraco.GetContentByTag( rootPageModel, tagPage.Name.Replace('-', '.'), tagGroup, baseUrl); } if (contentByTag == null) { return new HttpNotFoundResult(); } if (p != null && p.Value == 1) { return new RedirectToUmbracoPageResult(model.Content, UmbracoContext); } if (p == null || p.Value <= 0) { p = 1; } //TODO: I wonder about the performance of this - when we end up with thousands of blog posts, // this will probably not be so efficient. I wonder if using an XPath lookup for batches of children // would work? The children count could be cached. I'd rather not put blog posts under 'month' nodes // just for the sake of performance. Hrm.... Examine possibly too. var totalPosts = contentByTag.PostCount; var pageSize = rootPageModel.PageSize; var totalPages = totalPosts == 0 ? 1 : Convert.ToInt32(Math.Ceiling((double)totalPosts / pageSize)); //Invalid page, redirect without pages if (totalPages < p) { return new RedirectToUmbracoPageResult(model.Content.Parent, UmbracoContext); } var pager = new PagerModel( pageSize, p.Value - 1, totalPages, totalPages > p ? model.Content.Url.EnsureEndsWith('?') + "p=" + (p + 1) : null, p > 2 ? model.Content.Url.EnsureEndsWith('?') + "p=" + (p - 1) : p > 1 ? model.Content.Url : null); var listModel = new ListModel(tagPage, contentByTag.Posts, pager); return View(PathHelper.GetThemeViewPath(listModel, "List"), listModel); }
public ActionResult RenderTagsOrCategoriesRss(RenderModel model, string tagGroup, string baseUrl, int maxItems) { var tagPage = model.Content as ArticulateVirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(ArticulateVirtualPage)); } //create a blog model of the main page var rootPageModel = new MasterModel(model.Content.Parent); var contentByTag = Umbraco.GetContentByTag( rootPageModel, tagPage.Name, tagGroup, baseUrl); //super hack - but this is because we are replacing '.' with '-' in StringExtensions.EncodePath method // so if we get nothing, we'll retry with replacing back if (contentByTag == null) { contentByTag = Umbraco.GetContentByTag( rootPageModel, tagPage.Name.Replace('-', '.'), tagGroup, baseUrl); } if (contentByTag == null) { return HttpNotFound(); } var feed = FeedGenerator.GetFeed(rootPageModel, contentByTag.Posts.Take(maxItems)); return new RssResult(feed, rootPageModel); }