public async Task <IActionResult> List(ContentOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var pager = new Pager(pagerParameters, siteSettings.PageSize);

            var sitemaps = (await _sitemapManager.GetSitemapsAsync())
                           .OfType <SitemapIndex>();

            if (!string.IsNullOrWhiteSpace(options.Search))
            {
                sitemaps = sitemaps.Where(x => x.Name.Contains(options.Search, StringComparison.OrdinalIgnoreCase));
            }

            var count = sitemaps.Count();

            var results = sitemaps
                          .Skip(pager.GetStartIndex())
                          .Take(pager.PageSize)
                          .ToList();

            // Maintain previous route data when generating page links
            var routeData = new RouteData();

            routeData.Values.Add("Options.Search", options.Search);

            var pagerShape = (await New.Pager(pager)).TotalItemCount(count).RouteData(routeData);

            var model = new ListSitemapIndexViewModel
            {
                SitemapIndexes = results.Select(sm => new SitemapIndexListEntry {
                    SitemapId = sm.SitemapId, Name = sm.Name, Enabled = sm.Enabled
                }).ToList(),
                Options = options,
                Pager   = pagerShape
            };

            model.Options.ContentsBulkAction = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = S["Delete"], Value = nameof(ContentsBulkAction.Remove)
                }
            };

            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> List(SitemapIndexListOptions options, PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var pager = new Pager(pagerParameters, siteSettings.PageSize);

            // default options
            if (options == null)
            {
                options = new SitemapIndexListOptions();
            }

            var sitemaps = (await _sitemapManager.GetSitemapsAsync())
                           .OfType <SitemapIndex>();

            if (!string.IsNullOrWhiteSpace(options.Search))
            {
                sitemaps = sitemaps.Where(smp => smp.Name.Contains(options.Search));
            }

            var count = sitemaps.Count();

            var results = sitemaps
                          .Skip(pager.GetStartIndex())
                          .Take(pager.PageSize)
                          .ToList();

            // Maintain previous route data when generating page links
            var routeData = new RouteData();

            routeData.Values.Add("Options.Search", options.Search);

            var pagerShape = (await New.Pager(pager)).TotalItemCount(count).RouteData(routeData);

            var model = new ListSitemapIndexViewModel
            {
                SitemapIndexes = results.Select(sm => new SitemapIndexListEntry {
                    SitemapId = sm.SitemapId, Name = sm.Name, Enabled = sm.Enabled
                }).ToList(),
                Options = options,
                Pager   = pagerShape
            };

            return(View(model));
        }
        public async Task ValidatePathAsync(string path, IUpdateModel updater, string sitemapId = null)
        {
            // Keep localized text as similar to Autoroute as possible.
            if (path == "/")
            {
                updater.ModelState.AddModelError(Prefix, Path, S["Your permalink can't be set to the homepage"]);
            }

            if (path.IndexOfAny(InvalidCharactersForPath) > -1 || path.IndexOf(' ') > -1)
            {
                var invalidCharactersForMessage = string.Join(", ", InvalidCharactersForPath.Select(c => $"\"{c}\""));
                updater.ModelState.AddModelError(Prefix, Path, S["Please do not use any of the following characters in your permalink: {0}. No spaces are allowed (please use dashes or underscores instead).", invalidCharactersForMessage]);
            }

            // Precludes possibility of collision with Autoroute as Autoroute excludes . as a valid path character.
            if (!path.EndsWith(Sitemap.PathExtension))
            {
                updater.ModelState.AddModelError(Prefix, Path, S["Your permalink must end with {0}.", Sitemap.PathExtension]);
            }

            if (path.Length > MaxPathLength)
            {
                updater.ModelState.AddModelError(Prefix, Path, S["Your permalink is too long. The permalink can only be up to {0} characters.", MaxPathLength]);
            }

            var routeExists = false;

            if (string.IsNullOrEmpty(sitemapId))
            {
                routeExists = (await _sitemapManager.GetSitemapsAsync())
                              .Any(p => String.Equals(p.Path, path.TrimStart('/'), StringComparison.OrdinalIgnoreCase));
            }
            else
            {
                routeExists = (await _sitemapManager.GetSitemapsAsync())
                              .Any(p => p.SitemapId != sitemapId && String.Equals(p.Path, path.TrimStart('/'), StringComparison.OrdinalIgnoreCase));
            }

            if (routeExists)
            {
                updater.ModelState.AddModelError(Prefix, Path, S["Your permalink is already in use."]);
            }
        }
Exemple #4
0
        public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
        {
            if (!(step is AllSitemapsDeploymentStep))
            {
                return;
            }

            var sitemaps = await _sitemapManager.GetSitemapsAsync();

            var jArray = JArray.FromObject(sitemaps, Serializer);

            result.Steps.Add(new JObject(
                                 new JProperty("name", "Sitemaps"),
                                 new JProperty("data", jArray)
                                 ));
        }
        public override async Task BuildSitemapTypeAsync(SitemapIndex sitemap, SitemapBuilderContext context)
        {
            context.Response = new SitemapResponse
            {
                ResponseElement = new XElement(Namespace + "sitemapindex",
                                               new XAttribute(XNamespace.Xmlns + "xsi", SchemaInstance),
                                               new XAttribute(SchemaInstance + "schemaLocation", SchemaLocation))
            };

            var indexSource = sitemap.SitemapSources.FirstOrDefault() as SitemapIndexSource;

            if (indexSource == null)
            {
                return;
            }

            var containedSitemaps = (await _sitemapManager.GetSitemapsAsync())
                                    .Where(s => s.Enabled && indexSource.ContainedSitemapIds.Any(id => id == s.SitemapId));

            foreach (var containedSitemap in containedSitemaps)
            {
                var xmlSitemap = new XElement(Namespace + "sitemap");
                var loc        = new XElement(Namespace + "loc");

                var routeValues = new RouteValueDictionary(_sitemapsOptions.GlobalRouteValues)
                {
                    [_sitemapsOptions.SitemapIdKey] = containedSitemap.SitemapId
                };

                loc.Add(context.HostPrefix + context.UrlHelper.Action(routeValues["Action"].ToString(), routeValues));
                xmlSitemap.Add(loc);

                var lastModDate = await _sitemapModifiedDateProvider.GetLastModifiedDateAsync(containedSitemap);

                if (lastModDate.HasValue)
                {
                    var lastMod = new XElement(Namespace + "lastmod");
                    lastMod.Add(lastModDate.GetValueOrDefault().ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture));
                    xmlSitemap.Add(lastMod);
                }

                context.Response.ResponseElement.Add(xmlSitemap);
            }
        }
Exemple #6
0
        private async Task BuildEntriesAsync(string identifier)
        {
            var document = new SitemapRouteDocument()
            {
                Identifier = identifier
            };

            var sitemaps = await _sitemapManager.GetSitemapsAsync();

            foreach (var sitemap in sitemaps)
            {
                if (!sitemap.Enabled)
                {
                    continue;
                }

                document.SitemapIds[sitemap.Path]        = sitemap.SitemapId;
                document.SitemapPaths[sitemap.SitemapId] = sitemap.Path;
            }

            _document = document;
        }