public ActionResult ListRss(int languageId)
        {
            DateTime? maxAge = null;
            var protocol = _webHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var selfLink = Url.Action("rss", "News", new { languageId = languageId }, protocol);
            var newsLink = Url.RouteUrl("NewsArchive", null, protocol);

            var title = "{0} - News".FormatInvariant(_storeContext.CurrentStore.Name);

            if (_newsSettings.MaxAgeInDays > 0)
                maxAge = DateTime.UtcNow.Subtract(new TimeSpan(_newsSettings.MaxAgeInDays, 0, 0, 0));

            var language = _languageService.GetLanguageById(languageId);
            var feed = new SmartSyndicationFeed(new Uri(newsLink), title);

            feed.AddNamespaces(true);
            feed.Init(selfLink, language);

            if (!_newsSettings.Enabled)
                return new RssActionResult { Feed = feed };

            var items = new List<SyndicationItem>();
            var newsItems = _newsService.GetAllNews(languageId, _storeContext.CurrentStore.Id, 0, int.MaxValue, false, maxAge);

            foreach (var news in newsItems)
            {
                var newsUrl = Url.RouteUrl("NewsItem", new { SeName = news.GetSeName(news.LanguageId, ensureTwoPublishedLanguages: false) }, "http");

                var item = feed.CreateItem(news.Title, news.Short, newsUrl, news.CreatedOnUtc, news.Full);

                items.Add(item);
            }

            feed.Items = items;

            return new RssActionResult { Feed = feed };
        }
        public ActionResult ForumRss(int id)
        {
            if (!_forumSettings.ForumsEnabled)
                return HttpNotFound();

            var language = _workContext.WorkingLanguage;
            var protocol = _webHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var selfLink = Url.Action("ForumRSS", "Boards", null, protocol);
            var forumLink = Url.Action("Forum", "Boards", new { id = id }, protocol);

            var feed = new SmartSyndicationFeed(new Uri(forumLink), _storeContext.CurrentStore.Name, T("Forum.ForumFeedDescription"));

            feed.AddNamespaces(false);
            feed.Init(selfLink, language);

            if (!_forumSettings.ForumFeedsEnabled)
                return new RssActionResult { Feed = feed };

            var forum = _forumService.GetForumById(id);

            if (forum == null)
                return new RssActionResult { Feed = feed };

            feed.Title = new TextSyndicationContent("{0} - {1}".FormatInvariant(_storeContext.CurrentStore.Name, forum.GetLocalized(x => x.Name, language.Id)));

            var items = new List<SyndicationItem>();
            var topics = _forumService.GetAllTopics(id, 0, string.Empty, ForumSearchType.All, 0, 0, _forumSettings.ForumFeedCount);

            var viewsText = T("Forum.Views");
            var repliesText = T("Forum.Replies");

            foreach (var topic in topics)
            {
                string topicUrl = Url.RouteUrl("TopicSlug", new { id = topic.Id, slug = topic.GetSeName() }, "http");
                var synopsis = "{0}: {1}, {2}: {3}".FormatInvariant(repliesText, topic.NumReplies, viewsText, topic.Views);

                var item = feed.CreateItem(topic.Subject, synopsis, topicUrl, topic.LastPostTime ?? topic.UpdatedOnUtc);

                items.Add(item);
            }

            feed.Items = items;

            return new RssActionResult { Feed = feed };
        }
        public ActionResult ActiveDiscussionsRss(int forumId = 0)
        {
            if (!_forumSettings.ForumsEnabled)
                return HttpNotFound();

            var language = _workContext.WorkingLanguage;
            var protocol = _webHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var selfLink = Url.Action("ActiveDiscussionsRSS", "Boards", null, protocol);
            var discussionLink = Url.Action("ActiveDiscussions", "Boards", null, protocol);

            var title = "{0} - {1}".FormatInvariant(_storeContext.CurrentStore.Name, T("Forum.ActiveDiscussionsFeedTitle"));

            var feed = new SmartSyndicationFeed(new Uri(discussionLink), title, T("Forum.ActiveDiscussionsFeedDescription"));

            feed.AddNamespaces(false);
            feed.Init(selfLink, language);

            if (!_forumSettings.ActiveDiscussionsFeedEnabled)
                return new RssActionResult { Feed = feed };

            var items = new List<SyndicationItem>();
            var topics = _forumService.GetActiveTopics(forumId, _forumSettings.ActiveDiscussionsFeedCount);

            var viewsText = T("Forum.Views");
            var repliesText = T("Forum.Replies");

            foreach (var topic in topics)
            {
                string topicUrl = Url.RouteUrl("TopicSlug", new { id = topic.Id, slug = topic.GetSeName() }, "http");
                var synopsis = "{0}: {1}, {2}: {3}".FormatInvariant(repliesText, topic.NumReplies, viewsText, topic.Views);

                var item = feed.CreateItem(topic.Subject, synopsis, topicUrl, topic.LastPostTime ?? topic.UpdatedOnUtc);

                items.Add(item);
            }

            feed.Items = items;

            return new RssActionResult { Feed = feed };
        }
예제 #4
0
        /// <summary>
        /// Creates a RSS feed with forum topics
        /// </summary>
        /// <param name="urlHelper">UrlHelper to generate URLs</param>
        /// <returns>SmartSyndicationFeed object</returns>
        public virtual SmartSyndicationFeed CreateForumRssFeed(UrlHelper urlHelper, int forumId)
        {
            if (urlHelper == null)
                throw new ArgumentNullException("urlHelper");

            var language = _services.WorkContext.WorkingLanguage;
            var protocol = _services.WebHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var selfLink = urlHelper.Action("ForumRSS", "Boards", null, protocol);
            var forumLink = urlHelper.Action("Forum", "Boards", new { id = forumId }, protocol);

            var feed = new SmartSyndicationFeed(new Uri(forumLink), _services.StoreContext.CurrentStore.Name, _services.Localization.GetResource("Forum.ForumFeedDescription"));

            feed.AddNamespaces(false);
            feed.Init(selfLink, language);

            if (!_forumSettings.ForumFeedsEnabled)
                return feed;

            var forum = GetForumById(forumId);

            if (forum == null)
                return feed;

            feed.Title = new TextSyndicationContent("{0} - {1}".FormatInvariant(_services.StoreContext.CurrentStore.Name, forum.GetLocalized(x => x.Name, language.Id)));

            var items = new List<SyndicationItem>();
            var topics = GetAllTopics(forumId, 0, string.Empty, ForumSearchType.All, 0, 0, _forumSettings.ForumFeedCount);

            var viewsText = _services.Localization.GetResource("Forum.Views");
            var repliesText = _services.Localization.GetResource("Forum.Replies");

            foreach (var topic in topics)
            {
                string topicUrl = urlHelper.RouteUrl("TopicSlug", new { id = topic.Id, slug = topic.GetSeName() }, "http");
                var synopsis = "{0}: {1}, {2}: {3}".FormatInvariant(repliesText, topic.NumReplies, viewsText, topic.Views);

                var item = feed.CreateItem(topic.Subject, synopsis, topicUrl, topic.LastPostTime ?? topic.UpdatedOnUtc);

                items.Add(item);
            }

            feed.Items = items;

            return feed;
        }
예제 #5
0
        /// <summary>
        /// Creates a RSS feed with blog posts
        /// </summary>
        /// <param name="urlHelper">UrlHelper to generate URLs</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>SmartSyndicationFeed object</returns>
        public virtual SmartSyndicationFeed CreateRssFeed(UrlHelper urlHelper, int languageId)
        {
            if (urlHelper == null)
                throw new ArgumentNullException("urlHelper");

            DateTime? maxAge = null;
            var protocol = _services.WebHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var selfLink = urlHelper.RouteUrl("BlogRSS", new { languageId = languageId }, protocol);
            var blogLink = urlHelper.RouteUrl("Blog", null, protocol);

            var title = "{0} - Blog".FormatInvariant(_services.StoreContext.CurrentStore.Name);

            if (_blogSettings.MaxAgeInDays > 0)
                maxAge = DateTime.UtcNow.Subtract(new TimeSpan(_blogSettings.MaxAgeInDays, 0, 0, 0));

            var language = _languageService.GetLanguageById(languageId);
            var feed = new SmartSyndicationFeed(new Uri(blogLink), title);

            feed.AddNamespaces(false);
            feed.Init(selfLink, language);

            if (!_blogSettings.Enabled)
                return feed;

            var items = new List<SyndicationItem>();
            var blogPosts = GetAllBlogPosts(_services.StoreContext.CurrentStore.Id, languageId, null, null, 0, int.MaxValue, false, maxAge);

            foreach (var blogPost in blogPosts)
            {
                var blogPostUrl = urlHelper.RouteUrl("BlogPost", new { SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false) }, "http");

                var item = feed.CreateItem(blogPost.Title, blogPost.Body, blogPostUrl, blogPost.CreatedOnUtc);

                items.Add(item);
            }

            feed.Items = items;

            return feed;
        }
        public ActionResult RecentlyAddedProductsRss()
        {
            var protocol = _services.WebHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var selfLink = Url.RouteUrl("RecentlyAddedProductsRSS", null, protocol);
            var recentProductsLink = Url.RouteUrl("RecentlyAddedProducts", null, protocol);

            var title = "{0} - {1}".FormatInvariant(_services.StoreContext.CurrentStore.Name, T("RSS.RecentlyAddedProducts"));

            var feed = new SmartSyndicationFeed(new Uri(recentProductsLink), title, T("RSS.InformationAboutProducts"));

            feed.AddNamespaces(true);
            feed.Init(selfLink, _services.WorkContext.WorkingLanguage);

            if (!_catalogSettings.RecentlyAddedProductsEnabled)
                return new RssActionResult { Feed = feed };

            var items = new List<SyndicationItem>();
            var searchContext = new ProductSearchContext
            {
                LanguageId = _services.WorkContext.WorkingLanguage.Id,
                OrderBy = ProductSortingEnum.CreatedOn,
                PageSize = _catalogSettings.RecentlyAddedProductsNumber,
                StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode,
                VisibleIndividuallyOnly = true
            };

            var products = _productService.SearchProducts(searchContext);
            var storeUrl = _services.StoreContext.CurrentStore.Url;

            foreach (var product in products)
            {
                string productUrl = Url.RouteUrl("Product", new { SeName = product.GetSeName() }, "http");
                if (productUrl.HasValue())
                {
                    var item = feed.CreateItem(
                        product.GetLocalized(x => x.Name),
                        product.GetLocalized(x => x.ShortDescription),
                        productUrl,
                        product.CreatedOnUtc,
                        product.FullDescription);

                    try
                    {
                        // we add only the first picture
                        var picture = product.ProductPictures.OrderBy(x => x.DisplayOrder).Select(x => x.Picture).FirstOrDefault();

                        if (picture != null)
                        {
                            feed.AddEnclosue(item, picture, _pictureService.GetPictureUrl(picture, _mediaSettings.ProductDetailsPictureSize, false, storeUrl));
                        }
                    }
                    catch { }

                    items.Add(item);
                }
            }

            feed.Items = items;

            return new RssActionResult { Feed = feed };
        }