diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs index 3beef6e9968..00a1117ceee 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/SiteSettingsController.cs @@ -2,84 +2,84 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information -namespace Dnn.PersonaBar.SiteSettings.Services -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Data; - using System.Dynamic; - using System.Globalization; - using System.IO; - using System.Linq; - using System.Net; - using System.Net.Http; - using System.Text.RegularExpressions; - using System.Threading; - using System.Web; - using System.Web.Http; - - using Dnn.PersonaBar.Library; - using Dnn.PersonaBar.Library.Attributes; - using Dnn.PersonaBar.SiteSettings.Services.Dto; - using DotNetNuke.Abstractions; - using DotNetNuke.Common; - using DotNetNuke.Common.Lists; - using DotNetNuke.Common.Utilities; - using DotNetNuke.Entities.Controllers; - using DotNetNuke.Entities.Host; - using DotNetNuke.Entities.Icons; - using DotNetNuke.Entities.Modules; - using DotNetNuke.Entities.Portals; - using DotNetNuke.Entities.Profile; - using DotNetNuke.Entities.Tabs; - using DotNetNuke.Entities.Urls; - using DotNetNuke.Entities.Users; - using DotNetNuke.Instrumentation; - using DotNetNuke.Security.Roles; - using DotNetNuke.Services.Exceptions; - using DotNetNuke.Services.FileSystem; - using DotNetNuke.Services.Installer.Packages; - using DotNetNuke.Services.Localization; - using DotNetNuke.Services.Personalization; - using DotNetNuke.Services.Search.Internals; - using DotNetNuke.UI.Internals; - using DotNetNuke.UI.Skins; - using DotNetNuke.Web.Api; - using DotNetNuke.Web.UI.WebControls; - - using Constants = Dnn.PersonaBar.Library.Constants; - using FileInfo = System.IO.FileInfo; +namespace Dnn.PersonaBar.SiteSettings.Services +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Data; + using System.Dynamic; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Text.RegularExpressions; + using System.Threading; + using System.Web; + using System.Web.Http; + + using Dnn.PersonaBar.Library; + using Dnn.PersonaBar.Library.Attributes; + using Dnn.PersonaBar.SiteSettings.Services.Dto; + using DotNetNuke.Abstractions; + using DotNetNuke.Common; + using DotNetNuke.Common.Lists; + using DotNetNuke.Common.Utilities; + using DotNetNuke.Entities.Controllers; + using DotNetNuke.Entities.Host; + using DotNetNuke.Entities.Icons; + using DotNetNuke.Entities.Modules; + using DotNetNuke.Entities.Portals; + using DotNetNuke.Entities.Profile; + using DotNetNuke.Entities.Tabs; + using DotNetNuke.Entities.Urls; + using DotNetNuke.Entities.Users; + using DotNetNuke.Instrumentation; + using DotNetNuke.Security.Roles; + using DotNetNuke.Services.Exceptions; + using DotNetNuke.Services.FileSystem; + using DotNetNuke.Services.Installer.Packages; + using DotNetNuke.Services.Localization; + using DotNetNuke.Services.Personalization; + using DotNetNuke.Services.Search.Internals; + using DotNetNuke.UI.Internals; + using DotNetNuke.UI.Skins; + using DotNetNuke.Web.Api; + using DotNetNuke.Web.UI.WebControls; + + using Constants = Dnn.PersonaBar.Library.Constants; + using FileInfo = System.IO.FileInfo; [MenuPermission(MenuName = Components.Constants.Constants.MenuName)] public class SiteSettingsController : PersonaBarApiController { - - // Field Boost Settings - they are scaled down by 10. - private const int DefaultSearchTitleBoost = 50; - private const string AuthFailureMessage = "Authorization has been denied for this request."; - private const int DefaultSearchTagBoost = 40; - private const int DefaultSearchContentBoost = 35; - private const int DefaultSearchDescriptionBoost = 20; - private const int DefaultSearchAuthorBoost = 15; - - // Field Bosst Setting Names - private const string SearchTitleBoostSetting = "Search_Title_Boost"; - private const string SearchTagBoostSetting = "Search_Tag_Boost"; - private const string SearchContentBoostSetting = "Search_Content_Boost"; - private const string SearchDescriptionBoostSetting = "Search_Description_Boost"; - private const string SearchAuthorBoostSetting = "Search_Author_Boost"; - - private const double DefaultMessagingThrottlingInterval = 0.5; // set default MessagingThrottlingInterval value to 30 seconds. - private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(SiteSettingsController)); - private readonly Components.SiteSettingsController _controller = new Components.SiteSettingsController(); - - protected INavigationManager NavigationManager { get; } - - public SiteSettingsController(INavigationManager navigationManager) - { - this.NavigationManager = navigationManager; - } + + // Field Boost Settings - they are scaled down by 10. + private const int DefaultSearchTitleBoost = 50; + private const string AuthFailureMessage = "Authorization has been denied for this request."; + private const int DefaultSearchTagBoost = 40; + private const int DefaultSearchContentBoost = 35; + private const int DefaultSearchDescriptionBoost = 20; + private const int DefaultSearchAuthorBoost = 15; + + // Field Bosst Setting Names + private const string SearchTitleBoostSetting = "Search_Title_Boost"; + private const string SearchTagBoostSetting = "Search_Tag_Boost"; + private const string SearchContentBoostSetting = "Search_Content_Boost"; + private const string SearchDescriptionBoostSetting = "Search_Description_Boost"; + private const string SearchAuthorBoostSetting = "Search_Author_Boost"; + + private const double DefaultMessagingThrottlingInterval = 0.5; // set default MessagingThrottlingInterval value to 30 seconds. + private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(SiteSettingsController)); + private readonly Components.SiteSettingsController _controller = new Components.SiteSettingsController(); + + protected INavigationManager NavigationManager { get; } + + public SiteSettingsController(INavigationManager navigationManager) + { + this.NavigationManager = navigationManager; + } #region Site Info API @@ -310,7 +310,11 @@ public HttpResponseMessage GetDefaultPagesSettings(int? portalId, string culture } var portal = PortalController.Instance.GetPortal(pid, cultureCode); - var portalSettings = new PortalSettings(portal); + var localizedPortalSettings = PortalController.Instance.GetPortalSettings(portal.PortalID, cultureCode); + + int redirectAfterLoginTabId = int.TryParse(localizedPortalSettings["Redirect_AfterLogin"], out redirectAfterLoginTabId) ? redirectAfterLoginTabId : -1; + int redirectAfterLogoutTabId = int.TryParse(localizedPortalSettings["Redirect_AfterLogout"], out redirectAfterLogoutTabId) ? redirectAfterLogoutTabId : -1; + int redirectAfterRegistrationTabId = int.TryParse(localizedPortalSettings["Redirect_AfterRegistration"], out redirectAfterRegistrationTabId) ? redirectAfterRegistrationTabId : -1; return this.Request.CreateResponse(HttpStatusCode.OK, new { @@ -338,13 +342,13 @@ public HttpResponseMessage GetDefaultPagesSettings(int? portalId, string culture TermsTabName = this.TabSanitizer(portal.TermsTabId, pid)?.TabName, PrivacyTabId = this.TabSanitizer(portal.PrivacyTabId, pid)?.TabID, PrivacyTabName = this.TabSanitizer(portal.PrivacyTabId, pid)?.TabName, - RedirectAfterLoginTabId = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogin, pid)?.TabID, - RedirectAfterLoginTabName = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogin, pid)?.TabName, - RedirectAfterLogoutTabId = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogout, pid)?.TabID, - RedirectAfterLogoutTabName = this.TabSanitizer(portalSettings.Registration.RedirectAfterLogout, pid)?.TabName, - RedirectAfterRegistrationTabId = this.TabSanitizer(portalSettings.Registration.RedirectAfterRegistration, pid)?.TabID, - RedirectAfterRegistrationTabName = this.TabSanitizer(portalSettings.Registration.RedirectAfterRegistration, pid)?.TabName, - portalSettings.PageHeadText, + RedirectAfterLoginTabId = this.TabSanitizer(redirectAfterLoginTabId, pid)?.TabID, + RedirectAfterLoginTabName = this.TabSanitizer(redirectAfterLoginTabId, pid)?.TabName, + RedirectAfterLogoutTabId = this.TabSanitizer(redirectAfterLogoutTabId, pid)?.TabID, + RedirectAfterLogoutTabName = this.TabSanitizer(redirectAfterLogoutTabId, pid)?.TabName, + RedirectAfterRegistrationTabId = this.TabSanitizer(redirectAfterRegistrationTabId, pid)?.TabID, + RedirectAfterRegistrationTabName = this.TabSanitizer(redirectAfterRegistrationTabId, pid)?.TabName, + PageHeadText = localizedPortalSettings["PageHeadText"], }, }); } @@ -394,10 +398,11 @@ public HttpResponseMessage UpdateDefaultPagesSettings(UpdateDefaultPagesSettings portalInfo.TermsTabId = this.ValidateTabId(request.TermsTabId, pid); portalInfo.PrivacyTabId = this.ValidateTabId(request.PrivacyTabId, pid); PortalController.Instance.UpdatePortalInfo(portalInfo); - - PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogin", this.ValidateTabId(request.RedirectAfterLoginTabId, pid).ToString(), false, cultureCode); - PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogout", this.ValidateTabId(request.RedirectAfterLogoutTabId, pid).ToString(), false, cultureCode); - PortalController.UpdatePortalSetting(pid, "Redirect_AfterRegistration", this.ValidateTabId(request.RedirectAfterRegistrationTabId, pid).ToString(), false, cultureCode); + + var portalSettings = PortalController.Instance.GetCurrentSettings(); + PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogin", this.ValidateTabId(request.RedirectAfterLoginTabId, pid).ToString(), false, cultureCode); + PortalController.UpdatePortalSetting(pid, "Redirect_AfterLogout", this.ValidateTabId(request.RedirectAfterLogoutTabId, pid).ToString(), false, cultureCode); + PortalController.UpdatePortalSetting(pid, "Redirect_AfterRegistration", this.ValidateTabId(request.RedirectAfterRegistrationTabId, pid).ToString(), false, cultureCode); PortalController.UpdatePortalSetting(pid, "PageHeadText", string.IsNullOrEmpty(request.PageHeadText) ? "false" : request.PageHeadText); return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true }); @@ -3212,40 +3217,40 @@ public HttpResponseMessage UpdateOtherSettings(UpdateOtherSettingsRequest reques return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } } - - private static void GetResourceFiles(SortedList fileList, string path) - { - var folders = Directory.GetDirectories(path); - - foreach (var folder in folders) - { - var objFolder = new DirectoryInfo(folder); - - bool resxFilesDirectory = (objFolder.Name.ToLowerInvariant() == Localization.LocalResourceDirectory.ToLowerInvariant()) || - (objFolder.Name.ToLowerInvariant() == Localization.ApplicationResourceDirectory.Replace("~/", "").ToLowerInvariant()) || - (folder.ToLowerInvariant().EndsWith("\\portals\\_default")); - - if (resxFilesDirectory) - { - var sysLocale = Localization.SystemLocale.ToLowerInvariant(); - foreach (var file in Directory.GetFiles(objFolder.FullName, "*.resx")) - { - var fileInfo = new FileInfo(file); - var match = LanguagesController.FileInfoRegex.Match(fileInfo.Name); - - if (match.Success && match.Groups[1].Value.ToLowerInvariant() != sysLocale) - { - continue; - } - fileList.Add(fileInfo.FullName, fileInfo); - } - } - else - { - GetResourceFiles(fileList, folder); - } - } - } + + private static void GetResourceFiles(SortedList fileList, string path) + { + var folders = Directory.GetDirectories(path); + + foreach (var folder in folders) + { + var objFolder = new DirectoryInfo(folder); + + bool resxFilesDirectory = (objFolder.Name.ToLowerInvariant() == Localization.LocalResourceDirectory.ToLowerInvariant()) || + (objFolder.Name.ToLowerInvariant() == Localization.ApplicationResourceDirectory.Replace("~/", "").ToLowerInvariant()) || + (folder.ToLowerInvariant().EndsWith("\\portals\\_default")); + + if (resxFilesDirectory) + { + var sysLocale = Localization.SystemLocale.ToLowerInvariant(); + foreach (var file in Directory.GetFiles(objFolder.FullName, "*.resx")) + { + var fileInfo = new FileInfo(file); + var match = LanguagesController.FileInfoRegex.Match(fileInfo.Name); + + if (match.Success && match.Groups[1].Value.ToLowerInvariant() != sysLocale) + { + continue; + } + fileList.Add(fileInfo.FullName, fileInfo); + } + } + else + { + GetResourceFiles(fileList, folder); + } + } + } #endregion @@ -3261,263 +3266,263 @@ private bool IsLanguagePublished(int portalId, string code) } return isPublished; } - - private string GetTranslatedPages(PortalSettings portalSettings, string code) - { - string status = ""; - if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) - { - int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated && !t.IsDeleted select t).Count(); - status = translatedCount.ToString(CultureInfo.InvariantCulture); - } - return status; - } - - private string GetLocalizedStatus(PortalSettings portalSettings, string code) - { - string status = ""; - if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) - { - int defaultPageCount = this.GetLocalizedPages(portalSettings.PortalId, portalSettings.DefaultLanguage, false).Count; - int currentPageCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; - status = $"{currentPageCount / (float)defaultPageCount:#0%}"; - } - return status; - } - - private string GetLocalizablePages(int portalId, string code) - { - int count = this.GetLocalizedPages(portalId, code, false).Count(t => !t.Value.IsDeleted); - return count.ToString(CultureInfo.CurrentUICulture); - } - - private TabCollection GetLocalizedPages(int portalId, string code, bool includeNeutral) - { - return TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, includeNeutral); - } - - private int GetPublishedLocalizedPages(int portalId, string code) - { - var localizedTabs = TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, false); - return localizedTabs.Count(t => TabController.Instance.IsTabPublished(t.Value)); - } - - private string GetTranslatedStatus(PortalSettings portalSettings, string code) - { - string status = ""; - if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) - { - int localizedCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; - int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated select t).Count(); - status = $"{translatedCount / (float)localizedCount:#0%}"; - } - return status; - } - - private bool IsDefaultLanguage(PortalSettings portalSettings, string code) - { - return code == portalSettings.DefaultLanguage; - } - - private bool IsLocalized(PortalSettings portalSettings, string code) - { - return (code != portalSettings.DefaultLanguage && this.GetLocalizedPages(portalSettings.PortalId, code, false).Count > 0); - } - - private bool CanDeleteProperty(ProfilePropertyDefinition definition) - { - switch (definition.PropertyName.ToLowerInvariant()) - { - case "lastname": - case "firstname": - case "preferredtimezone": - case "preferredlocale": - return false; - default: - return true; - } - } - - private string GetAbsoluteServerPath() - { - var httpContext = this.Request.Properties["MS_HttpContext"] as HttpContextWrapper; - if (httpContext != null) - { - var strServerPath = httpContext.Request.MapPath(httpContext.Request.ApplicationPath); - if (!strServerPath.EndsWith("\\")) - { - strServerPath += "\\"; - } - return strServerPath; - } - else - { - return string.Empty; - } - } - - private string DisplayDataType(int dataType) - { - var retValue = Null.NullString; - var listController = new ListController(); - var definitionEntry = listController.GetListEntryInfo("DataType", dataType); - if (definitionEntry != null) - { - retValue = definitionEntry.Value; - } - return retValue; - } - - private bool ValidateProperty(ProfilePropertyDefinition definition, out HttpResponseMessage httpPropertyValidationError) - { - bool isValid = true; - httpPropertyValidationError = null; - var objListController = new ListController(); - string strDataType = objListController.GetListEntryInfo("DataType", definition.DataType).Value; - Regex propertyNameRegex = new Regex("^[a-zA-Z0-9]+$"); - if (!propertyNameRegex.Match(definition.PropertyName).Success) - { - isValid = false; - httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("NoSpecialCharacterName.Text", Components.Constants.Constants.LocalResourcesFile))); - } - - switch (strDataType) - { - case "Text": - if (definition.Required && definition.Length == 0) - { - isValid = Null.NullBoolean; - } - break; - } - - if (isValid == false) - { - httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, - string.Format(Localization.GetString("RequiredTextBox", Components.Constants.Constants.LocalResourcesFile))); - } - return isValid; - } - - private bool IsHttpAliasValid(string strAlias) - { - bool isValid = true; - if (string.IsNullOrEmpty(strAlias)) - { - isValid = false; - } - else - { - if (strAlias.IndexOf("://", StringComparison.Ordinal) != -1) - { - strAlias = strAlias.Remove(0, strAlias.IndexOf("://", StringComparison.Ordinal) + 3); - } - if (strAlias.IndexOf("\\\\", StringComparison.Ordinal) != -1) - { - strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\", StringComparison.Ordinal) + 2); - } - - // Validate Alias, this needs to be done with lowercase, downstream we only check with lowercase variables - if (!PortalAliasController.ValidateAlias(strAlias.ToLowerInvariant(), false)) - { - isValid = false; - } - } - return isValid; - } - - private static string ResourceFile(string filename, string language) - { - return Localization.GetResourceFileName(filename, language, "", Globals.GetPortalSettings().PortalId); - } - - private bool IsLanguageEnabled(int portalId, string code) - { - Locale enabledLanguage; - return LocaleController.Instance.GetLocales(portalId).TryGetValue(code, out enabledLanguage); - } - - private bool CanEnableDisable(PortalSettings portalSettings, string code) - { - bool canEnable; - if (this.IsLanguageEnabled(portalSettings.PortalId, code)) - { - canEnable = !this.IsDefaultLanguage(portalSettings, code) && !this.IsLanguagePublished(portalSettings.PortalId, code); - } - else - { - canEnable = !this.IsDefaultLanguage(portalSettings, code); - } - return canEnable; - } - - private CultureDropDownTypes GetCultureDropDownType(int portalId) - { - CultureDropDownTypes displayType; - string viewType = this.GetLanguageDisplayMode(portalId); - switch (viewType) - { - case "NATIVE": - displayType = CultureDropDownTypes.NativeName; - break; - case "ENGLISH": - displayType = CultureDropDownTypes.EnglishName; - break; - default: - displayType = CultureDropDownTypes.DisplayName; - break; - } - return displayType; - } - - private string GetLanguageDisplayMode(int portalId) - { - string viewTypePersonalizationKey = "LanguageDisplayMode:ViewType" + portalId; - var personalizationController = new PersonalizationController(); - var personalization = personalizationController.LoadProfile(this.UserInfo.UserID, portalId); - - string viewType = Convert.ToString(personalization.Profile[viewTypePersonalizationKey]); - return string.IsNullOrEmpty(viewType) ? "NATIVE" : viewType; - } - - private SearchStatistics GetSearchStatistics() - { - try - { - return InternalSearchController.Instance.GetSearchStatistics(); - } - catch (SearchIndexEmptyException) - { - return null; - } - } - - private void ClearEntriesCache(string listName, int portalId) - { - string cacheKey = string.Format(DataCache.ListEntriesCacheKey, portalId, listName); - DataCache.RemoveCache(cacheKey); - } - - private TabInfo TabSanitizer(int tabId, int portalId) - { - var tab = TabController.Instance.GetTab(tabId, portalId); - if (tab != null && !tab.IsDeleted) - { - return tab; - } - else - { - return null; - } - } - - private int ValidateTabId(int tabId, int portalId) - { - var tab = TabController.Instance.GetTab(tabId, portalId); - return tab != null && !tab.IsDeleted ? tab.TabID : Null.NullInteger; - } + + private string GetTranslatedPages(PortalSettings portalSettings, string code) + { + string status = ""; + if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) + { + int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated && !t.IsDeleted select t).Count(); + status = translatedCount.ToString(CultureInfo.InvariantCulture); + } + return status; + } + + private string GetLocalizedStatus(PortalSettings portalSettings, string code) + { + string status = ""; + if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) + { + int defaultPageCount = this.GetLocalizedPages(portalSettings.PortalId, portalSettings.DefaultLanguage, false).Count; + int currentPageCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; + status = $"{currentPageCount / (float)defaultPageCount:#0%}"; + } + return status; + } + + private string GetLocalizablePages(int portalId, string code) + { + int count = this.GetLocalizedPages(portalId, code, false).Count(t => !t.Value.IsDeleted); + return count.ToString(CultureInfo.CurrentUICulture); + } + + private TabCollection GetLocalizedPages(int portalId, string code, bool includeNeutral) + { + return TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, includeNeutral); + } + + private int GetPublishedLocalizedPages(int portalId, string code) + { + var localizedTabs = TabController.Instance.GetTabsByPortal(portalId).WithCulture(code, false); + return localizedTabs.Count(t => TabController.Instance.IsTabPublished(t.Value)); + } + + private string GetTranslatedStatus(PortalSettings portalSettings, string code) + { + string status = ""; + if (!this.IsDefaultLanguage(portalSettings, code) && this.IsLocalized(portalSettings, code)) + { + int localizedCount = this.GetLocalizedPages(portalSettings.PortalId, code, false).Count; + int translatedCount = (from t in TabController.Instance.GetTabsByPortal(portalSettings.PortalId).WithCulture(code, false).Values where t.IsTranslated select t).Count(); + status = $"{translatedCount / (float)localizedCount:#0%}"; + } + return status; + } + + private bool IsDefaultLanguage(PortalSettings portalSettings, string code) + { + return code == portalSettings.DefaultLanguage; + } + + private bool IsLocalized(PortalSettings portalSettings, string code) + { + return (code != portalSettings.DefaultLanguage && this.GetLocalizedPages(portalSettings.PortalId, code, false).Count > 0); + } + + private bool CanDeleteProperty(ProfilePropertyDefinition definition) + { + switch (definition.PropertyName.ToLowerInvariant()) + { + case "lastname": + case "firstname": + case "preferredtimezone": + case "preferredlocale": + return false; + default: + return true; + } + } + + private string GetAbsoluteServerPath() + { + var httpContext = this.Request.Properties["MS_HttpContext"] as HttpContextWrapper; + if (httpContext != null) + { + var strServerPath = httpContext.Request.MapPath(httpContext.Request.ApplicationPath); + if (!strServerPath.EndsWith("\\")) + { + strServerPath += "\\"; + } + return strServerPath; + } + else + { + return string.Empty; + } + } + + private string DisplayDataType(int dataType) + { + var retValue = Null.NullString; + var listController = new ListController(); + var definitionEntry = listController.GetListEntryInfo("DataType", dataType); + if (definitionEntry != null) + { + retValue = definitionEntry.Value; + } + return retValue; + } + + private bool ValidateProperty(ProfilePropertyDefinition definition, out HttpResponseMessage httpPropertyValidationError) + { + bool isValid = true; + httpPropertyValidationError = null; + var objListController = new ListController(); + string strDataType = objListController.GetListEntryInfo("DataType", definition.DataType).Value; + Regex propertyNameRegex = new Regex("^[a-zA-Z0-9]+$"); + if (!propertyNameRegex.Match(definition.PropertyName).Success) + { + isValid = false; + httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + string.Format(Localization.GetString("NoSpecialCharacterName.Text", Components.Constants.Constants.LocalResourcesFile))); + } + + switch (strDataType) + { + case "Text": + if (definition.Required && definition.Length == 0) + { + isValid = Null.NullBoolean; + } + break; + } + + if (isValid == false) + { + httpPropertyValidationError = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, + string.Format(Localization.GetString("RequiredTextBox", Components.Constants.Constants.LocalResourcesFile))); + } + return isValid; + } + + private bool IsHttpAliasValid(string strAlias) + { + bool isValid = true; + if (string.IsNullOrEmpty(strAlias)) + { + isValid = false; + } + else + { + if (strAlias.IndexOf("://", StringComparison.Ordinal) != -1) + { + strAlias = strAlias.Remove(0, strAlias.IndexOf("://", StringComparison.Ordinal) + 3); + } + if (strAlias.IndexOf("\\\\", StringComparison.Ordinal) != -1) + { + strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\", StringComparison.Ordinal) + 2); + } + + // Validate Alias, this needs to be done with lowercase, downstream we only check with lowercase variables + if (!PortalAliasController.ValidateAlias(strAlias.ToLowerInvariant(), false)) + { + isValid = false; + } + } + return isValid; + } + + private static string ResourceFile(string filename, string language) + { + return Localization.GetResourceFileName(filename, language, "", Globals.GetPortalSettings().PortalId); + } + + private bool IsLanguageEnabled(int portalId, string code) + { + Locale enabledLanguage; + return LocaleController.Instance.GetLocales(portalId).TryGetValue(code, out enabledLanguage); + } + + private bool CanEnableDisable(PortalSettings portalSettings, string code) + { + bool canEnable; + if (this.IsLanguageEnabled(portalSettings.PortalId, code)) + { + canEnable = !this.IsDefaultLanguage(portalSettings, code) && !this.IsLanguagePublished(portalSettings.PortalId, code); + } + else + { + canEnable = !this.IsDefaultLanguage(portalSettings, code); + } + return canEnable; + } + + private CultureDropDownTypes GetCultureDropDownType(int portalId) + { + CultureDropDownTypes displayType; + string viewType = this.GetLanguageDisplayMode(portalId); + switch (viewType) + { + case "NATIVE": + displayType = CultureDropDownTypes.NativeName; + break; + case "ENGLISH": + displayType = CultureDropDownTypes.EnglishName; + break; + default: + displayType = CultureDropDownTypes.DisplayName; + break; + } + return displayType; + } + + private string GetLanguageDisplayMode(int portalId) + { + string viewTypePersonalizationKey = "LanguageDisplayMode:ViewType" + portalId; + var personalizationController = new PersonalizationController(); + var personalization = personalizationController.LoadProfile(this.UserInfo.UserID, portalId); + + string viewType = Convert.ToString(personalization.Profile[viewTypePersonalizationKey]); + return string.IsNullOrEmpty(viewType) ? "NATIVE" : viewType; + } + + private SearchStatistics GetSearchStatistics() + { + try + { + return InternalSearchController.Instance.GetSearchStatistics(); + } + catch (SearchIndexEmptyException) + { + return null; + } + } + + private void ClearEntriesCache(string listName, int portalId) + { + string cacheKey = string.Format(DataCache.ListEntriesCacheKey, portalId, listName); + DataCache.RemoveCache(cacheKey); + } + + private TabInfo TabSanitizer(int tabId, int portalId) + { + var tab = TabController.Instance.GetTab(tabId, portalId); + if (tab != null && !tab.IsDeleted) + { + return tab; + } + else + { + return null; + } + } + + private int ValidateTabId(int tabId, int portalId) + { + var tab = TabController.Instance.GetTab(tabId, portalId); + return tab != null && !tab.IsDeleted ? tab.TabID : Null.NullInteger; + } #endregion } -} +}