public DefaultUrlProvider(IOptions <RequestHandlerSettings> requestSettings, ILogger <DefaultUrlProvider> logger, ISiteDomainMapper siteDomainMapper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility)
 {
     _requestSettings        = requestSettings.Value;
     _logger                 = logger;
     _siteDomainMapper       = siteDomainMapper;
     _uriUtility             = uriUtility;
     _umbracoContextAccessor = umbracoContextAccessor;
 }
Exemple #2
0
 public AliasUrlProvider(IOptions <RequestHandlerSettings> requestConfig, ISiteDomainMapper siteDomainMapper, UriUtility uriUtility, IPublishedValueFallback publishedValueFallback, IUmbracoContextAccessor umbracoContextAccessor)
 {
     _requestConfig          = requestConfig.Value;
     _siteDomainMapper       = siteDomainMapper;
     _uriUtility             = uriUtility;
     _publishedValueFallback = publishedValueFallback;
     _umbracoContextAccessor = umbracoContextAccessor;
 }
    /// <summary>
    ///     Gets the culture assigned to a document by domains, in the context of a current Uri.
    /// </summary>
    /// <param name="content">The document.</param>
    /// <param name="umbracoContextAccessor"></param>
    /// <param name="siteDomainHelper"></param>
    /// <param name="current">An optional current Uri.</param>
    /// <returns>The culture assigned to the document by domains.</returns>
    /// <remarks>
    ///     <para>
    ///         In 1:1 multilingual setup, a document contains several cultures (there is not
    ///         one document per culture), and domains, withing the context of a current Uri, assign
    ///         a culture to that document.
    ///     </para>
    /// </remarks>
    public static string?GetCultureFromDomains(
        this IPublishedContent content,
        IUmbracoContextAccessor umbracoContextAccessor,
        ISiteDomainMapper siteDomainHelper,
        Uri?current = null)
    {
        IUmbracoContext umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext();

        return(DomainUtilities.GetCultureFromDomains(content.Id, content.Path, current, umbracoContext, siteDomainHelper));
    }
Exemple #4
0
 public DefaultUrlProvider(
     IOptionsMonitor <RequestHandlerSettings> requestSettings,
     ILogger <DefaultUrlProvider> logger,
     ISiteDomainMapper siteDomainMapper,
     IUmbracoContextAccessor umbracoContextAccessor,
     UriUtility uriUtility)
     : this(
         requestSettings,
         logger,
         siteDomainMapper,
         umbracoContextAccessor,
         uriUtility,
         StaticServiceProvider.Instance.GetRequiredService <ILocalizationService>())
 {
 }
Exemple #5
0
    public DefaultUrlProvider(
        IOptionsMonitor <RequestHandlerSettings> requestSettings,
        ILogger <DefaultUrlProvider> logger,
        ISiteDomainMapper siteDomainMapper,
        IUmbracoContextAccessor umbracoContextAccessor,
        UriUtility uriUtility,
        ILocalizationService localizationService)
    {
        _requestSettings        = requestSettings.CurrentValue;
        _logger                 = logger;
        _siteDomainMapper       = siteDomainMapper;
        _umbracoContextAccessor = umbracoContextAccessor;
        _uriUtility             = uriUtility;
        _localizationService    = localizationService;

        requestSettings.OnChange(x => _requestSettings = x);
    }
Exemple #6
0
        public MacroRenderingController(
            IUmbracoMapper umbracoMapper,
            IUmbracoComponentRenderer componentRenderer,
            IVariationContextAccessor variationContextAccessor,
            IMacroService macroService,
            IUmbracoContextAccessor umbracoContextAccessor,
            IShortStringHelper shortStringHelper,
            ISiteDomainMapper siteDomainHelper)

        {
            _umbracoMapper            = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
            _componentRenderer        = componentRenderer ?? throw new ArgumentNullException(nameof(componentRenderer));
            _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
            _macroService             = macroService ?? throw new ArgumentNullException(nameof(macroService));
            _umbracoContextAccessor   = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
            _shortStringHelper        = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
            _siteDomainHelper         = siteDomainHelper ?? throw new ArgumentNullException(nameof(siteDomainHelper));
        }
Exemple #7
0
        /// <summary>
        /// Finds the domain for the specified node, if any, that best matches a specified uri.
        /// </summary>
        /// <param name="domainCache">A domain cache.</param>
        /// <param name="siteDomainMapper">The site domain helper.</param>
        /// <param name="nodeId">The node identifier.</param>
        /// <param name="current">The uri, or null.</param>
        /// <param name="culture">The culture, or null.</param>
        /// <returns>The domain and its uri, if any, that best matches the specified uri and culture, else null.</returns>
        /// <remarks>
        /// <para>If at least a domain is set on the node then the method returns the domain that
        /// best matches the specified uri and culture, else it returns null.</para>
        /// <para>If culture is null, uses the default culture for the installation instead. Otherwise,
        /// will try with the specified culture, else return null.</para>
        /// </remarks>
        internal static DomainAndUri?DomainForNode(IDomainCache?domainCache, ISiteDomainMapper siteDomainMapper, int nodeId, Uri current, string?culture = null)
        {
            // be safe
            if (nodeId <= 0)
            {
                return(null);
            }

            // get the domains on that node
            Domain[]? domains = domainCache?.GetAssigned(nodeId).ToArray();

            // none?
            if (domains is null || domains.Length == 0)
            {
                return(null);
            }

            // else filter
            // it could be that none apply (due to culture)
            return(SelectDomain(domains, current, culture, domainCache?.DefaultCulture, siteDomainMapper.MapDomain));
        }
 /// <summary>
 ///     Sets the site domain helper.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="helper">A helper.</param>
 public static IUmbracoBuilder SetSiteDomainHelper(this IUmbracoBuilder builder, ISiteDomainMapper helper)
 {
     builder.Services.AddUnique(helper);
     return(builder);
 }
Exemple #9
0
        /// <summary>
        /// Gets the culture assigned to a document by domains, in the context of a current Uri.
        /// </summary>
        /// <param name="contentId">The document identifier.</param>
        /// <param name="contentPath">The document path.</param>
        /// <param name="current">An optional current Uri.</param>
        /// <param name="umbracoContext">An Umbraco context.</param>
        /// <param name="siteDomainMapper">The site domain helper.</param>
        /// <returns>The culture assigned to the document by domains.</returns>
        /// <remarks>
        /// <para>In 1:1 multilingual setup, a document contains several cultures (there is not
        /// one document per culture), and domains, withing the context of a current Uri, assign
        /// a culture to that document.</para>
        /// </remarks>
        public static string?GetCultureFromDomains(int contentId, string contentPath, Uri?current, IUmbracoContext umbracoContext, ISiteDomainMapper siteDomainMapper)
        {
            if (umbracoContext == null)
            {
                throw new InvalidOperationException("A current UmbracoContext is required.");
            }

            if (current == null)
            {
                current = umbracoContext.CleanedUmbracoUrl;
            }

            // get the published route, else the preview route
            // if both are null then the content does not exist
            var route = umbracoContext.Content?.GetRouteById(contentId) ??
                        umbracoContext.Content?.GetRouteById(true, contentId);

            if (route == null)
            {
                return(null);
            }

            var          pos    = route.IndexOf('/');
            DomainAndUri?domain = pos == 0
                ? null
                : DomainForNode(umbracoContext.Domains, siteDomainMapper, int.Parse(route.Substring(0, pos), CultureInfo.InvariantCulture), current);

            var    rootContentId = domain?.ContentId ?? -1;
            Domain?wcDomain      = FindWildcardDomainInPath(umbracoContext.Domains?.GetAll(true), contentPath, rootContentId);

            if (wcDomain != null)
            {
                return(wcDomain.Culture);
            }

            if (domain != null)
            {
                return(domain.Culture);
            }

            return(umbracoContext.Domains?.DefaultCulture);
        }
Exemple #10
0
        /// <summary>
        /// Find the domains for the specified node, if any, that match a specified uri.
        /// </summary>
        /// <param name="domainCache">A domain cache.</param>
        /// <param name="siteDomainMapper">The site domain helper.</param>
        /// <param name="nodeId">The node identifier.</param>
        /// <param name="current">The uri, or null.</param>
        /// <param name="excludeDefault">A value indicating whether to exclude the current/default domain. True by default.</param>
        /// <returns>The domains and their uris, that match the specified uri, else null.</returns>
        /// <remarks>If at least a domain is set on the node then the method returns the domains that
        /// best match the specified uri, else it returns null.</remarks>
        internal static IEnumerable <DomainAndUri>?DomainsForNode(IDomainCache?domainCache, ISiteDomainMapper siteDomainMapper, int nodeId, Uri current, bool excludeDefault = true)
        {
            // be safe
            if (nodeId <= 0)
            {
                return(null);
            }

            // get the domains on that node
            Domain[]? domains = domainCache?.GetAssigned(nodeId).ToArray();

            // none?
            if (domains is null || domains.Length == 0)
            {
                return(null);
            }

            // get the domains and their uris
            DomainAndUri[] domainAndUris = SelectDomains(domains, current).ToArray();

            // filter
            return(siteDomainMapper.MapDomains(domainAndUris, current, excludeDefault, null, domainCache?.DefaultCulture).ToArray());
        }