/// <summary> /// Gets formatted string with name and value of given keys for a specified site. /// If site name is not specified, global settings are retrieved. /// </summary> /// <param name="keys">Keys</param> /// <param name="siteName">Site name</param> private string FormatKeys(IEnumerable <SettingsKeyInfo> keys, string siteName) { var sb = new StringBuilder(""); foreach (var key in keys) { // Append key display name var displayName = ResHelper.LocalizeString(key.KeyDisplayName); sb.Append(displayName + (displayName.EndsWithCSafe(":") ? " " : ": ")); // Append value var value = SettingsKeyInfoProvider.GetValue(key.KeyName, siteName); sb.Append(value); // Append extra information if required var isValueInherited = SettingsKeyInfoProvider.IsValueInherited(key.KeyName, siteName); if (isValueInherited) { sb.Append(" (inherited)"); } if (key.KeyIsCustom) { sb.Append(" (custom)"); } sb.AppendLine(); sb.AppendLine(); } return(sb.ToString()); }
/// <summary> /// Attempts to upgrade settings from the old way to he new-one. /// </summary> /// <param name="site">site we are importing for</param> /// <returns>true on success, false on failure</returns> private static void ImportTwitterSettings(SiteInfo site) { TwitterApplicationInfo twittAppInfo = new TwitterApplicationInfo() { TwitterApplicationDisplayName = site.DisplayName + "Twitter App", TwitterApplicationName = site.SiteName + "TwitterApp", TwitterApplicationConsumerKey = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterConsumerKey"), TwitterApplicationConsumerSecret = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterConsumerSecret"), TwitterApplicationSiteID = site.SiteID }; if (String.IsNullOrWhiteSpace(twittAppInfo.TwitterApplicationConsumerKey) || String.IsNullOrWhiteSpace(twittAppInfo.TwitterApplicationConsumerSecret)) { return; } try { TwitterApplicationInfoProvider.SetTwitterApplicationInfo(twittAppInfo); twittAppInfo = TwitterApplicationInfoProvider.GetTwitterApplicationInfo(site.SiteName + "TwitterApp", site.SiteName); } catch (Exception ex) { EventLogProvider.LogException("Upgrade to 8.0", "Upgrade of SocialMarketing", ex, additionalMessage: "Error during Twitter application storage to DB for site " + site.SiteName, siteId: site.SiteID); return; } TwitterAccountInfo twittAccountInfo = new TwitterAccountInfo() { TwitterAccountName = site.SiteName + "TwitterChannel", TwitterAccountDisplayName = site.DisplayName + " Twitter Channel", TwitterAccountTwitterApplicationID = twittAppInfo.TwitterApplicationID, TwitterAccountSiteID = site.SiteID, TwitterAccountAccessToken = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterAccessToken"), TwitterAccountAccessTokenSecret = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterAccessTokenSecret"), TwitterAccountIsDefault = true, }; twittAccountInfo.TwitterAccountUserID = GetTwitterUserId(twittAppInfo, twittAccountInfo); if (String.IsNullOrWhiteSpace(twittAccountInfo.TwitterAccountAccessToken) || String.IsNullOrWhiteSpace(twittAccountInfo.TwitterAccountAccessTokenSecret)) { return; } try { TwitterAccountInfoProvider.SetTwitterAccountInfo(twittAccountInfo); } catch (Exception ex) { EventLogProvider.LogException("Upgrade to 8.0", "Upgrade of SocialMarketing", ex, additionalMessage: "Error during Twitter channel storage to DB for site " + site.SiteName, siteId: site.SiteID); return; } // URL shortener if (!SettingsKeyInfoProvider.IsValueInherited(site.SiteName + ".CMSTwitterURLShortenerType")) { string shortener = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterURLShortenerType"); SettingsKeyInfoProvider.SetValue(site.SiteName + ".CMSSocialMarketingURLShorteningTwitter", shortener); } return; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (SettingsCategoryInfo == null) { plcContent.Append(GetString("settings.keys.nocategoryselected")); StopProcessing = true; return; } ScriptHelper.RegisterTooltip(Page); ScriptHelper.RegisterBootstrapTooltip(Page, ".info-icon > i"); // Loop through all the groups in the category int groupCount = 0; bool hasOnlyGlobalKeys = true; var groups = GetGroups(SettingsCategoryInfo); foreach (var group in groups) { // Get keys var keys = GetKeys(group.CategoryID).ToArray(); // Skip empty group if (!keys.Any()) { continue; } groupCount++; // Add category panel for the group var pnlGroup = GetCategoryPanel(group, groupCount); plcContent.Append(pnlGroup); // Loop through all the keys in the group int keyCount = 0; foreach (var keyInfo in keys) { // Increase key number for unique control identification keyCount++; // Update flag when non-global-only key exists if (!keyInfo.KeyIsGlobal) { hasOnlyGlobalKeys = false; } // Create key item var keyItem = new SettingsKeyItem { ParentCategoryPanel = pnlGroup, KeyName = keyInfo.KeyName, KeyType = keyInfo.KeyType, ValidationRegexPattern = keyInfo.KeyValidation, CategoryName = group.CategoryName, ExplanationText = ResHelper.LocalizeString(keyInfo.KeyExplanationText) }; Panel pnlRow = new Panel { CssClass = "form-group" }; pnlGroup.Controls.Add(pnlRow); // Add label cell to the beginning of the row var pnlLabelCell = new Panel { CssClass = "editing-form-label-cell" }; pnlRow.Controls.AddAt(0, pnlLabelCell); // Continue with the value cell pnlRow.Controls.Add(new LiteralControl(@"<div class=""editing-form-value-cell"">")); // Create placeholder for the editing control that may end up in an update panel var pnlValueCell = new Panel { CssClass = "settings-group-inline keep-white-space-fixed" }; var pnlValue = new Panel { CssClass = "editing-form-control-nested-control keep-white-space-fixed" }; pnlValueCell.Controls.Add(pnlValue); var pnlIcons = new Panel { CssClass = "settings-info-group keep-white-space-fixed" }; pnlValueCell.Controls.Add(pnlIcons); // Don't show help icon when not provided. (Help icon will be shown if macro resolution results in an empty string.) if (!String.IsNullOrWhiteSpace(keyInfo.KeyDescription)) { Label helpIcon = GetIcon("icon-question-circle", ResHelper.LocalizeString(keyInfo.KeyDescription)); pnlIcons.Controls.Add(helpIcon); } CMSCheckBox chkInherit = null; if (mSiteId > 0) { // Wrap in update panel for inherit checkbox postback var pnlValueUpdate = new UpdatePanel { ID = string.Format("pnlValueUpdate{0}{1}", groupCount, keyCount), UpdateMode = UpdatePanelUpdateMode.Conditional, }; pnlRow.Controls.Add(pnlValueUpdate); // Add inherit checkbox chkInherit = GetInheritCheckBox(groupCount, keyCount); keyItem.InheritCheckBox = chkInherit; pnlValueUpdate.ContentTemplateContainer.Controls.Add(chkInherit); pnlValueUpdate.ContentTemplateContainer.Controls.Add(pnlValueCell); } else { pnlRow.Controls.Add(pnlValueCell); // Add "current site does not inherit the global value" warning for global settings if (SiteContext.CurrentSite != null) { var isCurrentSiteValueInherited = SettingsKeyInfoProvider.IsValueInherited(keyInfo.KeyName, SiteContext.CurrentSiteID); if (!isCurrentSiteValueInherited) { string inheritWarningText = String.Format(GetString("settings.currentsitedoesnotinherit"), ResHelper.LocalizeString(SiteContext.CurrentSite.DisplayName)); Label inheritWarningImage = GetIcon("icon-exclamation-triangle warning-icon", HTMLHelper.HTMLEncode(inheritWarningText)); pnlIcons.Controls.Add(inheritWarningImage); } } } // Add explanation text if (!String.IsNullOrWhiteSpace(keyItem.ExplanationText)) { Panel pnlExplanationText = new Panel { CssClass = "explanation-text-settings" }; LocalizedLiteral explanationText = new LocalizedLiteral { Text = keyItem.ExplanationText }; pnlExplanationText.Controls.Add(explanationText); pnlRow.Controls.Add(pnlExplanationText); } pnlRow.Controls.Add(new LiteralControl(@"</div>")); // Get current values keyItem.KeyIsInherited = SettingsKeyInfoProvider.IsValueInherited(keyInfo.KeyName, SiteName); keyItem.KeyValue = SettingsKeyInfoProvider.GetValue(keyInfo.KeyName, SiteName); // Get value string keyValue; bool isInherited; if (RequestHelper.IsPostBack() && (chkInherit != null)) { isInherited = Request.Form[chkInherit.UniqueID] != null; keyValue = isInherited ? SettingsKeyInfoProvider.GetValue(keyInfo.KeyName) : SettingsKeyInfoProvider.GetValue(keyInfo.KeyName, SiteName); } else { isInherited = keyItem.KeyIsInherited; keyValue = keyItem.KeyValue; // Set the inherit checkbox state if (!RequestHelper.IsPostBack() && chkInherit != null) { chkInherit.Checked = isInherited; } } // Add value editing control var enabled = !isInherited; FormEngineUserControl control = GetFormEngineUserControl(keyInfo, groupCount, keyCount); if (control != null) { // Add form engine value editing control control.Value = keyValue; pnlValue.Controls.Add(control); // Set form control enabled value, does not work when moved before plcControl.Controls.Add(control) control.Enabled = enabled; keyItem.ValueControl = control; if (chkInherit != null) { chkInherit.CheckedChanged += (sender, args) => { control.Value = keyValue; }; } } else { // Add simple value editing control switch (keyInfo.KeyType.ToLowerCSafe()) { case "boolean": // Add checkbox value editing control var @checked = ValidationHelper.GetBoolean(keyValue, false); CMSCheckBox chkValue = GetValueCheckBox(groupCount, keyCount, @checked, enabled); pnlValue.Controls.Add(chkValue); keyItem.ValueControl = chkValue; if (chkInherit != null) { chkInherit.CheckedChanged += (sender, args) => { chkValue.Checked = @checked; }; } break; case "longtext": // Add text area value editing control var longText = keyValue; var txtValueTextArea = GetValueTextArea(groupCount, keyCount, longText, enabled); if (txtValueTextArea != null) { // Text area control was loaded successfully pnlValue.Controls.Add(txtValueTextArea); keyItem.ValueControl = txtValueTextArea; if (chkInherit != null) { chkInherit.CheckedChanged += (sender, args) => { txtValueTextArea.Text = longText; }; } } else { // Text area control was not loaded successfully var errorLabel = new FormControlError { ErrorTitle = "[Error loading the editing control, check the event log for more details]", }; pnlValue.Controls.Add(errorLabel); } break; default: // Add textbox value editing control var text = keyValue; TextBox txtValue = GetValueTextBox(groupCount, keyCount, text, enabled); pnlValue.Controls.Add(txtValue); keyItem.ValueControl = txtValue; if (chkInherit != null) { chkInherit.CheckedChanged += (sender, args) => { txtValue.Text = text; }; } break; } } // Add label to the label cell when associated control has been resolved pnlLabelCell.Controls.Add(GetLabel(keyInfo, keyItem.ValueControl, groupCount, keyCount)); // Add error label if KeyType is integer or validation expression defined or FormControl is used if ((keyInfo.KeyType == "int") || (keyInfo.KeyType == "double") || (keyItem.ValidationRegexPattern != null) || (control != null)) { Label lblError = GetLabelError(groupCount, keyCount); pnlIcons.Controls.Add(lblError); keyItem.ErrorLabel = lblError; } mKeyItems.Add(keyItem); } } // Show info message when other than global-only global keys are displayed if ((mSiteId <= 0) && (CategoryID > 0) && !hasOnlyGlobalKeys && AllowGlobalInfoMessage) { ShowInformation(GetString("settings.keys.globalsettingsnote")); } // Display export and reset links only if some groups were found. if (groupCount > 0) { // Add reset link if required if (!RequestHelper.IsPostBack() && QueryHelper.GetInteger("resettodefault", 0) == 1) { ShowInformation(GetString("Settings-Keys.ValuesWereResetToDefault")); } } else { // Hide "These settings are global ..." message if no setting found in this group if (!string.IsNullOrEmpty(mSearchText)) { var ltrScript = new Literal { Text = ScriptHelper.GetScript("DisableHeaderActions();") }; plcContent.Append(ltrScript); lblNoData.Visible = true; } } }
/// <summary> /// Attempts to upgrade settings from the old way to he new-one. /// </summary> /// <param name="site">site we are importing for</param> /// <returns>true on success, false on failure</returns> private static void ImportFacebookSettings(SiteInfo site) { FacebookApplicationInfo fbAppInfo = new FacebookApplicationInfo() { FacebookApplicationDisplayName = site.DisplayName + " Facebook App", FacebookApplicationName = site.SiteName + "FacebookApp", FacebookApplicationSiteID = site.SiteID, FacebookApplicationConsumerKey = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSFacebookConnectApiKey"), FacebookApplicationConsumerSecret = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSFacebookApplicationSecret") }; if (String.IsNullOrWhiteSpace(fbAppInfo.FacebookApplicationConsumerKey) || String.IsNullOrWhiteSpace(fbAppInfo.FacebookApplicationConsumerSecret)) { return; } try { FacebookApplicationInfoProvider.SetFacebookApplicationInfo(fbAppInfo); fbAppInfo = FacebookApplicationInfoProvider.GetFacebookApplicationInfo(site.SiteName + "FacebookApp", site.SiteName); } catch (Exception ex) { // LogException EventLogProvider.LogException("Upgrade to 8.0", "Upgrade of SocialMarketing", ex, additionalMessage: "Error during Facebook Application storage to DB for site " + site.SiteName, siteId: site.SiteID); return; } // FB Page Part FacebookAccountInfo fbPageInfo = new FacebookAccountInfo() { FacebookAccountFacebookApplicationID = fbAppInfo.FacebookApplicationID, FacebookAccountSiteID = site.SiteID, FacebookAccountDisplayName = site.DisplayName + " Facebook Page", FacebookAccountName = site.SiteName + "FacebookPage", FacebookAccountIsDefault = true, }; FacebookPageAccessTokenData?accToken = GetToken(SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSFacebookAccessToken")); if (accToken.HasValue) { fbPageInfo.FacebookPageAccessToken = accToken.Value; } else { // Log error importing settings for site EventLogProvider.LogEvent(EventType.ERROR, "Upgrade to 8.0", "Upgrade of SocialMarketing", eventDescription: "Error during parsing of PageAccessToken for site " + site.SiteName, siteId: site.SiteID); return; } FacebookPageIdentityData?PIData = GetPageIdentity(site); if (PIData.HasValue) { fbPageInfo.FacebookPageIdentity = PIData.Value; } else { // Log error importing settings for site EventLogProvider.LogEvent(EventType.ERROR, "Upgrade to 8.0", "Upgrade of SocialMarketing", eventDescription: "Error during Getting of PageIdentity for site " + site.SiteName, siteId: site.SiteID); return; } if (String.IsNullOrWhiteSpace(fbPageInfo.FacebookPageAccessToken.AccessToken) || String.IsNullOrWhiteSpace(fbPageInfo.FacebookPageIdentity.PageId) || String.IsNullOrWhiteSpace(fbPageInfo.FacebookPageIdentity.PageUrl)) { return; } try { FacebookAccountInfoProvider.SetFacebookAccountInfo(fbPageInfo); } catch (Exception ex) { // Log Exception EventLogProvider.LogException("Upgrade to 8.0", "Upgrade of SocialMarketing", ex, additionalMessage: "Error during Facebook Page storage to DB for site " + site.SiteName, siteId: site.SiteID); return; } // URL shortener if (!SettingsKeyInfoProvider.IsValueInherited(site.SiteName + ".CMSFacebookURLShortenerType")) { string shortener = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSFacebookURLShortenerType"); SettingsKeyInfoProvider.SetValue(site.SiteName + ".CMSSocialMarketingURLShorteningFacebook", shortener); } return; }