コード例 #1
0
        /// <summary>
        /// Returns an RSS feed of Articles
        /// </summary>
        /// <returns></returns>
        public RssChannel GetRssFeed()
        {
            RssChannel ArticlesRSS = new RssChannel();

            IList<Article> ArticleList = _contentItemService.FindSyndicatedContentItemsBySection(this.Section, new ContentItemQuerySettings(ContentItemSortBy.PublishedAt, ContentItemSortDirection.DESC));

            foreach(Article a in ArticleList)
            {
                RssItem r = new RssItem();
                r.Author = a.CreatedBy.FullName;

                //Collate catagories to a string
                string catagories = string.Empty;
                for(int i=0; i < a.Categories.Count; i++)
                {
                    catagories += a.Categories[i].Name + ((i != a.Categories.Count - 1) ? " / " : ".");
                }
                r.Category = catagories;

                r.Description = a.Summary;
                r.ItemId = (int)a.Id;
                r.Link = UrlHelper.GetFullUrlFromSection(this.Section) + "/" + a.Id;
                r.PubDate = a.CreatedAt;
                r.Title = a.Title;

                ArticlesRSS.RssItems.Add(r);
            }

            return ArticlesRSS;
        }
コード例 #2
0
        public RssChannel GetRssFeed()
        {
            RssChannel channel = new RssChannel();
            channel.Title = this.Section.Title;
            // channel.Link = "" (can't determine link here because the ArticleModule has no notion of any URL context).
            channel.Description = this.Section.Title; // TODO: Section needs a description.
            channel.Language = this.Section.Node.Culture;
            channel.PubDate = DateTime.Now;
            channel.LastBuildDate = DateTime.Now;
            IList articles = null;
            // We can have an rss feed for the normal article list but also for the category view.
            if (base.ModulePathInfo.ToLower().IndexOf("category") > 0)
            {
                string expression = @"^\/category\/(\d+)";
                Regex categoryRegex = new Regex(expression, RegexOptions.Singleline|RegexOptions.CultureInvariant|RegexOptions.Compiled);
                if (categoryRegex.IsMatch(base.ModulePathInfo))
                {
                    this._currentCategoryId = Int32.Parse(categoryRegex.Match(base.ModulePathInfo).Groups[1].Value);
                    articles = GetRssArticlesByCategory();
                    // We still need the category for the title.
                    ArticleCategory category = (ArticleCategory)base.NHSession.Load(typeof(ArticleCategory), this._currentCategoryId);
                    channel.Title += String.Format(" ({0}) ", category.Title);
                }
            }
            else
            {
                int maxNumberOfItems = Int32.Parse(this.Section.Settings["NUMBER_OF_ARTICLES_IN_LIST"].ToString());
                articles = GetRssArticles(maxNumberOfItems);
            }

            DisplayType displayType = (DisplayType)Enum.Parse(typeof(DisplayType), this.Section.Settings["DISPLAY_TYPE"].ToString());
            foreach (Article article in articles)
            {
                RssItem item = new RssItem();
                item.ItemId = article.Id;
                item.Title = article.Title;
                // item.Link = "" (can't determine link here)
                item.Link = UrlHelper.GetFullUrlFromSection(base.Section) + "/" + item.ItemId; //Why? Otherwise limits module development :)
                if (displayType == DisplayType.FullContent)
                {
                    item.Description = article.Content;
                }
                else
                {
                    item.Description = article.Summary;
                }
                item.Author = article.ModifiedBy.FullName;
                if (article.Category != null)
                {
                    item.Category = article.Category.Title;
                }
                else
                {
                    item.Category = String.Empty;
                }
                item.PubDate = article.DateOnline;
                channel.RssItems.Add(item);
            }
            return channel;
        }