using System; using System.Collections.Generic; using System.Data; using CMS.PortalControls; using CMS.GlobalHelper; using CMS.SettingsProvider; public partial class CMSWebParts_Localization_languageselectionwithflags : CMSAbstractLanguageWebPart { #region "Variables" private string mLayoutSeparator = " "; private string imgFlagIcon = String.Empty; public string selectionClass = String.Empty; #endregion #region "Public properties" /// /// Gets or sets the display layout. /// public string DisplayLayout { get { return ValidationHelper.GetString(GetValue("DisplayLayout"), ""); } set { SetValue("DisplayLayout", value); mLayoutSeparator = value.ToLowerCSafe() == "vertical" ? "" : " "; } } /// /// Gets or sets the value than indicates whether culture names are displayed. /// public bool ShowCultureNames { get { return ValidationHelper.GetBoolean(GetValue("ShowCultureNames"), true); } set { SetValue("ShowCultureNames", value); } } /// /// Gets or sets the separator between items. /// public string Separator { get { return ValidationHelper.GetString(GetValue("Separator"), ""); } set { SetValue("Separator", value); } } #endregion #region "Methods" /// /// OnPreRender event handler. /// /// Event argument protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); SetupControl(); } /// /// Reloads data for partial caching. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do nothing } else { List cultures = GetCultures(); if ((cultures != null) && ((cultures.Count > 1) || (HideCurrentCulture && (cultures.Count > 0)))) { // Render the cultures ltlHyperlinks.Text = String.Empty; mLayoutSeparator = DisplayLayout.ToLowerCSafe() == "vertical" ? "" : " "; bool addSeparator = false; // Loop thru all cultures foreach (string[] data in cultures) { string url = data[0]; string code = data[1]; string name = data[2]; // Get flag icon URL imgFlagIcon = UIHelper.GetFlagIconUrl(Page, code, "16x16"); if (addSeparator) { ltlHyperlinks.Text += Separator + mLayoutSeparator; } if (ShowCultureNames) { // Add flag icon before the link text ltlHyperlinks.Text += ""; ltlHyperlinks.Text += ""; ltlHyperlinks.Text += HTMLHelper.HTMLEncode(name); // Set surrounding div css class selectionClass = "languageSelectionWithCultures"; } else { ltlHyperlinks.Text += "" + ""; // Set surrounding div css class selectionClass = "languageSelection"; } ltlHyperlinks.Text += ""; addSeparator = true; } } // Hide webpart if there isn't more than one culture else { Visible = false; } if (string.IsNullOrEmpty(selectionClass)) { ltrDivOpen.Text = ""; } else { ltrDivOpen.Text = ""; } ltrDivClose.Text = ""; // Check if RTL hack must be applied if (CultureHelper.IsPreferredCultureRTL()) { ltrDivOpen.Text += "a"; } } } #endregion }