public ActionResult ListRss()
        {
            DateTime?maxAge   = null;
            var      protocol = _webHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var      selfLink = Url.RouteUrl("BlogRSS", null, protocol);
            var      blogLink = Url.RouteUrl("Blog", null, protocol);
            var      language = _services.WorkContext.WorkingLanguage;
            var      store    = _services.StoreContext.CurrentStore;
            var      title    = "{0} - Blog".FormatInvariant(store.Name);

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

            var feed = new SmartSyndicationFeed(new Uri(blogLink), title);

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

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

            var items     = new List <SyndicationItem>();
            var blogPosts = _blogService.GetAllBlogPosts(store.Id, null, null, 0, int.MaxValue, language.Id, false, maxAge);

            foreach (var blogPost in blogPosts)
            {
                var blogPostUrl = Url.RouteUrl("BlogPost", new { SeName = blogPost.GetSeName(ensureTwoPublishedLanguages: false) }, protocol);
                var content     = blogPost.GetLocalized(x => x.Body, detectEmptyHtml: true).Value;

                if (content.HasValue())
                {
                    content = WebHelper.MakeAllUrlsAbsolute(content, Request);
                }

                var item = feed.CreateItem(
                    blogPost.GetLocalized(x => x.Title),
                    content,
                    blogPostUrl,
                    blogPost.CreatedOnUtc);

                items.Add(item);

                Services.DisplayControl.Announce(blogPost);
            }

            feed.Items = items;

            Services.DisplayControl.AnnounceRange(blogPosts);

            return(new RssActionResult {
                Feed = feed
            });
        }
Example #2
0
        public ActionResult ListRss()
        {
            DateTime?maxAge   = null;
            var      language = _services.WorkContext.WorkingLanguage;
            var      store    = _services.StoreContext.CurrentStore;
            var      protocol = _webHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var      selfLink = Url.Action("rss", "News", null, protocol);
            var      newsLink = Url.RouteUrl("NewsArchive", null, protocol);
            var      title    = "{0} - News".FormatInvariant(store.Name);

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

            var feed = new SmartSyndicationFeed(new Uri(newsLink), title);

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

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

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

            foreach (var news in newsItems)
            {
                var newsUrl = Url.RouteUrl("NewsItem", new { SeName = news.GetSeName(ensureTwoPublishedLanguages: false) }, protocol);
                var content = news.GetLocalized(x => x.Full, true).Value;

                if (content.HasValue())
                {
                    content = WebHelper.MakeAllUrlsAbsolute(content, Request);
                }

                var item = feed.CreateItem(
                    news.GetLocalized(x => x.Title),
                    news.GetLocalized(x => x.Short),
                    newsUrl,
                    news.CreatedOnUtc,
                    content);

                items.Add(item);
            }

            feed.Items = items;

            Services.DisplayControl.AnnounceRange(newsItems);

            return(new RssActionResult {
                Feed = feed
            });
        }
Example #3
0
        public ActionResult ListRss(int?languageId)
        {
            languageId = languageId ?? _services.WorkContext.WorkingLanguage.Id;

            DateTime?maxAge       = null;
            var      protocol     = _webHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var      selfLink     = Url.RouteUrl("BlogRSS", new { languageId }, protocol);
            var      blogLink     = Url.RouteUrl("Blog", null, protocol);
            var      currentStore = _services.StoreContext.CurrentStore;
            var      title        = "{0} - Blog".FormatInvariant(currentStore.Name);

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

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

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

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

            var items     = new List <SyndicationItem>();
            var blogPosts = _blogService.GetAllBlogPosts(currentStore.Id, languageId.Value, null, null, 0, int.MaxValue, false, maxAge);

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

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

                items.Add(item);

                Services.DisplayControl.Announce(blogPost);
            }

            feed.Items = items;

            return(new RssActionResult {
                Feed = feed
            });
        }
Example #4
0
        public ActionResult ListRss(int?languageId)
        {
            languageId = languageId ?? _services.WorkContext.WorkingLanguage.Id;

            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(_services.StoreContext.CurrentStore.Name);

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

            var language = _languageService.GetLanguageById(languageId.Value);
            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.Value, _services.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) }, protocol);

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

                items.Add(item);
            }

            feed.Items = items;

            Services.DisplayControl.AnnounceRange(newsItems);

            return(new RssActionResult {
                Feed = feed
            });
        }
        public async Task <IActionResult> RecentlyAddedProductsRSS(CatalogSearchQuery query)
        {
            // TODO: (mc) find a more prominent place for the "NewProducts" link (may be in main menu?)
            var store              = Services.StoreContext.CurrentStore;
            var protocol           = Services.WebHelper.IsCurrentConnectionSecured() ? "https" : "http";
            var selfLink           = Url.RouteUrl("RecentlyAddedProductsRSS", null, protocol);
            var recentProductsLink = Url.RouteUrl("RecentlyAddedProducts", null, protocol);
            var title              = $"{store.Name} - {T("RSS.RecentlyAddedProducts")}";
            var feed = new SmartSyndicationFeed(new Uri(recentProductsLink), title, T("RSS.InformationAboutProducts"));

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

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

            var items = new List <SyndicationItem>();

            query.Sorting.Clear();
            query = query
                    .BuildFacetMap(false)
                    .SortBy(ProductSortingEnum.CreatedOn)
                    .Slice(0, _catalogSettings.RecentlyAddedProductsNumber);

            var result = await _catalogSearchService.SearchAsync(query);

            var hits = await result.GetHitsAsync();

            var storeUrl = store.GetHost();

            // Prefetching.
            var fileIds = hits
                          .Select(x => x.MainPictureId ?? 0)
                          .Where(x => x != 0)
                          .Distinct()
                          .ToArray();

            var files = (await Services.MediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

            foreach (var product in hits)
            {
                var productUrl = Url.RouteUrl("Product", new { SeName = await product.GetActiveSlugAsync() }, protocol);
                if (productUrl.HasValue())
                {
                    var content = product.GetLocalized(x => x.FullDescription).Value;

                    if (content.HasValue())
                    {
                        content = WebHelper.MakeAllUrlsAbsolute(content, Request);
                    }

                    var item = feed.CreateItem(
                        product.GetLocalized(x => x.Name),
                        product.GetLocalized(x => x.ShortDescription),
                        productUrl,
                        product.CreatedOnUtc,
                        content);

                    try
                    {
                        // We add only the first media file.
                        if (files.TryGetValue(product.MainPictureId ?? 0, out var file))
                        {
                            var url = Services.MediaService.GetUrl(file, _mediaSettings.ProductDetailsPictureSize, storeUrl, false);
                            feed.AddEnclosure(item, file, url);
                        }
                    }
                    catch
                    {
                    }

                    items.Add(item);
                }
            }

            feed.Items = items;

            Services.DisplayControl.AnnounceRange(hits);

            return(new RssActionResult {
                Feed = feed
            });
        }
        public ActionResult RecentlyAddedProductsRss(CatalogSearchQuery query)
        {
            // TODO: (mc) find a more prominent place for the "NewProducts" link (may be in main menu?)
            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 || _catalogSettings.RecentlyAddedProductsNumber <= 0)
            {
                return(new RssActionResult {
                    Feed = feed
                });
            }

            var items = new List <SyndicationItem>();

            query.Sorting.Clear();
            query = query
                    .BuildFacetMap(false)
                    .SortBy(ProductSortingEnum.CreatedOn)
                    .Slice(0, _catalogSettings.RecentlyAddedProductsNumber);

            var result = _catalogSearchService.Search(query);

            var storeUrl = Services.StoreService.GetHost(Services.StoreContext.CurrentStore);

            // Prefecthing
            var allPictureInfos = Services.PictureService.GetPictureInfos(result.Hits);

            //_mediaSettings.ProductDetailsPictureSize, false, storeUrl

            foreach (var product in result.Hits)
            {
                string productUrl = Url.RouteUrl("Product", new { SeName = product.GetSeName() }, protocol);
                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 = Services.PictureService.GetPictureById(product.MainPictureId.GetValueOrDefault());
                        if (picture != null)
                        {
                            feed.AddEnclosure(item, picture, Services.PictureService.GetUrl(picture, _mediaSettings.ProductDetailsPictureSize, FallbackPictureType.NoFallback, storeUrl));
                        }
                    }
                    catch { }

                    items.Add(item);
                }
            }

            feed.Items = items;

            Services.DisplayControl.AnnounceRange(result.Hits);

            return(new RssActionResult {
                Feed = feed
            });
        }