/// <summary> /// Executes the syndication result on the given context. /// </summary> /// <param name="context">The current context.</param> public virtual void Write(IStreamResponse response) { var writer = new XmlTextWriter(response.OutputStream, Encoding.UTF8); var ui = new Client.Helpers.UIHelper(); // Write headers response.ContentType = ContentType; response.ContentEncoding = Encoding.UTF8; var feed = new SyndicationFeed() { Title = new TextSyndicationContent(Config.Site.Title), LastUpdatedTime = Posts.First().Published.Value, Description = new TextSyndicationContent(Config.Site.Description), }; feed.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(App.Env.AbsoluteUrl("~/")))); var items = new List<SyndicationItem>(); foreach (var post in Posts) { var item = new SyndicationItem() { Title = SyndicationContent.CreatePlaintextContent(post.Title), PublishDate = post.Published.Value, Summary = SyndicationContent.CreateHtmlContent(post.Body) }; item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(App.Env.AbsoluteUrl("~/" + post.Type.Slug + "/" + post.Slug)))); items.Add(item); } feed.Items = items; var formatter = GetFormatter(feed); formatter.WriteTo(writer); writer.Flush(); writer.Close(); }
/// <summary> /// Gets the author list. /// </summary> /// <returns>The list of authors</returns> private IEnumerable <ListItem> GetAuthors() { var authors = Mapper.Map <IEnumerable <Piranha.Models.Author>, IEnumerable <ListItem> >(api.Authors.Get()); var ui = new Client.Helpers.UIHelper(); foreach (var item in authors) { item.GravatarUrl = ui.GravatarUrl(item.Email, 40); } return(authors); }
/// <summary> /// Gets the edit model for the author with the given id. /// </summary> /// <param name="api">The current api</param> /// <param name="id">The unique id</param> /// <returns>The edit model</returns> public static EditModel GetById(Api api, Guid id) { var author = api.Authors.GetSingle(id); if (author != null) { var model = Mapper.Map<Piranha.Models.Author, EditModel>(author); var ui = new Client.Helpers.UIHelper(); model.GravatarUrl = ui.GravatarUrl(model.Email, 80); return model; } return null; }
/// <summary> /// Gets the edit model for the author with the given id. /// </summary> /// <param name="api">The current api</param> /// <param name="id">The unique id</param> /// <returns>The edit model</returns> public static EditModel GetById(Api api, Guid id) { var author = api.Authors.GetSingle(id); if (author != null) { var model = Mapper.Map <Piranha.Models.Author, EditModel>(author); var ui = new Client.Helpers.UIHelper(); model.GravatarUrl = ui.GravatarUrl(model.Email, 80); return(model); } return(null); }
/// <summary> /// Executes the syndication result on the given context. /// </summary> /// <param name="context">The current context.</param> public virtual void Write(IStreamResponse response) { var writer = new XmlTextWriter(response.OutputStream, Encoding.UTF8); var ui = new Client.Helpers.UIHelper(); // Write headers response.ContentType = ContentType; response.ContentEncoding = Encoding.UTF8; var feed = new SyndicationFeed() { Title = new TextSyndicationContent(Config.Site.Title), LastUpdatedTime = Posts.First().Published.Value, Description = new TextSyndicationContent(Config.Site.Description), }; feed.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(App.Env.AbsoluteUrl("~/")))); var items = new List <SyndicationItem>(); foreach (var post in Posts) { var item = new SyndicationItem() { Title = SyndicationContent.CreatePlaintextContent(post.Title), PublishDate = post.Published.Value, Summary = SyndicationContent.CreateHtmlContent(post.Body) }; item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(App.Env.AbsoluteUrl("~/" + post.Type.Slug + "/" + post.Slug)))); items.Add(item); } feed.Items = items; var formatter = GetFormatter(feed); formatter.WriteTo(writer); writer.Flush(); writer.Close(); }
/// <summary> /// Checks if the provided comment should be regarded as spam. /// </summary> /// <param name="comment">The comment</param> /// <returns>True if the comment should be regarded as spam</returns> public bool CommentCheck(Models.Comment comment) { var post = Client.Models.PostModel.GetById(comment.PostId); if (post != null) { var ui = new Client.Helpers.UIHelper(); var value = Call(CommentCheckUrl, new { blog = HttpUtility.UrlEncode(Config.Akismet.ApiKey), user_ip = HttpUtility.UrlEncode(comment.IP), user_agent = HttpUtility.UrlEncode(comment.UserAgent), referrer = "", permalink = HttpUtility.UrlEncode(App.Env.AbsoluteUrl(ui.Permalink(post))), comment_type = "comment", comment_author = HttpUtility.UrlEncode(comment.Author), comment_author_email = HttpUtility.UrlEncode(comment.Email), comment_author_url = HttpUtility.UrlEncode(comment.WebSite), comment_content = HttpUtility.UrlEncode(comment.Body) }); return Convert.ToBoolean(value); } return false; }
/// <summary> /// Checks if the provided comment should be regarded as spam. /// </summary> /// <param name="comment">The comment</param> /// <returns>True if the comment should be regarded as spam</returns> public bool CommentCheck(Models.Comment comment) { var post = Client.Models.PostModel.GetById(comment.PostId); if (post != null) { var ui = new Client.Helpers.UIHelper(); var value = Call(CommentCheckUrl, new { blog = HttpUtility.UrlEncode(Config.Akismet.ApiKey), user_ip = HttpUtility.UrlEncode(comment.IP), user_agent = HttpUtility.UrlEncode(comment.UserAgent), referrer = "", permalink = HttpUtility.UrlEncode(App.Env.AbsoluteUrl(ui.Permalink(post))), comment_type = "comment", comment_author = HttpUtility.UrlEncode(comment.Author), comment_author_email = HttpUtility.UrlEncode(comment.Email), comment_author_url = HttpUtility.UrlEncode(comment.WebSite), comment_content = HttpUtility.UrlEncode(comment.Body) }); return(Convert.ToBoolean(value)); } return(false); }
/// <summary> /// Gets the author list. /// </summary> /// <returns>The list of authors</returns> private IEnumerable<ListItem> GetAuthors() { var authors = Mapper.Map<IEnumerable<Piranha.Models.Author>, IEnumerable<ListItem>>(api.Authors.Get()); var ui = new Client.Helpers.UIHelper(); foreach (var item in authors) { item.GravatarUrl = ui.GravatarUrl(item.Email, 40); } return authors; }
/// <summary> /// Takes care of any mail notifications that should be sent. /// </summary> private void HandleNotifications() { if (Config.Comments.NotifyAuthor || Config.Comments.NotifyModerators) { if (App.Mail != null) { using (var api = new Api()) { var post = api.Posts.GetSingle(PostId); if (post != null) { var recipients = new List <Mail.Address>(); var mail = new Mail.Message(); if (Hooks.Mail.OnCommentMail != null) { // Generate custom mail mail = Hooks.Mail.OnCommentMail(post, this); } else { // Generate default mail var ui = new Client.Helpers.UIHelper(); mail.Subject = "New comment posted on " + post.Title; mail.Body = String.Format(Mail.Defaults.NewComment, ui.GravatarUrl(Email, 80), App.Env.AbsoluteUrl(ui.Permalink(post)), post.Title, Author, Created.ToString("yyyy-MM-dd HH:mm:ss"), Body.Replace("\n", "<br/>")); } if (Config.Comments.NotifyAuthor && !String.IsNullOrWhiteSpace(post.Author.Email)) { // Add author address recipients.Add(new Mail.Address() { Email = post.Author.Email, Name = post.Author.Name }); } if (Config.Comments.NotifyModerators && !String.IsNullOrWhiteSpace(Config.Comments.Moderators)) { // Add moderator addresses foreach (var moderator in Config.Comments.Moderators.Split(new char[] { ',' })) { recipients.Add(new Mail.Address() { Email = moderator.Trim(), Name = moderator.Trim() }); } } // Send mail App.Mail.Send(mail, recipients.ToArray()); } } } else { App.Logger.Log(Log.LogLevel.ERROR, "Models.Comment.HandleNotifications: No mail provider configured."); } } }