public Dictionary <string, int> GetTags(int nodeId, bool getAll) { var tagIds = GetIdsFromCsvProperty(IPublishedContentHelper.GetNode(nodeId), "uBlogsyPostTags", getAll, false); var allTags = tagIds .ToIPublishedContent(true) .Select(x => x.GetPropertyValue <string>("uTagsyTagName")) .Where(x => !string.IsNullOrEmpty(x)).ToList(); // create dictionary with tags and the number of times they are used var tagCloud = new Dictionary <string, int>(); foreach (var tag in allTags.OrderBy(x => x)) { if (tagCloud.ContainsKey(tag)) { tagCloud[tag]++; } else { tagCloud.Add(tag, 1); } } return(tagCloud); }
/// <summary> /// Gets posts related by the value of a property. /// </summary> /// <param name="postId"></param> /// <param name="itemAlias"></param> /// <param name="posts"></param> /// <param name="matchCount"></param> /// <returns></returns> protected IEnumerable <IPublishedContent> GetRelatedPosts(int postId, string itemAlias, IEnumerable <IPublishedContent> posts, int matchCount) { IPublishedContent current = IPublishedContentHelper.GetNode(postId); // get this page's items to compare List <string> currentItems = current.GetProperty(itemAlias).Value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); List <IPublishedContent> nodes = new List <IPublishedContent>(); foreach (IPublishedContent n in posts) { if (n.Id != current.Id) { // get items as string array List <string> items = n.GetProperty(itemAlias).Value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); // check if currentItems and items have at least matchCount in common bool intersects = CollectionHelper.HashSetIntersects(currentItems, items, true, matchCount); if (intersects) { nodes.Add(n); } } } return(nodes); }
/// <summary> /// Returns an IEnumberable of all authors /// </summary> /// <param name="postId"></param> /// <returns></returns> public IEnumerable <IPublishedContent> GetAuthors(int postId, bool getAll) { // get all authors var allAuthors = new List <string>(); var posts = getAll ? GetPosts(postId) : new List <IPublishedContent>() { IPublishedContentHelper.GetNode(postId) }; foreach (var n in posts) { allAuthors.AddRange(n.GetProperty("uBlogsyPostAuthor").Value.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); // take care of multiple author scenario } var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); return(allAuthors.Select(x => x.Trim()).Distinct().Select(x => umbracoHelper.TypedContent(x)).Where(x => x != null)); }
/// <summary> /// Performs search on the given search term. /// </summary> /// <param name="searchTerm"></param> /// <returns></returns> protected IEnumerable <IPublishedContent> DoSearch(int nodeId, string searchTerm, IEnumerable <IPublishedContent> sorted) { List <IPublishedContent> nodes = new List <IPublishedContent>(); // remove multiple spaces string cleanedSearchTerm = Regex.Replace(searchTerm, "\\s+", " "); // search using examine IEnumerable <SearchResult> results = ExamineManager.Instance.Search(cleanedSearchTerm, true); // add results to nodes list for returning foreach (var r in results) { nodes.Add(IPublishedContentHelper.GetNode(r.Id)); } // split string when multiple words are typed IEnumerable <string> searchTerms = cleanedSearchTerm.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); // do examine search for each foreach (var term in searchTerms) { results = ExamineManager.Instance.Search(term, true); foreach (var r in results) { if (!nodes.Any(x => x.Id == r.Id)) { nodes.Add(IPublishedContentHelper.GetNode(r.Id)); } } nodes.AddRange(GetPostsWithPropertyValue(term, "uBlogsyPostTags", sorted)); nodes.AddRange(GetPostsWithPropertyValue(term, "uBlogsyPostLabels", sorted)); nodes.AddRange(GetPostsWithPropertyValue(term, "uBlogsyPostAuthor", sorted)); } // get distinct and filter by path! var landing = DataService.Instance.GetLanding(IPublishedContentHelper.GetNode(nodeId)); return(nodes .Distinct(new IPublishedContentNodeEqualityComparer()) .Where(x => x.Path.StartsWith(landing.Path))); }
/// <summary> /// Returns all the posts. /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public IEnumerable <IPublishedContent> GetPosts(int nodeId) { string cacheKey = "NoLuceneFallBack_GetPosts_uBlogsyPosts"; var cached = CacheHelper.GetFromRequestCache(cacheKey) as IEnumerable <IPublishedContent>; if (cached != null) { return(cached); } var landing = DataService.Instance.GetLanding(IPublishedContentHelper.GetNode(nodeId)); IEnumerable <IPublishedContent> nodes = landing.DescendentsOrSelf("uBlogsyPost", new[] { "uBlogsyContainerPage", "uBlogsyPage", "uBlogsyContainerComment", "uBlogsyComment" }).OrderByDescending(x => x.GetProperty("uBlogsyPostDate").Value); // cache the result CacheHelper.AddToRequestCache(cacheKey, nodes); return(nodes); }
/// <summary> /// Gets comments. /// </summary> /// <param name="nodeId"></param> /// <param name="getAll"></param> /// <returns></returns> public IEnumerable <IPublishedContent> GetComments(int nodeId, bool getAll) { List <IPublishedContent> comments; if (getAll) { // get posts var posts = GetPosts(nodeId); comments = new List <IPublishedContent>(); // get comments in posts foreach (var post in posts) { var postComments = post.DescendantsOrSelf("uBlogsyComment"); comments.AddRange(postComments); } } else { comments = IPublishedContentHelper.GetNode(nodeId).DescendantsOrSelf("uBlogsyComment").ToList(); } return(comments.OrderByDescending(x => x.GetPropertyValue("uBlogsyCommentDate"))); }
/// <summary> /// Gets labels. /// </summary> /// <param name="nodeId"></param> /// <param name="getAll"></param> /// <returns></returns> public IEnumerable <IPublishedContent> GetLabels(int nodeId, bool getAll) { var labelIds = GetIdsFromCsvProperty(IPublishedContentHelper.GetNode(nodeId), "uBlogsyPostLabels", getAll, true); return(labelIds.ToIPublishedContent(true)); }