예제 #1
0
        /// <summary>
        /// Posts trackbacks and pingbacks for the specified entry.
        /// </summary>
        public static void Run(Entry entry, Blog blog, BlogUrlHelper urlHelper)
        {
            if (!blog.TrackbacksEnabled)
            {
                return;
            }

            if (!Config.Settings.Tracking.EnablePingBacks && !Config.Settings.Tracking.EnableTrackBacks)
            {
                return;
            }

            if (entry != null)
            {
                VirtualPath blogUrl = urlHelper.BlogUrl();
                Uri fullyQualifiedUrl = blogUrl.ToFullyQualifiedUrl(blog);

                var notify = new Notifier
                {
                    FullyQualifiedUrl = fullyQualifiedUrl.AbsoluteUri,
                    BlogName = blog.Title,
                    Title = entry.Title,
                    PostUrl = urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(blog),
                    Description = entry.HasDescription ? entry.Description : entry.Title,
                    Text = entry.Body
                };

                //This could take a while, do it on another thread
                ThreadHelper.FireAndForget(notify.Notify, "Exception occured while attempting trackback notification");
            }
        }
예제 #2
0
        public ActionResult Index()
        {
            var searchUrl = UrlHelper.SearchPageUrl().ToFullyQualifiedUrl(Blog);

            string manifestXml = string.Format(ManifestXml, Blog.Title, Blog.SubTitle, Blog.Email, searchUrl);

            return(Content(manifestXml, "application/opensearchdescription+xml"));
        }
예제 #3
0
        //Text to insert into a file with pingback service location
        public static string GetPingbackTag(BlogUrlHelper urlHelper, Entry entry)
        {
            VirtualPath blogUrl = urlHelper.BlogUrl();
            Uri absoluteUrl = blogUrl.ToFullyQualifiedUrl(entry.Blog);

            return string.Format(CultureInfo.InvariantCulture,
                "<link rel=\"pingback\" href=\"{0}Services/Pingback/{1}.aspx\"></link>",
                absoluteUrl.AbsoluteUri,
                entry.Id);
        }
예제 #4
0
        //Body of text to insert into a post with Trackback
        public static string TrackBackTag(Entry entry, Blog blog, BlogUrlHelper urlHelper)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            Uri entryUrl = urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(blog);
            return String.Format(CultureInfo.InvariantCulture, Resources.TrackbackTag, entryUrl, entryUrl, entry.Title,
                                 urlHelper.BlogUrl(), entry.Id.ToString(CultureInfo.InvariantCulture));
        }
예제 #5
0
 public AkismetSpamService(string apiKey, Blog blog, AkismetClient akismetClient, BlogUrlHelper urlHelper)
 {
     _blog = blog;
     _akismet = akismetClient ?? new AkismetClient(apiKey, urlHelper.BlogUrl().ToFullyQualifiedUrl(blog));
     IWebProxy proxy = HttpHelper.GetProxy();
     if (proxy != null)
     {
         _akismet.Proxy = proxy;
     }
     _urlHelper = urlHelper ?? new BlogUrlHelper(null, null);
 }
예제 #6
0
 public SubtextContext(Blog blog, RequestContext requestContext, BlogUrlHelper urlHelper, ObjectRepository repository,
                       IPrincipal user, ICache cache, IDependencyResolver serviceLocator)
 {
     Blog = blog;
     RequestContext = requestContext;
     UrlHelper = urlHelper;
     Repository = repository;
     User = user ?? requestContext.HttpContext.User;
     Cache = cache ?? new SubtextCache(requestContext.HttpContext.Cache);
     ServiceLocator = serviceLocator;
 }
예제 #7
0
        public virtual void Write(IEnumerable<Blog> blogs, TextWriter writer, BlogUrlHelper urlHelper)
        {
            var settings = new XmlWriterSettings
            {
                Encoding = Encoding.UTF8,
                OmitXmlDeclaration = true,
                ConformanceLevel = ConformanceLevel.Document,
                Indent = true,
                IndentChars = ("\t")
            };

            using(XmlWriter xmlWriter = XmlWriter.Create(writer, settings))
            {
                if(xmlWriter != null)
                {
                    xmlWriter.WriteStartDocument();

                    //OPML ROOT
                    xmlWriter.WriteStartElement("opml");
                    xmlWriter.WriteAttributeString("version", "1.0");
                    xmlWriter.WriteStartElement("head");
                    xmlWriter.WriteStartElement("title");
                    xmlWriter.WriteString(ConfigurationManager.AppSettings["AggregateTitle"]);
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteEndElement();
                    //Body
                    xmlWriter.WriteStartElement("body");

                    xmlWriter.WriteStartElement("outline");
                    xmlWriter.WriteAttributeString("text", ConfigurationManager.AppSettings["AggregateTitle"] + " Feeds");
                    foreach(Blog blog in blogs)
                    {
                        xmlWriter.WriteStartElement("outline");

                        string title = blog.Title;
                        string xmlUrl = urlHelper.RssUrl(blog).ToString();

                        xmlWriter.WriteAttributeString("type", "rss");
                        xmlWriter.WriteAttributeString("text", title);
                        xmlWriter.WriteAttributeString("xmlUrl", xmlUrl);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement(); //outline
                    xmlWriter.WriteEndElement(); //body
                    xmlWriter.WriteEndElement(); //opml
                    xmlWriter.Flush();
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Converts a LinkCategoryCollection into a single LinkCategory with its own LinkCollection.
        /// </summary>
        public static LinkCategory MergeLinkCategoriesIntoSingleLinkCategory(string title, CategoryType catType,
                                                                             IEnumerable<LinkCategory> links,
                                                                             BlogUrlHelper urlHelper, Blog blog)
        {
            if (!links.IsNullOrEmpty())
            {
                var mergedLinkCategory = new LinkCategory { Title = title };

                var merged = from linkCategory in links
                             select GetLinkFromLinkCategory(linkCategory, catType, urlHelper, blog);
                mergedLinkCategory.Links.AddRange(merged);
                return mergedLinkCategory;
            }

            return null;
        }
예제 #9
0
        public void Ctor_WithAllNonNullArgs_SetsProperties()
        {
            //arrange
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
            var urlHelper = new BlogUrlHelper(requestContext, new RouteCollection());
            ObjectRepository objectRepository = new Mock<ObjectRepository>().Object;
            var blog = new Blog();

            //act
            var subtextContext = new SubtextContext(blog, requestContext, urlHelper, objectRepository, null, null, null);

            //assert
            Assert.AreEqual(blog, subtextContext.Blog);
            Assert.AreEqual(urlHelper, subtextContext.UrlHelper);
            Assert.AreEqual(requestContext, subtextContext.RequestContext);
            Assert.AreEqual(objectRepository, subtextContext.Repository);
        }
        public static void AddCommunityCredits(Entry entry, BlogUrlHelper urlHelper, Blog blog)
        {
            string result;

            bool commCreditsEnabled;

            if (!bool.TryParse(ConfigurationManager.AppSettings["CommCreditEnabled"], out commCreditsEnabled))
            {
                return;
            }

            if (commCreditsEnabled && entry.IsActive)
            {
                var wsCommunityCredit = new AffiliateServices();

                string url = urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(blog).ToString();
                string category = String.Empty;
                if (entry.PostType == PostType.BlogPost)
                {
                    category = "Blog";
                }
                else if (entry.PostType == PostType.Story)
                {
                    category = "Article";
                }
                string description = "Blogged about: " + entry.Title;

                string firstName = string.Empty;
                string lastName = blog.Author;
                string email = blog.Email;
                string affiliateCode = ConfigurationManager.AppSettings["CommCreditAffiliateCode"];
                string affiliateKey = ConfigurationManager.AppSettings["CommCreditAffiliateKey"];

                Log.InfoFormat("Sending notification to community credit for url {0} in category {1} for user {2}", url,
                               category, email);

                result = wsCommunityCredit.AddCommunityCredit(email, firstName, lastName, description, url, category,
                                                              affiliateCode, affiliateKey);

                Log.InfoFormat("Response Received was: {0}", result);
                if (!result.Equals("Success"))
                {
                    throw new CommunityCreditNotificationException(result);
                }
            }
        }
예제 #11
0
        private static Link GetLinkFromLinkCategory(LinkCategory linkCategory, CategoryType catType, BlogUrlHelper urlHelper, Blog blog)
        {
            var link = new Link { Title = linkCategory.Title };

            switch (catType)
            {
                case CategoryType.StoryCollection:
                    link.Url = urlHelper.CategoryUrl(linkCategory).ToFullyQualifiedUrl(blog).ToString();
                    break;

                case CategoryType.PostCollection:
                    link.Url = urlHelper.CategoryUrl(linkCategory).ToFullyQualifiedUrl(blog).ToString();
                    link.Rss = urlHelper.CategoryRssUrl(linkCategory);
                    break;

                case CategoryType.ImageCollection:
                    link.Url = urlHelper.GalleryUrl(linkCategory.Id).ToFullyQualifiedUrl(blog).ToString();
                    break;
            }
            link.NewWindow = false;
            return link;
        }
예제 #12
0
        public void EntryUrl_WithEntryHavingPostTypeOfNone_ThrowsArgumentException()
        {
            //arrange
            var httpContext = new Mock<HttpContextBase>();
            var requestContext = new RequestContext(httpContext.Object, new RouteData());
            var helper = new BlogUrlHelper(requestContext, new RouteCollection());

            //act
            UnitTestHelper.AssertThrows<ArgumentException>(() => helper.EntryUrl(new Entry(PostType.None)));
        }
예제 #13
0
 public SearchEngine(Blog blog, BlogUrlHelper urlHelper, string connectionString)
 {
     _blog = blog;
     _procedures = new StoredProcedures(connectionString);
     _urlHelper = urlHelper;
 }
예제 #14
0
 public static Mock<ISubtextContext> SetupUrlHelper(this Mock<ISubtextContext> context, BlogUrlHelper urlHelper)
 {
     context.Setup(c => c.UrlHelper).Returns(urlHelper);
     return context;
 }
예제 #15
0
 //Text to insert into a file with pinkback service location
 public static string GetPingPackTag(BlogUrlHelper urlHelper)
 {
     return string.Format(CultureInfo.InvariantCulture,
                          "<link rel=\"pingback\" href=\"{0}Services/Pingback.aspx\"></link>",
                          urlHelper.BlogUrl());
 }
예제 #16
0
 /// <summary>
 /// Converts a LinkCategoryCollection into a single LinkCategory with its own LinkCollection.
 /// </summary>
 public static LinkCategory BuildLinks(this ObjectRepository repository, string title, CategoryType catType, Blog blog, BlogUrlHelper urlHelper)
 {
     ICollection<LinkCategory> links = repository.GetCategories(catType, true /* activeOnly */);
     return MergeLinkCategoriesIntoSingleLinkCategory(title, catType, links, urlHelper, blog);
 }
예제 #17
0
 public AdminUrlHelper(BlogUrlHelper urlHelper)
 {
     Url = urlHelper;
 }
예제 #18
0
 private static AdminUrlHelper SetupUrlHelper(string appPath, RouteData routeData)
 {
     var routes = new RouteCollection();
     var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);
     Routes.RegisterRoutes(subtextRoutes);
     var httpContext = new Mock<HttpContextBase>();
     httpContext.Setup(c => c.Request.ApplicationPath).Returns(appPath);
     httpContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s);
     var requestContext = new RequestContext(httpContext.Object, routeData);
     var helper = new BlogUrlHelper(requestContext, routes);
     return new AdminUrlHelper(helper);
 }
예제 #19
0
        private void GetPosts(XmlNode connectorNode, string currentFolder)
        {
            IPagedCollection<EntryStatsView> posts;
            if (currentFolder.Equals("/"))
            {
                posts = Repository.GetEntries(PostType.BlogPost, -1, 0, 1000);
            }
            else
            {
                string categoryName = currentFolder.Substring(1, currentFolder.Length - 2);
                LinkCategory category = Repository.GetLinkCategory(categoryName, false);
                posts = Repository.GetEntries(PostType.BlogPost, category.Id, 0, 1000);
            }

            // Create the "Files" node.
            XmlNode oFilesNode = XmlUtil.AppendElement(connectorNode, "Files");
            foreach (var entry in posts)
            {
                // Create the "File" node.
                if (entry.IsActive)
                {
                    XmlNode oFileNode = XmlUtil.AppendElement(oFilesNode, "File");

                    //TODO: Seriously refactor.
                    var urlHelper = new BlogUrlHelper(null, null);

                    XmlUtil.SetAttribute(oFileNode, "name",
                                         string.Format(CultureInfo.InvariantCulture, "{0}|{1}", entry.Title,
                                                       urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(Config.CurrentBlog)));
                    XmlUtil.SetAttribute(oFileNode, "size", entry.DateModifiedUtc.ToShortDateString());
                }
            }
        }
예제 #20
0
 public AccountController(BlogUrlHelper urlHelper, IAccountService service)
 {
     BlogUrlHelper = urlHelper;
     AccountService = service;
 }
예제 #21
0
        /// <summary>
        /// Writes the RSD for the specified blog into the XmlWriter.
        /// </summary>
        public void WriteRsd(XmlWriter writer, Blog blog, BlogUrlHelper urlHelper)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("rsd", "http://archipelago.phrasewise.com/rsd");
            writer.WriteAttributeString("version", "1.0");
            writer.WriteStartElement("service");
            writer.WriteElementString("engineName", "Subtext");
            writer.WriteElementString("engineLink", "http://subtextproject.com/");
            writer.WriteElementString("homePageLink", urlHelper.BlogUrl().ToFullyQualifiedUrl(blog).ToString());

            writer.WriteStartElement("apis");

            //When we have more than one API, we'll list them here.
            writer.WriteStartElement("api");
            writer.WriteAttributeString("name", "MetaWeblog");
            writer.WriteAttributeString("preferred", "true");
            writer.WriteAttributeString("apiLink", urlHelper.MetaWeblogApiUrl(blog).ToString());
            writer.WriteAttributeString("blogID", blog.Id.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement(); // </api>

            writer.WriteEndElement(); // </apis>

            writer.WriteEndElement(); // </service>
            writer.WriteEndElement(); // </rsd>
            writer.WriteEndDocument();
            writer.Flush();
        }
예제 #22
0
        public void EntryUrl_WithNullEntry_ThrowsArgumentNullException()
        {
            //arrange
            var httpContext = new Mock<HttpContextBase>();
            var requestContext = new RequestContext(httpContext.Object, new RouteData());
            var helper = new BlogUrlHelper(requestContext, new RouteCollection());

            //act, assert
            UnitTestHelper.AssertThrowsArgumentNullException(() => helper.EntryUrl(null));
        }
예제 #23
0
 public AdminUrlHelper(BlogUrlHelper urlHelper)
 {
     Url = urlHelper;
 }