public static Task SendVerifyEmail(UmbracoHelper umbracoHelper, IMember member, string verifyGUID) { var emailTemplate = GetEmailTeplate(Constants.VerifyEmailNewMemberTemplate); var body = emailTemplate?.EmailTemplateEmailBody?.ToString() .Replace(GuidReplacementString, umbracoHelper.NiceUrlWithDomain(Constants.HomePageId) + "umbraco/Surface/AuthSurface/verifyEmail?verifyGUID=" + verifyGUID + "&wid=" + Constants.HomePageId) .Replace(MemberReplaceString, member.Username); return(SendGridMailForTemplate(emailTemplate, body, member.Email)); }
// GET: BlogFeeds public ActionResult Rss() { UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current); const int NUMBER_OF_FEED_ITEMS = 10; const string DATE_FORMAT = "ddd, dd MMM yyyy hh:mm:ss zzz"; const string ARTICLE_TITLE_PROPERTY_ALIAS = "pageTitle"; const string ARTICLE_AUTHOR_ALIAS = "CreatorName"; const string ARTICLE_DATE_PROPERTY_ALIAS = "publishedDate"; const int CONTENT_PREVIEW_LENGTH = 500; var currentPage = Request.Url.ToString(); List <RSSFeedItem> results = new List <RSSFeedItem>(); IPublishedContent homePage = umbracoHelper.TypedContentAtRoot().FirstOrDefault(x => x.ContentType.Alias.Equals("home")); IPublishedContent blogPage = homePage.Children.Where(x => x.DocumentTypeAlias == "blogHome").FirstOrDefault(); IList <BlogPost> feedItems = blogPage.Descendants <BlogPost>().OrderByDescending(x => x.UpdateDate).Take(NUMBER_OF_FEED_ITEMS).ToList(); DateTime lastBuildDate = feedItems.Max(x => x.UpdateDate); string siteUrl = homePage.UrlWithDomain(); string feedUrl = Request.Url.PathAndQuery; var feedParentUrl = blogPage.UrlWithDomain(); foreach (var page in feedItems) { // Obsolete. See https://skrift.io/articles/archive/strongly-typed-models-in-the-umbraco-grid/ string articleDescription = umbracoHelper.Truncate(umbraco.library.StripHtml(page.GetGridHtml("gridEditor", "bootstrap3").ToString()), CONTENT_PREVIEW_LENGTH).ToString().Replace("…", "..."); string title = page.HasProperty(ARTICLE_TITLE_PROPERTY_ALIAS) ? page.GetPropertyValue <string>(ARTICLE_TITLE_PROPERTY_ALIAS) : page.Name; string author = !string.IsNullOrEmpty(page.CreatorName) ? page.CreatorName : "Guest"; string link = umbracoHelper.NiceUrlWithDomain(page.Id); string publishedDate = ((DateTime)page.GetPropertyValue(ARTICLE_DATE_PROPERTY_ALIAS)).ToString(DATE_FORMAT); string permaLink = page.UrlWithDomain(); List <string> categoryList = new List <string>(); if (page.HasProperty("category")) { foreach (var item in page.Category) { categoryList.Add(item); } } results.Add(new RSSFeedItem(articleDescription, title, author, link, categoryList, publishedDate, permaLink)); } RSSFeed viewModel = new RSSFeed(feedParentUrl, lastBuildDate.ToString(DATE_FORMAT), currentPage, results); return(View(viewModel)); }
/// <summary> /// Gets data about the current context from the Umbraco content tree /// </summary> public IDictionary <string, string> BuildTrail() { var breadcrumb = new Dictionary <string, string>(); var umbraco = new UmbracoHelper(UmbracoContext.Current); var isTopLevelSection = false; // Start with the parent node of the current node, which is effectively its folder, // unless we're only one folder deep because then we want to have the main section // highlighted. if (UmbracoContext.Current.PageId.HasValue) { var node = umbraco.TypedContent(UmbracoContext.Current.PageId); if (node.Parent != null && node.Parent.Parent == null) { isTopLevelSection = true; } else { node = node.Parent; } // Add data for each ancestor node in the hierarchy while (node != null) { breadcrumb.Add(node.Name, isTopLevelSection ? string.Empty : umbraco.NiceUrlWithDomain(node.Id)); node = node.Parent; if (isTopLevelSection) { isTopLevelSection = false; } } } // Reverse it so we start from the root, and return var reversedKeys = breadcrumb.Keys.Reverse(); return(reversedKeys.ToDictionary(key => key, key => breadcrumb[key])); }
public XDocument Export(IEnumerable <IContent> posts, BlogMLDocument document) { var nsContent = XNamespace.Get("http://purl.org/rss/1.0/modules/content/"); var nsDsq = XNamespace.Get("http://www.disqus.com/"); var nsDc = XNamespace.Get("http://purl.org/dc/elements/1.1/"); var nsWp = XNamespace.Get("http://wordpress.org/export/1.0/"); var xChannel = new XElement("channel"); var xDoc = new XDocument( new XElement("rss", new XAttribute("version", "2.0"), new XAttribute(XNamespace.Xmlns + "content", nsContent), new XAttribute(XNamespace.Xmlns + "dsq", nsDsq), new XAttribute(XNamespace.Xmlns + "dc", nsDc), new XAttribute(XNamespace.Xmlns + "wp", nsWp), xChannel)); var umbHelper = new UmbracoHelper(UmbracoContext.Current); var markDown = new MarkdownDeep.Markdown(); foreach (var post in posts) { var blogMlPost = document.Posts.FirstOrDefault(x => x.Title.Content == post.Name); //TODO: Add logging here if we cant find it if (blogMlPost == null) { continue; } //no comments to import if (blogMlPost.Comments.Any() == false) { continue; } var body = post.GetValue <string>("richText"); if (body.IsNullOrWhiteSpace()) { body = markDown.Transform(post.GetValue <string>("markdown")); } var xItem = new XElement("item", new XElement("title", post.Name), new XElement("link", umbHelper.NiceUrlWithDomain(post.Id)), new XElement(nsContent + "encoded", new XCData(body)), new XElement(nsDsq + "thread_identifier", post.Key.ToString()), new XElement(nsWp + "post_date_gmt", post.GetValue <DateTime>("publishedDate").ToUniversalTime().ToIsoString()), new XElement(nsWp + "comment_status", "open")); foreach (var comment in blogMlPost.Comments) { string commentText = comment.Content.Content; if (comment.Content.ContentType == BlogMLContentType.Base64) { commentText = Encoding.UTF8.GetString(Convert.FromBase64String(comment.Content.Content)); } var xComment = new XElement(nsWp + "comment", new XElement(nsWp + "comment_id", comment.Id), new XElement(nsWp + "comment_author", comment.UserName), new XElement(nsWp + "comment_author_email", comment.UserEmailAddress), new XElement(nsWp + "comment_author_url", comment.UserUrl == null ? string.Empty : comment.UserUrl.ToString()), new XElement(nsWp + "comment_date_gmt", comment.CreatedOn.ToUniversalTime().ToIsoString()), new XElement(nsWp + "comment_content", commentText), new XElement(nsWp + "comment_approved", comment.ApprovalStatus == BlogMLApprovalStatus.Approved ? 1 : 0)); xItem.Add(xComment); } xChannel.Add(xItem); } return(xDoc); }
public XDocument Export(IEnumerable<IContent> posts, BlogMLDocument document) { var nsContent = XNamespace.Get("http://purl.org/rss/1.0/modules/content/"); var nsDsq = XNamespace.Get("http://www.disqus.com/"); var nsDc = XNamespace.Get("http://purl.org/dc/elements/1.1/"); var nsWp = XNamespace.Get("http://wordpress.org/export/1.0/"); var xChannel = new XElement("channel"); var xDoc = new XDocument( new XElement("rss", new XAttribute("version", "2.0"), new XAttribute(XNamespace.Xmlns + "content", nsContent), new XAttribute(XNamespace.Xmlns + "dsq", nsDsq), new XAttribute(XNamespace.Xmlns + "dc", nsDc), new XAttribute(XNamespace.Xmlns + "wp", nsWp), xChannel)); var umbHelper = new UmbracoHelper(UmbracoContext.Current); var markDown = new MarkdownDeep.Markdown(); foreach (var post in posts) { var blogMlPost = document.Posts.FirstOrDefault(x => x.Title.Content == post.Name); //TODO: Add logging here if we cant find it if (blogMlPost == null) continue; //no comments to import if (blogMlPost.Comments.Any() == false) continue; var body = post.GetValue<string>("richText"); if (body.IsNullOrWhiteSpace()) { body = markDown.Transform(post.GetValue<string>("markdown")); } var xItem = new XElement("item", new XElement("title", post.Name), new XElement("link", umbHelper.NiceUrlWithDomain(post.Id)), new XElement(nsContent + "encoded", new XCData(body)), new XElement(nsDsq + "thread_identifier", post.Key.ToString()), new XElement(nsWp + "post_date_gmt", post.GetValue<DateTime>("publishedDate").ToUniversalTime().ToIsoString()), new XElement(nsWp + "comment_status", "open")); foreach (var comment in blogMlPost.Comments) { string commentText = comment.Content.Content; if (comment.Content.ContentType == BlogMLContentType.Base64) commentText = Encoding.UTF8.GetString(Convert.FromBase64String(comment.Content.Content)); var xComment = new XElement(nsWp + "comment", new XElement(nsWp + "comment_id", comment.Id), new XElement(nsWp + "comment_author", comment.UserName), new XElement(nsWp + "comment_author_email", comment.UserEmailAddress), new XElement(nsWp + "comment_author_url", comment.UserUrl == null ? string.Empty : comment.UserUrl.ToString()), new XElement(nsWp + "comment_date_gmt", comment.CreatedOn.ToUniversalTime().ToIsoString()), new XElement(nsWp + "comment_content", commentText), new XElement(nsWp + "comment_approved", comment.ApprovalStatus == BlogMLApprovalStatus.Approved ? 1 : 0)); xItem.Add(xComment); } xChannel.Add(xItem); } return xDoc; }
/// <summary> /// Gets the NiceUrlWithDomain for the content item /// </summary> /// <param name="doc"></param> /// <returns></returns> public static string NiceUrlWithDomain(this IPublishedContent doc) { var umbHelper = new UmbracoHelper(UmbracoContext.Current); return umbHelper.NiceUrlWithDomain(doc.Id); }
/// <summary> /// Gets data about the current context from the Umbraco content tree /// </summary> public IDictionary <string, string> BuildTrail() { var breadcrumb = new Dictionary <string, string>(); var umbraco = new UmbracoHelper(UmbracoContext.Current); var isTopLevelSection = false; // Start with the parent node of the current node, which is effectively its folder, // unless we're only one folder deep because then we want to have the main section // highlighted. if (UmbracoContext.Current.PageId.HasValue) { var node = umbraco.TypedContent(UmbracoContext.Current.PageId); if (node.Parent != null && node.Parent.Parent == null) { isTopLevelSection = true; } else { node = node.Parent; } // Add data for each ancestor node in the hierarchy while (node != null) { try { // If there are child pages with the same name as the parent, keep the breadcrumb trail tidy by skipping the child if (!breadcrumb.ContainsKey(node.Name)) { breadcrumb.Add(node.Name, isTopLevelSection ? string.Empty : umbraco.NiceUrlWithDomain(node.Id)); } } catch (ArgumentException ex) { // Report it, but we don't want to page to crash due to an error in the breadcrumb ex.Data.Add("Adding node name", node.Name); ex.Data.Add("Adding node URL", isTopLevelSection ? string.Empty : umbraco.NiceUrlWithDomain(node.Id)); var keyCount = 1; foreach (var key in breadcrumb.Keys) { ex.Data.Add($"Already added node {keyCount} name", key); ex.Data.Add($"Already added node {keyCount} URL", breadcrumb[key]); keyCount++; } ex.ToExceptionless().Submit(); } node = node.Parent; if (isTopLevelSection) { isTopLevelSection = false; } } } // Reverse it so we start from the root, and return var reversedKeys = breadcrumb.Keys.Reverse(); return(reversedKeys.ToDictionary(key => key, key => breadcrumb[key])); }