Example #1
0
        /// <summary>
        /// The constructor that initializes all the properties of this trackback
        /// message.
        /// </summary>
        /// <param name="item">The IShowed item causing the trackback.</param>
        /// <param name="urlToNotifyTrackback">The url to which the trackback message is sent.</param>
        public TrackbackMessage(IShowed item, Uri urlToNotifyTrackback)
        {
            if (item == null)
                throw new ArgumentNullException("post");

            Title = item.Title;
            PostUrl = item.AbsoluteLink;
            Excerpt = item.Title;
            BlogName = BlogSettings.Instance.Name;
            UrlToNotifyTrackback = urlToNotifyTrackback;
        }
Example #2
0
    /// <summary>
    /// Executes the pings from the new thread.
    /// </summary>
    private void Ping(IShowed item)
    {
        try
        {
            System.Threading.Thread.Sleep(2000);

            // Ping the specified ping services.
            PingService.Send();

            // Send trackbacks and pingbacks.
            if (item.Content.ToLowerInvariant().Contains("http"))
                Manager.Send(item);
        }
        catch (Exception)
        { }
    }
Example #3
0
        /// <summary>
        /// Sends the trackback or pingback message.
        /// <remarks>
        /// It will try to send a trackback message first, and if the refered web page
        /// doesn't support trackbacks, a pingback is sent.
        /// </remarks>
        /// <para>
        /// Gets all anchors from the content of the IShowed item and ignores links to ourselves.
        /// From all the rest of the links, we resolve them and check for trackback links,
        /// if present we send trackback, else we do a pingback.
        /// </para>
        /// </summary>
        public static void Send(IShowed item)
        {
            foreach (Uri url in GetUrlsFromContent(item.Content))
              {
                if (url.Host == SupportUtilities.AbsoluteWebRoot.Host)
                    continue;

                string pageContent = ReadFromWeb(url);
                Uri trackbackUrl = GetTrackBackUrlFromPage(pageContent);
                bool isTrackbackSent = false;

                if (trackbackUrl != null)
                {
                    TrackbackMessage message = new TrackbackMessage(item, trackbackUrl);
                    isTrackbackSent = Trackback.Send(message);
                }

                if (!isTrackbackSent)
                {
                    Pingback.Send(item.AbsoluteLink, url);
                }
              }
        }
        /// <summary>
        /// Writes the RSS channel item element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to write channel item element information to.</param>
        /// <param name="publishable">The <see cref="IShowed"/> used to generate channel item content.</param>
        private static void WriteRssItem(XmlWriter writer, IShowed publishable)
        {
            //------------------------------------------------------------
                //	Cast IShowed as Post to support comments/trackback
                //------------------------------------------------------------
                Post post = publishable as Post;
                Comment comment = publishable as Comment;

                //------------------------------------------------------------
                //	Raise serving event
                //------------------------------------------------------------
                ServingEventArgs arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);
                publishable.OnServing(arg);
                if (arg.Cancel)
                {
                    return;
                }

                //------------------------------------------------------------
                //	Modify post content to make references absolute
                //------------------------------------------------------------
                string content = ConvertPathsToAbsolute(arg.Body);

                writer.WriteStartElement("item");
                //------------------------------------------------------------
                //	Write required channel item elements
                //------------------------------------------------------------
                writer.WriteElementString("title", publishable.Title);
                writer.WriteElementString("description", content);
                writer.WriteElementString("link", SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString());

                //------------------------------------------------------------
                //	Write optional channel item elements
                //------------------------------------------------------------
                writer.WriteElementString("author", publishable.Author);
                if (post != null)
                {
                    writer.WriteElementString("comments", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                }
                writer.WriteElementString("guid", SyndicationGenerator.GetPermaLink(publishable).ToString());
                writer.WriteElementString("pubDate", SyndicationGenerator.ToRfc822DateTime(publishable.DateCreated));

                //------------------------------------------------------------
                //	Write channel item category elements
                //------------------------------------------------------------
                if (publishable.Categories != null)
                {
                    foreach (Category category in publishable.Categories)
                    {
                        writer.WriteElementString("category", category.Title);
                    }
                }

                //------------------------------------------------------------
                //	Write Dublin Core syndication extension elements
                //------------------------------------------------------------
                if (!String.IsNullOrEmpty(publishable.Author))
                {
                    writer.WriteElementString("dc", "publisher", "http://purl.org/dc/elements/1.1/", publishable.Author);
                }

                //------------------------------------------------------------
                //	Write pingback syndication extension elements
                //------------------------------------------------------------
                Uri pingbackServer;
                if (Uri.TryCreate(String.Concat(SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/'), "/ZaszBlogHttpHandlers/PingBack.ashx"), UriKind.RelativeOrAbsolute, out pingbackServer))
                {
                    writer.WriteElementString("pingback", "server", "http://madskills.com/public/xml/rss/module/pingback/", pingbackServer.ToString());
                    writer.WriteElementString("pingback", "target", "http://madskills.com/public/xml/rss/module/pingback/", SyndicationGenerator.GetPermaLink(publishable).ToString());
                }

                //------------------------------------------------------------
                //	Write slash syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.Comments != null)
                {
                    writer.WriteElementString("slash", "comments", "http://purl.org/rss/1.0/modules/slash/", post.Comments.Count.ToString());
                }

                //------------------------------------------------------------
                //	Write trackback syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.TrackbackLink != null)
                {
                    writer.WriteElementString("trackback", "ping", "http://madskills.com/public/xml/rss/module/trackback/", post.TrackbackLink.ToString());
                }

                //------------------------------------------------------------
                //	Write well-formed web syndication extension elements
                //------------------------------------------------------------
                writer.WriteElementString("wfw", "comment", "http://wellformedweb.org/CommentAPI/", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                writer.WriteElementString("wfw", "commentRss", "http://wellformedweb.org/CommentAPI/", SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/') + "/ZaszBlogHttpHandlers/Syndication.ashx?post=" + publishable.Id.ToString());

                //------------------------------------------------------------
                //	Write </item> element
                //------------------------------------------------------------
                writer.WriteEndElement();
        }
        /// <summary>
        /// Writes the Atom feed entry element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to write feed entry element information to.</param>
        /// <param name="publishable">The <see cref="IShowed"/> used to generate feed entry content.</param>
        private static void WriteAtomEntry(XmlWriter writer, IShowed publishable)
        {
            Post post = publishable as Post;
                Comment comment = publishable as Comment;

                //------------------------------------------------------------
                //	Raise serving event
                //------------------------------------------------------------
                ServingEventArgs arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);
                publishable.OnServing(arg);
                if (arg.Cancel)
                {
                    return;
                }

                //------------------------------------------------------------
                //	Modify publishable content to make references absolute
                //------------------------------------------------------------
                string content = ConvertPathsToAbsolute(arg.Body);

                writer.WriteStartElement("entry");
                //------------------------------------------------------------
                //	Write required entry elements
                //------------------------------------------------------------
                writer.WriteElementString("id", SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString());
                writer.WriteElementString("title", publishable.Title);
                writer.WriteElementString("updated", SyndicationGenerator.ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));

                //------------------------------------------------------------
                //	Write recommended entry elements
                //------------------------------------------------------------
                writer.WriteStartElement("link");
                writer.WriteAttributeString("rel", "self");
                writer.WriteAttributeString("href", SyndicationGenerator.GetPermaLink(publishable).ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("link");
                writer.WriteAttributeString("href", SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("author");
                writer.WriteElementString("name", publishable.Author);
                writer.WriteEndElement();

                writer.WriteStartElement("summary");
                writer.WriteAttributeString("type", "html");
                writer.WriteString(content);
                writer.WriteEndElement();

                //------------------------------------------------------------
                //	Write optional entry elements
                //------------------------------------------------------------
                writer.WriteElementString("published", SyndicationGenerator.ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));

                writer.WriteStartElement("link");
                writer.WriteAttributeString("rel", "related");
                writer.WriteAttributeString("href", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                writer.WriteEndElement();

                //------------------------------------------------------------
                //	Write entry category elements
                //------------------------------------------------------------
                if (publishable.Categories != null)
                {
                    foreach (Category category in publishable.Categories)
                    {
                        writer.WriteStartElement("category");
                        writer.WriteAttributeString("term", category.Title);
                        writer.WriteEndElement();
                    }
                }

                //------------------------------------------------------------
                //	Write pingback syndication extension elements
                //------------------------------------------------------------
                Uri pingbackServer;
                if (Uri.TryCreate(String.Concat(SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/'), "ZaszBlogHttpHandlers/Pingback.ashx"), UriKind.RelativeOrAbsolute, out pingbackServer))
                {
                    writer.WriteElementString("pingback", "server", "http://madskills.com/public/xml/rss/module/pingback/", pingbackServer.ToString());
                    writer.WriteElementString("pingback", "target", "http://madskills.com/public/xml/rss/module/pingback/", SyndicationGenerator.GetPermaLink(publishable).ToString());
                }

                //------------------------------------------------------------
                //	Write slash syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.Comments != null)
                {
                    writer.WriteElementString("slash", "comments", "http://purl.org/rss/1.0/modules/slash/", post.Comments.Count.ToString());
                }

                //------------------------------------------------------------
                //	Write trackback syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.TrackbackLink != null)
                {
                    writer.WriteElementString("trackback", "ping", "http://madskills.com/public/xml/rss/module/trackback/", post.TrackbackLink.ToString());
                }

                //------------------------------------------------------------
                //	Write well-formed web syndication extension elements
                //------------------------------------------------------------
                writer.WriteElementString("wfw", "comment", "http://wellformedweb.org/CommentAPI/", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                writer.WriteElementString("wfw", "commentRss", "http://wellformedweb.org/CommentAPI/", SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/') + "ZaszBlogHttpHandlers/Syndication.ashx?post=" + publishable.Id.ToString());

                //------------------------------------------------------------
                //	Write </entry> element
                //------------------------------------------------------------
                writer.WriteEndElement();
        }
 private static Uri GetPermaLink(IShowed publishable)
 {
     Post post = publishable as Post;
     if (post != null)
     {
         return post.PermaLink;
     }
     return SupportUtilities.ConvertToAbsolute(publishable.RelativeLink);
 }
 /// <summary>
 /// A converter delegate used for converting Results to Posts.
 /// </summary>
 private static IShowed ConvertToIShowed(IShowed item)
 {
     return item;
 }