internal static PostsByTagModel GetContentByTag(this UmbracoHelper helper, IMasterModel masterModel, string tag, string tagGroup, string baseUrlName) { //TODO: Use the new 7.1.2 tags API to do this //TODO: Umbraco core needs to have a method to get content by tag(s), in the meantime we // need to run a query var sql = new Sql().Select("cmsTagRelationship.nodeId, cmsTagRelationship.tagId, cmsTags.tag") .From("cmsTagRelationship") .InnerJoin("cmsTags") .On("cmsTagRelationship.tagId = cmsTags.id") .Where("cmsTags.tag = @tagName AND cmsTags." + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("group") + " = @tagGroup", new { tagName = tag, tagGroup = tagGroup }); var taggedContent = ApplicationContext.Current.DatabaseContext.Database.Fetch<TagDto>(sql); return taggedContent.GroupBy(x => x.TagId) .Select(x => new PostsByTagModel( helper.TypedContent( x.Select(t => t.NodeId).Distinct()) .Select(c => new PostModel(c)).OrderByDescending(c => c.PublishedDate), x.First().Tag, masterModel.RootBlogNode.Url.EnsureEndsWith('/') + baseUrlName + "/" + x.First().Tag.ToLowerInvariant())) .FirstOrDefault(); }
/// <summary> /// Get the search url without the 'term' query string /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <returns></returns> public static string ArticulateSearchUrl(this UrlHelper url, IMasterModel model) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url.EnsureEndsWith('/') + model.RootBlogNode.GetPropertyValue<string>("searchUrlName"); }
/// <summary> /// Returns the url for a single category /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <param name="category"></param> /// <returns></returns> public static string ArticulateCategoryUrl(this UrlHelper url, IMasterModel model, string category) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url.EnsureEndsWith('/') + model.RootBlogNode.GetPropertyValue<string>("categoriesUrlName").EnsureEndsWith('/') + category.SafeEncodeUrlSegments(); }
public static string GetThemeViewPath(IMasterModel model, string viewName) { if (model.Theme.IsNullOrWhiteSpace()) { throw new InvalidOperationException("No theme has been set for this Articulate root, republish the root with a selected theme"); } var path = "~/App_Plugins/Articulate/Themes/{0}/Views/{1}.cshtml"; return string.Format(path, model.Theme, viewName); }
protected virtual SyndicationItem GetFeedItem(IMasterModel model, PostModel post, string rootUrl) { var posturl = post.UrlWithDomain(); //Cannot continue if the url cannot be resolved - probably has publishing issues if (posturl.StartsWith("#")) { return null; } var appPath = _umbracoContext.HttpContext.Request.ApplicationPath; var rootUri = new Uri(rootUrl); var mediaRoot = rootUri.GetLeftPart(UriPartial.Authority) + appPath.EnsureStartsWith('/').TrimEnd('/'); var content = _relativeMediaHref.Replace(GetPostContent(post), match => { if (match.Groups.Count == 2) { return $" href=\"{rootUrl.TrimEnd('/')}{match.Groups[1].Value.EnsureStartsWith('/')}\""; } return null; }); content = _relativeMediaSrc.Replace(content, match => { if (match.Groups.Count == 2) { return $" src=\"{mediaRoot}{match.Groups[1].Value.EnsureStartsWith('/')}\""; } return null; }); var item = new SyndicationItem( post.Name, new TextSyndicationContent(content, TextSyndicationContentKind.Html), new Uri(posturl), post.Id.ToString(CultureInfo.InvariantCulture), post.PublishedDate) { PublishDate = post.PublishedDate, //don't include this as it will override the main content bits //Summary = new TextSyndicationContent(post.Excerpt) }; //TODO: attempting to add media:thumbnail... //item.ElementExtensions.Add(new SyndicationElementExtension("thumbnail", "http://search.yahoo.com/mrss/", "This is a test!")); foreach (var c in post.Categories) { item.Categories.Add(new SyndicationCategory(c)); } return item; }
/// <summary> /// Returns a list of the most recent posts /// </summary> /// <param name="helper"></param> /// <param name="masterModel"></param> /// <param name="count"></param> /// <returns></returns> public static IEnumerable<PostModel> GetRecentPosts(this UmbracoHelper helper, IMasterModel masterModel, int count) { 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"); } var rootPageModel = new ListModel(listNode, new PagerModel(count, 0, 1)); return rootPageModel.Children<PostModel>(); }
protected virtual Uri GetBlogImage(IMasterModel rootPageModel) { Uri logoUri = null; try { logoUri = rootPageModel.BlogLogo.IsNullOrWhiteSpace() ? null : new Uri(rootPageModel.BlogLogo); } catch (Exception ex) { LogHelper.Error<ArticulateRssController>("Could not convert the blog logo path to a Uri", ex); } return logoUri; }
/// <summary> /// Returns a list of all categories belonging to this articualte root /// </summary> /// <param name="helper"></param> /// <param name="masterModel"></param> /// <returns></returns> public static IEnumerable<string> GetAllCategories(this UmbracoHelper helper, IMasterModel masterModel) { //TODO: We want to use the core for this but it's not available, this needs to be implemented: http://issues.umbraco.org/issue/U4-9290 var appContext = helper.UmbracoContext.Application; var sqlSyntax = appContext.DatabaseContext.SqlSyntax; var sql = GetTagQuery("cmsTags.id, cmsTags.tag, cmsTags.[group], Count(*) as NodeCount", masterModel, sqlSyntax) .Where("cmsTags." + sqlSyntax.GetQuotedColumnName("group") + " = @tagGroup", new { tagGroup = "ArticulateCategories" }) .GroupBy("cmsTags.id", "cmsTags.tag", "cmsTags." + sqlSyntax.GetQuotedColumnName("group") + @""); return appContext.DatabaseContext.Database.Fetch<TagDto>(sql).Select(x => x.Tag).WhereNotNull().OrderBy(x => x); }
protected virtual SyndicationItem GetFeedItem(IMasterModel model, PostModel post, string rootUrl) { var content = _relativeMediaHref.Replace(GetPostContent(post), match => { if (match.Groups.Count == 2) { return " href=\"" + rootUrl.TrimEnd('/') + match.Groups[1].Value.EnsureStartsWith('/') + "\""; } return null; }); content = _relativeMediaSrc.Replace(content, match => { if (match.Groups.Count == 2) { return " src=\"" + rootUrl.TrimEnd('/') + match.Groups[1].Value.EnsureStartsWith('/') + "\""; } return null; }); var item = new SyndicationItem( post.Name, new TextSyndicationContent(content, TextSyndicationContentKind.Html), new Uri(post.UrlWithDomain()), post.Id.ToString(CultureInfo.InvariantCulture), post.PublishedDate) { PublishDate = post.PublishedDate, //don't include this as it will override the main content bits //Summary = new TextSyndicationContent(post.Excerpt) }; //TODO: attempting to add media:thumbnail... //item.ElementExtensions.Add(new SyndicationElementExtension("thumbnail", "http://search.yahoo.com/mrss/", "This is a test!")); foreach (var c in post.Categories) { item.Categories.Add(new SyndicationCategory(c)); } return item; }
public SyndicationFeed GetFeed(IMasterModel rootPageModel, IEnumerable<PostModel> posts) { var feed = new SyndicationFeed( rootPageModel.BlogTitle, rootPageModel.BlogDescription, new Uri(rootPageModel.RootBlogNode.UrlWithDomain()), GetFeedItems(rootPageModel, posts)) { Generator = "Articulate, blogging built on Umbraco", ImageUrl = GetBlogImage(rootPageModel) }; //TODO: attempting to add media:thumbnail... //feed.AttributeExtensions.Add(new XmlQualifiedName("media", "http://www.w3.org/2000/xmlns/"), "http://search.yahoo.com/mrss/"); return feed; }
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 ListModel(listNode); var tagsBaseUrl = masterModel.RootBlogNode.GetPropertyValue<string>("tagsUrlName"); var contentByTags = helper.GetContentByTags(rootPageModel, "ArticulateTags", tagsBaseUrl); return new PostTagCollection(contentByTags); }
public TagListModel( IMasterModel masterModel, string name, int pageSize, PostTagCollection tags) : base(masterModel.RootBlogNode) { _name = name; Theme = masterModel.Theme; RootBlogNode = masterModel.RootBlogNode; BlogArchiveNode = masterModel.BlogArchiveNode; PageSize = pageSize; BlogTitle = masterModel.BlogTitle; BlogDescription = masterModel.BlogDescription; Tags = tags; BlogBanner = masterModel.BlogBanner; BlogLogo = masterModel.BlogLogo; DisqusShortName = masterModel.DisqusShortName; CustomRssFeed = masterModel.CustomRssFeed; }
/// <summary> /// Gets the path to the currently assigned theme. /// </summary> /// <param name="model"> /// The <see cref="IMasterModel"/>. /// </param> /// <returns> /// The <see cref="string"/> representing the path to the starter kit theme folder. /// </returns> public static string GetThemePath(IMasterModel model) { const string Path = "~/App_Plugins/Merchello.Bazaar/Themes/{0}/"; return string.Format(Path, model.Theme); }
internal static IEnumerable <AuthorModel> GetContentByAuthors(this UmbracoHelper helper, IMasterModel masterModel) { var authorsNode = GetAuthorsNode(masterModel); var authors = authorsNode.Children.ToList(); //TODO: Should we have a paged result instead of returning everything? var pager = new PagerModel(int.MaxValue, 0, 1); var listNodes = GetListNodes(masterModel); var listNodeIds = listNodes.Select(x => x.Id).ToArray(); //used to lazily retrieve posts by author - as it turns out however this extra work to do this lazily in case the //Children property of the AuthorModel is not used is a waste because as soon as we get the latest post date for an author it will //iterate. Oh well, it's still lazy just in case. var lazyAuthorPosts = new Lazy <Dictionary <string, Tuple <IPublishedContent, List <IPublishedContent> > > >(() => { var authorNames = authors.Select(x => x.Name).ToArray(); //this will track author names to document ids var postsWithAuthors = new Dictionary <int, Tuple <string, IPublishedContent> >(); var posts = helper.GetPostsSortedByPublishedDate(pager, x => { //ensure there's an author and one that matches someone in the author list var xmlNode = x.SelectSingleNode("author [not(@isDoc)]"); var hasName = xmlNode != null && authorNames.Contains(xmlNode.Value); if (hasName) { postsWithAuthors[int.Parse(x.GetAttribute("id", ""))] = Tuple.Create(xmlNode.Value, authors.First(a => a.Name == xmlNode.Value)); } return(hasName); }, listNodeIds); //this tracks all documents to an author name/author content var authorPosts = new Dictionary <string, Tuple <IPublishedContent, List <IPublishedContent> > >(); //read forward foreach (var post in posts) { var authorInfo = postsWithAuthors[post.Id]; var authorName = authorInfo.Item1; var authorContent = authorInfo.Item2; if (authorPosts.ContainsKey(authorName)) { authorPosts[authorName].Item2.Add(post); } else { authorPosts.Add(authorName, Tuple.Create(authorContent, new List <IPublishedContent> { post })); } } return(authorPosts); }); return(authors.OrderBy(x => x.Name) .Select(x => new AuthorModel(x, GetLazyAuthorPosts(x, lazyAuthorPosts), pager, GetPostCount(helper, x.Name, listNodeIds)))); }
internal static IEnumerable<PostsByTagModel> GetContentByTags(this UmbracoHelper helper, IMasterModel masterModel, string tagGroup, string baseUrlName) { var tags = helper.TagQuery.GetAllContentTags(tagGroup).ToArray(); if (!tags.Any()) { return Enumerable.Empty<PostsByTagModel>(); } //TODO: Use the new 7.1.2 tags API to do this //TODO: This query will also cause problems if/when a site ends up with thousands of tags! It will fail. var sql = new Sql() .Select("cmsTagRelationship.nodeId, cmsTagRelationship.tagId, cmsTags.tag") .From("cmsTags") .InnerJoin("cmsTagRelationship") .On("cmsTagRelationship.tagId = cmsTags.id") .InnerJoin("cmsContent") .On("cmsContent.nodeId = cmsTagRelationship.nodeId") .InnerJoin("umbracoNode") .On("umbracoNode.id = cmsContent.nodeId") .Where("umbracoNode.nodeObjectType = @nodeObjectType", new { nodeObjectType = Constants.ObjectTypes.Document }) //only get nodes underneath the current articulate root .Where("umbracoNode." + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("path") + " LIKE @path", new { path = masterModel.RootBlogNode.Path + ",%" }) .Where("tagId IN (@tagIds) AND cmsTags." + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("group") + " = @tagGroup", new { tagIds = tags.Select(x => x.Id).ToArray(), tagGroup = tagGroup }); var taggedContent = ApplicationContext.Current.DatabaseContext.Database.Fetch<TagDto>(sql); return taggedContent.GroupBy(x => x.TagId) .Select(x => new PostsByTagModel( helper.TypedContent( x.Select(t => t.NodeId).Distinct()) .WhereNotNull() .Select(c => new PostModel(c)).OrderByDescending(c => c.PublishedDate), x.First().Tag, masterModel.RootBlogNode.Url.EnsureEndsWith('/') + baseUrlName + "/" + x.First().Tag.ToLowerInvariant())) .OrderBy(x => x.TagName); }
/// <summary> /// Gets the basic tag SQL used to retrieve tags for a given articulate root node /// </summary> /// <param name="selectCols"></param> /// <param name="masterModel"></param> /// <param name="sqlSyntax"></param> /// <returns></returns> /// <remarks> /// TODO: We won't need this when this is fixed http://issues.umbraco.org/issue/U4-9290 /// </remarks> private static Sql GetTagQuery(string selectCols, IMasterModel masterModel, ISqlSyntaxProvider sqlSyntax) { var sql = new Sql() .Select(selectCols) .From("cmsTags") .InnerJoin("cmsTagRelationship") .On("cmsTagRelationship.tagId = cmsTags.id") .InnerJoin("cmsContent") .On("cmsContent.nodeId = cmsTagRelationship.nodeId") .InnerJoin("umbracoNode") .On("umbracoNode.id = cmsContent.nodeId") .Where("umbracoNode.nodeObjectType = @nodeObjectType", new {nodeObjectType = Constants.ObjectTypes.Document}) //only get nodes underneath the current articulate root .Where("umbracoNode." + sqlSyntax.GetQuotedColumnName("path") + " LIKE @path", new {path = masterModel.RootBlogNode.Path + ",%"}); return sql; }
/// <summary> /// Returns the url for a single tag /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <param name="tag"></param> /// <returns></returns> public static string ArticulateTagUrl(this UrlHelper url, IMasterModel model, string tag) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url.EnsureEndsWith('/') + "tags/" + tag.SafeEncodeUrlSegments(); }
/// <summary> /// Returns the url for a single category /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <param name="category"></param> /// <returns></returns> public static string ArticulateCategoryUrl(this UrlHelper url, IMasterModel model, string category) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url.EnsureEndsWith('/') + "categories/" + category.SafeEncodeUrlSegments(); }
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 ListModel(listNode); var tagsBaseUrl = masterModel.RootBlogNode.GetPropertyValue <string>("tagsUrlName"); var contentByTags = helper.GetContentByTags(rootPageModel, "ArticulateTags", tagsBaseUrl); return(new PostTagCollection(contentByTags)); }
/// <summary> /// The Home Blog Url /// </summary> public static string ArticulateRootUrl(this UrlHelper url, IMasterModel model) { return(model.RootBlogNode == null ? null : model.RootBlogNode.Url); }
/// <summary> /// Returns the main rss feed url for this blog /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <returns></returns> public static string ArticulateRssUrl(this UrlHelper url, IMasterModel model) { return(model.CustomRssFeed.IsNullOrWhiteSpace() ? model.RootBlogNode.UrlWithDomain().EnsureEndsWith('/') + "rss" : model.CustomRssFeed); }
/// <summary> /// Returns the url of a themed asset /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <param name="relativeAssetPath"></param> /// <returns></returns> public static string ThemedAsset(this UrlHelper url, IMasterModel model, string relativeAssetPath) { return(VirtualPathUtility.ToAbsolute(PathHelper.GetThemePath(model)).EnsureEndsWith('/') + "assets/" + relativeAssetPath); }
/// <summary> /// The get theme partial view path. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="viewName"> /// The view name. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetThemePartialViewPath(IMasterModel model, string viewName) { return(GetThemePartialViewPath(model.Theme, viewName)); }
/// <summary> /// The get theme account path. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetThemeAccountPath(IMasterModel model) { const string Path = "~/App_Plugins/Merchello.Bazaar/Themes/{0}/Account/"; return(string.Format(Path, model.Theme)); }
public static string GetThemePath(IMasterModel model) { var path = "~/App_Plugins/Articulate/Themes/{0}/"; return(string.Format(path, model.Theme)); }
/// <summary> /// Returns a list of all categories /// </summary> /// <param name="helper"></param> /// <param name="masterModel"></param> /// <returns></returns> public static IEnumerable <string> GetAllCategories(this UmbracoHelper helper, IMasterModel masterModel) { //TODO: Make this somehow only lookup tag categories that are relavent to posts underneath the current Articulate root node! return(helper.TagQuery.GetAllContentTags("ArticulateCategories").Select(x => x.Text)); }
/// <summary> /// Returns the URL for the tag list /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <returns></returns> public static string ArticulateTagsUrl(this UrlHelper url, IMasterModel model) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url.EnsureEndsWith('/') + "tags"; }
internal static IEnumerable <PostsByTagModel> GetContentByTags(this UmbracoHelper helper, IMasterModel masterModel, string tagGroup, string baseUrlName) { var tags = helper.TagQuery.GetAllContentTags(tagGroup).ToArray(); if (!tags.Any()) { return(Enumerable.Empty <PostsByTagModel>()); } //TODO: Use the new 7.1.2 tags API to do this //TODO: Umbraco core needs to have a method to get content by tag(s), in the meantime we // need to run a query var sql = new Sql().Select("cmsTagRelationship.nodeId, cmsTagRelationship.tagId, cmsTags.tag") .From("cmsTagRelationship") .InnerJoin("cmsTags") .On("cmsTagRelationship.tagId = cmsTags.id") .Where("tagId IN (@tagIds) AND cmsTags." + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("group") + " = @tagGroup", new { tagIds = tags.Select(x => x.Id).ToArray(), tagGroup = tagGroup }); var taggedContent = ApplicationContext.Current.DatabaseContext.Database.Fetch <TagDto>(sql); return(taggedContent.GroupBy(x => x.TagId) .Select(x => new PostsByTagModel( helper.TypedContent( x.Select(t => t.NodeId).Distinct()) .Select(c => new PostModel(c)).OrderByDescending(c => c.PublishedDate), x.First().Tag, masterModel.RootBlogNode.Url.EnsureEndsWith('/') + baseUrlName + "/" + x.First().Tag.ToLowerInvariant())) .OrderBy(x => x.TagName)); }
internal static IEnumerable<PostsByTagModel> GetContentByTags(this UmbracoHelper helper, IMasterModel masterModel, string tagGroup, string baseUrlName) { var tags = helper.TagQuery.GetAllContentTags(tagGroup).ToArray(); if (!tags.Any()) { return Enumerable.Empty<PostsByTagModel>(); } //TODO: We want to use the core for this but it's not available, this needs to be implemented: http://issues.umbraco.org/issue/U4-9290 var appContext = helper.UmbracoContext.Application; var sqlSyntax = appContext.DatabaseContext.SqlSyntax; Func<IEnumerable<PostsByTagModel>> getResult = () => { var taggedContent = new List<TagDto>(); //process in groups to not exceed the max SQL params foreach (var tagBatch in tags.InGroupsOf(2000)) { var sql = GetTagQuery("cmsTagRelationship.nodeId, cmsTagRelationship.tagId, cmsTags.tag", masterModel, sqlSyntax) .Where("tagId IN (@tagIds) AND cmsTags." + sqlSyntax.GetQuotedColumnName("group") + " = @tagGroup", new { tagIds = tagBatch.Select(x => x.Id).ToArray(), tagGroup = tagGroup }); taggedContent.AddRange(appContext.DatabaseContext.Database.Fetch<TagDto>(sql)); } var result = new List<PostsByTagModel>(); foreach (var groupedTags in taggedContent.GroupBy(x => x.TagId)) { //will be the same tag name for all of these tag Ids var tagName = groupedTags.First().Tag; var publishedContent = helper.TypedContent(groupedTags.Select(t => t.NodeId).Distinct()).WhereNotNull(); var model = new PostsByTagModel( publishedContent.Select(c => new PostModel(c)).OrderByDescending(c => c.PublishedDate), tagName, masterModel.RootBlogNode.Url.EnsureEndsWith('/') + baseUrlName + "/" + tagName.ToLowerInvariant()); result.Add(model); } return result.OrderBy(x => x.TagName).ToArray(); }; #if DEBUG return getResult(); #else //cache this result for a short amount of time return appContext.ApplicationCache.RuntimeCache.GetCacheItem<IEnumerable<PostsByTagModel>>( string.Concat(typeof(UmbracoHelperExtensions).Name, "GetContentByTags", masterModel.RootBlogNode.Id, tagGroup), getResult, TimeSpan.FromSeconds(30)); #endif }
/// <summary> /// Returns a list of all categories belonging to this articualte root /// </summary> /// <param name="helper"></param> /// <param name="masterModel"></param> /// <returns></returns> public static IEnumerable <string> GetAllCategories(this UmbracoHelper helper, IMasterModel masterModel) { //TODO: We want to use the core for this but it's not available, this needs to be implemented: http://issues.umbraco.org/issue/U4-9290 var appContext = helper.UmbracoContext.Application; var sqlSyntax = appContext.DatabaseContext.SqlSyntax; var sql = GetTagQuery("cmsTags.id, cmsTags.tag, cmsTags.[group], Count(*) as NodeCount", masterModel, sqlSyntax) .Where("cmsTags." + sqlSyntax.GetQuotedColumnName("group") + " = @tagGroup", new { tagGroup = "ArticulateCategories" }) .GroupBy("cmsTags.id", "cmsTags.tag", "cmsTags." + sqlSyntax.GetQuotedColumnName("group") + @""); return(appContext.DatabaseContext.Database.Fetch <TagDto>(sql).Select(x => x.Tag).WhereNotNull().OrderBy(x => x)); }
public static HtmlHelper RequiresThemedJs(this HtmlHelper html, IMasterModel model, string filePath) { return(html.RequiresJs(PathHelper.GetThemePath(model) + "Assets/js" + filePath.EnsureStartsWith('/'))); }
/// <summary> /// Returns a list of the most recent posts /// </summary> /// <param name="helper"></param> /// <param name="masterModel"></param> /// <param name="count"></param> /// <returns></returns> public static IEnumerable <PostModel> GetRecentPosts(this UmbracoHelper helper, IMasterModel masterModel, int count) { 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"); } var pager = new PagerModel(count, 0, 1); var listItems = helper.GetPostsSortedByPublishedDate(listNode.Id, pager); var rootPageModel = new ListModel(listNode, listItems, pager); return(rootPageModel.Children <PostModel>()); }
/// <summary> /// Returns a list of all categories /// </summary> /// <param name="helper"></param> /// <param name="masterModel"></param> /// <returns></returns> public static IEnumerable<string> GetAllCategories(this UmbracoHelper helper, IMasterModel masterModel) { //TODO: Make this somehow only lookup tag categories that are relavent to posts underneath the current Articulate root node! return helper.TagQuery.GetAllContentTags("ArticulateCategories").Select(x => x.Text); }
/// <summary> /// The themed partial. /// </summary> /// <param name="html"> /// The html. /// </param> /// <param name="model"> /// The model. /// </param> /// <param name="partialName"> /// The partial name. /// </param> /// <param name="viewData"> /// The view data. /// </param> /// <returns> /// The <see cref="IHtmlString"/>. /// </returns> public static IHtmlString ThemedPartial(this HtmlHelper html, IMasterModel model, string partialName, ViewDataDictionary viewData = null) { var path = PathHelper.GetThemePartialViewPath(model, partialName); return(html.Partial(path, viewData)); }
public static HtmlHelper RequiresThemedJsFolder(this HtmlHelper html, IMasterModel model) { return(html.RequiresJsFolder(PathHelper.GetThemePath(model) + "Assets/js")); }
internal static PostsByTagModel GetContentByTag(this UmbracoHelper helper, IMasterModel masterModel, string tag, string tagGroup, string baseUrlName, long page, long pageSize) { //TODO: We want to use the core for this but it's not available, this needs to be implemented: http://issues.umbraco.org/issue/U4-9290 var appContext = helper.UmbracoContext.Application; var sqlSyntax = appContext.DatabaseContext.SqlSyntax; PostsByTagModel GetResult() { var sqlTags = GetTagQuery("umbracoNode.id", masterModel, sqlSyntax); if (sqlSyntax is MySqlSyntaxProvider) { sqlTags.Where("cmsTags.tag = @tagName AND cmsTags." + sqlSyntax.GetQuotedColumnName("group") + " = @tagGroup", new { tagName = tag, tagGroup = tagGroup }); } else { //For whatever reason, SQLCE and even SQL SERVER are not willing to lookup //tags with hyphens in them, it's super strange, so we force the tag column to be - what it already is!! what tha. sqlTags.Where("CAST(cmsTags.tag AS NVARCHAR(200)) = @tagName AND cmsTags." + sqlSyntax.GetQuotedColumnName("group") + " = @tagGroup", new { tagName = tag, tagGroup = tagGroup }); } //get the publishedDate property type id on the ArticulatePost content type var publishedDatePropertyTypeId = appContext.DatabaseContext.Database.ExecuteScalar <int>(@"SELECT cmsPropertyType.id FROM cmsContentType INNER JOIN cmsPropertyType ON cmsPropertyType.contentTypeId = cmsContentType.nodeId WHERE cmsContentType.alias = @contentTypeAlias AND cmsPropertyType.alias = @propertyTypeAlias", new { contentTypeAlias = "ArticulatePost", propertyTypeAlias = "publishedDate" }); var sqlContent = GetContentByTagQueryForPaging("umbracoNode.id", masterModel, sqlSyntax, publishedDatePropertyTypeId); sqlContent.Append("WHERE umbracoNode.id IN (").Append(sqlTags).Append(")"); //order by the dataDate field which will be the publishedDate sqlContent.OrderBy("cmsPropertyData.dataDate DESC"); //TODO: ARGH This still returns multiple non distinct Ids :( var taggedContent = appContext.DatabaseContext.Database.Page <int>(page, pageSize, sqlContent); var result = new List <PostsByTagModel>(); var publishedContent = helper.TypedContent(taggedContent.Items).WhereNotNull(); var model = new PostsByTagModel( publishedContent.Select(c => new PostModel(c)), tag, masterModel.RootBlogNode.Url.EnsureEndsWith('/') + baseUrlName + "/" + tag.ToLowerInvariant(), Convert.ToInt32(taggedContent.TotalItems)); result.Add(model); return(result.FirstOrDefault()); } #if DEBUG return(GetResult()); #else //cache this result for a short amount of time return((PostsByTagModel)appContext.ApplicationCache.RuntimeCache.GetCacheItem( string.Concat(typeof(UmbracoHelperExtensions).Name, "GetContentByTag", masterModel.RootBlogNode.Id, tagGroup), getResult, TimeSpan.FromSeconds(30))); #endif }
/// <summary> /// The get theme partial view path. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="viewName"> /// The view name. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetThemePartialViewPath(IMasterModel model, string viewName) { return GetThemePartialViewPath(model.Theme, viewName); }
/// <summary> /// The themed partial. /// </summary> /// <param name="html"> /// The html. /// </param> /// <param name="model"> /// The model. /// </param> /// <param name="partialName"> /// The partial name. /// </param> /// <param name="viewData"> /// The view data. /// </param> /// <returns> /// The <see cref="IHtmlString"/>. /// </returns> public static IHtmlString ThemedPartial(this HtmlHelper html, IMasterModel model, string partialName, ViewDataDictionary viewData = null) { var path = PathHelper.GetThemePartialViewPath(model, partialName); return html.Partial(path, viewData); }
private IEnumerable<SyndicationItem> GetFeedItems(IMasterModel model, IEnumerable<PostModel> posts) { var rootUrl = model.RootBlogNode.UrlWithDomain(); return posts.Select(post => GetFeedItem(model, post, rootUrl)).WhereNotNull().ToList(); }
/// <summary> /// Returns a list of the most recent posts /// </summary> /// <param name="helper"></param> /// <param name="masterModel"></param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <returns></returns> public static IEnumerable <PostModel> GetRecentPosts(this UmbracoHelper helper, IMasterModel masterModel, int page, int pageSize) { var listNodes = GetListNodes(masterModel); var listNodeIds = listNodes.Select(x => x.Id).ToArray(); var pager = new PagerModel(pageSize, page - 1, 1); var listItems = helper.GetPostsSortedByPublishedDate(pager, null, listNodeIds); var rootPageModel = new ListModel(listNodes[0], listItems, pager); return(rootPageModel.Posts); }
/// <summary> /// Returns the url of a themed asset /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <param name="relativeAssetPath"></param> /// <returns></returns> public static string ThemedAsset(this UrlHelper url, IMasterModel model, string relativeAssetPath) { return VirtualPathUtility.ToAbsolute(PathHelper.GetThemePath(model)).EnsureEndsWith('/') + "assets/" + relativeAssetPath; }
public static string GetThemePartialViewPath(IMasterModel model, string viewName) { var path = "~/App_Plugins/Articulate/Themes/{0}/Views/Partials/{1}.cshtml"; return(string.Format(path, model.Theme, viewName)); }
/// <summary> /// Returns the url for a single tag /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <param name="tag"></param> /// <returns></returns> public static string ArticulateTagUrl(this UrlHelper url, IMasterModel model, string tag) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url.EnsureEndsWith('/') + model.RootBlogNode.GetPropertyValue<string>("tagsUrlName").EnsureEndsWith('/') + tag.SafeEncodeUrlSegments(); }
internal static IEnumerable <PostsByTagModel> GetContentByTags(this UmbracoHelper helper, IMasterModel masterModel, string tagGroup, string baseUrlName) { var tags = helper.TagQuery.GetAllContentTags(tagGroup).ToArray(); if (!tags.Any()) { return(Enumerable.Empty <PostsByTagModel>()); } //TODO: We want to use the core for this but it's not available, this needs to be implemented: http://issues.umbraco.org/issue/U4-9290 var appContext = helper.UmbracoContext.Application; var sqlSyntax = appContext.DatabaseContext.SqlSyntax; IEnumerable <PostsByTagModel> GetResult() { var taggedContent = new List <TagDto>(); //process in groups to not exceed the max SQL params foreach (var tagBatch in tags.InGroupsOf(2000)) { var sql = GetTagQuery("cmsTagRelationship.nodeId, cmsTagRelationship.tagId, cmsTags.tag", masterModel, sqlSyntax) .Where("tagId IN (@tagIds) AND cmsTags." + sqlSyntax.GetQuotedColumnName("group") + " = @tagGroup", new { tagIds = tagBatch.Select(x => x.Id).ToArray(), tagGroup = tagGroup }); taggedContent.AddRange(appContext.DatabaseContext.Database.Fetch <TagDto>(sql)); } var result = new List <PostsByTagModel>(); foreach (var groupedTags in taggedContent.GroupBy(x => x.TagId)) { //will be the same tag name for all of these tag Ids var tagName = groupedTags.First().Tag; var publishedContent = helper.TypedContent(groupedTags.Select(t => t.NodeId).Distinct()).WhereNotNull(); var model = new PostsByTagModel( publishedContent.Select(c => new PostModel(c)).OrderByDescending(c => c.PublishedDate), tagName, masterModel.RootBlogNode.Url.EnsureEndsWith('/') + baseUrlName + "/" + tagName.ToLowerInvariant()); result.Add(model); } return(result.OrderBy(x => x.TagName).ToArray()); } #if DEBUG return(GetResult()); #else //cache this result for a short amount of time return((IEnumerable <PostsByTagModel>)appContext.ApplicationCache.RuntimeCache.GetCacheItem( string.Concat(typeof(UmbracoHelperExtensions).Name, "GetContentByTags", masterModel.RootBlogNode.Id, tagGroup), getResult, TimeSpan.FromSeconds(30))); #endif }
public RssResult(SyndicationFeed feed, IMasterModel model) { _feed = feed; _model = model; }
public static PostTagCollection GetPostTagCollection(this UmbracoHelper helper, IMasterModel masterModel) { var tagsBaseUrl = masterModel.RootBlogNode.GetPropertyValue <string>("tagsUrlName"); var contentByTags = helper.GetContentByTags(masterModel, "ArticulateTags", tagsBaseUrl); return(new PostTagCollection(contentByTags)); }
/// <summary> /// Returns the main rss feed url for this blog /// </summary> /// <param name="url"></param> /// <param name="model"></param> /// <returns></returns> public static string ArticulateRssUrl(this UrlHelper url, IMasterModel model) { return model.CustomRssFeed.IsNullOrWhiteSpace() ? model.RootBlogNode.UrlWithDomain().EnsureEndsWith('/') + "rss" : model.CustomRssFeed; }
public static string ArticulateCreateBlogEntryUrl(this UrlHelper url, IMasterModel model) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url.EnsureEndsWith('/') + "a-new/"; }
/// <summary> /// The Home Blog Url /// </summary> public static string ArticulateRootUrl(this UrlHelper url, IMasterModel model) { return model.RootBlogNode == null ? null : model.RootBlogNode.Url; }
internal static PostsByTagModel GetContentByTag(this UmbracoHelper helper, IMasterModel masterModel, string tag, string tagGroup, string baseUrlName) { //TODO: Use the new 7.1.2 tags API to do this var sql = new Sql() .Select("cmsTagRelationship.nodeId, cmsTagRelationship.tagId, cmsTags.tag") .From("cmsTags") .InnerJoin("cmsTagRelationship") .On("cmsTagRelationship.tagId = cmsTags.id") .InnerJoin("cmsContent") .On("cmsContent.nodeId = cmsTagRelationship.nodeId") .InnerJoin("umbracoNode") .On("umbracoNode.id = cmsContent.nodeId") .Where("umbracoNode.nodeObjectType = @nodeObjectType", new {nodeObjectType = Constants.ObjectTypes.Document}) //only get nodes underneath the current articulate root .Where("umbracoNode." + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("path") + " LIKE @path", new {path = masterModel.RootBlogNode.Path + ",%"}) .Where("cmsTags.tag = @tagName AND cmsTags." + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("group") + " = @tagGroup", new { tagName = tag, tagGroup = tagGroup }); var taggedContent = ApplicationContext.Current.DatabaseContext.Database.Fetch<TagDto>(sql); return taggedContent.GroupBy(x => x.TagId) .Select(x => new PostsByTagModel( helper.TypedContent( x.Select(t => t.NodeId).Distinct()) .WhereNotNull() .Select(c => new PostModel(c)).OrderByDescending(c => c.PublishedDate), x.First().Tag, masterModel.RootBlogNode.Url.EnsureEndsWith('/') + baseUrlName + "/" + x.First().Tag.ToLowerInvariant())) .FirstOrDefault(); }