Example #1
0
        public virtual VirtualPath EntryUrl(IEntryIdentity entry, Blog entryBlog)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }
            if (entry.PostType == PostType.None)
            {
                throw new ArgumentException(Resources.Argument_EntryMustHaveValidPostType, "entry");
            }

            if (entry.Id.IsNull())
            {
                return(null);
            }

            string routeName;
            var    routeValues = new RouteValueDictionary();

            if (entry.PostType == PostType.BlogPost)
            {
#if DEBUG
                var blogEntry = entry as Entry;
                if (blogEntry != null && blogEntry.IsActive && blogEntry.DateSyndicated.Year == 1)
                {
                    throw new InvalidOperationException("DateSyndicated was not properly set.");
                }
#endif
                routeValues.Add("year", entry.DateSyndicated.ToString("yyyy", CultureInfo.InvariantCulture));
                routeValues.Add("month", entry.DateSyndicated.ToString("MM", CultureInfo.InvariantCulture));
                routeValues.Add("day", entry.DateSyndicated.ToString("dd", CultureInfo.InvariantCulture));
                routeName = "entry-";
            }
            else
            {
                routeName = "article-";
            }

            if (string.IsNullOrEmpty(entry.EntryName))
            {
                routeValues.Add("id", entry.Id);
                routeName += "by-id";
            }
            else
            {
                routeValues.Add("slug", entry.EntryName);
                routeName += "by-slug";
            }
            if (entryBlog != null)
            {
                routeValues.Add("subfolder", entryBlog.Subfolder);
            }

            VirtualPathData virtualPath = Routes.GetVirtualPath(RequestContext, routeName, routeValues);
            if (virtualPath != null)
            {
                return(virtualPath.VirtualPath);
            }
            return(null);
        }
        private void CreateTrackbackAndSendResponse(ISubtextContext subtextContext, IEntryIdentity entry, int entryId)
        {
            HttpContextBase context  = subtextContext.RequestContext.HttpContext;
            string          title    = SafeParam(context, "title");
            string          excerpt  = SafeParam(context, "excerpt");
            string          urlText  = SafeParam(context, "url");
            string          blogName = SafeParam(context, "blog_name");

            Uri url = urlText.ParseUri();

            if (url == null)
            {
                SendTrackbackResponse(context, 1, Resources.TrackbackResponse_NoUrl);
                return;
            }

            if (entry == null ||
                !IsSourceVerification(url,
                                      subtextContext.UrlHelper.EntryUrl(entry).ToFullyQualifiedUrl(subtextContext.Blog)))
            {
                SendTrackbackResponse(context, 2,
                                      String.Format(CultureInfo.InvariantCulture,
                                                    Resources.TrackbackResponse_NoRelevantLink, url));
                return;
            }

            var trackback = new Trackback(entryId, title, url, blogName, excerpt, Blog.TimeZone.Now);
            ICommentSpamService feedbackService = null;
            Blog blog = subtextContext.Blog;

            if (blog.FeedbackSpamServiceEnabled)
            {
                feedbackService = new AkismetSpamService(blog.FeedbackSpamServiceKey, blog, null, Url);
            }
            var commentService = new CommentService(SubtextContext, new CommentFilter(SubtextContext, feedbackService));

            commentService.Create(trackback, true /*runFilters*/);
            //TODO: Create this using IoC container
            var emailService = new EmailService(EmailProvider.Instance(), new EmbeddedTemplateEngine(), subtextContext);

            emailService.EmailCommentToBlogAuthor(trackback);
        }
Example #3
0
        public virtual VirtualPath EntryUrl(IEntryIdentity entry, Blog entryBlog)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }
            if (entry.PostType == PostType.None)
            {
                throw new ArgumentException(Resources.Argument_EntryMustHaveValidPostType, "entry");
            }

            if (entry.Id.IsNull())
            {
                return null;
            }

            string routeName;
            var routeValues = new RouteValueDictionary();

            if (entry.PostType == PostType.BlogPost)
            {
            #if DEBUG
                var blogEntry = entry as Entry;
                if (blogEntry != null && blogEntry.IsActive && blogEntry.DateSyndicated.Year == 1)
                {
                    throw new InvalidOperationException("DateSyndicated was not properly set.");
                }
            #endif
                routeValues.Add("year", entry.DateSyndicated.ToString("yyyy", CultureInfo.InvariantCulture));
                routeValues.Add("month", entry.DateSyndicated.ToString("MM", CultureInfo.InvariantCulture));
                routeValues.Add("day", entry.DateSyndicated.ToString("dd", CultureInfo.InvariantCulture));
                routeName = "entry-";
            }
            else
            {
                routeName = "article-";
            }

            if (string.IsNullOrEmpty(entry.EntryName))
            {
                routeValues.Add("id", entry.Id);
                routeName += "by-id";
            }
            else
            {
                routeValues.Add("slug", entry.EntryName);
                routeName += "by-slug";
            }
            if (entryBlog != null)
            {
                routeValues.Add("subfolder", entryBlog.Subfolder);
            }

            VirtualPathData virtualPath = Routes.GetVirtualPath(RequestContext, routeName, routeValues);
            if (virtualPath != null)
            {
                return virtualPath.VirtualPath;
            }
            return null;
        }
Example #4
0
 public virtual VirtualPath EntryUrl(IEntryIdentity entry)
 {
     return EntryUrl(entry, null);
 }
        private static Entry CreateWelcomeBlogPost(ISubtextContext context, Blog blog, IEntryPublisher entryPublisher, AdminUrlHelper adminUrlHelper, IEntryIdentity article)
        {
            string body = ScriptHelper.UnpackEmbeddedScriptAsString("WelcomePost.htm");
            string articleUrl = context.UrlHelper.EntryUrl(article);
            body = String.Format(body, articleUrl, adminUrlHelper.Home(), context.UrlHelper.HostAdminUrl("default.aspx"));

            var entry = new Entry(PostType.BlogPost)
            {
                Title = "Welcome to Subtext!",
                EntryName = "welcome-to-subtext",
                BlogId = blog.Id,
                Author = blog.Author,
                Body = body,
                DateCreated = DateTime.Now,
                DateModified = DateTime.Now,
                DateSyndicated = DateTime.Now,
                IsActive = true,
                IncludeInMainSyndication = true,
                DisplayOnHomePage = true,
                AllowComments = true
            };

            entryPublisher.Publish(entry);
            return entry;
        }
Example #6
0
 public virtual VirtualPath EntryUrl(IEntryIdentity entry)
 {
     return(EntryUrl(entry, null));
 }
Example #7
0
        private static Entry CreateWelcomeBlogPost(ISubtextContext context, Blog blog, IEntryPublisher entryPublisher, AdminUrlHelper adminUrlHelper, IEntryIdentity article)
        {
            string body       = ScriptHelper.UnpackEmbeddedScriptAsString("WelcomePost.htm");
            string articleUrl = context.UrlHelper.EntryUrl(article);

            body = String.Format(body, articleUrl, adminUrlHelper.Home(), context.UrlHelper.HostAdminUrl("default.aspx"));

            var entry = new Entry(PostType.BlogPost)
            {
                Title                    = "Welcome to Subtext!",
                EntryName                = "welcome-to-subtext",
                BlogId                   = blog.Id,
                Author                   = blog.Author,
                Body                     = body,
                DateCreated              = DateTime.Now,
                DateModified             = DateTime.Now,
                DateSyndicated           = DateTime.Now,
                IsActive                 = true,
                IncludeInMainSyndication = true,
                DisplayOnHomePage        = true,
                AllowComments            = true
            };

            entryPublisher.Publish(entry);
            return(entry);
        }
Example #8
0
        private void CreateTrackbackAndSendResponse(ISubtextContext subtextContext, IEntryIdentity entry, int entryId)
        {
            HttpContextBase context = subtextContext.RequestContext.HttpContext;
            string title = SafeParam(context, "title");
            string excerpt = SafeParam(context, "excerpt");
            string urlText = SafeParam(context, "url");
            string blogName = SafeParam(context, "blog_name");

            Uri url = urlText.ParseUri();
            if (url == null)
            {
                SendTrackbackResponse(context, 1, Resources.TrackbackResponse_NoUrl);
                return;
            }

            if (entry == null ||
               !IsSourceVerification(url,
                                     subtextContext.UrlHelper.EntryUrl(entry).ToFullyQualifiedUrl(subtextContext.Blog)))
            {
                SendTrackbackResponse(context, 2,
                                      String.Format(CultureInfo.InvariantCulture,
                                                    Resources.TrackbackResponse_NoRelevantLink, url));
                return;
            }

            var trackback = new Trackback(entryId, title, url, blogName, excerpt);
            ICommentSpamService feedbackService = null;
            Blog blog = subtextContext.Blog;
            if (blog.FeedbackSpamServiceEnabled)
            {
                feedbackService = new AkismetSpamService(blog.FeedbackSpamServiceKey, blog, null, Url);
            }
            var commentService = new CommentService(SubtextContext, new CommentFilter(SubtextContext, feedbackService));
            commentService.Create(trackback, true/*runFilters*/);
            //TODO: Create this using IoC container
            var emailService = new EmailService(EmailProvider.Instance(), new EmbeddedTemplateEngine(), subtextContext);
            emailService.EmailCommentToBlogAuthor(trackback);
        }