Esempio n. 1
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);
        }
Esempio n. 2
0
        private ContentTreeItem GetHomepageTreeItem()
        {
            var homepage = _homeAliasService.GetHomePage();

            if (homepage == null)
            {
                var routeValues = _aliasService.Get("");
                if (routeValues == null)
                {
                    throw new InvalidOperationException("Homepage content item was not found.");
                }

                int id;
                if (!int.TryParse((string)routeValues["id"], out id))
                {
                    throw new InvalidOperationException("Homepage content item was not found.");
                }

                homepage = _contentManager.Get(id);
            }

            return(new ContentTreeItem
            {
                Content = homepage.As <ContentPart>(),
                Path = "",
                Name = "",
                Title = homepage.As <TitlePart>().Title,
                Children = new List <ContentTreeItem>(),
            });
        }
Esempio n. 3
0
        public string GetLocalizedHomeUrl()
        {
            var currentCulture = _workContextAccessor.GetContext().CurrentCulture;
            var home           = _homeAliasService.GetHomePage();

            if (home.Is <LocalizationPart>() &&
                home.As <LocalizationPart>().Culture != null &&
                home.As <LocalizationPart>().Culture.Culture != currentCulture)
            {
                home = _localizationService.GetLocalizedContentItem(home, currentCulture);
            }
            return(home != null?Url.ItemDisplayUrl(home) : ProperUrl(""));
        }
Esempio n. 4
0
        private ContentItem GetCurrentContentItem()
        {
            var alias = _orchardServices.WorkContext.HttpContext.Request.AppRelativeCurrentExecutionFilePath.Substring(1).Trim('/');

            if (alias == "")
            {
                var homePage = _homeAliasService.GetHomePage();
                return(homePage != null ? homePage.ContentItem : null);
            }

            var autoroutePart = _orchardServices.ContentManager.Query <AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == alias).Slice(0, 1).SingleOrDefault();

            return(autoroutePart != null ? autoroutePart.ContentItem : null);
        }
Esempio n. 5
0
        public override void Build(BuildContext context)
        {
            var homeAliasRoute = _homeAliasService.GetHomeRoute() ?? new RouteValueDictionary();
            var root           = new XElement("HomeAlias", homeAliasRoute.Select(x => new XElement(Capitalize(x.Key), x.Value)));
            var homePage       = _homeAliasService.GetHomePage(VersionOptions.Latest);

            // If the home alias points to a content item, store its identifier in addition to the routevalues,
            // so we can publish the home page alias during import where the ID primary key value of the home page might have changed,
            // so we can't rely on the route values in that case.
            if (homePage != null)
            {
                var homePageIdentifier = _contentManager.GetItemMetadata(homePage).Identity.ToString();
                root.Attr("Id", homePageIdentifier);
            }

            context.RecipeDocument.Element("Orchard").Add(root);
        }