Esempio n. 1
0
 /// <param name="dt">if non-null then the post must be dated on that date</param>
 public Entry GetBlogPost(string postid, DateTime?dt)
 {
     if (dt == null)
     {
         return(dataService.GetEntry(postid));
     }
     else
     {
         EntryCollection entries = dataService.GetEntriesForDay(dt.Value, null, null, 1, 10, null);
         return(entries.FirstOrDefault(e =>
                                       Pass(() => dasBlogSettings.GetPermaTitle(e.CompressedTitle), () => SettingsUtils.GetPermaTitle(e.CompressedTitle, opts.TitlePermalinkSpaceReplacement))
                                       .Replace(Pass(() => dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, () => opts.TitlePermalinkSpaceReplacement), string.Empty)
                                       == postid));
     }
 }
        private string MakePermaLink(Entry entry)
        {
            string link;

            if (_dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique)
            {
                link = _dasBlogSettings.GetPermaTitle(entry.CompressedTitleUnique);
            }
            else
            {
                link = _dasBlogSettings.GetPermaTitle(entry.CompressedTitle);
            }

            return(link);
        }
Esempio n. 3
0
        /// <param name="dt">if non-null then the post must be dated on that date</param>
        public Entry GetBlogPost(string posttitle, DateTime?dt)
        {
            posttitle = posttitle.Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, string.Empty);

            if (dt == null)
            {
                return(dataService.GetEntry(posttitle));
            }
            else
            {
                var entries = dataService.GetEntriesForDay(dt.Value, null, null, 1, 10, null);

                return(entries.FirstOrDefault(e => dasBlogSettings.GetPermaTitle(e.CompressedTitle)
                                              .Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, string.Empty) == posttitle));
            }
        }
Esempio n. 4
0
        public ProfilePost(IDasBlogSettings dasBlogSettings)
        {
            _dasBlogSettings = dasBlogSettings;

            CreateMap <Entry, PostViewModel>()
            .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
            .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content))
            .ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
            .ForMember(dest => dest.Categories, opt => opt.MapFrom(src => ConvertCategory(src.Categories)))
            .ForMember(dest => dest.EntryId, opt => opt.MapFrom(src => src.EntryId))
            .ForMember(dest => dest.AllowComments, opt => opt.MapFrom(src => src.AllowComments))
            .ForMember(dest => dest.IsPublic, opt => opt.MapFrom(src => src.IsPublic))
            .ForMember(dest => dest.Syndicated, opt => opt.MapFrom(src => src.Syndicated))
            .ForMember(dest => dest.PermaLink, opt => opt.MapFrom(src => _dasBlogSettings.GetPermaTitle(src.CompressedTitle)))
            .ForMember(dest => dest.CreatedDateTime, opt => opt.MapFrom(src => src.CreatedLocalTime))
            .ForMember(dest => dest.ModifiedDateTime, opt => opt.MapFrom(src => src.ModifiedLocalTime));

            CreateMap <PostViewModel, Entry>()
            .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
            .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content))
            .ForMember(dest => dest.Description, opt => opt.MapFrom(src => (src.Description == null) ? string.Empty : src.Description))
            .ForMember(dest => dest.Categories, opt => opt.MapFrom(src => string.Join(";", src.AllCategories.Where(x => x.Checked).Select(x => x.Category))))
            .ForMember(dest => dest.EntryId, opt => opt.MapFrom(src => src.EntryId))
            .ForMember(dest => dest.AllowComments, opt => opt.MapFrom(src => src.AllowComments))
            .ForMember(dest => dest.IsPublic, opt => opt.MapFrom(src => src.IsPublic))
            .ForMember(dest => dest.Syndicated, opt => opt.MapFrom(src => src.Syndicated))
            .ForMember(dest => dest.CreatedUtc, opt => opt.MapFrom(src => src.CreatedDateTime))
            .ForMember(dest => dest.ModifiedLocalTime, opt => opt.MapFrom(src => src.ModifiedDateTime));

            CreateMap <CategoryCacheEntry, CategoryViewModel>()
            .ForMember(dest => dest.Category, opt => opt.MapFrom(src => src.DisplayName))
            .ForMember(dest => dest.CategoryUrl, opt => opt.MapFrom(src => ConvertCategory(src.DisplayName).FirstOrDefault().CategoryUrl));

            CreateMap <CategoryViewModel, CategoryCacheEntry>()
            .ForMember(dest => dest.DisplayName, opt => opt.MapFrom(src => src.Category));

            CreateMap <Comment, CommentViewModel>()
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Author))
            .ForMember(dest => dest.Text, opt => opt.MapFrom(src => src.Content))
            .ForMember(dest => dest.GravatarHashId, opt => opt.MapFrom(src => GetGravatarHash(src.AuthorEmail)))
            .ForMember(dest => dest.Date, opt => opt.MapFrom(src => src.CreatedLocalTime))
            .ForMember(dest => dest.HomePageUrl, opt => opt.MapFrom(src => src.AuthorHomepage));

            CreateMap <AddCommentViewModel, Comment>()
            .ForMember(dest => dest.Author, opt => opt.MapFrom(src => src.Name))
            .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Comment))
            .ForMember(dest => dest.AuthorEmail, opt => opt.MapFrom(src => src.Email))
            .ForMember(dest => dest.TargetEntryId, opt => opt.MapFrom(src => src.TargetEntryId))
            .ForMember(dest => dest.AuthorHomepage, opt => opt.MapFrom(src => src.HomePage));

            CreateMap <Entry, CategoryPostItem>()
            .ForMember(dest => dest.BlogTitle, opt => opt.MapFrom(src => src.Title))
            .ForMember(dest => dest.BlogId, opt => opt.MapFrom(src => src.EntryId));
        }
Esempio n. 5
0
        public urlset GetGoogleSiteMap()
        {
            urlset root = new urlset();

            root.url = new urlCollection();

            //Default first...
            url basePage = new url(dasBlogSettings.GetBaseUrl(), DateTime.Now, changefreq.daily, 1.0M);

            root.url.Add(basePage);

            //Archives next...
            url archivePage = new url(dasBlogSettings.RelativeToRoot("archives"), DateTime.Now, changefreq.daily, 1.0M);

            root.url.Add(archivePage);

            //All Pages
            EntryCollection entryCache = dataService.GetEntries(false);

            foreach (Entry e in entryCache)
            {
                if (e.IsPublic)
                {
                    //Start with a RARE change freq...newer posts are more likely to change more often.
                    // The older a post, the less likely it is to change...
                    changefreq freq = changefreq.daily;

                    //new stuff?
                    if (e.CreatedLocalTime < DateTime.Now.AddMonths(-9))
                    {
                        freq = changefreq.yearly;
                    }
                    else if (e.CreatedLocalTime < DateTime.Now.AddDays(-30))
                    {
                        freq = changefreq.monthly;
                    }
                    else if (e.CreatedLocalTime < DateTime.Now.AddDays(-7))
                    {
                        freq = changefreq.weekly;
                    }
                    if (e.CreatedLocalTime > DateTime.Now.AddDays(-2))
                    {
                        freq = changefreq.hourly;
                    }

                    //Add comments pages, since comments have indexable content...
                    // Only add comments if we aren't showing comments on permalink pages already
                    if (dasBlogSettings.SiteConfiguration.ShowCommentsWhenViewingEntry == false)
                    {
                        url commentPage = new url(dasBlogSettings.GetCommentViewUrl(e.CompressedTitle), e.CreatedLocalTime, freq, 0.7M);
                        root.url.Add(commentPage);
                    }

                    //then add permalinks
                    url permaPage = new url(dasBlogSettings.RelativeToRoot(dasBlogSettings.GetPermaTitle(e.CompressedTitle)), e.CreatedLocalTime, freq, 0.9M);
                    root.url.Add(permaPage);
                }
            }

            //All Categories
            CategoryCacheEntryCollection catCache = dataService.GetCategories();

            foreach (CategoryCacheEntry cce in catCache)
            {
                if (cce.IsPublic)
                {
                    url catPage = new url(dasBlogSettings.GetCategoryViewUrl(cce.Name), DateTime.Now, changefreq.weekly, 0.6M);
                    root.url.Add(catPage);
                }
            }

            return(root);
        }
        private RssRoot GetRssCore(string category, int maxDayCount, int maxEntryCount)
        {
            EntryCollection entries = null;

            //We only build the entries if blogcore doesn't exist and we'll need them later...
            if (dataService.GetLastEntryUpdate() == DateTime.MinValue)
            {
                entries = BuildEntries(category, maxDayCount, maxEntryCount);
            }

            var documentRoot = new RssRoot();;

            //However, if we made it this far, the not-modified check didn't work, and we may not have entries...
            if (entries == null)
            {
                entries = BuildEntries(category, maxDayCount, maxEntryCount);
            }

            documentRoot.Namespaces.Add("dc", "http://purl.org/dc/elements/1.1/");
            documentRoot.Namespaces.Add("trackback", "http://madskills.com/public/xml/rss/module/trackback/");
            documentRoot.Namespaces.Add("pingback", "http://madskills.com/public/xml/rss/module/pingback/");
            documentRoot.Namespaces.Add("webfeeds", "http://webfeeds.org/rss/1.0");
            if (dasBlogSettings.SiteConfiguration.EnableComments)
            {
                documentRoot.Namespaces.Add("wfw", "http://wellformedweb.org/CommentAPI/");
                documentRoot.Namespaces.Add("slash", "http://purl.org/rss/1.0/modules/slash/");
            }
            if (dasBlogSettings.SiteConfiguration.EnableGeoRss)
            {
                documentRoot.Namespaces.Add("georss", "http://www.georss.org/georss");
            }

            var ch = new RssChannel();

            if (category == null)
            {
                ch.Title = dasBlogSettings.SiteConfiguration.Title;
            }
            else
            {
                ch.Title = dasBlogSettings.SiteConfiguration.Title + " - " + category;
            }

            if (string.IsNullOrEmpty(dasBlogSettings.SiteConfiguration.Description))
            {
                ch.Description = dasBlogSettings.SiteConfiguration.Subtitle;
            }
            else
            {
                ch.Description = dasBlogSettings.SiteConfiguration.Description;
            }

            ch.Link      = dasBlogSettings.GetBaseUrl();
            ch.Copyright = dasBlogSettings.SiteConfiguration.Copyright;
            if (!string.IsNullOrEmpty(dasBlogSettings.SiteConfiguration.RssLanguage))
            {
                ch.Language = dasBlogSettings.SiteConfiguration.RssLanguage;
            }

            ch.ManagingEditor = dasBlogSettings.SiteConfiguration.Contact;
            ch.WebMaster      = dasBlogSettings.SiteConfiguration.Contact;
            ch.Image          = null;

            if (!string.IsNullOrWhiteSpace(dasBlogSettings.SiteConfiguration.ChannelImageUrl))
            {
                var channelImage = new DasBlog.Services.Rss.Rss20.ChannelImage();
                channelImage.Title = ch.Title;
                channelImage.Link  = ch.Link;
                if (dasBlogSettings.SiteConfiguration.ChannelImageUrl.StartsWith("http"))
                {
                    channelImage.Url = dasBlogSettings.SiteConfiguration.ChannelImageUrl;
                }
                else
                {
                    channelImage.Url = dasBlogSettings.RelativeToRoot(dasBlogSettings.SiteConfiguration.ChannelImageUrl);
                }
                ch.Image = channelImage;
            }

            var xdoc         = new XmlDocument();
            var rootElements = new List <XmlElement>();

            var wflogo = xdoc.CreateElement("webfeeds", "logo", "http://webfeeds.org/rss/1.0");

            wflogo.InnerText = dasBlogSettings.RelativeToRoot(dasBlogSettings.SiteConfiguration.ChannelImageUrl);
            rootElements.Add(wflogo);

            var wfanalytics = xdoc.CreateElement("webfeeds", "analytics", "http://webfeeds.org/rss/1.0");
            var attribId    = xdoc.CreateAttribute("id");

            attribId.Value = dasBlogSettings.MetaTags.GoogleAnalyticsID;
            wfanalytics.Attributes.Append(attribId);

            var attribEngine = xdoc.CreateAttribute("engine");

            attribEngine.Value = "GoogleAnalytics";
            wfanalytics.Attributes.Append(attribEngine);

            rootElements.Add(wfanalytics);

            ch.anyElements = rootElements.ToArray();

            ch.Items = new RssItemCollection();
            documentRoot.Channels.Add(ch);

            foreach (var entry in entries)
            {
                if (entry.IsPublic == false || entry.Syndicated == false)
                {
                    continue;
                }
                var doc2        = new XmlDocument();
                var anyElements = new List <XmlElement>();
                var item        = new RssItem();
                item.Title            = entry.Title;
                item.Guid             = new DasBlog.Services.Rss.Rss20.Guid();
                item.Guid.IsPermaLink = false;
                item.Guid.Text        = dasBlogSettings.GetPermaLinkUrl(entry.EntryId);
                item.Link             = dasBlogSettings.RelativeToRoot(dasBlogSettings.GetPermaTitle(entry.CompressedTitle));
                User user = dasBlogSettings.GetUser(entry.Author);

                XmlElement trackbackPing = doc2.CreateElement("trackback", "ping", "http://madskills.com/public/xml/rss/module/trackback/");
                trackbackPing.InnerText = dasBlogSettings.GetTrackbackUrl(entry.EntryId);
                anyElements.Add(trackbackPing);

                XmlElement pingbackServer = doc2.CreateElement("pingback", "server", "http://madskills.com/public/xml/rss/module/pingback/");
                pingbackServer.InnerText = dasBlogSettings.PingBackUrl;
                anyElements.Add(pingbackServer);

                XmlElement pingbackTarget = doc2.CreateElement("pingback", "target", "http://madskills.com/public/xml/rss/module/pingback/");
                pingbackTarget.InnerText = dasBlogSettings.GetPermaLinkUrl(entry.EntryId);
                anyElements.Add(pingbackTarget);

                XmlElement dcCreator = doc2.CreateElement("dc", "creator", "http://purl.org/dc/elements/1.1/");
                if (user != null)
                {
                    dcCreator.InnerText = user.DisplayName;
                }
                anyElements.Add(dcCreator);

                // Add GeoRSS if it exists.
                if (dasBlogSettings.SiteConfiguration.EnableGeoRss)
                {
                    var latitude  = new Nullable <double>();
                    var longitude = new Nullable <double>();

                    if (entry.Latitude.HasValue)
                    {
                        latitude = entry.Latitude;
                    }
                    else
                    {
                        if (dasBlogSettings.SiteConfiguration.EnableDefaultLatLongForNonGeoCodedPosts)
                        {
                            latitude = dasBlogSettings.SiteConfiguration.DefaultLatitude;
                        }
                    }

                    if (entry.Longitude.HasValue)
                    {
                        longitude = entry.Longitude;
                    }
                    else
                    {
                        if (dasBlogSettings.SiteConfiguration.EnableDefaultLatLongForNonGeoCodedPosts)
                        {
                            longitude = dasBlogSettings.SiteConfiguration.DefaultLongitude;
                        }
                    }

                    if (latitude.HasValue && longitude.HasValue)
                    {
                        XmlElement geoLoc = doc2.CreateElement("georss", "point", "http://www.georss.org/georss");
                        geoLoc.InnerText = String.Format(CultureInfo.InvariantCulture, "{0:R} {1:R}", latitude, longitude);
                        anyElements.Add(geoLoc);
                    }
                }

                if (dasBlogSettings.SiteConfiguration.EnableComments)
                {
                    if (entry.AllowComments)
                    {
                        XmlElement commentApi = doc2.CreateElement("wfw", "comment", "http://wellformedweb.org/CommentAPI/");
                        commentApi.InnerText = dasBlogSettings.GetCommentViewUrl(entry.CompressedTitle.Replace("+", dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement));
                        anyElements.Add(commentApi);
                    }

                    XmlElement commentRss = doc2.CreateElement("wfw", "commentRss", "http://wellformedweb.org/CommentAPI/");
                    commentRss.InnerText = dasBlogSettings.GetEntryCommentsRssUrl(entry.EntryId);
                    anyElements.Add(commentRss);

                    //for RSS conformance per FeedValidator.org
                    int commentsCount = dataService.GetPublicCommentsFor(entry.EntryId).Count;
                    if (commentsCount > 0)
                    {
                        XmlElement slashComments = doc2.CreateElement("slash", "comments", "http://purl.org/rss/1.0/modules/slash/");
                        slashComments.InnerText = commentsCount.ToString();
                        anyElements.Add(slashComments);
                    }
                    item.Comments = dasBlogSettings.GetCommentViewUrl(entry.CompressedTitle.Replace("+", dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement));
                }
                item.Language = entry.Language;

                if (entry.Categories != null && entry.Categories.Length > 0)
                {
                    if (item.Categories == null)
                    {
                        item.Categories = new RssCategoryCollection();
                    }

                    string[] cats = entry.Categories.Split(';');
                    foreach (string c in cats)
                    {
                        RssCategory cat      = new RssCategory();
                        string      cleanCat = c.Replace('|', '/');
                        cat.Text = cleanCat;
                        item.Categories.Add(cat);
                    }
                }
                if (entry.Attachments.Count > 0)
                {
                    // RSS currently supports only a single enclsoure so we return the first one
                    item.Enclosure        = new Enclosure();
                    item.Enclosure.Url    = entry.Attachments[0].Name;
                    item.Enclosure.Type   = entry.Attachments[0].Type;
                    item.Enclosure.Length = entry.Attachments[0].Length.ToString();
                }
                item.PubDate = entry.CreatedUtc.ToString("R");
                if (ch.LastBuildDate == null || ch.LastBuildDate.Length == 0)
                {
                    ch.LastBuildDate = item.PubDate;
                }

                if (!dasBlogSettings.SiteConfiguration.AlwaysIncludeContentInRSS &&
                    entry.Description != null &&
                    entry.Description.Trim().Length > 0)
                {
                    item.Description = PreprocessItemContent(entry.EntryId, entry.Description);
                }
                else
                {
                    if (dasBlogSettings.SiteConfiguration.HtmlTidyContent == false)
                    {
                        item.Description = "<div>" + PreprocessItemContent(entry.EntryId, entry.Content) + "</div>";
                    }
                    else
                    {
                        item.Description = ContentFormatter.FormatContentAsHTML(PreprocessItemContent(entry.EntryId, entry.Content));


                        try
                        {
                            string xhtml = ContentFormatter.FormatContentAsXHTML(PreprocessItemContent(entry.EntryId, entry.Content));
                            doc2.LoadXml(xhtml);
                            anyElements.Add((XmlElement)doc2.SelectSingleNode("//*[local-name() = 'body'][namespace-uri()='http://www.w3.org/1999/xhtml']"));
                        }
                        catch //(Exception ex)
                        {
                            //Debug.Write(ex.ToString());
                            // absorb
                        }
                    }
                }

                item.anyElements = anyElements.ToArray();
                ch.Items.Add(item);
            }

            return(documentRoot);
        }