/// <summary> /// Add new post /// </summary> /// <param name="detail">Post</param> /// <returns>Saved post with new ID</returns> public PostDetail Add(PostDetail detail) { if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.CreateNewPosts)) throw new System.UnauthorizedAccessException(); var post = new Post(); Save(post, detail); return ToJsonDetail(post); }
/// <summary> /// Add new post /// </summary> /// <param name="detail">Post</param> /// <returns>Saved post with new ID</returns> public PostDetail Add(PostDetail detail) { if (!Security.IsAuthorizedTo(Rights.CreateNewPosts)) throw new UnauthorizedAccessException(); var post = new Post(); Save(post, detail); return Json.GetPostDetail(post); }
/// <summary> /// Update post /// </summary> /// <param name="detail">Post to update</param> /// <param name="action">Action</param> /// <returns>True on success</returns> public bool Update(PostDetail detail, string action) { if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.EditOwnPosts)) throw new System.UnauthorizedAccessException(); var post = (from p in Post.Posts.ToList() where p.Id == detail.Id select p).FirstOrDefault(); if (post != null) { if (action == "publish") { post.IsPublished = true; post.DateModified = DateTime.Now; post.Save(); } else if (action == "unpublish") { post.IsPublished = false; post.DateModified = DateTime.Now; post.Save(); } else { Save(post, detail); } return true; } return false; }
static void Save(Post post, PostDetail detail) { post.Title = detail.Title; post.Author = detail.Author; post.Description = GetDescription(detail.Description, detail.Content); post.Content = detail.Content; post.IsPublished = detail.IsPublished; post.HasCommentsEnabled = detail.HasCommentsEnabled; post.IsDeleted = detail.IsDeleted; post.DateCreated = DateTime.ParseExact(detail.DateCreated, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); // if changing slug, should be unique if (post.Slug != detail.Slug) post.Slug = GetUniqueSlug(detail.Slug); UpdatePostCategories(post, detail.Categories); UpdatePostTags(post, FilterTags(detail.Tags)); post.Save(); }
public bool Update(PostDetail post, string action) { return true; }
public PostDetail Add(PostDetail post) { return new PostDetail() { Id = Guid.NewGuid() }; }
static void Save(Post post, PostDetail detail) { post.Title = detail.Title; //post.BottomLineForConstribution = detail.BottomLineForConstribution; post.Author = detail.Author; //if we can't find author anymore, at least their userId stays in tact so we can pay them. if (detail.Author != ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN) { var user = Membership.GetUser(detail.Author); if (user != null) post.AuthorUserId = (Guid)user.ProviderUserKey; var Member = RDN.Library.Cache.SiteCache.GetPublicMemberFull(post.Author); if (Member != null) { post.AuthorDerbyName = Member.DerbyName; post.AuthorDerbyId = Member.MemberId; } } else { post.AuthorUserId = new Guid("885e1e16-0f8e-44a8-bb36-4fce12ef6360"); } post.Description = detail.Description; post.Content = detail.Content; if (String.IsNullOrEmpty(post.Content)) post.Content = "Please Add Content"; post.Slug = detail.Slug; post.IsPublished = detail.IsPublished; post.HasCommentsEnabled = detail.HasCommentsEnabled; post.IsDeleted = detail.IsDeleted; post.IsSavedForApproval = detail.IsSavedForApproval; post.DisabledAutoPosting = detail.DisabledAutoPosting; post.DisablePaymentsForPost = detail.DisablePaymentsForPost; DateTime posted = DateTime.UtcNow; DateTime.TryParseExact(detail.DateCreated, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out posted); post.DateCreated = posted; if (!String.IsNullOrEmpty(detail.InitialImageUrl)) post.InitialImageUrl = detail.InitialImageUrl.Replace("\"", ""); if (!String.IsNullOrEmpty(detail.MainImageUrl)) post.MainImageUrl = detail.MainImageUrl.Replace("\"", ""); UpdatePostCategories(post, detail.Categories); UpdatePostTags(post, FilterTags(detail.Tags)); post.Save(); PostManager.SavePostToDb(post.Id, post.DisabledAutoPosting, post.DisablePaymentsForPost); }
/// <summary> /// Update post /// </summary> /// <param name="detail">Post to update</param> /// <param name="action">Action</param> /// <returns>True on success</returns> public bool Update(PostDetail detail, string action) { try { if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.EditOwnPosts)) throw new System.UnauthorizedAccessException(); var post = (from p in Post.Posts.ToList() where p.Id == detail.Id select p).FirstOrDefault(); if (post != null) { if (action == "publishSelf") { detail.IsPublished = true; post.DateModified = DateTime.Now; Save(post, detail); SendEmailAboutNewPostPublishedToAuthor(post.Author, post.AbsoluteLink.ToString(), post.DateCreated.ToUniversalTime()); SendEmailAboutNewPostPublishedToChiefs(post.AbsoluteLink.ToString(), post.DateCreated); } if (action == "publish") { post.IsPublished = true; post.DateModified = DateTime.Now; //publish to facebook. post.Save(); SendEmailAboutNewPostPublishedToAuthor(post.Author, post.AbsoluteLink.ToString(), post.DateCreated.ToUniversalTime()); SendEmailAboutNewPostPublishedToChiefs(post.AbsoluteLink.ToString(), post.DateCreated); } else if (action == "unpublish") { post.IsPublished = false; post.DateModified = DateTime.Now; post.Save(); } else if (action == "unpublishSelf") { detail.IsPublished = false; post.DateModified = DateTime.Now; Save(post, detail); } else if (action == "submitForApproval") { detail.IsSavedForApproval = true; post.DateModified = DateTime.Now; SendEmailAboutNewPostWaitingApprovalChiefs(post.AbsoluteLink.ToString()); Save(post, detail); } else { Save(post, detail); } return true; } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, GetType()); } return false; }
/// <summary> /// Add new post /// </summary> /// <param name="detail">Post</param> /// <returns>Saved post with new ID</returns> public PostDetail Add(PostDetail detail, string action) { var post = new Post(); try { if (action == "RNFeedSubmittal") { detail.IsSavedForApproval = true; post.DateModified = DateTime.Now; Save(post, detail); SendEmailAboutNewPostWaitingApprovalChiefs(post.AbsoluteLink.ToString()); return ToJsonDetail(post); } if (action == "DNNSubmittal") { detail.IsSavedForApproval = true; post.DateModified = DateTime.Now; Save(post, detail); return ToJsonDetail(post); } if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.CreateNewPosts)) throw new System.UnauthorizedAccessException(); if (action == "publishSelf") { detail.IsPublished = true; post.DateModified = DateTime.Now; Save(post, detail); SendEmailAboutNewPostPublishedToAuthor(post.Author, post.AbsoluteLink.ToString(), post.DateCreated.ToUniversalTime()); SendEmailAboutNewPostPublishedToChiefs(post.AbsoluteLink.ToString(), post.DateCreated); } if (action == "publish") { post.IsPublished = true; post.DateModified = DateTime.Now; //publish to facebook. Save(post, detail); SendEmailAboutNewPostPublishedToAuthor(post.Author, post.AbsoluteLink.ToString(), post.DateCreated.ToUniversalTime()); SendEmailAboutNewPostPublishedToChiefs(post.AbsoluteLink.ToString(), post.DateCreated); } else if (action == "unpublish") { post.IsPublished = false; post.DateModified = DateTime.Now; Save(post, detail); } else if (action == "unpublishSelf") { detail.IsPublished = false; post.DateModified = DateTime.Now; Save(post, detail); } else if (action == "submitForApproval") { detail.IsSavedForApproval = true; post.DateModified = DateTime.Now; Save(post, detail); SendEmailAboutNewPostWaitingApprovalChiefs(post.AbsoluteLink.ToString()); } else { Save(post, detail); } } catch (Exception e) { ErrorDatabaseManager.AddException(e, GetType()); } return ToJsonDetail(post); }
public static bool ScanRSSFeeds() { var fact = RSSFactory.Initilize(); var feeds = fact.PullAllFeedsToScan(10000, 0); for (int i = 0; i < feeds.Count; i++) { int postCount = 0; try { if (!String.IsNullOrEmpty(feeds[i].RSSUrl)) { XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; XmlReader reader = XmlReader.Create(feeds[i].RSSUrl, settings); SyndicationFeed feed = SyndicationFeed.Load(reader); string authorName = ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN; if (!String.IsNullOrEmpty(feeds[i].AuthorUserName)) { authorName = feeds[i].AuthorUserName; } var latestPosts = feed.Items.Where(x => x.PublishDate >= feeds[i].LastChecked).ToList(); for (int j = 0; j < latestPosts.Count; j++) { try { PostDetail detail = new PostDetail(); var p = latestPosts[j]; detail.Author = authorName; foreach (SyndicationElementExtension ext in p.ElementExtensions) { if (ext.GetObject<XElement>().Name.LocalName == "encoded") detail.Content = ext.GetObject<XElement>().Value; } if (p.Content != null) detail.Content = (p.Content as TextSyndicationContent).Text; if (p.Summary != null) { detail.Description = (p.Summary as TextSyndicationContent).Text; if (String.IsNullOrEmpty(detail.Content)) detail.Content = detail.Description; } detail.Title = p.Title.Text; detail.DateCreated = DateTime.UtcNow.ToString(); detail.IsSavedForApproval = true; detail.Tags = new List<TagItem>(); detail.Categories = new List<CategoryItem>(); detail.HasCommentsEnabled = true; foreach (var cat in feeds[i].Categories) { detail.Categories.Add(new CategoryItem() { Id = cat.CategoryRNId, Title = Category.GetCategory(cat.CategoryRNId).Title }); } foreach (var tag in feeds[i].Tags) { detail.Tags.Add(new TagItem() { TagName = tag.TagName }); } detail.MainImageUrl = feeds[i].MainImageUrl; detail.InitialImageUrl = feeds[i].InitialImageUrl; detail.FeedId = feeds[i].FeedId; PostRepository repo = new PostRepository(); detail = repo.Add(detail, "RNFeedSubmittal"); PostManager.AddPostForFeed(detail.Id, feeds[i].FeedId); postCount += 1; } catch (Exception exception) { } } } } catch (Exception exception) { if (!String.IsNullOrEmpty(exception.Message) && !exception.Message.Contains("The operation has timed out") && !exception.Message.Contains(@"c:\windows\system32\inetsrv\NA") && !exception.Message.Contains("Unable to connect to the remote serve") && !exception.Message.Contains("remote name could not be resolved")) ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: feeds[i].RSSUrl); } fact.FinishFeedPolling(feeds[i].FeedId, postCount); } return true; }
public void ScanAllPages() { ILogger log = LoggerManager.GetLogger(GetType().Assembly, this.GetType()); for (int i = 2528; i < 7776; i++) { log.Log(GetType(), Level.Info, i, null); try { WebClient client = new WebClient(); string html = client.DownloadString("http://www.derbynews.net/?p=" + i); HtmlDocument doc = new HtmlDocument(); //doc.Load("http://www.derbynews.net/?p=" + i); doc.LoadHtml(html); var content = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'blog-wrapper')]"); if (content != null) { if (!String.IsNullOrEmpty(content.InnerHtml)) { var header = doc.DocumentNode.SelectSingleNode("//h2[contains(@class, 'post-header')]"); PostDetail detail = new PostDetail(); detail.IsSavedForApproval = true; detail.Tags = new List<TagItem>(); detail.Title = header.InnerText.Replace("’", "").Replace("&",""); detail.Author = ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN; detail.Categories = new List<CategoryItem>(); detail.HasCommentsEnabled = true; int imgNumber = 0; var images = doc.DocumentNode.SelectNodes("//img"); if (images != null) { foreach (var image in images) { try { string src = image.Attributes["src"].Value; log.Log(GetType(), Level.Info, src, null); if (!String.IsNullOrEmpty(src) && !src.Contains("gravatar") && !src.Contains("http://scontent-a.cdninstagram") && !src.Contains("disquscdn")) { WebClient dlFile = new WebClient(); dlFile.DownloadFile(src, HttpContext.Current.Server.MapPath(BlogService.GetDirectory("/").FullPath + "/DNNImages/" + i + "-" + imgNumber + VirtualPathUtility.GetExtension(src))); //dlFile.DownloadFile(src, "C:/Personal/" + i + "-" + imgNumber + VirtualPathUtility.GetExtension(src)); } var newNodeStr = "<!-- IMG[" + i + "-" + imgNumber + "] -->"; var newNode = HtmlNode.CreateNode(newNodeStr); doc.DocumentNode.InnerHtml = doc.DocumentNode.InnerHtml.Replace(image.OuterHtml, newNode.InnerHtml); //image.Remove(); } catch (Exception exception) { } } } var mainContent = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'main-content')]"); detail.Content = mainContent.InnerHtml; var date = doc.DocumentNode.SelectSingleNode("//span[contains(@class, 'date-span')]"); //detail.DateCreated = date.InnerText.Replace("\n", "").Replace("\t", "").Trim(); var dateLink = date.SelectSingleNode("a"); DateTime dateCre = DateTime.UtcNow; var datePulled = dateLink.InnerText; var split = datePulled.Split(' '); string day = split[0]; day = day.Replace("rd", "").Replace("th", "").Replace("nd", "").Replace("st", ""); datePulled = day + " " + split[1] + " " + split[2]; DateTime.TryParse(datePulled, out dateCre); //if (DateTime.TryParse(datePulled, "dd MMMM yyyy", DateTimeStyles.None, out dateCre)) ; detail.DateCreated = dateCre.ToString("yyyy-MM-dd HH:mm"); var authorForDNN = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'author-bio-content')]"); var dnnAuthorName = authorForDNN.SelectSingleNode("h4"); detail.BottomLineForConstribution = "By " + dnnAuthorName.InnerText + " for Derby News Network"; var tagCloud = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'tagcloud')]"); var tags = tagCloud.SelectNodes("a"); if (tags != null) foreach (var tag in tags) { detail.Tags.Add(new TagItem() { TagName = tag.InnerText }); } detail.Tags.Add(new TagItem() { TagName = "Derby News Network" }); detail.MainImageUrl = "http://rollinnews.com/FILES%2f2014%2f09%2f11%2fDerby-News-Network.jpg.axdx"; detail.InitialImageUrl = "http://rollinnews.com/FILES%2f2014%2f09%2f11%2fDerby-News-Network1.jpg.axdx"; PostRepository repo = new PostRepository(); detail = repo.Add(detail, "DNNSubmittal"); } } } catch (Exception exception) { log.Log(GetType(), Level.Error, "Error occured", exception); } } }