public async Task <ActionResult> EntryEdit_Partial(EditModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { BlogEntry data = await dataProvider.GetItemAsync(model.Identity); if (data == null) { throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found"), model.Identity); } // save updated item data = model.GetData(data); // merge new data into original model.SetData(data); // and all the data back into model for final display UpdateStatusEnum status = await dataProvider.UpdateItemAsync(data); if (status != UpdateStatusEnum.OK) { throw new Error(this.__ResStr("errSaving", "An unexpected error occurred saving the blog entry - {0}", status)); } return(FormProcessed(model, this.__ResStr("okSaved", "Blog entry saved"))); } }
public async Task <ActionResult> CommentAdd(int?blogEntry) { int entryNum = blogEntry ?? 0; int blogCategory; using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) { BlogEntry data = null; if (entryNum != 0) { data = await entryDP.GetItemAsync(entryNum); } if (data == null) { return(new EmptyResult()); } blogCategory = data.CategoryIdentity; if (!data.OpenForComments) { if (data.Comments == 0) { return(new EmptyResult()); } } } AddModel model = new AddModel { CategoryIdentity = blogCategory, EntryIdentity = entryNum, Captcha = new RecaptchaV2Data(), }; await model.UpdateDataAsync(); return(View(model)); }
public async Task <ActionResult> CategoryHeader(int?blogEntry) { int category; Manager.TryGetUrlArg <int>("BlogCategory", out category); int entry = (int)(blogEntry ?? 0); if (entry != 0) { using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) { BlogEntry data = await entryDP.GetItemAsync(entry); if (data != null) { category = data.CategoryIdentity; } } } if (category != 0) { using (BlogCategoryDataProvider dataProvider = new BlogCategoryDataProvider()) { BlogCategory data = await dataProvider.GetItemAsync(category); if (data != null) { DisplayModel model = new DisplayModel(); model.SetData(data); Module.Title = data.Category.ToString(); return(View(model)); } } } return(new EmptyResult()); }
public async Task <ActionResult> EntryDisplay(int?blogEntry) { int entryNum = blogEntry ?? 0; using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { BlogEntry data = null; if (entryNum != 0) { data = await dataProvider.GetItemAsync(entryNum); } if (data == null) { MarkNotFound(); return(View("NotFound")); } Manager.CurrentPage.EvaluatedCanonicalUrl = await BlogConfigData.GetEntryCanonicalNameAsync(entryNum); if (!string.IsNullOrWhiteSpace(data.Keywords)) { Manager.CurrentPage.Keywords = data.Keywords; Manager.MetatagsManager.AddMetatag("news_keywords", data.Keywords.ToString()); } Manager.CurrentPage.Description = data.Title; Manager.PageTitle = data.Title; DisplayModel model = new DisplayModel(); model.SetData(data); Module.Title = data.Title; return(View(model)); } }
private GridDefinition GetGridModel(int blogCategory) { return(new GridDefinition { ModuleGuid = Module.ModuleGuid, SettingsModuleGuid = Module.PermanentGuid, RecordType = typeof(BrowseItem), AjaxUrl = GetActionUrl(nameof(EntriesBrowse_GridData)), ExtraData = new BrowseItem.ExtraData { BlogCategory = blogCategory }, DirectDataAsync = async(int skip, int take, List <DataProviderSortInfo> sort, List <DataProviderFilterInfo> filters) => { // filter by category if (blogCategory != 0) { filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo { Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = blogCategory, }); } using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) { using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) { DataProviderGetRecords <BlogEntry> browseItems = await entryDP.GetItemsAsync(skip, take, sort, filters); return new DataSourceResult { Data = (from s in browseItems.Data select new BrowseItem(Module, categoryDP, s)).ToList <object>(), Total = browseItems.Total }; } } }, }); }
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> Remove(int blogEntry) { using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { await dataProvider.RemoveItemAsync(blogEntry); return(Reload(null, Reload: ReloadEnum.ModuleParts)); } }
private async Task <bool> TestOpenForCommentsAsync(int blogEntry) { using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) { BlogEntry ent = await entryDP.GetItemAsync(blogEntry); if (ent == null) { throw new InternalError("Entry with id {0} not found", blogEntry); } return(ent.OpenForComments); } }
public async Task <ActionResult> EntryAdd_Partial(AddModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { if (!await dataProvider.AddItemAsync(model.GetData())) { throw new Error(this.__ResStr("alreadyExists", "An error occurred adding this new blog entry")); } return(FormProcessed(model, this.__ResStr("okSaved", "New blog entry saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule)); } }
public async Task <ActionResult> EntryEdit(int blogEntry) { using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) { EditModel model = new EditModel { }; BlogEntry data = await dataProvider.GetItemAsync(blogEntry); if (data == null) { throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found"), blogEntry); } model.SetData(data); Module.Title = data.Title; return(View(model)); } }
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)); } }
/// <summary> /// Create a blog based news site map for the current site. /// </summary> public async Task CreateAsync(bool slow = false) { string file = GetTempFile(); await FileSystem.FileSystemProvider.DeleteFileAsync(file); // header await FileSystem.FileSystemProvider.AppendAllTextAsync(file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n" + "<urlset xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns =\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\" >\r\n" ); // Dynamic Urls in types DynamicUrlsImpl dynamicUrls = new DynamicUrlsImpl(); List <Type> types = dynamicUrls.GetDynamicUrlTypes(); foreach (Type type in types) { object obj = Activator.CreateInstance(type); ISiteMapDynamicUrls iSiteMap = obj as ISiteMapDynamicUrls; if (iSiteMap != null) { BlogEntryDataProvider blogEntryDP = obj as BlogEntryDataProvider; if (blogEntryDP != null) // limit to blog entries { await iSiteMap.FindDynamicUrlsAsync(AddNewsSiteMapPageAsync, ValidForNewsSiteMap); } } } // end await FileSystem.FileSystemProvider.AppendAllTextAsync(file, "</urlset>\r\n" ); string finalFile = GetFile(); await FileSystem.FileSystemProvider.DeleteFileAsync(finalFile); await FileSystem.FileSystemProvider.MoveFileAsync(file, finalFile); }
public async Task <ActionResult> Archive(int?blogCategory) { int category = (int)(blogCategory ?? 0); BlogModule blogMod = new BlogModule(); DisplayModel model = new DisplayModel() { }; using (BlogEntryDataProvider entryDP = 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 }); } int year = 0, month = 0, count = 0; int totalRecs = 0, start = 0, incr = 100; for ( ; ;) { DataProviderGetRecords <BlogEntry> data = await entryDP.GetItemsAsync(start, incr, sort, filters); if (data.Data.Count == 0) { return(new EmptyResult()); } foreach (BlogEntry entry in data.Data) { if (entry.DatePublished.Month != month || entry.DatePublished.Year != year) { if (count > 0) { DateTime d = new DateTime(year, month, 1).AddMonths(1).AddSeconds(-1); model.Actions.New(await blogMod.GetAction_BlogAsync(null, category, StartDate: d, Count: count)); count = 0; } month = entry.DatePublished.Month; year = entry.DatePublished.Year; } ++count; } start += incr; if (start >= totalRecs) { if (count > 0) { DateTime d = new DateTime(year, month, 1).AddMonths(1).AddSeconds(-1); model.Actions.New(await blogMod.GetAction_BlogAsync(null, category, StartDate: d, Count: count)); } break; } } 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)); } }
// 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)); } }