Exemplo n.º 1
0
        private void ProcessAlias(AutoroutePart part)
        {
            // Generate an alias if one as not already been entered.
            if (String.IsNullOrWhiteSpace(part.DisplayAlias))
            {
                part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
            }

            // If the generated alias is empty, compute a new one.
            if (String.IsNullOrWhiteSpace(part.DisplayAlias))
            {
                _autorouteService.Value.ProcessPath(part);
                _tomeltServices.Notifier.Warning(T("The permalink could not be generated, a new slug has been defined: \"{0}\"", part.Path));
                return;
            }

            // Check for permalink conflict, unless we are trying to set the home page.
            var previous = part.Path;

            if (!_autorouteService.Value.ProcessPath(part))
            {
                _tomeltServices.Notifier.Warning(
                    T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
                      previous, part.Path, part.ContentItem.ContentType));
            }
        }
Exemplo n.º 2
0
        bool FindRoute(IEnumerable <Tuple <string, int> > HPLocalizations, int orgItemId, string culture, out string newUrl, bool AddTild = true)
        {
            newUrl = null;
            Tuple <string, int> contentLoc = HPLocalizations.Where(t => t.Item1 == culture).FirstOrDefault();

            if (contentLoc != null)
            {
                ContentItem content = _orchardServices.ContentManager.Get(contentLoc.Item2, VersionOptions.Published);
                if (content.Id == orgItemId) // no reroute needed
                {
                    return(false);
                }
                AutoroutePart localizedRoutePart = content.Parts.Single(p => p is AutoroutePart).As <AutoroutePart>();
                if (localizedRoutePart != null)
                {
                    string returnUrl = localizedRoutePart.Path;
                    if (!returnUrl.StartsWith("~/"))
                    {
                        returnUrl = ("~/" + returnUrl).Replace("//", "/");
                    }
                    if (!AddTild)
                    {
                        if (returnUrl.StartsWith("~"))
                        {
                            returnUrl = returnUrl.Substring(1);
                        }
                    }
                    newUrl = returnUrl;
                    return(true);
                }
            }
            return(false);
        }
        private void PublishAlias(AutoroutePart part)
        {
            ProcessAlias(part);

            // should it become the home page ?
            if (part.DisplayAlias == "/")
            {
                part.DisplayAlias = String.Empty;

                // regenerate the alias for the previous home page
                var currentHomePages = _orchardServices.ContentManager.Query <AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
                foreach (var current in currentHomePages.Where(x => x.Id != part.Id))
                {
                    if (current != null)
                    {
                        current.CustomPattern = String.Empty; // force the regeneration
                        current.DisplayAlias  = _autorouteService.Value.GenerateAlias(current);

                        // we changed the alias of the previous homepage, so publish this change if the content item was published.
                        if (current.IsPublished())
                        {
                            _orchardServices.ContentManager.Publish(current.ContentItem);
                        }
                    }
                    _autorouteService.Value.PublishAlias(current);
                }
            }

            _autorouteService.Value.PublishAlias(part);
        }
        public void PublishAlias(AutoroutePart part)
        {
            var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues;

            _aliasService.Replace(part.DisplayAlias, displayRouteValues, AliasSource, true);
            _routeEvents.Routed(part, part.DisplayAlias);
        }
        private List <dynamic> ItemsMultiLanguage(AutoroutePart autoroutePart)
        {
            string CiType = ((ContentItem)autoroutePart.ContentItem).ContentType;
            int    id     = ((ContentItem)autoroutePart.ContentItem).Id;
            //  string tipoCI = item.ContentItem.ContentType;
            //  int id = ((ContentItem)autoroutePart.ContentItem).Id;

            int masterid        = 0;
            int teoric_masterid = 0;

            try {
                teoric_masterid = ((ContentItem)autoroutePart.ContentItem).As <LocalizationPart>().MasterContentItem.Id;
                masterid        = teoric_masterid;
            } catch {
                masterid = id;
            }
            var            contentsLocalized = _orchardServices.ContentManager.Query(CiType).Where <LocalizationPartRecord>(l => l.MasterContentItemId == masterid || l.Id == masterid).List();
            List <dynamic> ListShape         = new List <dynamic>();

            foreach (ContentItem singleCi in contentsLocalized)
            {
                List <dynamic> list2 = new List <dynamic>();
                list2.Add(_orchardServices.ContentManager.BuildDisplay(singleCi));
                // var merged=new List<dynamic>(ListShape);
                ListShape.AddRange(list2.Where(p2 =>
                                               ListShape.All(p1 => p1.ContentItem.Id != p2.ContentItem.Id)));
                // ListShape = merged;
            }
            return(ListShape);
        }
        public bool ProcessPath(AutoroutePart part)
        {
            var parthWithSamePath = _contentManager.Query <AutoroutePart, AutoroutePartRecord>()
                                    .Where(p => p.DisplayAlias != null && p.DisplayAlias.Equals(part.Path, StringComparison.InvariantCultureIgnoreCase) &&
                                           p.ContentItemRecord.Id != part.Id)
                                    .Count();

            if (parthWithSamePath > 0)
            {
                var pathsLikeThis = GetSimilarPaths(part.Path).ToArray();

                // Don't include *this* part in the list
                // of slugs to consider for conflict detection.
                pathsLikeThis = pathsLikeThis.Where(p => p.ContentItem.Id != part.ContentItem.Id).ToArray();

                if (pathsLikeThis.Any())
                {
                    var originalPath = part.Path;
                    var newPath      = GenerateUniqueSlug(part, pathsLikeThis.Select(p => p.Path));
                    part.DisplayAlias = newPath;

                    if (originalPath != newPath)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 7
0
        private void ProcessAlias(AutoroutePart part)
        {
            // generate an alias if one as not already been entered
            if (String.IsNullOrWhiteSpace(part.DisplayAlias))
            {
                part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
            }

            // should it become the home page ?
            if (part.DisplayAlias != "/" && _orchardServices.Authorizer.Authorize(Permissions.SetHomePage))
            {
                // if it's the current home page, do nothing
                var currentHomePages = _orchardServices.ContentManager.Query <AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
                if (currentHomePages.Any(x => x.Id == part.Id))
                {
                    return;
                }

                var previous = part.Path;
                if (!_autorouteService.Value.ProcessPath(part))
                {
                    _orchardServices.Notifier.Warning(T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
                                                        previous, part.Path, part.ContentItem.ContentType));
                }
            }
        }
Exemplo n.º 8
0
        //Finds localized route part for the specified content and culture
        //Returns true if localized url for content and culture exists; otherwise - false
        public bool TryFindLocalizedRoute(ContentItem routableContent, string cultureName, out AutoroutePart localizedRoute) {
            if (!routableContent.Parts.Any(p => p.Is<ILocalizableAspect>())) {
                localizedRoute = null;
                return false;
            }

            //var siteCulture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
            IEnumerable<LocalizationPart> localizations = _localizationService.GetLocalizations(routableContent, VersionOptions.Published);

            ILocalizableAspect localizationPart = null, siteCultureLocalizationPart = null;
            foreach (LocalizationPart l in localizations) {
                if (l.Culture.Culture == cultureName) {
                    localizationPart = l;
                    break;
                }
                if (l.Culture == null && siteCultureLocalizationPart == null) {
                    siteCultureLocalizationPart = l;
                }
            }

            //try get localization part for default site culture
            if (localizationPart == null) {
                localizationPart = siteCultureLocalizationPart;
            }

            if (localizationPart == null) {
                localizedRoute = null;
                return false;
            }

            ContentItem localizedContentItem = localizationPart.ContentItem;
            localizedRoute = localizedContentItem.Parts.Single(p => p is AutoroutePart).As<AutoroutePart>();
            return true;
        }
Exemplo n.º 9
0
        private void PublishAlias(AutoroutePart part)
        {
            ProcessAlias(part);

            var usr = _orchardServices.WorkContext.CurrentUser;
            var r   = usr.As <UserRolesPart>();

            if (r.Roles.Any(p => p == "vendedor"))
            {
                //part.ContentItemPath = string.Concat("tiendas/", usr.UserName, "/", part.Path);
                //viewModel.CurrentUrl = viewModel.CurrentUrl.Replace(viewModel.FixedPart, "");
                part.DisplayAlias = string.Concat("tiendas/", usr.UserName, "/", part.DisplayAlias);
            }


            // should it become the home page ?
            if (part.DisplayAlias == "/")
            {
                part.DisplayAlias = String.Empty;

                // regenerate the alias for the previous home page
                var currentHomePages = _orchardServices.ContentManager.Query <AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
                foreach (var current in currentHomePages.Where(x => x.Id != part.Id))
                {
                    if (current != null)
                    {
                        current.CustomPattern = String.Empty; // force the regeneration
                        current.DisplayAlias  = _autorouteService.Value.GenerateAlias(current);
                    }
                    _autorouteService.Value.PublishAlias(current);
                }
            }

            _autorouteService.Value.PublishAlias(part);
        }
Exemplo n.º 10
0
        public string GenerateAlias(AutoroutePart part)
        {
            if (part == null)
            {
                throw new ArgumentNullException("part");
            }

            string pattern = GetDefaultPattern(part.ContentItem.ContentType).Pattern;

            // String.Empty forces pattern based generation. "/" forces homepage
            if (part.UseCustomPattern &&
                (!String.IsNullOrWhiteSpace(part.CustomPattern) || String.Equals(part.CustomPattern, "/")))
            {
                pattern = part.CustomPattern;
            }

            // Convert the pattern and route values via tokens
            var path = _tokenizer.Replace(pattern, BuildTokenContext(part.ContentItem), new ReplaceOptions {
                Encoding = ReplaceOptions.NoEncode
            });

            // removing trailing slashes in case the container is empty, and tokens are base on it (e.g. home page)
            while (path.StartsWith("/"))
            {
                path = path.Substring(1);
            }

            return(path);
        }
        private void SetupRoutePart(PackagePart packagePartToMapTo) {
            var contentItem = new ContentItem { ContentType = "Package" };
            var routePart = new AutoroutePart {Record = new AutoroutePartRecord()};
            contentItem.Weld(routePart);
            contentItem.Weld(packagePartToMapTo);

        }
Exemplo n.º 12
0
        public void PublishAlias(AutoroutePart part) {
            var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues;

            _aliasService.Replace(part.DisplayAlias, displayRouteValues, AliasSource);

            _routeEvents.Routed(part, part.DisplayAlias);
        }
Exemplo n.º 13
0
        private void PublishAlias(AutoroutePart part)
        {
            ProcessAlias(part);

            // Should it become the home page?
            if (part.PromoteToHomePage)
            {
                // Get the current homepage an unmark it as the homepage.
                var currentHomePage = _homeAliasService.GetHomePage(VersionOptions.Latest);
                if (currentHomePage != null && currentHomePage.Id != part.Id)
                {
                    var autoroutePart = currentHomePage.As <AutoroutePart>();

                    if (autoroutePart != null)
                    {
                        autoroutePart.PromoteToHomePage = false;
                        if (autoroutePart.IsPublished())
                        {
                            _tomeltServices.ContentManager.Publish(autoroutePart.ContentItem);
                        }
                    }
                }

                // Update the home alias to point to this item being published.
                _homeAliasService.PublishHomeAlias(part);
            }

            _autorouteService.Value.PublishAlias(part);
        }
Exemplo n.º 14
0
        public void RemoveAliases(AutoroutePart part)
        {
            // todo: remove all aliases for this part

            var aliasSource = "Autoroute:View:" + part.Id;

            _aliasService.DeleteBySource(aliasSource);
        }
Exemplo n.º 15
0
        //Finds route part for the specified URL
        //Returns true if specified url corresponds to some content and route exists; otherwise - false

        #region ILocalizableContentService Members

        public bool TryGetRouteForUrl(string url, out AutoroutePart route) {
            //first check for route (fast, case sensitive, not precise)
            route = _contentManager.Query<AutoroutePart, AutoroutePartRecord>()
                .ForVersion(VersionOptions.Published)
                .Where(r => r.DisplayAlias == url)
                .List()
                .FirstOrDefault();

            return route != null;
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        //Finds route part for the specified URL
        //Returns true if specified url corresponds to some content and route exists; otherwise - false

        #region ILocalizableContentService Members

        public bool TryGetRouteForUrl(string url, out AutoroutePart route)
        {
            //first check for route (fast, case sensitive, not precise)
            route = _contentManager.Query <AutoroutePart, AutoroutePartRecord>()
                    .ForVersion(VersionOptions.Published)
                    .Where(r => r.DisplayAlias == url)
                    .List()
                    .FirstOrDefault();

            return(route != null);
        }
        public string GenerateAlias(AutoroutePart part)
        {
            if (part == null)
            {
                throw new ArgumentNullException("part");
            }
            var settings    = part.TypePartDefinition.Settings.GetModel <AutorouteSettings>();
            var itemCulture = _cultureManager.GetSiteCulture();

            // If we are editing an existing content item.
            if (part.Record.Id != 0)
            {
                ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id);
                var         aspect      = contentItem.As <ILocalizableAspect>();

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

            if (settings.UseCulturePattern)
            {
                // TODO: Refactor the below so that we don't need to know about Request.Form["Localization.SelectedCulture"].
                // If we are creating from a form post we use the form value for culture.
                var context         = _httpContextAccessor.Current();
                var selectedCulture = context.Request.Form["Localization.SelectedCulture"];
                if (!String.IsNullOrEmpty(selectedCulture))
                {
                    itemCulture = selectedCulture;
                }
            }

            var pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern;

            // String.Empty forces pattern based generation.
            if (part.UseCustomPattern && (!String.IsNullOrWhiteSpace(part.CustomPattern)))
            {
                pattern = part.CustomPattern;
            }

            // Convert the pattern and route values via tokens.
            var path = _tokenizer.Replace(pattern, BuildTokenContext(part.ContentItem), new ReplaceOptions {
                Encoding = ReplaceOptions.NoEncode
            });

            // Removing trailing slashes in case the container is empty, and tokens are base on it (e.g. home page).
            while (path.StartsWith("/"))
            {
                path = path.Substring(1);
            }

            return(path);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
 public static ContentTreeItem ToTreeItem(this AutoroutePart content)
 {
     return(new ContentTreeItem
     {
         Content = content,
         Path = content.DisplayAlias.ToLowerInvariant(),
         Title = content.As <TitlePart>().Title,
         Name = content.DisplayAlias.Split('/').Last(),
         Level = content.DisplayAlias.Split('/').Length,
         Children = new List <ContentTreeItem>()
     });
 }
Exemplo n.º 21
0
        void RemoveAlias(AutoroutePart part)
        {
            // Is this the current home page?
            var homePageRoute = _aliasService.Get("");
            var homePageId    = homePageRoute.ContainsKey("id") ? int.Parse(homePageRoute["id"].ToString()) : default(int);

            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);
        }
Exemplo n.º 22
0
        public string GenerateUniqueSlug(AutoroutePart part, IEnumerable <string> existingPaths)
        {
            if (existingPaths == null || !existingPaths.Contains(part.Path))
            {
                return(part.Path);
            }

            int?version = existingPaths.Select(s => GetSlugVersion(part.Path, s)).OrderBy(i => i).LastOrDefault();

            return(version != null
                ? string.Format("{0}-{1}", part.Path, version)
                : part.Path);
        }
Exemplo n.º 23
0
        private void ProcessAlias(AutoroutePart part) {
            // generate an alias if one as not already been entered
            if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
                part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
            }

            // should it become the home page ?
            if (part.DisplayAlias != "/") {
                var previous = part.Path;
                if (!_autorouteService.Value.ProcessPath(part))
                    _orchardServices.Notifier.Warning(T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
                                                 previous, part.Path, part.ContentItem.ContentType));
            }
        }
Exemplo n.º 24
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);
            });
        }
Exemplo n.º 25
0
        public void Create()
        {
            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }

            var owner = _membershipService.GetUser(Owner);

            _authenticationService.SetAuthenticatedUserForRequest(owner);

            var dashboard = _contentManager.Create(Consts.GenericDashboardContentType, VersionOptions.Draft);

            dashboard.As <CommonPart>().Owner = owner;
            dashboard.As <TitlePart>().Title  = Title;

            if (!String.IsNullOrWhiteSpace(MenuText))
            {
                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    var menuItem = _contentManager.Create <ContentMenuItemPart>("ContentMenuItem");
                    menuItem.Content = dashboard;
                    menuItem.As <MenuPart>().MenuPosition = Position.GetNext(_navigationManager.BuildMenu(menu));
                    menuItem.As <MenuPart>().MenuText     = MenuText;
                    menuItem.As <MenuPart>().Menu         = menu;
                }
            }

            if (Homepage)
            {
                AutoroutePart autoroutePart = dashboard.As <AutoroutePart>();
                if (autoroutePart != null)
                {
                    autoroutePart.UseCustomPattern = true;
                    autoroutePart.CustomPattern    = "/";
                }
            }

            var dashboardPart = dashboard.As <GenericDashboardPart>();

            dashboardPart.PortletList = Portlets;
            dashboardPart.ShowConfigurableItemsCountInHeader = ShowConfigurableItemsCountInHeader;
            dashboardPart.CreatePortletsOnPublishing         = true;
            _contentManager.Publish(dashboard);
        }
        public string GenerateAlias(AutoroutePart part) {

            if (part == null) {
                throw new ArgumentNullException("part");
            }
            var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
            var itemCulture = _cultureManager.GetSiteCulture();

            //if we are editing an existing content item
            if (part.Record.Id != 0) {
                ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id);
                var aspect = contentItem.As<ILocalizableAspect>();

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

            if (settings.UseCulturePattern) {
                // TODO: Refactor the below so that we don't need to know about Request.Form["Localization.SelectedCulture"].
                // If we are creating from a form post we use the form value for culture.
                HttpContextBase context = _httpContextAccessor.Current();
                if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) {
                    itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
                }
            }

            string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern;

            // String.Empty forces pattern based generation. "/" forces homepage.
            if (part.UseCustomPattern
                && (!String.IsNullOrWhiteSpace(part.CustomPattern) || String.Equals(part.CustomPattern, "/"))) {
                pattern = part.CustomPattern;
            }

            // Convert the pattern and route values via tokens.
            var path = _tokenizer.Replace(pattern, BuildTokenContext(part.ContentItem), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });

            // Removing trailing slashes in case the container is empty, and tokens are base on it (e.g. home page).
            while (path.StartsWith("/")) {
                path = path.Substring(1);
            }

            return path;
        }
Exemplo n.º 27
0
        public void Create()
        {
            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }

            var owner = _membershipService.GetUser(Owner);

            _authenticationService.SetAuthenticatedUserForRequest(owner);

            var emptyItem = _contentManager.Create(ContentTypes.EmptyContentType, VersionOptions.Draft);

            emptyItem.As <ICommonPart>().Owner = owner;
            emptyItem.As <TitlePart>().Title   = Title;

            if (!String.IsNullOrWhiteSpace(MenuText))
            {
                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    var menuItem = _contentManager.Create <ContentMenuItemPart>("ContentMenuItem");
                    menuItem.Content = emptyItem;
                    menuItem.As <MenuPart>().MenuPosition = Position.GetNext(_navigationManager.BuildMenu(menu));
                    menuItem.As <MenuPart>().MenuText     = MenuText;
                    menuItem.As <MenuPart>().Menu         = menu;
                }
            }

            if (Homepage)
            {
                AutoroutePart autoroutePart = emptyItem.As <AutoroutePart>();
                if (autoroutePart != null)
                {
                    autoroutePart.UseCustomPattern = true;
                    autoroutePart.CustomPattern    = "/";
                }
            }

            _contentManager.Publish(emptyItem);

            Context.Output.WriteLine(T("EmptyItem created successfully.").Text);
        }
Exemplo n.º 28
0
        private void PublishAlias(AutoroutePart part) {
            ProcessAlias(part);

            // should it become the home page ?
            if (part.DisplayAlias == "/") {
                part.DisplayAlias = String.Empty;

                // regenerate the alias for the previous home page
                var currentHomePages = _orchardServices.ContentManager.Query<AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
                foreach (var current in currentHomePages) {
                    if (current != null) {
                        current.DisplayAlias = _autorouteService.Value.GenerateAlias(current);
                    }
                    _autorouteService.Value.PublishAlias(current);
                }
            }

            _autorouteService.Value.PublishAlias(part);
        }
Exemplo n.º 29
0
        private void ProcessAlias(AutoroutePart part)
        {
            // generate an alias if one as not already been entered
            if (String.IsNullOrWhiteSpace(part.DisplayAlias))
            {
                part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
            }

            // should it become the home page ?
            if (part.DisplayAlias != "/")
            {
                var previous = part.Path;
                if (!_autorouteService.Value.ProcessPath(part))
                {
                    _orchardServices.Notifier.Warning(T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
                                                        previous, part.Path, part.ContentItem.ContentType));
                }
            }
        }
Exemplo n.º 30
0
        private void ProcessAlias(AutoroutePart part) {
            // Generate an alias if one as not already been entered.
            if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
                part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
            }

            // If the generated alias is empty, compute a new one.
            if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
                _autorouteService.Value.ProcessPath(part);
                _orchardServices.Notifier.Warning(T("The permalink could not be generated, a new slug has been defined: \"{0}\"", part.Path));
                return;
            }

            // Check for permalink conflict, unless we are trying to set the home page.
            var previous = part.Path;
            if (!_autorouteService.Value.ProcessPath(part))
                _orchardServices.Notifier.Warning(
                    T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"", 
                                                previous, part.Path, part.ContentItem.ContentType));
        }
Exemplo n.º 31
0
        public string GenerateAlias(AutoroutePart part) {

            if (part == null) {
                throw new ArgumentNullException("part");
            }

            var defaultRoutePattern = GetDefaultPattern(part.ContentItem.ContentType);

            var pattern = part.UseCustomPattern ? part.CustomPattern : defaultRoutePattern.Pattern;

            // Convert the pattern and route values via tokens
            var path = _tokenizer.Replace(pattern, BuildTokenContext(part.ContentItem), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });

            // removing trailing slashes in case the container is empty, and tokens are base on it (e.g. home page)
            while(path.StartsWith("/")) {
                path = path.Substring(1);
            }

            return path;
        }
Exemplo n.º 32
0
        private void ProcessAlias(AutoroutePart part) {
            // generate an alias if one as not already been entered
            if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
                part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
            }

            // should it become the home page ?
            if (part.DisplayAlias != "/" && _orchardServices.Authorizer.Authorize(Permissions.SetHomePage)) {
                // if it's the current home page, do nothing
                var currentHomePages = _orchardServices.ContentManager.Query<AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
                if (currentHomePages.Any(x => x.Id == part.Id)) {
                    return;
                }

                var previous = part.Path;
                if (!_autorouteService.Value.ProcessPath(part))
                    _orchardServices.Notifier.Warning(T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
                                                 previous, part.Path, part.ContentItem.ContentType));
            }
        }
Exemplo n.º 33
0
        //Finds route part for the specified URL
        //Returns true if specified url corresponds to some content and route exists; otherwise - false

        #region ILocalizableContentService Members

        public bool TryGetRouteForUrl(string url, out AutoroutePart route)
        {
            if (string.IsNullOrWhiteSpace(url))   //look for homepage
            {
                var routeValues = _aliasService.Get(string.Empty);
                var homeCI      = _contentManager.Get(int.Parse(routeValues["Id"].ToString()));

                route = homeCI.As <AutoroutePart>();
            }
            else
            {
                //first check for route (fast, case sensitive, not precise)
                route = _contentManager.Query <AutoroutePart, AutoroutePartRecord>()
                        .ForVersion(VersionOptions.Published)
                        .Where(r => r.DisplayAlias == url)
                        .List()
                        .FirstOrDefault();
            }

            return(route != null);
        }
Exemplo n.º 34
0
        public bool ProcessPath(AutoroutePart part)
        {
            var pathsLikeThis = GetSimilarPaths(part.Path).ToArray();

            // Don't include *this* part in the list
            // of slugs to consider for conflict detection
            pathsLikeThis = pathsLikeThis.Where(p => p.ContentItem.Id != part.ContentItem.Id).ToArray();

            if (pathsLikeThis.Any())
            {
                var originalPath = part.Path;
                var newPath      = GenerateUniqueSlug(part, pathsLikeThis.Select(p => p.Path));
                part.DisplayAlias = newPath;

                if (originalPath != newPath)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 35
0
        private void PublishAlias(AutoroutePart part) {
            ProcessAlias(part);

            // Should it become the home page?
            if (part.PromoteToHomePage) {
                // Get the current homepage an unmark it as the homepage.
                var currentHomePage = _homeAliasService.GetHomePage(VersionOptions.Latest);
                if(currentHomePage != null && currentHomePage.Id != part.Id) {
                    var autoroutePart = currentHomePage.As<AutoroutePart>();

                    if (autoroutePart != null) {
                        autoroutePart.PromoteToHomePage = false;
                        if(autoroutePart.IsPublished())
                            _orchardServices.ContentManager.Publish(autoroutePart.ContentItem);
                    }
                }

                // Update the home alias to point to this item being published.
                _homeAliasService.PublishHomeAlias(part);
            }
            
            _autorouteService.Value.PublishAlias(part);
        }
        public void RemoveAliases(AutoroutePart part)
        {
            // https://github.com/OrchardCMS/Orchard/issues/5137
            // If the alias of the specified part is empty while not being the homepage,
            // we need to make sure we are not removing all empty aliases in order to prevent losing the homepage content item being the homepage.
            if (String.IsNullOrWhiteSpace(part.Path))
            {
                if (!IsHomePage(part))
                {
                    // The item being removed is NOT the homepage, so we need to make sure we're not removing the alias for the homepage.
                    var aliasRecordId = GetHomePageAliasRecordId();

                    // Remove all aliases EXCEPT for the alias of the homepage.
                    _aliasStorage.Remove(x => x.Path == part.Path && x.Source == AliasSource && x.Id != aliasRecordId);

                    // Done.
                    return;
                }
            }

            // Safe to delete all aliases for the specified part since it is definitely not the homepage.
            _aliasService.Delete(part.Path, AliasSource);
        }
Exemplo n.º 37
0
        public string GenerateAlias(AutoroutePart part) {

            if (part == null) {
                throw new ArgumentNullException("part");
            }

            string pattern = GetDefaultPattern(part.ContentItem.ContentType).Pattern;
            
            // String.Empty forces pattern based generation. "/" forces homepage
            if(part.UseCustomPattern 
                && (!String.IsNullOrWhiteSpace(part.CustomPattern) || String.Equals(part.CustomPattern, "/"))) {
                pattern = part.CustomPattern;
            }

            // Convert the pattern and route values via tokens
            var path = _tokenizer.Replace(pattern, BuildTokenContext(part.ContentItem), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });

            // removing trailing slashes in case the container is empty, and tokens are base on it (e.g. home page)
            while(path.StartsWith("/")) {
                path = path.Substring(1);
            }

            return path;
        }
Exemplo n.º 38
0
        private void PublishAlias(AutoroutePart part) {
            ProcessAlias(part);

            // should it become the home page ?
            if (part.DisplayAlias == "/") {
                part.DisplayAlias = String.Empty;

                // regenerate the alias for the previous home page
                var currentHomePages = _orchardServices.ContentManager.Query<AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
                foreach (var current in currentHomePages.Where(x => x.Id != part.Id)) {
                    if (current != null) {
                        current.CustomPattern = String.Empty; // force the regeneration
                        current.DisplayAlias = _autorouteService.Value.GenerateAlias(current);

                        // we changed the alias of the previous homepage, so publish this change if the content item was published.
                        if(current.IsPublished())
                            _orchardServices.ContentManager.Publish(current.ContentItem);
                    }
                    _autorouteService.Value.PublishAlias(current);
                }
            }

            _autorouteService.Value.PublishAlias(part);
        }
Exemplo n.º 39
0
        public void PublishAlias(AutoroutePart part) {
            var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues;
            var aliasSource = "Autoroute:View:" + part.Id;

            _aliasService.Replace(part.DisplayAlias, displayRouteValues, aliasSource);    
        }
Exemplo n.º 40
0
        public void RemoveAliases(AutoroutePart part) {
            
            // todo: remove all aliases for this part

            var aliasSource = "Autoroute:View:" + part.Id;
            _aliasService.DeleteBySource(aliasSource);
        }
Exemplo n.º 41
0
        //Finds localized route part for the specified content and culture
        //Returns true if localized url for content and culture exists; otherwise - false
        public bool TryFindLocalizedRoute(ContentItem routableContent, string cultureName, out AutoroutePart localizedRoute)
        {
            if (!routableContent.Parts.Any(p => p.Is <ILocalizableAspect>()))
            {
                localizedRoute = null;
                return(false);
            }

            //var siteCulture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
            IEnumerable <LocalizationPart> localizations = _localizationService.GetLocalizations(routableContent, VersionOptions.Published);

            ILocalizableAspect localizationPart = null, siteCultureLocalizationPart = null;

            foreach (LocalizationPart l in localizations)
            {
                if (l.Culture.Culture == cultureName)
                {
                    localizationPart = l;
                    break;
                }
                if (l.Culture == null && siteCultureLocalizationPart == null)
                {
                    siteCultureLocalizationPart = l;
                }
            }

            //try get localization part for default site culture
            if (localizationPart == null)
            {
                localizationPart = siteCultureLocalizationPart;
            }

            if (localizationPart == null)
            {
                localizedRoute = null;
                return(false);
            }

            ContentItem localizedContentItem = localizationPart.ContentItem;

            localizedRoute = localizedContentItem.Parts.Single(p => p is AutoroutePart).As <AutoroutePart>();
            return(true);
        }
Exemplo n.º 42
0
        public bool ProcessPath(AutoroutePart part) {

            var pathsLikeThis = GetSimilarPaths(part.Path).ToArray();

            // Don't include *this* part in the list
            // of slugs to consider for conflict detection
            pathsLikeThis = pathsLikeThis.Where(p => p.ContentItem.Id != part.ContentItem.Id).ToArray();

            if (pathsLikeThis.Any()) {
                var originalPath = part.Path;
                var newPath = GenerateUniqueSlug(part, pathsLikeThis.Select(p => p.Path));
                part.DisplayAlias = newPath;

                if (originalPath != newPath)
                    return false;
            }

            return true;
        }
Exemplo n.º 43
0
 private void CreateAlias(AutoroutePart part)
 {
     ProcessAlias(part);
 }
 private void CreateAlias(AutoroutePart part) {
     ProcessAlias(part);
 }
        void RemoveAlias(AutoroutePart part) {
            // Is this the current home page?
            var homePageRoute = _aliasService.Get("");
            var homePageId = homePageRoute.ContainsKey("id") ? int.Parse(homePageRoute["id"].ToString()) : default(int);

            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);
        }
Exemplo n.º 46
0
        public void RemoveAliases(AutoroutePart part) {
            // https://github.com/OrchardCMS/Orchard/issues/5137
            // If the alias of the specified part is empty while not being the homepage,
            // we need to make sure we are not removing all empty aliases in order to prevent losing the homepage content item being the homepage.
            if (String.IsNullOrWhiteSpace(part.Path)) {
                if (!IsHomePage(part)) {
                    // The item being removed is NOT the homepage, so we need to make sure we're not removing the alias for the homepage.
                    var aliasRecordId = GetHomePageAliasRecordId();

                    // Remove all aliases EXCEPT for the alias of the homepage.
                    _aliasStorage.Remove(x => x.Path == part.Path && x.Source == AliasSource && x.Id != aliasRecordId);

                    // Done.
                    return;
                }
            }

            // Safe to delete all aliases for the specified part since it is definitely not the homepage.
            _aliasService.Delete(part.Path, AliasSource);
        }
Exemplo n.º 47
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\" 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);
        }
Exemplo n.º 48
0
 public void RemoveAliases(AutoroutePart part)
 {
     _aliasService.Delete(part.Path, AliasSource);
 }
Exemplo n.º 49
0
        public void RemoveAliases(AutoroutePart part) {
            
            // todo: remove all aliases for this part

            _aliasService.Delete(part.DisplayAlias);
        }
Exemplo n.º 50
0
 public void RemoveAliases(AutoroutePart part) {
     _aliasService.Delete(part.Path, AliasSource);
 }
Exemplo n.º 51
0
        public string GenerateUniqueSlug(AutoroutePart part, IEnumerable<string> existingPaths) {
            if (existingPaths == null || !existingPaths.Contains(part.Path))
                return part.Path;

            int? version = existingPaths.Select(s => GetSlugVersion(part.Path, s)).OrderBy(i => i).LastOrDefault();

            return version != null
                ? string.Format("{0}-{1}", part.Path, version)
                : part.Path;
        }
 void RemoveAlias(AutoroutePart part) {
     _autorouteService.Value.RemoveAliases(part);
 }
Exemplo n.º 53
0
 void RemoveAlias(AutoroutePart part)
 {
     _autorouteService.Value.RemoveAliases(part);
 }