public static IEnumerable <Url> GetCustomUrls(int pageId)
        {
            ActionResult actionResult = new ActionResult();

            if (!SecurityService.Instance.CanManagePage(pageId))
            {
                actionResult.AddError("CustomUrlPortalAlias.Error", Localization.GetString("CustomUrlPortalAlias.Error"));
            }

            IEnumerable <Url> data = Managers.UrlManager.GetCustomUrls(pageId);

            return(data);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage SavePageAsTemplate(PageTemplate pageTemplate)
        {
            if (!_securityService.CanExportPage(pageTemplate.TabId))
            {
                return(GetForbiddenResponse());
            }

            try
            {
                pageTemplate.Clean();
                var templateFilename = _templateController.SaveAsTemplate(pageTemplate);
                var response         = string.Format(Localization.GetString("ExportedMessage"), templateFilename);

                return(Request.CreateResponse(HttpStatusCode.OK, new
                {
                    Status = 0,
                    Response = response
                }));
            }
            catch (TemplateException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, ex.Message }));
            }
        }
Ejemplo n.º 3
0
        public PageUrlResult CreateCustomUrl(SaveUrlDto dto, TabInfo tab)
        {
            var        portalSettings = PortalController.Instance.GetCurrentPortalSettings();
            PortalInfo aliasPortal    = new PortalAliasController().GetPortalByPortalAliasID(dto.SiteAliasKey);

            if (aliasPortal != null && portalSettings.PortalId != aliasPortal.PortalID)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPortalAlias.Error"),
                    SuggestedUrlPath = String.Empty,
                });
            }

            var  urlPath = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            // Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"),
                    SuggestedUrlPath = "/" + urlPath,
                });
            }

            // Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"),
                    SuggestedUrlPath = "/" + urlPath,
                });
            }

            if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == dto.Path.ValueOrEmpty().ToLowerInvariant() &&
                                (u.PortalAliasId == dto.SiteAliasKey || u.PortalAliasId == -1)))
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("DuplicateUrl.Error"),
                });
            }

            var seqNum        = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1;
            var portalLocales = LocaleController.Instance.GetLocales(portalSettings.PortalId);

            // Get the culture code of selected portal alias
            var alias = PortalAliasController.Instance
                        .GetPortalAliasesByPortalId(portalSettings.PortalId)
                        .SingleOrDefault(a => a.PortalAliasID == dto.SiteAliasKey);
            Func <KeyValuePair <string, Locale>, bool> localeFilter = null;

            if (alias != null &&
                !string.IsNullOrWhiteSpace(alias.CultureCode))
            {
                localeFilter = l => l.Key == alias.CultureCode;
            }
            else
            {
                localeFilter = l => l.Value.KeyID == dto.LocaleKey;
            }

            var cultureCode = portalLocales.Where(localeFilter)
                              .Select(l => l.Value.Code)
                              .SingleOrDefault() ?? portalSettings.CultureCode;

            var portalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;

            if (portalAliasUsage == PortalAliasUsageType.Default)
            {
                if (string.IsNullOrEmpty(cultureCode) || alias == null)
                {
                    return(new PageUrlResult
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("InvalidRequest.Error"),
                    });
                }
            }
            else
            {
                var cultureAlias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId)
                                   .FirstOrDefault(a => a.CultureCode == cultureCode);

                if (portalLocales.Count > 1 && !portalSettings.ContentLocalizationEnabled && (string.IsNullOrEmpty(cultureCode) || cultureAlias == null))
                {
                    return(new PageUrlResult
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("InvalidRequest.Error"),
                    });
                }
            }

            var tabUrl = new TabUrlInfo
            {
                TabId            = tab.TabID,
                SeqNum           = seqNum,
                PortalAliasId    = dto.SiteAliasKey,
                PortalAliasUsage = portalAliasUsage,
                QueryString      = dto.QueryString.ValueOrEmpty(),
                Url         = dto.Path.ValueOrEmpty(),
                CultureCode = cultureCode,
                HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                IsSystem    = false,
            };

            TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);

            return(new PageUrlResult
            {
                Success = true,
                Id = seqNum, // returns Id of the created Url
            });
        }
Ejemplo n.º 4
0
        public void CreatePageFromTemplate(int templateId, TabInfo tab, int portalId)
        {
            // create the page from a template
            if (templateId != Null.NullInteger)
            {
                var xmlDoc = new XmlDocument {
                    XmlResolver = null
                };
                try
                {
                    // open the XML file
                    var fileId       = Convert.ToInt32(templateId);
                    var templateFile = FileManager.Instance.GetFile(fileId);
                    xmlDoc.Load(FileManager.Instance.GetFileContent(templateFile));
                }
                catch (Exception ex)
                {
                    DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                    throw new PageException(Localization.GetString("BadTemplate"));
                }
                TabController.DeserializePanes(xmlDoc.SelectSingleNode("//portal/tabs/tab/panes"), tab.PortalID, tab.TabID, PortalTemplateModuleAction.Ignore, new Hashtable());
                //save tab permissions
                RibbonBarManager.DeserializeTabPermissions(xmlDoc.SelectNodes("//portal/tabs/tab/tabpermissions/permission"), tab);

                var tabIndex   = 0;
                var exceptions = string.Empty;
                // ReSharper disable once PossibleNullReferenceException
                foreach (XmlNode tabNode in xmlDoc.SelectSingleNode("//portal/tabs").ChildNodes)
                {
                    //Create second tab onward tabs. Note first tab is already created above.
                    if (tabIndex > 0)
                    {
                        try
                        {
                            TabController.DeserializeTab(tabNode, null, portalId, PortalTemplateModuleAction.Replace);
                        }
                        catch (Exception ex)
                        {
                            DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                            exceptions += string.Format("Template Tab # {0}. Error {1}<br/>", tabIndex + 1, ex.Message);
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(tab.SkinSrc) && !String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode, "skinsrc", "")))
                        {
                            tab.SkinSrc = XmlUtils.GetNodeValue(tabNode, "skinsrc", "");
                        }
                        if (string.IsNullOrEmpty(tab.ContainerSrc) && !String.IsNullOrEmpty(XmlUtils.GetNodeValue(tabNode, "containersrc", "")))
                        {
                            tab.ContainerSrc = XmlUtils.GetNodeValue(tabNode, "containersrc", "");
                        }
                        bool isSecure;
                        if (bool.TryParse(XmlUtils.GetNodeValue(tabNode, "issecure", ""), out isSecure))
                        {
                            tab.IsSecure = isSecure;
                        }

                        TabController.Instance.UpdateTab(tab);
                    }
                    tabIndex++;
                }

                if (!string.IsNullOrEmpty(exceptions))
                {
                    throw new PageException(exceptions);
                }
            }
        }
Ejemplo n.º 5
0
        public PageUrlResult UpdateCustomUrl(SaveUrlDto dto, TabInfo tab)
        {
            var  portalSettings = PortalController.Instance.GetCurrentPortalSettings();
            var  urlPath        = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            // Clean Url
            var options =
                UrlRewriterUtils.ExtendOptionsForCustomURLs(
                    UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            // now clean the path
            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"),
                    SuggestedUrlPath = "/" + urlPath,
                });
            }

            // Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, tab.TabID, portalSettings, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"),
                    SuggestedUrlPath = "/" + urlPath,
                });
            }

            var cultureCode = LocaleController.Instance.GetLocales(portalSettings.PortalId)
                              .Where(l => l.Value.KeyID == dto.LocaleKey)
                              .Select(l => l.Value.Code)
                              .SingleOrDefault() ?? portalSettings.DefaultLanguage;

            var statusCodeKey = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture);
            var tabUrl        = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id && t.HttpStatus == statusCodeKey);

            if (statusCodeKey == "200")
            {
                // We need to check if we are updating a current url or creating a new 200
                if (tabUrl == null)
                {
                    // Just create Url
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = "200",
                        IsSystem    = dto.IsSystem, // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
                else
                {
                    if (!tabUrl.Url.Equals("/" + urlPath, StringComparison.OrdinalIgnoreCase))
                    {
                        // Change the original 200 url to a redirect
                        tabUrl.HttpStatus = "301";
                        tabUrl.SeqNum     = dto.Id;
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);

                        // Add new custom url
                        tabUrl.Url              = dto.Path.ValueOrEmpty();
                        tabUrl.HttpStatus       = "200";
                        tabUrl.SeqNum           = tab.TabUrls.Max(t => t.SeqNum) + 1;
                        tabUrl.CultureCode      = cultureCode;
                        tabUrl.PortalAliasId    = dto.SiteAliasKey;
                        tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                        tabUrl.QueryString      = dto.QueryString.ValueOrEmpty();
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                    }
                    else
                    {
                        // Update the original 200 url
                        tabUrl.CultureCode      = cultureCode;
                        tabUrl.PortalAliasId    = dto.SiteAliasKey;
                        tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                        tabUrl.QueryString      = dto.QueryString.ValueOrEmpty();
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                    }
                }
            }
            else
            {
                // Update the original non 200 url
                if (tabUrl == null)
                {
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = statusCodeKey,
                        IsSystem    = dto.IsSystem, // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
                else
                {
                    tabUrl.CultureCode      = cultureCode;
                    tabUrl.PortalAliasId    = dto.SiteAliasKey;
                    tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                    tabUrl.Url         = dto.Path.ValueOrEmpty();
                    tabUrl.HttpStatus  = statusCodeKey;
                    tabUrl.QueryString = dto.QueryString.ValueOrEmpty();
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
            }

            return(new PageUrlResult
            {
                Success = true,
            });
        }