public async Task <ActionResult> CommentAdd_Partial(AddModel model) { await model.UpdateDataAsync(); using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) { BlogEntry blogEntry = await entryDP.GetItemAsync(model.EntryIdentity); if (blogEntry == null) { throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found."), model.EntryIdentity); } if (!blogEntry.OpenForComments) { throw new InternalError("Can't add comments to this blog entry"); } if (!ModelState.IsValid) { return(PartialView(model)); } using (BlogCommentDataProvider blogCommentDP = new BlogCommentDataProvider(model.EntryIdentity)) { BlogComment blogComment = model.GetData(); if (!await blogCommentDP.AddItemAsync(blogComment)) { throw new Error(this.__ResStr("alreadyExists", "An error occurred adding this new comment")); } // send notification email BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); if (config.NotifyNewComment) { SendEmail sendEmail = new SendEmail(); object parms = new { Description = !blogComment.Approved ? this.__ResStr("needApproval", "This comment requires your approval.") : this.__ResStr("autoApproval", "This comment has been automatically approved."), Category = (await blogEntry.GetCategoryAsync()).ToString(), Title = blogEntry.Title.ToString(), Url = Manager.CurrentSite.MakeUrl(await BlogConfigData.GetEntryCanonicalNameAsync(blogEntry.Identity)), Comment = Utility.HtmlDecode(model.Comment), UserName = model.Name, UserEmail = model.Email, UserWebsite = model.Website, }; string subject = this.__ResStr("newComment", "New Blog Comment ({0} - {1})", blogEntry.Title.ToString(), Manager.CurrentSite.SiteDomain); await sendEmail.PrepareEmailMessageAsync(config.NotifyEmail, subject, await sendEmail.GetEmailFileAsync(Package.GetCurrentPackage(this), "New Comment.txt"), Parameters : parms); await sendEmail.SendAsync(true); } if (!blogComment.Approved) { return(FormProcessed(model, this.__ResStr("okSavedReview", "New comment saved - It will be reviewed before becoming publicly viewable"), OnClose: OnCloseEnum.ReloadPage, OnPopupClose: OnPopupCloseEnum.ReloadParentPage)); } else { return(FormProcessed(model, this.__ResStr("okSaved", "New comment added"), OnClose: OnCloseEnum.ReloadPage, OnPopupClose: OnPopupCloseEnum.ReloadParentPage)); } } } }
public async Task <ActionResult> BlogConfig() { using (BlogConfigDataProvider dataProvider = new BlogConfigDataProvider()) { Model model = new Model { }; BlogConfigData data = await dataProvider.GetItemAsync(); if (data == null) { throw new Error(this.__ResStr("notFound", "The blog settings were not found.")); } model.SetData(data); return(View(model)); } }
public async Task <ActionResult> BlogConfig_Partial(Model model) { using (BlogConfigDataProvider dataProvider = new BlogConfigDataProvider()) { BlogConfigData data = await dataProvider.GetItemAsync();// get the original item if (!ModelState.IsValid) { return(PartialView(model)); } data = model.GetData(data); // merge new data into original model.SetData(data); // and all the data back into model for final display await dataProvider.UpdateConfigAsync(data); return(FormProcessed(model, this.__ResStr("okSaved", "Blog settings saved"))); } }
public async Task <ModuleAction> GetAction_BlogAsync(string url, int blogCategory = 0, DateTime?StartDate = null, int Count = 0) { BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); QueryHelper query = new QueryHelper(); if (string.IsNullOrWhiteSpace(url)) { url = await BlogConfigData.GetCategoryCanonicalNameAsync(blogCategory); } else { url = ModulePermanentUrl; query.Add("BlogCategory", blogCategory.ToString()); } string date = null; if (StartDate != null) { query.Add("StartDate", StartDate.ToString()); date = Formatting.Date_Month_YYYY((DateTime)StartDate); if (StartDate >= DateTime.UtcNow) { date = this.__ResStr("latest", "{0} - Latest", date); } } else { Count = 0;// must have a date for Count to be displayed } return(new ModuleAction(this) { Url = string.IsNullOrWhiteSpace(url) ? ModulePermanentUrl : url, QueryArgsDict = query, Image = "#Display", LinkText = Count != 0 ? this.__ResStr("countLink", "{0} ({1})", date, Count) : this.__ResStr("displayLink", "Blog"), MenuText = Count != 0 ? this.__ResStr("countMenu", "{0} ({1})", date, Count) : this.__ResStr("displayText", "Blog"), Tooltip = Count != 0 ? this.__ResStr("countTooltip", "Display blog entries starting {0}", date, Count) : this.__ResStr("displayTooltip", "Display the blog"), Legend = Count != 0 ? this.__ResStr("countLegend", "Displays the blog entries starting {0}", date, Count) : this.__ResStr("displayLegend", "Displays the blog"), Style = ModuleAction.ActionStyleEnum.Normal, Category = ModuleAction.ActionCategoryEnum.Read, Mode = ModuleAction.ActionModeEnum.Any, Location = ModuleAction.ActionLocationEnum.NoAuto, }); }
internal async Task UpdateDataAsync() { BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); GravatarsEnabled = config.ShowGravatar; using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) { BlogCategory cat = await categoryDP.GetItemAsync(CategoryIdentity); if (cat == null) { throw new InternalError("Category with id {0} not found", CategoryIdentity); } ShowCaptcha = cat.UseCaptcha; ShowGravatar = GravatarsEnabled; } OpenForComments = await TestOpenForCommentsAsync(EntryIdentity); }
public async Task <string> RenderAsync(string model) { HtmlBuilder hb = new HtmlBuilder(); hb.Append($@"<div class='yt_yetawf_blog_gravatar t_display'>"); YTagBuilder tagImg = new YTagBuilder("img"); BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); string url = GravatarUrl(model, config.GravatarSize, config.GravatarRating, config.GravatarDefault); tagImg.Attributes.Add("src", url); tagImg.Attributes.Add("alt", this.__ResStr("altGravatar", "Gravatar image - {0}", model)); hb.Append(tagImg.ToString(YTagRenderMode.StartTag)); hb.Append($@"</div>"); return(hb.ToString()); }
public async Task <ModuleAction> GetAction_RssFeedAsync(int blogCategory = 0) { BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); if (!config.Feed) { return(null); } //if (blogCategory == 0) // manager.TryGetUrlArg<int>("BlogCategory", out blogCategory); object qargs = null, qargsHR = null; if (blogCategory != 0) { qargs = new { BlogCategory = blogCategory, }; using (BlogCategoryDataProvider dataProvider = new BlogCategoryDataProvider()) { BlogCategory data = await dataProvider.GetItemAsync(blogCategory); if (data != null) { qargsHR = new { Title = data.Category.ToString().Truncate(80) } } ; } } return(new ModuleAction(this) { Url = Utility.UrlFor(typeof(RssController), nameof(RssController.RssFeed)), QueryArgs = qargs, QueryArgsHR = qargsHR, Image = await CustomIconAsync("RssFeed.png"), Style = ModuleAction.ActionStyleEnum.NewWindow, LinkText = this.__ResStr("rssLink", "RSS Feed"), MenuText = this.__ResStr("rssMenu", "RSS Feed"), Tooltip = this.__ResStr("rssTT", "Display the blog's RSS Feed"), Legend = this.__ResStr("rssLegend", "Displays the blog's RSS Feed"), Category = ModuleAction.ActionCategoryEnum.Read, Mode = ModuleAction.ActionModeEnum.Any, Location = ModuleAction.ActionLocationEnum.ModuleLinks, }); } }
public async Task <ActionResult> Summary() { //int category; //Manager.TryGetUrlArg<int>("BlogCategory", out category); BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> { new DataProviderSortInfo { Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending }, }; List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> { new DataProviderFilterInfo { Field = nameof(BlogEntry.Published), Operator = "==", Value = true }, }; //if (category != 0) // filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo { Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = category }); DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, Module.Entries, sort, filters); if (data.Data.Count == 0) { return(new EmptyResult()); } EntryDisplayModule dispMod = new EntryDisplayModule(); List <Entry> list = new List <Entry>(); foreach (BlogEntry d in data.Data) { ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(d.Identity); list.Add(new Entry(d, dispMod, viewAction)); } DisplayModel model = new DisplayModel() { BlogEntries = list, }; return(View(model)); } }
public async Task <ActionResult> CommentsDisplay(int?blogEntry) { int entryNum = blogEntry ?? 0; BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); DisplayModel model = new DisplayModel() { }; CommentEditModule editMod = new CommentEditModule(); using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) { BlogEntry entry = null; if (entryNum != 0) { entry = await entryDP.GetItemAsync(entryNum); } if (entry == null) { return(new EmptyResult()); } model.OpenForComments = entry.OpenForComments; } using (BlogCommentDataProvider commentDP = new BlogCommentDataProvider(entryNum)) { DataProviderGetRecords <BlogComment> comments = await commentDP.GetItemsAsync(0, 0, null, null); if (!model.OpenForComments && comments.Total == 0) { return(new EmptyResult()); } model.ShowGravatars = config.ShowGravatar; model.CanApprove = await Resource.ResourceAccess.IsResourceAuthorizedAsync(Info.Resource_AllowManageComments); model.CanRemove = await Resource.ResourceAccess.IsResourceAuthorizedAsync(Info.Resource_AllowManageComments); List <CommentData> list = new List <CommentData>(); foreach (BlogComment d in comments.Data) { ModuleAction editAction = await editMod.GetAction_EditAsync(Module.EditUrl, d.EntryIdentity, d.Identity); ModuleAction approveAction = await Module.GetAction_ApproveAsync(d.CategoryIdentity, d.Identity); ModuleAction removeAction = await Module.GetAction_RemoveAsync(d.CategoryIdentity, d.Identity); if (model.CanApprove || model.CanRemove) { list.Add(new CommentData(d, editAction, approveAction, removeAction)); } else { if (!d.Deleted && d.Approved) { list.Add(new CommentData(d, editAction, approveAction, removeAction)); } } } model.Comments = list; int pending = (from d in comments.Data where !d.Deleted && !d.Approved select d).Count(); model.PendingApproval = pending; int commentsTotal = (from c in comments.Data where !c.Deleted select c).Count(); // set a module title string title; if (commentsTotal > 0 && pending > 0) { if (commentsTotal > 1) { if (pending > 1) { title = this.__ResStr("commentsPs", "{0} Comments - {1} Comments Pending Approval", commentsTotal, pending); } else { title = this.__ResStr("commentsP", "{0} Comments - 1 Comment Pending Approval", commentsTotal); } } else { title = this.__ResStr("commentP", "1 Comment Pending Approval"); } } else { if (commentsTotal > 1) { title = this.__ResStr("comments", "{0} Comments", commentsTotal); } else if (commentsTotal == 1) { title = this.__ResStr("comment1", "1 Comment"); } else { title = this.__ResStr("comment0", "No Comments"); } } Module.Title = title; return(View(model)); } }
internal async Task UpdateDataAsync() { BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); GravatarsEnabled = config.ShowGravatar; }
// Windows RSS Publisher's Guide http://blogs.msdn.com/b/rssteam/archive/2005/08/02/publishersguide.aspx public async Task <ActionResult> RssFeed(int?blogCategory) { BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); if (!config.Feed) { throw new Error(this.__ResStr("noFeed", "The feed is no longer available")); } int categoryIdentity = blogCategory ?? 0; BlogCategory category = null; if (categoryIdentity != 0) { using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) { category = await categoryDP.GetItemAsync(categoryIdentity); if (!category.Syndicated) { throw new Error(this.__ResStr("noFeed", "The feed is no longer available")); } } } using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> { new DataProviderSortInfo { Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending }, }; List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> { new DataProviderFilterInfo { Field = nameof(BlogEntry.Published), Operator = "==", Value = true }, }; if (categoryIdentity != 0) { filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo { Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = categoryIdentity }); } DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, 0, sort, filters); string url = string.IsNullOrWhiteSpace(config.FeedMainUrl) ? Manager.CurrentSite.HomePageUrl : config.FeedMainUrl; List <SyndicationItem> items = new List <SyndicationItem>(); EntryDisplayModule dispMod = new EntryDisplayModule(); DateTime lastUpdated = DateTime.MinValue; foreach (BlogEntry blogEntry in data.Data) { if (categoryIdentity == 0) { using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) { category = await categoryDP.GetItemAsync(blogEntry.CategoryIdentity); if (!category.Syndicated) { continue; } } } ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(blogEntry.Identity); if (viewAction == null) { continue; } SyndicationItem sItem = new SyndicationItem(blogEntry.Title.ToString(), blogEntry.Text, new Uri(viewAction.GetCompleteUrl())); DateTime updDate = blogEntry.DateUpdated ?? blogEntry.DateCreated; sItem.LastUpdatedTime = updDate; if (!string.IsNullOrEmpty(category.SyndicationEmail)) { sItem.Authors.Add(new SyndicationPerson(category.SyndicationEmail)); } sItem.Categories.Add(new SyndicationCategory(category.Category.ToString())); if (!string.IsNullOrEmpty(category.SyndicationCopyright.ToString())) { sItem.Copyright = new TextSyndicationContent(category.SyndicationCopyright.ToString()); } sItem.PublishDate = blogEntry.DatePublished; if (!string.IsNullOrEmpty(blogEntry.DisplayableSummary)) { sItem.Summary = new TextSyndicationContent(blogEntry.DisplayableSummary); } lastUpdated = updDate > lastUpdated ? updDate : lastUpdated; items.Add(sItem); } SyndicationFeed feed; if (categoryIdentity != 0) { feed = new SyndicationFeed(category.Category.ToString(), category.Description.ToString(), new Uri(Manager.CurrentSite.MakeUrl(url)), items); } else { feed = new SyndicationFeed(config.FeedTitle, config.FeedSummary, new Uri(Manager.CurrentSite.MakeUrl(url)), items); } if (config.FeedImage != null) { feed.ImageUrl = new Uri(Manager.CurrentSite.MakeUrl(ImageHTML.FormatUrl(BlogConfigData.ImageType, null, config.FeedImage))); //$$$ caching issue } if (lastUpdated != DateTime.MinValue) { feed.LastUpdatedTime = lastUpdated; } return(new RssResult(feed)); } }
public async Task <ActionResult> Blog(DateTime?StartDate = null) { int category; Manager.TryGetUrlArg <int>("BlogCategory", out category); BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> { new DataProviderSortInfo { Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending }, }; List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> { new DataProviderFilterInfo { Field = nameof(BlogEntry.Published), Operator = "==", Value = true }, }; if (category != 0) { filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo { Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = category }); } DateTime sdShown = DateTime.MaxValue; if (StartDate != null) { sdShown = ((DateTime)StartDate).Date; if (sdShown < DateTime.UtcNow) { filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo { Field = nameof(BlogEntry.DatePublished), Operator = "<=", Value = sdShown }); } else { sdShown = DateTime.MaxValue; } } DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, config.Entries, sort, filters); if (data.Data.Count == 0) { return(new EmptyResult()); } string rssUrl = string.IsNullOrWhiteSpace(config.FeedMainUrl) ? Manager.CurrentSite.HomePageUrl : config.FeedMainUrl; Manager.LinkAltManager.AddLinkAltTag(AreaRegistration.CurrentPackage.AreaName, "application/rss+xml", config.FeedTitle, rssUrl); EntryEditModule editMod = new EntryEditModule(); EntryDisplayModule dispMod = new EntryDisplayModule(); List <Entry> list = new List <Entry>(); foreach (BlogEntry d in data.Data) { ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(d.Identity, ReadMore : d.Summary != d.Text); ModuleAction editAction = await editMod.GetAction_EditAsync(null, d.Identity); list.Add(new Entry(d, editMod, dispMod, editAction, viewAction)); } DisplayModel model = new DisplayModel() { BlogEntries = list, CategoryIdentity = category, StartDate = sdShown == DateTime.MaxValue ? null : (DateTime?)sdShown, }; return(View(model)); } }