private AlternativeUrlInfo GetAlternativeUrlInfo(string url, int altUrlId = 0)
    {
        AlternativeUrlInfo alternativeUrl;

        if (altUrlId > 0)
        {
            alternativeUrl = AlternativeUrlInfoProvider.GetAlternativeUrlInfo(altUrlId);
            if (alternativeUrl == null)
            {
                return(null);
            }
        }
        else
        {
            alternativeUrl = new AlternativeUrlInfo
            {
                AlternativeUrlDocumentID = EditedDocument.DocumentID,
                AlternativeUrlSiteID     = SiteContext.CurrentSiteID
            };
        }

        alternativeUrl.AlternativeUrlUrl = AlternativeUrlHelper.NormalizeAlternativeUrl(url);

        return(alternativeUrl);
    }
        /// <summary>
        /// Returns a page by its URL.
        /// </summary>
        /// <param name="pageUrl">Page preview URL.</param>
        /// <returns><see cref="TreeNode"/> representing the page, otherwise returns null.</returns>
        /// <exception cref="ArgumentNullException"> if <paramref name="pageUrl"/> is <c>null</c>.</exception>
        public TreeNode GetPage(string pageUrl)
        {
            pageUrl = pageUrl ?? throw new ArgumentNullException(nameof(pageUrl));

            NormalizedAlternativeUrl alternativeUrl = AlternativeUrlHelper.NormalizeAlternativeUrl(pageUrl);

            // Handle the site root
            if (String.IsNullOrEmpty(alternativeUrl.NormalizedUrl))
            {
                return(new TreeProvider().SelectSingleNode(site.SiteName, "/", site.DefaultVisitorCulture));
            }

            return(AlternativeUrlHelper.GetConflictingPage(new AlternativeUrlInfo()
            {
                AlternativeUrlSiteID = site.SiteID,
                AlternativeUrlUrl = alternativeUrl,
            }));
        }
Beispiel #3
0
    protected override void OnInit(EventArgs e)
    {
        var showSlugsList = string.Equals(QueryHelper.GetString("subtab", null), PageRoutingUIHelper.SLUGS_LIST_SUBTAB_NAME, StringComparison.InvariantCultureIgnoreCase);

        if (showSlugsList)
        {
            URLHelper.Redirect(URLHelper.ResolveUrl(PageRoutingUIHelper.GetSlugsListingPath(Node.NodeID, Node.DocumentCulture)));
        }

        DocumentManager.RegisterEvents    = false;
        DocumentManager.UseDocumentHelper = false;
        DocumentManager.CheckPermissions  = false;

        base.OnInit(e);

        // Enable split mode
        EnableSplitMode = true;

        // Register the scripts
        ScriptHelper.RegisterLoader(Page);

        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement("CMS.Content", "Properties.URLs"))
        {
            RedirectToUIElementAccessDenied("CMS.Content", "Properties.URLs");
        }

        pnlAlternativeUrls.Visible = AlternativeUrlHelper.IsAlternativeUrlUIEnabled(Node.NodeSiteID);
        pnlPageUrlPath.Visible     = pnlContainer.Visible = PageRoutingHelper.GetRoutingMode(Node.NodeSiteID) == PageRoutingModeEnum.BasedOnContentTree;

        // Hide option to view all slugs when only one culture is assigned to the site
        btnDisplaySlugs.Visible = Node.Site.HasMultipleCultures;

        ScriptHelper.RegisterModule(this, "CMS/Clamp", new
        {
            elementWithTextSelector = ".static-textpanel"
        });
    }
 private static string GetDocumentIdentification(string pageName, string pageCulture)
 {
     return(HTMLHelper.HTMLEncode(AlternativeUrlHelper.GetDocumentIdentification(pageName, pageCulture)));
 }
 private static string GetDocumentIdentification(TreeNode page)
 {
     return(HTMLHelper.HTMLEncode(AlternativeUrlHelper.GetDocumentIdentification(page.DocumentName, page.DocumentCulture)));
 }
    /// <summary>
    /// Returns <see cref="String.Empty"/> when <paramref name="alternativeUrl"/> was saved.
    /// If error occurs during saving the <paramref name="alternativeUrl"/>, corresponding error message is returned.
    /// </summary>
    private string SaveData(AlternativeUrlInfo alternativeUrl)
    {
        alternativeUrl.AlternativeUrlUrl = AlternativeUrlHelper.NormalizeAlternativeUrl(txtAltUrl.Text);

        if (String.IsNullOrWhiteSpace(alternativeUrl.AlternativeUrlUrl.NormalizedUrl))
        {
            return(GetString("general.requiresvalue"));
        }

        try
        {
            AlternativeUrlInfoProvider.SetInfoCheckForConflictingPage(alternativeUrl);
        }
        catch (InvalidAlternativeUrlException ex) when(ex.CollisionData != null)
        {
            var collisionData = ex.CollisionData;

            if (collisionData.CultureVersionExists)
            {
                var editDocumentLink = $"<a onclick=\"window.CMSContentManager.changed(false); EditDocument({collisionData.NodeID}, 'Properties.URLs', {ScriptHelper.GetString(collisionData.CultureCode)})\">{GetDocumentIdentification(collisionData.PageName, collisionData.CultureCode)}</a>";
                return(String.Format(GetString("alternativeurl.isinconflictwithpage"), alternativeUrl.AlternativeUrlUrl, editDocumentLink));
            }
            else
            {
                var editDocumentLink = $"<a onclick=\"window.CMSContentManager.changed(false); EditDocument({collisionData.NodeID}, 'Properties.URLs|{PageRoutingUIHelper.SLUGS_LIST_SUBTAB_NAME}', {ScriptHelper.GetString(collisionData.ExistingCultureCode)})\">{collisionData.PageName}</a>";
                return(String.Format(GetString("alternativeurl.isinconflictwithnottranslatedpage"), alternativeUrl.AlternativeUrlUrl, GetCultureShortName(collisionData.CultureCode), editDocumentLink));
            }
        }
        catch (InvalidAlternativeUrlException ex) when(ex.ConflictingAlternativeUrl != null)
        {
            var page             = DocumentHelper.GetDocument(ex.ConflictingAlternativeUrl.AlternativeUrlDocumentID, new TreeProvider());
            var editDocumentLink = $"<a onclick=\"window.CMSContentManager.changed(false); EditDocument({page.NodeID}, 'Properties.URLs', {ScriptHelper.GetString(page.DocumentCulture)})\">{GetDocumentIdentification(page)}</a>";

            return(String.Format(GetString("alternativeurl.isinconflictwithalternativeurl"), alternativeUrl.AlternativeUrlUrl, editDocumentLink));
        }
        catch (InvalidAlternativeUrlException ex) when(!String.IsNullOrEmpty(ex.ExcludedUrl) || ex.AlternativeUrl != null)
        {
            var errorMessage = SettingsKeyInfoProvider.GetValue("CMSAlternativeURLsErrorMessage", Node.NodeSiteID);

            return(String.IsNullOrEmpty(errorMessage) ?
                   GetString("settingskey.cmsalternativeurlsfallbackerrormessage") :
                   ResHelper.LocalizeString(errorMessage));
        }
        catch (InvalidAlternativeUrlException)
        {
            return(String.Format(GetString("general.mustbeunique"), TypeHelper.GetNiceObjectTypeName(AlternativeUrlInfo.OBJECT_TYPE)));
        }
        catch (RegexMatchTimeoutException)
        {
            return(String.Format(GetString("settingskey.cmsalternativeurlstimeouterrormessage"), alternativeUrl.AlternativeUrlUrl));
        }
        catch (Exception ex)
        {
            Service.Resolve <IEventLogService>().LogException("Alternative URLs", "EDIT", ex);
            return(GetString("alternativeurl.generalerror"));
        }

        DocumentManager.SaveDocument();

        txtAltUrl.Text = alternativeUrl.AlternativeUrlUrl.NormalizedUrl;

        return(String.Empty);
    }
    /// <summary>
    /// Returns <see cref="String.Empty"/> when <paramref name="alternativeUrl"/> was saved.
    /// If error occurs during saving the <paramref name="alternativeUrl"/>, corresponding error message is returned.
    /// </summary>
    private string SaveData(AlternativeUrlInfo alternativeUrl)
    {
        if (String.IsNullOrWhiteSpace(alternativeUrl.AlternativeUrlUrl.NormalizedUrl))
        {
            return(GetString("general.requiresvalue"));
        }

        try
        {
            AlternativeUrlInfoProvider.SetInfoCheckForConflictingPage(alternativeUrl);
        }
        catch (InvalidAlternativeUrlException ex) when(ex.ConflictingPage != null)
        {
            return(String.Format(GetString("alternativeurl.isinconflictwithpage"), alternativeUrl.AlternativeUrlUrl, AlternativeUrlHelper.GetDocumentIdentification(ex.ConflictingPage.DocumentNamePath, ex.ConflictingPage.DocumentCulture)));
        }
        catch (InvalidAlternativeUrlException ex) when(ex.ConflictingAlternativeUrl != null)
        {
            var page = DocumentHelper.GetDocument(ex.ConflictingAlternativeUrl.AlternativeUrlDocumentID, new TreeProvider());

            return(String.Format(GetString("alternativeurl.isinconflictwithalternativeurl"), alternativeUrl.AlternativeUrlUrl, AlternativeUrlHelper.GetDocumentIdentification(page.DocumentNamePath, page.DocumentCulture)));
        }
        catch (InvalidAlternativeUrlException ex) when(!String.IsNullOrEmpty(ex.ExcludedUrl) || ex.AlternativeUrl != null)
        {
            var errorMessage = SettingsKeyInfoProvider.GetValue("CMSAlternativeURLsErrorMessage", SiteContext.CurrentSiteID);

            return(String.IsNullOrEmpty(errorMessage) ?
                   GetString("settingskey.cmsalternativeurlsfallbackerrormessage") :
                   ResHelper.LocalizeString(errorMessage));
        }
        catch (InvalidAlternativeUrlException)
        {
            return(String.Format(GetString("general.mustbeunique"), TypeHelper.GetNiceObjectTypeName(AlternativeUrlInfo.OBJECT_TYPE)));
        }
        catch (RegexMatchTimeoutException)
        {
            return(String.Format(GetString("settingskey.cmsalternativeurlstimeouterrormessage"), alternativeUrl.AlternativeUrlUrl));
        }

        DocumentManager.SaveDocument();

        return(String.Empty);
    }