Exemplo n.º 1
0
 public static DateTime GetLatestModifedCommentDateTime(IBlogDataService dataService, CommentCollection comments)
 {
     return(SiteUtilities.GetLatestModifedCommentDateTime(dataService, comments));
 }
Exemplo n.º 2
0
        private RssRoot GetCommentsRssCore(CommentCollection _com, string guid)
        {
            //Try to get out as soon as possible with as little CPU as possible
            if (inASMX)
            {
                DateTime lastModified = SiteUtilities.GetLatestModifedCommentDateTime(dataService, _com);
                if (SiteUtilities.GetStatusNotModified(lastModified))
                {
                    return(null);
                }
            }

            if (inASMX)
            {
                string referrer = Context.Request.UrlReferrer != null?Context.Request.UrlReferrer.AbsoluteUri:"";
                if (ReferralBlackList.IsBlockedReferrer(referrer) == false)
                {
                    loggingService.AddReferral(
                        new LogDataItem(
                            Context.Request.RawUrl,
                            referrer,
                            Context.Request.UserAgent,
                            Context.Request.UserHostName));
                }
            }

            // TODO: Figure out why this code is copied and pasted from above rather than using a function (shame!)
            RssRoot    documentRoot = new RssRoot();
            RssChannel ch           = new RssChannel();

            if (guid != null && guid != String.Empty)
            {
                //Set the title for this RSS Comments feed
                ch.Title = siteConfig.Title + " - Comments on " + dataService.GetEntry(guid).Title;
            }
            else
            {
                ch.Title = siteConfig.Title + " - Comments";
            }
            ch.Link           = SiteUtilities.GetBaseUrl(siteConfig);
            ch.Copyright      = siteConfig.Copyright;
            ch.ManagingEditor = siteConfig.Contact;
            ch.WebMaster      = siteConfig.Contact;
            documentRoot.Channels.Add(ch);


            int i = 0;

            foreach (Comment c in _com)
            {
                List <XmlElement> anyElements = new List <XmlElement>();
                if (i == siteConfig.RssEntryCount)
                {
                    break;
                }
                i++;
                string  tempTitle = "";
                RssItem item      = new RssItem();

                if (c.TargetTitle != null && c.TargetTitle.Length > 0)
                {
                    tempTitle = " on \"" + c.TargetTitle + "\"";
                }

                if (c.Author == null || c.Author == "")
                {
                    item.Title = "Comment" + tempTitle;
                }
                else
                {
                    item.Title = "Comment by " + c.Author + tempTitle;
                }

                //Per the RSS Comments Spec it makes more sense for guid and link to be the same.
                // http://blogs.law.harvard.edu/tech/rss#comments
                // 11/11/05 - SDH - Now, I'm thinking not so much...
                item.Guid             = new Rss20.Guid();
                item.Guid.Text        = c.EntryId;
                item.Guid.IsPermaLink = false;
                item.Link             = SiteUtilities.GetCommentViewUrl(siteConfig, c.TargetEntryId, c.EntryId);

                item.PubDate = c.CreatedUtc.ToString("R");

                item.Description = c.Content.Replace(Environment.NewLine, "<br />");
                if (c.AuthorHomepage == null || c.AuthorHomepage == "")
                {
                    if (c.AuthorEmail == null || c.AuthorEmail == "")
                    {
                        if (!(c.Author == null || c.Author == ""))
                        {
                            item.Description = c.Content.Replace(Environment.NewLine, "<br />") + "<br /><br />" + "Posted by: " + c.Author;
                        }
                    }
                    else
                    {
                        string content = c.Content.Replace(Environment.NewLine, "<br />");
                        if (!siteConfig.SupressEmailAddressDisplay)
                        {
                            item.Description = content + "<br /><br />" + "Posted by: " + "<a href=\"mailto:" + SiteUtilities.SpamBlocker(c.AuthorEmail) + "\">" + c.Author + "</a>";
                        }
                        else
                        {
                            item.Description = content + "<br /><br />" + "Posted by: " + c.Author;
                        }
                    }
                }
                else
                {
                    if (c.AuthorHomepage.IndexOf("http://") < 0)
                    {
                        c.AuthorHomepage = "http://" + c.AuthorHomepage;
                    }
                    item.Description += "<br /><br />" + "Posted by: " + "<a href=\"" + c.AuthorHomepage +
                                        "\">" + c.Author + "</a>";
                }

                if (c.Author != null && c.Author.Length > 0)
                {
                    // the rss spec requires an email address in the author tag
                    // and it can not be obfuscated
                    // according to the feedvalidator
                    string email;

                    if (!siteConfig.SupressEmailAddressDisplay)
                    {
                        email = (c.AuthorEmail != null && c.AuthorEmail.Length > 0 ? c.AuthorEmail : "*****@*****.**");
                    }
                    else
                    {
                        email = "*****@*****.**";
                    }

                    item.Author = String.Format("{0} ({1})", email, c.Author);
                }

                item.Comments = SiteUtilities.GetCommentViewUrl(siteConfig, c.TargetEntryId, c.EntryId);

                if (ch.LastBuildDate == null || ch.LastBuildDate.Length == 0)
                {
                    ch.LastBuildDate = item.PubDate;
                }

                XmlDocument doc2 = new XmlDocument();
                try
                {
                    doc2.LoadXml(c.Content);
                    anyElements.Add((XmlElement)doc2.SelectSingleNode("//*[local-name() = 'body'][namespace-uri()='http://www.w3.org/1999/xhtml']"));
                }
                catch
                {
                    // absorb
                }
                item.anyElements = anyElements.ToArray();
                ch.Items.Add(item);
            }

            return(documentRoot);
        }