/// <summary> /// Creates the site. /// </summary> /// <param name="row">The row.</param> /// <returns></returns> public static CmsSite CreateSite(SiteDto.SiteRow row) { CmsSite site = new CmsSite(); site.Description = row.Description; if (String.IsNullOrEmpty(row.Domain)) { string rowDomain = row.Domain.Replace("\r\n", "\n"); string[] domains = rowDomain.Split(new char[] { '\n' }); site.Domains = domains; } site.ID = row.SiteId; site.Name = row.Name; // Add attributes site.Attributes = new StringDictionary(); foreach (SiteDto.main_GlobalVariablesRow varRow in row.Getmain_GlobalVariablesRows()) { site.Attributes.Add(varRow.KEY, varRow.VALUE); } return(site); }
public void PreCommitChanges(IDictionary context) { SiteDto dto = (SiteDto)context[_SiteDtoDestinationString]; if (dto != null && dto.Site.Count > 0) { SiteDto.SiteRow row = dto.Site[0]; // save Global variables for the site (afterthe site is saved) while (txtURL.Text.EndsWith("/")) { txtURL.Text = txtURL.Text.Substring(0, txtURL.Text.Length - 1); } mc.GlobalVariable.SetVariable("url", txtURL.Text, row.SiteId); mc.GlobalVariable.SetVariable("email", txtEmail.Text, row.SiteId); mc.GlobalVariable.SetVariable("phone", txtPhone.Text, row.SiteId); mc.GlobalVariable.SetVariable("address", txtAddress.Text, row.SiteId); mc.GlobalVariable.SetVariable("meta_keywords", txtKeywords.Text, row.SiteId); mc.GlobalVariable.SetVariable("meta_description", txtDescription.Text, row.SiteId); mc.GlobalVariable.SetVariable("default_template", ddTemplate.SelectedValue, row.SiteId); mc.GlobalVariable.SetVariable("page_include", PageInclude.Text, row.SiteId); mc.GlobalVariable.SetVariable("title", txtTitle.Text, row.SiteId); mc.GlobalVariable.SetVariable("sitetheme", SiteTheme.Text, row.SiteId); mc.GlobalVariable.SetVariable("cm_url", AdminUrl.Text, row.SiteId); } }
/// <summary> /// Saves the changes. /// </summary> /// <param name="context">The context.</param> public void SaveChanges(IDictionary context) { SiteDto dto = (SiteDto)context[_SiteDtoDestinationString]; SiteDto.SiteRow row = null; if (dto.Site != null && dto.Site.Count > 0) { row = dto.Site[0]; } else { if (!String.IsNullOrEmpty(SiteTemplatesList.SelectedValue)) { // create site from template FileStream fs = new FileStream(SiteTemplatesList.SelectedValue, FileMode.Open, FileAccess.Read); ImportExportHelper helper = new ImportExportHelper(); Guid[] ids = helper.ImportSite(fs, mc.CmsConfiguration.Instance.ApplicationId, Guid.Empty, true); if (ids.Length > 0) { context[_SiteDtoDestinationString] = mc.CMSContext.Current.GetSiteDto(ids[0], true); dto = (SiteDto)context[_SiteDtoDestinationString]; if (dto.Site.Count > 0) { row = dto.Site[0]; } else { throw new Exception(String.Format("Could not load the site after importing. id={0}", ids[0])); } } else { throw new Exception("Import function did not return siteId."); } } else { row = dto.Site.NewSiteRow(); row.SiteId = Guid.NewGuid(); row.ApplicationId = mc.CmsConfiguration.Instance.ApplicationId; } } row.Name = SiteName.Text; row.Description = SiteDescription.Text; row.IsActive = IsSiteActive.IsSelected; row.IsDefault = IsSiteDefault.IsSelected; row.Folder = SiteFolder.Text; row.Domain = SiteDomains.Text; if (row.RowState == DataRowState.Detached) { dto.Site.Rows.Add(row); /* * * SiteDto.ApplicationSiteRow appRow = dto.ApplicationSite.NewApplicationSiteRow(); * appRow.SiteId = row.SiteId; * appRow.ApplicationId = CatalogConfiguration.ApplicationId; * dto.ApplicationSite.Rows.Add(appRow); * */ } // Populate languages // Remove existing languages foreach (SiteDto.SiteLanguageRow langRow in dto.SiteLanguage.Rows) { if (langRow.RowState == DataRowState.Deleted) { continue; } bool found = false; foreach (ListItem item in LanguageList.RightItems) { if (item.Value.Equals(langRow.LanguageCode)) { found = true; break; } } if (!found) { langRow.Delete(); } } foreach (ListItem item in LanguageList.RightItems) { bool exists = false; foreach (SiteDto.SiteLanguageRow langRow in dto.SiteLanguage.Rows) { if (langRow.RowState != DataRowState.Deleted) { if (langRow.LanguageCode.Equals(item.Value)) { exists = true; } } } if (!exists) { SiteDto.SiteLanguageRow langRow = dto.SiteLanguage.NewSiteLanguageRow(); langRow.SiteId = row.SiteId; langRow.LanguageCode = item.Value; dto.SiteLanguage.Rows.Add(langRow); } } }
/// <summary> /// Handles the BeginRequest event of the context control. /// /// It will execute the following actions: /// /// 1. Determine which site this request belongs to. /// 2. Check if request is for the template.aspx and if it is redirect to the homepage instead. /// 3. Determine if it is a folder request or not and if it is detect the default page and redirect. /// 4. Restore settings from user cookies. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void context_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpContext context = app.Context; // Process only aspx pages and directories if (!(context.Request.Url.ToString().ToLower().IndexOf(".aspx") > 0) && !context.Request.Url.ToString().EndsWith("/")) { // If page name does not contain ".", then assume it is a folder and try to process the request if (context.Request.Url.Segments[context.Request.Url.Segments.Length - 1].ToString().Contains(".")) { return; } } CMSContext ctx = CMSContext.Create(context); // Determine SiteId SiteDto.SiteRow row = FindSiteFromUrl(ctx); // throw does not exist error if (row == null) { //throw new HttpException(404, "Site does not exist"); Write(null, null, "StoreClosed.htm"); } ctx.SiteId = row.SiteId; string appPath = ctx.Context.Request.ApplicationPath; if (appPath == "/") { appPath = String.Empty; } string outline = context.Request.RawUrl; int folderId = -1; if (ctx.AppPath.Length != 1) { outline = outline.Substring(ctx.AppPath.Length); } // Check if the request is for the template.aspx if (outline.Equals("/template.aspx", StringComparison.OrdinalIgnoreCase)) { ctx.Redirect(CMSContext.Current.ResolveUrl("~")); } // If empty, we assume it is the site root that we are requesting if (String.IsNullOrEmpty(outline)) { outline = "/"; } // Is it a folder? if (outline.EndsWith("/") || !outline.Contains(".")) { using (IDataReader reader = FileTreeItem.GetItemByOutlineAll(outline, CMSContext.Current.SiteId)) { if (reader.Read()) { folderId = (int)reader["PageId"]; } reader.Close(); } if (folderId != -1) { //try to find default page for folder using (IDataReader reader = FileTreeItem.GetFolderDefaultPage(folderId)) { if (reader.Read()) { string urlPage = String.Empty; if (context.Request.QueryString.Count > 0) { urlPage = reader.GetString(2) + "?" + context.Request.QueryString; } else { urlPage = reader.GetString(2); } // Add the relative path if (urlPage.StartsWith("/")) { urlPage = "~" + urlPage; } // Redirect ctx.Redirect(CMSContext.Current.ResolveUrl(urlPage)); } else { reader.Close(); throw new HttpException(204, "Default page for folder not found"); } reader.Close(); } } } // TODO: remove hard coded cookie names and put it into CMS configuration instead HttpCookie cookie; //CHECK ToolBar/ToolBox visible if (context.Request.Cookies[_toolBarVisibleCookieString] != null) { cookie = (HttpCookie)context.Request.Cookies[_toolBarVisibleCookieString]; CMSContext.Current.ToolBarVisible = Convert.ToBoolean(cookie.Value); } //CHECK ToolBox if (context.Request.Cookies[_toolBoxVisibleCookieString] != null) { cookie = (HttpCookie)context.Request.Cookies[_toolBoxVisibleCookieString]; CMSContext.Current.ToolBoxVisible = Convert.ToBoolean(cookie.Value); } //CHECK IsDesignMode CMSContext.Current.IsDesignMode = CommonHelper.CheckDesignMode(context); //CHECK CULTURE string currentCulture = string.Empty; //CHECK HIDDEN FIELDS if (!String.IsNullOrEmpty(context.Request.Form[_currentCultureRequestString])) { currentCulture = context.Request.Form[_currentCultureRequestString].Trim(); } else if (!String.IsNullOrEmpty(context.Request.QueryString[_currentCultureRequestString])) { currentCulture = context.Request.QueryString[_currentCultureRequestString].Trim(); } //CHECK QUERYSTRING if (!String.IsNullOrEmpty(context.Request.QueryString[_languageQueryString])) { currentCulture = context.Request.QueryString[_languageQueryString]; } //CHECK VERSION LANGUAGE if (!String.IsNullOrEmpty(context.Request.QueryString[_versionIdQueryString])) { int LangId = -1; int versionId = int.Parse(context.Request.QueryString[_versionIdQueryString]); //get version language id using (IDataReader reader = PageVersion.GetVersionById(versionId)) { if (reader.Read()) { LangId = (int)reader["LangId"]; } reader.Close(); } //get language name using (IDataReader lang = Language.LoadLanguage(LangId)) { if (lang.Read()) { currentCulture = CultureInfo.CreateSpecificCulture(lang["LangName"].ToString()).Name; } lang.Close(); } } if (currentCulture != string.Empty) { Thread.CurrentThread.CurrentCulture = new CultureInfo(currentCulture); Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentCulture); } else { //CHECK COOKIES if (context.Request.Cookies[_currentCultureCookieString] != null) { cookie = (HttpCookie)context.Request.Cookies[_currentCultureCookieString]; Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value); } else { // culture should be set to the one specified in the web.config file //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); } } if (!String.IsNullOrEmpty(currentCulture)) { //ConfigurationManager.AppSettings["HtmlEditorControl"]; cookie = new HttpCookie(_currentCultureCookieString); cookie.Expires = DateTime.Now.AddMonths(1); cookie.Value = Thread.CurrentThread.CurrentCulture.Name; context.Response.Cookies.Add(cookie); } }
/// <summary> /// Finds the site row from URL. /// </summary> /// <param name="ctx">The CTX.</param> /// <returns></returns> SiteDto.SiteRow FindSiteFromUrl(CMSContext ctx) { SiteDto.SiteRow siteRow = null; SiteDto sites = CMSContext.Current.GetSitesDto(CmsConfiguration.Instance.ApplicationId); string url = ctx.SitePath; string defaultDomain = ctx.Context.Request.Url.Host.Replace("www.", string.Empty); string appPath = ctx.Context.Request.ApplicationPath; Guid siteId = Guid.Empty; // Check if we have siteid reference if (!String.IsNullOrEmpty(ctx.Context.Request["siteid"])) { siteId = new Guid(ctx.Context.Request["siteid"]); } // Match score is used to score the URL matching site definitions, the higher the score, the better the match, // it is used to prevent lower matches overwriting higher matched int matchScore = 0; if (appPath == "/") { appPath = String.Empty; } foreach (SiteDto.SiteRow row in sites.Site.Rows) { // Check if site is active if (!row.IsActive) { continue; } // Check if we reference specific site id if (siteId != Guid.Empty && row.SiteId == siteId) { ctx.AppPath = row.Folder; if (String.IsNullOrEmpty(ctx.AppPath)) { ctx.AppPath = "/"; } siteRow = row; return(siteRow); } // Check if site is default if (row.IsDefault && siteRow == null) { siteRow = row; } // Split domains string rowDomain = row.Domain.Replace("\r\n", "\n"); string[] domains = rowDomain.Split(new char[] { '\n' }); // Cycle through domains foreach (string domain in domains) { int domainScoreModifier = 0; string d = domain; if (String.IsNullOrEmpty(domain)) { d = defaultDomain; } else { domainScoreModifier = 100; } if (url.Equals(d + row.Folder, StringComparison.OrdinalIgnoreCase)) { // Check matching score int newMatchScore = (row.Folder).Length + domainScoreModifier; if (newMatchScore <= matchScore) { continue; } matchScore = newMatchScore; ctx.AppPath = row.Folder; if (String.IsNullOrEmpty(ctx.AppPath)) { ctx.AppPath = "/"; } siteRow = row; } else if (url.Equals(d + appPath + row.Folder, StringComparison.OrdinalIgnoreCase)) { // Check matching score int newMatchScore = (appPath + row.Folder).Length + domainScoreModifier; if (newMatchScore <= matchScore) { continue; } matchScore = newMatchScore; ctx.AppPath = appPath + row.Folder; if (String.IsNullOrEmpty(ctx.AppPath)) { ctx.AppPath = "/"; } siteRow = row; } else if (url.StartsWith(d + appPath + row.Folder, StringComparison.OrdinalIgnoreCase)) { // Check matching score int newMatchScore = (appPath + row.Folder).Length + domainScoreModifier; if (newMatchScore <= matchScore) { continue; } matchScore = newMatchScore; ctx.AppPath = appPath + row.Folder; if (String.IsNullOrEmpty(ctx.AppPath)) { ctx.AppPath = "/"; } siteRow = row; } else if (url.StartsWith(d + row.Folder, StringComparison.OrdinalIgnoreCase)) { // Check matching score int newMatchScore = (row.Folder).Length + domainScoreModifier; if (newMatchScore <= matchScore) { continue; } matchScore = newMatchScore; ctx.AppPath = row.Folder; if (String.IsNullOrEmpty(ctx.AppPath)) { ctx.AppPath = "/"; } siteRow = row; } } } return(siteRow); }
/// <summary> /// Binds the membership form. /// </summary> /// <param name="id">The id.</param> private void BindMembershipForm(object id) { RolesList.DataSource = Roles.GetAllRoles(); RolesList.DataBind(); // Always enable everyone role ListItem item = RolesList.Items.FindByValue(AppRoles.EveryoneRole); if (item != null) { item.Selected = true; item.Enabled = false; } // Always enable registered role item = RolesList.Items.FindByValue(AppRoles.RegisteredRole); if (item != null) { item.Selected = true; item.Enabled = false; } MembershipUser user = null; if (id != null) { user = Membership.GetUser((Guid)id); } if (user != null) { ActionTd.Visible = true; PasswordTr.Visible = false; RecoveryCtrl.UserName = user.UserName; PasswordCtrl.UserName = user.UserName; IsApproved.IsSelected = user.IsApproved; IsLockedOut.IsSelected = user.IsLockedOut; LastActivityDate.Text = ManagementHelper.GetUserDateTime(user.LastActivityDate).ToString(); LastLockoutDate.Text = ManagementHelper.GetUserDateTime(user.LastLockoutDate).ToString(); LastLoginDate.Text = ManagementHelper.GetUserDateTime(user.LastLoginDate).ToString(); LastPasswordChangedDate.Text = ManagementHelper.GetUserDateTime(user.LastPasswordChangedDate).ToString(); UserNameTextBox.Text = user.UserName; UserNameTextBox.Enabled = false; EmailText.Text = user.Email; IsLockedOut.Enabled = false; CommentTextBox.Text = user.Comment; string[] roles = Roles.GetRolesForUser(user.UserName); if (roles != null) { foreach (string role in roles) { ListItem listItem = RolesList.Items.FindByValue(role); if (listItem != null) { listItem.Selected = true; } } } // Bind Login on behalf // Find out site url SiteDto.SiteDataTable sites = CMSContext.Current.GetSitesDto(CmsConfiguration.Instance.ApplicationId).Site; SiteDto.SiteRow site = null; if (sites != null && sites.Rows.Count > 0) { foreach (SiteDto.SiteRow siteRow in sites.Rows) { if (site == null && siteRow.IsActive) { site = siteRow; } if (siteRow.IsDefault && siteRow.IsActive) { site = siteRow; } } } if (site != null) { LoginOnBehalf.Visible = true; LoginOnBehalf.NavigateUrl = String.Format("{0}/login.aspx?customer={1}", GlobalVariable.GetVariable("url", site.SiteId), user.UserName); } else { LoginOnBehalf.Visible = false; } } else { UserNameTextBox.Enabled = true; IsLockedOut.Enabled = false; } }