Esempio n. 1
0
        void RemoveAlias(AutoroutePart part)
        {
            var homePageId = _homeAliasService.GetHomePageId(VersionOptions.Latest);

            // Is this the current home page?
            if (part.ContentItem.Id == homePageId)
            {
                _tomeltServices.Notifier.Warning(T("You removed the content item that served as the site's home page. \nMost possibly this means that instead of the home page a \"404 Not Found\" page will be displayed. \n\nTo prevent this you can e.g. publish a content item that has the \"Set as home page\" checkbox ticked."));
            }
            _autorouteService.Value.RemoveAliases(part);
        }
Esempio n. 2
0
        void RemoveAlias(AutoroutePart part)
        {
            var homePageId = _homeAliasService.GetHomePageId();

            // Is this the current home page?
            if (part.ContentItem.Id == homePageId)
            {
                _orchardServices.Notifier.Warning(T("You removed the content item that served as the site\'s home page. \nMost possibly this means that instead of the home page a \"404 Not Found\" error page will be displayed without a link to log in or access the dashboard. \n\nTo prevent this you can e.g. publish a content item that has the \"Set as home page\" checkbox ticked."));
            }
            _autorouteService.Value.RemoveAliases(part);
        }
Esempio n. 3
0
        void RemoveAlias(AutoroutePart part)
        {
            var homePageId = _homeAliasService.GetHomePageId(VersionOptions.Latest);

            // Is this the current home page?
            if (part.ContentItem.Id == homePageId)
            {
                _orchardServices.Notifier.Warning(T("You removed the content item that served as the site's home page. \nMost possibly this means that instead of the home page a \"404 Not Found\" page will be displayed. \n\nTo prevent this you can e.g. publish a content item that has the \"Set as home page\" checkbox ticked."));
            }

            _lockingProvider.Lock(LockString, () => {
                var publishedPart = _contentManager.Get <AutoroutePart>(part.ContentItem.Id, VersionOptions.Published);
                _autorouteService.Value.RemoveAliases(publishedPart);
            });
        }
Esempio n. 4
0
        protected override DriverResult Editor(AutoroutePart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var settings    = part.TypePartDefinition.Settings.GetModel <AutorouteSettings>();
            var itemCulture = _cultureManager.GetSiteCulture();

            // If we are editing an existing content item, check to see if we are an ILocalizableAspect so we can use its culture for alias generation.
            if (part.Record.Id != 0)
            {
                var localizableAspect = part.As <ILocalizableAspect>();

                if (localizableAspect != null)
                {
                    itemCulture = localizableAspect.Culture;
                }
            }

            if (settings.UseCulturePattern)
            {
                // Hack: if the LocalizedPart is attached to the content item, it will submit the following form value,
                // which we use to determine what culture to use for alias generation.
                var context = _httpContextAccessor.Current();
                if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"]))
                {
                    itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
                }
            }

            // We update the settings assuming that when
            // pattern culture = null or "" it means culture = default website culture
            // for patterns that we migrated.
            foreach (var pattern in settings.Patterns.Where(x => String.IsNullOrWhiteSpace(x.Culture)))
            {
                pattern.Culture = _cultureManager.GetSiteCulture();;
            }

            // We do the same for default patterns.
            foreach (var pattern in settings.DefaultPatterns.Where(x => String.IsNullOrWhiteSpace(x.Culture)))
            {
                pattern.Culture = _cultureManager.GetSiteCulture();
            }

            // If the content type has no pattern for autoroute, then use a default one.
            if (!settings.Patterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase)))
            {
                settings.Patterns = new List <RoutePattern> {
                    new RoutePattern {
                        Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture
                    }
                };
            }

            // If the content type has no defaultPattern for autoroute, then use a default one.
            if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase)))
            {
                // If we are in the default culture, check the old setting.
                if (String.Equals(itemCulture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase))
                {
                    if (!String.IsNullOrWhiteSpace(settings.DefaultPatternIndex))
                    {
                        var patternIndex = settings.DefaultPatternIndex;
                        settings.DefaultPatterns.Add(new DefaultPattern {
                            PatternIndex = patternIndex, Culture = itemCulture
                        });
                    }
                    else
                    {
                        settings.DefaultPatterns.Add(new DefaultPattern {
                            PatternIndex = "0", Culture = itemCulture
                        });
                    }
                }
                else
                {
                    settings.DefaultPatterns.Add(new DefaultPattern {
                        PatternIndex = "0", Culture = itemCulture
                    });
                }
            }

            var viewModel = new AutoroutePartEditViewModel {
                CurrentUrl     = part.DisplayAlias,
                Settings       = settings,
                CurrentCulture = itemCulture
            };

            // Retrieve home page.
            var homePageId = _homeAliasService.GetHomePageId(VersionOptions.Latest);
            var isHomePage = part.Id == homePageId;

            viewModel.IsHomePage        = isHomePage;
            viewModel.PromoteToHomePage = part.PromoteToHomePage;

            if (settings.PerItemConfiguration)
            {
                // If enabled, the list of all available patterns is displayed, and the user can select which one to use.
                // todo: later
            }

            var previous = part.DisplayAlias;

            if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null))
            {
                // Remove any leading slash in the permalink.
                if (viewModel.CurrentUrl != null)
                {
                    viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/');
                }

                part.DisplayAlias = viewModel.CurrentUrl;

                // Reset the alias if we need to force regeneration, and the user didn't provide a custom one.
                if (settings.AutomaticAdjustmentOnEdit && previous == part.DisplayAlias)
                {
                    part.DisplayAlias = String.Empty;
                }

                if (!_autorouteService.IsPathValid(part.DisplayAlias))
                {
                    updater.AddModelError("CurrentUrl", T("Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \", \"<\", \">\", \"\\\", \"|\", \"%\", \".\". No spaces are allowed (please use dashes or underscores instead)."));
                }

                if (part.DisplayAlias != null && part.DisplayAlias.Length > 1850)
                {
                    updater.AddModelError("CurrentUrl", T("Your permalink is too long. The permalink can only be up to 1,850 characters."));
                }

                // Mark the content item to be the homepage. Once this content isp ublished, the home alias will be updated to point to this content item.
                part.PromoteToHomePage = viewModel.PromoteToHomePage;
            }

            return(ContentShape("Parts_Autoroute_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix)));
        }