Exemplo n.º 1
0
 /// <summary>
 /// Inserts an element into the AtomCategoryCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the AtomCategory is to be inserted.
 /// </param>
 /// <param name="value">
 /// The AtomCategory to insert.
 /// </param>
 public virtual void Insert(int index, AtomCategory value)
 {
     this.List.Insert(index, value);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Removes the first occurrence of a specific AtomCategory from this AtomCategoryCollection.
 /// </summary>
 /// <param name="value">
 /// The AtomCategory value to remove from this AtomCategoryCollection.
 /// </param>
 public virtual void Remove(AtomCategory value)
 {
     this.List.Remove(value);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Determines whether a specfic AtomCategory value is in this AtomCategoryCollection.
 /// </summary>
 /// <param name="value">
 /// The AtomCategory value to locate in this AtomCategoryCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this AtomCategoryCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(AtomCategory value)
 {
     return(this.List.Contains(value));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this AtomCategoryCollection
 /// </summary>
 /// <param name="value">
 /// The AtomCategory value to locate in the AtomCategoryCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(AtomCategory value)
 {
     return(this.List.IndexOf(value));
 }
        private AtomRoot GetAtomCore(string category, int maxDayCount, int maxEntryCount)
        {
            if (RedirectToFeedBurnerIfNeeded(category) == true)
            {
                return null;
            }

            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);
            }

            //Try to get out as soon as possible with as little CPU as possible
            if ( inASMX )
            {
                if (SiteUtilities.GetStatusNotModified(SiteUtilities.GetLatestModifedEntryDateTime(dataService, entries)))
                    return null;
            }

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

            //not-modified didn't work, do we have this in cache?
            string CacheKey = "Atom:" + category + ":" + maxDayCount.ToString() + ":" + maxEntryCount.ToString();
            AtomRoot atomFeed = cache[CacheKey] as AtomRoot;
            if (atomFeed == null) //we'll have to build it...
            {
                atomFeed = new AtomRoot();

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

                if (siteConfig.RssLanguage != null && siteConfig.RssLanguage.Length >0)
                {
                    atomFeed.Lang = siteConfig.RssLanguage;
                }
                else //original default behavior of dasBlog
                {
                    atomFeed.Lang = "en-us";
                }

                if(category == null)
                {
                    atomFeed.Title = siteConfig.Title;
                }
                else
                {
                    atomFeed.Title = siteConfig.Title + " - " + category;
                }

                atomFeed.Tagline = siteConfig.Subtitle;
                atomFeed.Links.Add(new AtomLink(SiteUtilities.GetBaseUrl(siteConfig)));
                atomFeed.Links.Add(new AtomLink(SiteUtilities.GetAtomUrl(siteConfig),"self",null));
                atomFeed.Author = new AtomParticipant();
                atomFeed.Author.Name = siteConfig.Copyright;
                atomFeed.Generator = new AtomGenerator();
                atomFeed.Generator.Version = GetType().Assembly.GetName().Version.ToString();
                atomFeed.Icon = "favicon.ico";

                atomFeed.Id = SiteUtilities.GetBaseUrl(siteConfig);

                atomFeed.Logo = null;
                if (siteConfig.ChannelImageUrl != null && siteConfig.ChannelImageUrl.Trim().Length > 0)
                {
                    if (siteConfig.ChannelImageUrl.StartsWith("http"))
                    {
                        atomFeed.Logo = siteConfig.ChannelImageUrl;
                    }
                    else
                    {
                        atomFeed.Logo= SiteUtilities.RelativeToRoot(siteConfig,siteConfig.ChannelImageUrl);
                    }
                }

                DateTime feedModified = DateTime.MinValue;

                foreach (Entry entry in entries)
                {
                    if (entry.IsPublic == false || entry.Syndicated == false)
                    {
                        continue;
                    }

                    string entryLink = SiteUtilities.GetPermaLinkUrl(siteConfig, entry);
                    string entryGuid = SiteUtilities.GetPermaLinkUrl(siteConfig, entry.EntryId);

                    AtomEntry atomEntry = new AtomEntry(entry.Title, new AtomLink(entryLink), entryGuid, entry.CreatedUtc, entry.ModifiedUtc);
                    //atomEntry.Created = entry.CreatedUtc; //not needed in 1.0
                    atomEntry.Summary = PreprocessItemContent(entry.EntryId, entry.Description);

                    if (entry.Categories != null && entry.Categories.Length > 0)
                    {
                        if(atomEntry.Categories == null) atomEntry.Categories = new AtomCategoryCollection();

                        string[] cats = entry.Categories.Split(';');
                        foreach(string c in cats)
                        {
                            AtomCategory cat = new AtomCategory();

                            //paulb: scheme should be a valid IRI, acsording to the spec
                            // (http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.category)
                            // so I changed this to the Category view for specified category. Now the feed validator likes us again ;-)
                            cat.Scheme = SiteUtilities.GetCategoryViewUrl( siteConfig, c ); // "hierarchical";
                            // sub categories should be delimited using the path delimiter
                            string cleanCat = c.Replace('|', '/');
                            //Grab the first category, atom doesn't let us do otherwise!
                            cat.Term = HttpUtility.HtmlEncode(cleanCat);
                            cat.Label = HttpUtility.HtmlEncode(cleanCat);
                            atomEntry.Categories.Add(cat);
                        }
                    }

                    // only if we don't have a summary we emit the content
                    if ( siteConfig.AlwaysIncludeContentInRSS || entry.Description == null || entry.Description.Length == 0 )
                    {
                        atomEntry.Summary = null; // remove empty summary tag

                        try
                        {
                            AtomContent atomContent = new AtomContent();
                            atomContent.Type = "xhtml";

                            XmlDocument xmlDoc2 = new XmlDocument();
                            xmlDoc2.LoadXml(ContentFormatter.FormatContentAsXHTML(PreprocessItemContent(entry.EntryId, entry.Content),"div"));
                            atomContent.anyElements = new XmlElement[]{xmlDoc2.DocumentElement};

                            // set the langauge for the content item
                            atomContent.Lang = entry.Language;

                            atomEntry.Content = atomContent;
                        }
                        catch(Exception) //XHTML isn't happening today
                        {
                            //Try again as HTML
                            AtomContent atomContent = new AtomContent();
                            atomContent.Type = "html";
                            atomContent.TextContent = ContentFormatter.FormatContentAsHTML(PreprocessItemContent(entry.EntryId, entry.Content));
                            // set the langauge for the content item
                            atomContent.Lang = entry.Language;

                            atomEntry.Content = atomContent;
                        }
                    }

                    if (atomEntry.ModifiedUtc > feedModified)
                        feedModified = atomEntry.ModifiedUtc;

                    atomFeed.Entries.Add(atomEntry);
                }

                // set feed modified date to the most recent entry date
                atomFeed.ModifiedUtc = feedModified;
                cache.Insert(CacheKey,atomFeed,DateTime.Now.AddMinutes(5));
            }
            return atomFeed;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Adds an instance of type AtomCategory to the end of this AtomCategoryCollection.
 /// </summary>
 /// <param name="value">
 /// The AtomCategory to be added to the end of this AtomCategoryCollection.
 /// </param>
 public virtual void Add(AtomCategory value)
 {
     this.List.Add(value);
 }
Exemplo n.º 7
0
		/// <summary>
		/// Adds an instance of type AtomCategory to the end of this AtomCategoryCollection.
		/// </summary>
		/// <param name="value">
		/// The AtomCategory to be added to the end of this AtomCategoryCollection.
		/// </param>
		public virtual void Add(AtomCategory value)
		{
			this.List.Add(value);
		}
Exemplo n.º 8
0
		/// <summary>
		/// Determines whether a specfic AtomCategory value is in this AtomCategoryCollection.
		/// </summary>
		/// <param name="value">
		/// The AtomCategory value to locate in this AtomCategoryCollection.
		/// </param>
		/// <returns>
		/// true if value is found in this AtomCategoryCollection;
		/// false otherwise.
		/// </returns>
		public virtual bool Contains(AtomCategory value)
		{
			return this.List.Contains(value);
		}
Exemplo n.º 9
0
		/// <summary>
		/// Adds the elements of an array to the end of this AtomCategoryCollection.
		/// </summary>
		/// <param name="entries">
		/// The array whose elements are to be added to the end of this AtomCategoryCollection.
		/// </param>
		public virtual void AddRange(AtomCategory[] entries)
		{
			foreach (AtomCategory entry in entries)
			{
				this.List.Add(entry);
			}
		}
Exemplo n.º 10
0
		/// <summary>
		/// Initializes a new instance of the AtomCategoryCollection class, containing elements
		/// copied from an array.
		/// </summary>
		/// <param name="entries">
		/// The array whose elements are to be added to the new AtomCategoryCollection.
		/// </param>
		public AtomCategoryCollection(AtomCategory[] entries)
		{
			this.AddRange(entries);
		}
Exemplo n.º 11
0
		/// <summary>
		/// Removes the first occurrence of a specific AtomCategory from this AtomCategoryCollection.
		/// </summary>
		/// <param name="value">
		/// The AtomCategory value to remove from this AtomCategoryCollection.
		/// </param>
		public virtual void Remove(AtomCategory value)
		{
			this.List.Remove(value);
		}
Exemplo n.º 12
0
		/// <summary>
		/// Inserts an element into the AtomCategoryCollection at the specified index
		/// </summary>
		/// <param name="index">
		/// The index at which the AtomCategory is to be inserted.
		/// </param>
		/// <param name="value">
		/// The AtomCategory to insert.
		/// </param>
		public virtual void Insert(int index, AtomCategory value)
		{
			this.List.Insert(index, value);
		}
Exemplo n.º 13
0
		/// <summary>
		/// Return the zero-based index of the first occurrence of a specific value
		/// in this AtomCategoryCollection
		/// </summary>
		/// <param name="value">
		/// The AtomCategory value to locate in the AtomCategoryCollection.
		/// </param>
		/// <returns>
		/// The zero-based index of the first occurrence of the _ELEMENT value if found;
		/// -1 otherwise.
		/// </returns>
		public virtual int IndexOf(AtomCategory value)
		{
			return this.List.IndexOf(value);
		}