Esempio n. 1
0
 private Uri MakePermaLinkFromCompressedTitle(Entry entry)
 {
     if (Pass(() => dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique, () => opts.EnableTitlePermaLinkUnique))
     {
         return(Pass(() =>
                     new Uri(new Uri(dasBlogSettings.SiteConfiguration.Root)
                             , dasBlogSettings.RelativeToRoot(
                                 entry.CreatedUtc.ToString("yyyyMMdd") + "/" +
                                 dasBlogSettings.GetPermaTitle(entry.CompressedTitle)))
                     , () =>
                     new Uri(new Uri(opts.Root)
                             , SettingsUtils.RelativeToRoot(
                                 entry.CreatedUtc.ToString("yyyyMMdd") + "/" +
                                 SettingsUtils.GetPermaTitle(entry.CompressedTitle, opts.TitlePermalinkSpaceReplacement)
                                 , opts.Root))
                     ));
     }
     else
     {
         return(Pass(
                    () =>
                    new Uri(new Uri(dasBlogSettings.SiteConfiguration.Root)
                            , dasBlogSettings.RelativeToRoot(
                                dasBlogSettings.GetPermaTitle(entry.CompressedTitle)))
                    , () =>
                    new Uri(new Uri(opts.Root)
                            , SettingsUtils.RelativeToRoot(
                                SettingsUtils.GetPermaTitle(entry.CompressedTitle, opts.TitlePermalinkSpaceReplacement), opts.Root))
                    ));
     }
 }
Esempio n. 2
0
 private Uri MakePermaLinkFromCompressedTitle(Entry entry)
 {
     if (dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique)
     {
         return(new Uri(dasBlogSettings.RelativeToRoot(entry.CompressedTitle)));
     }
     else
     {
         return(new Uri(dasBlogSettings.RelativeToRoot(entry.CreatedUtc.ToString("yyyyMMdd") + "/" + entry.CompressedTitle)));
     }
 }
Esempio n. 3
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var imgUrl = Post.ImageUrl;

            output.TagMode = TagMode.SelfClosing;
            output.TagName = "img";

            if (!string.IsNullOrEmpty(imgUrl))
            {
                output.Attributes.SetAttribute("src", dasBlogSettings.RelativeToRoot(imgUrl));
            }
            else
            {
                if (!string.IsNullOrEmpty(DefaultImage))
                {
                    output.Attributes.SetAttribute("src", DefaultImage);
                }
            }

            if (!string.IsNullOrEmpty(Css))
            {
                output.Attributes.SetAttribute("class", Css);
            }

            if (!string.IsNullOrEmpty(Style))
            {
                output.Attributes.SetAttribute("style", Style);
            }
        }
Esempio n. 4
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            try
            {
                PostCount  = (int)ViewContext.ViewData[Constants.PostCount];
                PageNumber = (int)ViewContext.ViewData[Constants.PageNumber];
            }
            catch (NullReferenceException)
            {
                PostCount  = 0;
                PageNumber = 0;
            }

            var pagecontrol = string.Empty;

            output.TagName = "span";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.SetAttribute("class", "dbc-span-page-control");

            var content = await output.GetChildContentAsync();

            var seperator = " | ";

            if (!string.IsNullOrEmpty(content.GetContent()))
            {
                seperator = content.GetContent();
            }

            var separatorRequired = PostCount > 0 && PageNumber > 0;

            if (PostCount > 0)
            {
                pagecontrol = string.Format(PAGEANCHOR, dasBlogSettings.RelativeToRoot(string.Format("page/{0}", PageNumber + 1)), OlderPostsText, "older");
            }

            if (separatorRequired)
            {
                pagecontrol += seperator;
            }

            if (PageNumber > 0)
            {
                pagecontrol += string.Format(PAGEANCHOR, dasBlogSettings.RelativeToRoot(string.Format("page/{0}", PageNumber - 1)), NewerPostsText, "newer");
            }

            output.Content.SetHtmlContent(pagecontrol);
        }
Esempio n. 5
0
        public string SaveFile(Stream inputFile, string fileName)
        {
            dataService.SaveFile(inputFile, ref fileName);

            var file = string.Format("{0}{1}", virtBinaryPathRelativeToContentRoot, Path.GetFileName(fileName));

            return(dasBlogSettings.RelativeToRoot(file));
        }
Esempio n. 6
0
        public MetaWeblog.UrlInfo metaweblog_newMediaObject(object blogid, string username, string password, MetaWeblog.MediaType enc)
        {
            if (!_dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }
            UserToken token = _siteSecurity.Login(username, password);

            if (token == null)
            {
                throw new System.Security.SecurityException();
            }

            // Get the binary data
            string strPath = Path.Combine(_dasBlogSettings.RelativeToRoot(_dasBlogSettings.SiteConfiguration.BinariesDir), enc.name);

            // check if the name of the media type includes a subdirectory we need to create
            FileInfo fileInfo = new FileInfo(strPath);

            if (fileInfo.Directory.Exists == false && fileInfo.Directory.FullName != _dasBlogSettings.RelativeToRoot(_dasBlogSettings.SiteConfiguration.BinariesDir))
            {
                fileInfo.Directory.Create();
            }

            try
            {
                using (FileStream fs = new FileStream(strPath, FileMode.OpenOrCreate))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        bw.Write(enc.bits);
                    }
                }
            }
            catch (Exception e)
            {
                throw new XmlRpcException(e.ToString());
            }

            string path = Path.Combine(_dasBlogSettings.SiteConfiguration.BinariesDirRelative, enc.name);

            MetaWeblog.UrlInfo urlInfo = new MetaWeblog.UrlInfo();
            urlInfo.url = _dasBlogSettings.RelativeToRoot(path);
            return(urlInfo);
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var url     = string.Format(COMMENT_MANAGEMENT_URL, Post.EntryId);
            var message = "Manage Post Comments";

            output.TagName = "a";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.SetAttribute("href", dasBlogSettings.RelativeToRoot(url));
            output.Attributes.SetAttribute("class", "dbc-comment-management-link");

            output.Content.SetHtmlContent(message);
        }
Esempio n. 8
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagMode = TagMode.StartTagAndEndTag;
            output.TagName = "a";

            var content = await output.GetChildContentAsync();

            var css = content.GetContent();

            output.Attributes.SetAttribute("class", css);
            output.Attributes.SetAttribute("href", dasBlogSettings.RelativeToRoot(Post.PermaLink));
            output.Content.SetHtmlContent(Post.Title);
        }
Esempio n. 9
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagMode = TagMode.StartTagAndEndTag;
            output.TagName = "a";

            if (!string.IsNullOrEmpty(Css))
            {
                output.Attributes.SetAttribute("class", Css);
            }

            output.Attributes.SetAttribute("href", dasBlogSettings.RelativeToRoot(Post.PermaLink));
            await Task.CompletedTask;
        }
Esempio n. 10
0
        public FileSystemBinaryManager(IDasBlogSettings dasBlogSettings, IConfigFileService <MetaTags> metaTagFileService,
                                       IConfigFileService <SiteConfig> siteConfigFileService, IOptions <ConfigFilePathsDataOption> optionsAccessor)
        {
            this.dasBlogSettings       = dasBlogSettings;
            this.metaTagFileService    = metaTagFileService;
            this.siteConfigFileService = siteConfigFileService;
            options          = optionsAccessor.Value;
            contentBinaryUrl = dasBlogSettings.RelativeToRoot(options.BinaryUrlRelative);

            var physBinaryPathUrl = new Uri(contentBinaryUrl);

            var loggingDataService = LoggingDataServiceFactory.GetService(Path.Combine(dasBlogSettings.WebRootDirectory, dasBlogSettings.SiteConfiguration.LogDir));

            this.binaryDataService = BinaryDataServiceFactory.GetService(options.BinaryFolder, physBinaryPathUrl, loggingDataService);
        }
Esempio n. 11
0
        public MetaWeblog.UrlInfo metaweblog_newMediaObject(object blogid, string username, string password, MetaWeblog.MediaType enc)
        {
            VerifyAccess(username, password);

            Stream stream = new MemoryStream(enc.bits);

            var filePath = binaryManager.SaveFile(stream, enc.name);

            var urlInfo = new MetaWeblog.UrlInfo
            {
                url = Path.Combine(dasBlogSettings.RelativeToRoot(dasBlogSettings.SiteConfiguration.BinariesDir.TrimStart('~', '/')), enc.name)
            };

            return(urlInfo);
        }
Esempio n. 12
0
 protected void SinglePost(PostViewModel post)
 {
     if (post != null)
     {
         ViewData["PageTitle"]    = post.Title;
         ViewData["Description"]  = post.Content.StripHTMLFromText().CutLongString(80);
         ViewData["Keywords"]     = string.Join(",", post.Categories.Select(x => x.Category).ToArray());
         ViewData["Canonical"]    = dasBlogSettings.RelativeToRoot(post.PermaLink);
         ViewData["Author"]       = post.Author;
         ViewData["PageImageUrl"] = (post.ImageUrl?.Length > 0) ? post.ImageUrl : dasBlogSettings.MetaTags.TwitterImage;
     }
     else
     {
         DefaultPage();
     }
 }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagMode = TagMode.StartTagAndEndTag;
            output.TagName = "a";

            var content = await output.GetChildContentAsync();

            var title = content.GetContent();

            if (!string.IsNullOrEmpty(Css))
            {
                output.Attributes.SetAttribute("class", Css);
            }

            if (string.IsNullOrWhiteSpace(title))
            {
                title = Post.Title;
            }

            output.Attributes.SetAttribute("href", dasBlogSettings.RelativeToRoot(Post.PermaLink));
            output.Content.SetHtmlContent(title);
        }
Esempio n. 14
0
        public MetaWeblog.UrlInfo metaweblog_newMediaObject(object blogid, string username, string password, MetaWeblog.MediaType enc)
        {
            if (!dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }

            if (!VerifyLogin(username, password))
            {
                throw new SecurityException();
            }

            Stream stream = new MemoryStream(enc.bits);

            var filePath = binaryManager.SaveFile(stream, enc.name);

            var urlInfo = new MetaWeblog.UrlInfo
            {
                url = Path.Combine(dasBlogSettings.RelativeToRoot(dasBlogSettings.SiteConfiguration.BinariesDir.TrimStart('~')), enc.name)
            };

            return(urlInfo);
        }
Esempio n. 15
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);
            }

            // TODO: Detecting modified data?
            //DateTime lastModified = this.GetLatestModifedEntryDateTime(entries);

            //if (SiteUtilities.GetStatusNotModified(lastModified))
            //    return null;

            RssRoot 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/");
            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");
            }

            RssChannel ch = new RssChannel();

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

            if (_dasBlogSettings.SiteConfiguration.Description == null || _dasBlogSettings.SiteConfiguration.Description.Trim().Length == 0)
            {
                ch.Description = _dasBlogSettings.SiteConfiguration.Subtitle;
            }
            else
            {
                ch.Description = _dasBlogSettings.SiteConfiguration.Description;
            }

            ch.Link      = _dasBlogSettings.GetBaseUrl();
            ch.Copyright = _dasBlogSettings.SiteConfiguration.Copyright;
            if (_dasBlogSettings.SiteConfiguration.RssLanguage != null && _dasBlogSettings.SiteConfiguration.RssLanguage.Length > 0)
            {
                ch.Language = _dasBlogSettings.SiteConfiguration.RssLanguage;
            }
            ch.ManagingEditor = _dasBlogSettings.SiteConfiguration.Contact;
            ch.WebMaster      = _dasBlogSettings.SiteConfiguration.Contact;
            ch.Image          = null;
            if (_dasBlogSettings.SiteConfiguration.ChannelImageUrl != null && _dasBlogSettings.SiteConfiguration.ChannelImageUrl.Trim().Length > 0)
            {
                newtelligence.DasBlog.Web.Services.Rss20.ChannelImage channelImage = new newtelligence.DasBlog.Web.Services.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;
            }

            documentRoot.Channels.Add(ch);

            foreach (Entry entry in entries)
            {
                if (entry.IsPublic == false || entry.Syndicated == false)
                {
                    continue;
                }
                XmlDocument       doc2        = new XmlDocument();
                List <XmlElement> anyElements = new List <XmlElement>();
                RssItem           item        = new RssItem();
                item.Title            = entry.Title;
                item.Guid             = new newtelligence.DasBlog.Web.Services.Rss20.Guid();
                item.Guid.IsPermaLink = false;
                item.Guid.Text        = _dasBlogSettings.GetPermaLinkUrl(entry.EntryId);
                item.Link             = _dasBlogSettings.GetPermaLinkUrl(entry.EntryId);
                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.RelativeToRoot("pingback");
                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)
                {
                    Nullable <double> latitude  = new Nullable <double>();
                    Nullable <double> 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.EntryId);
                        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.EntryId);
                }
                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);
        }