コード例 #1
0
        /// <summary>
        /// Handles the specified @event.
        /// </summary>
        /// <param name="event">The @event.</param>
        public void Handle([NotNull] InitPageLoadEvent @event)
        {
            string browser = "{0} {1}".FormatWith(
                this.HttpRequestBase.Browser.Browser, this.HttpRequestBase.Browser.Version);
            string platform = this.HttpRequestBase.Browser.Platform;

            bool isSearchEngine;
            bool dontTrack;

            string userAgent = this.HttpRequestBase.UserAgent;

            bool isMobileDevice = UserAgentHelper.IsMobileDevice(userAgent) ||
                                  this.HttpRequestBase.Browser.IsMobileDevice;

            // try and get more verbose platform name by ref and other parameters
            UserAgentHelper.Platform(
                userAgent,
                this.HttpRequestBase.Browser.Crawler,
                ref platform,
                ref browser,
                out isSearchEngine,
                out dontTrack);

            dontTrack = !this.Get <YafBoardSettings>().ShowCrawlersInActiveList&& isSearchEngine;

            // don't track if this is a feed reader. May be to make it switchable in host settings.
            // we don't have page 'g' token for the feed page.
            if (browser.Contains("Unknown") && !dontTrack)
            {
                dontTrack = UserAgentHelper.IsFeedReader(userAgent);
            }

            @event.Data.DontTrack      = dontTrack;
            @event.Data.UserAgent      = userAgent;
            @event.Data.IsSearchEngine = isSearchEngine;
            @event.Data.IsMobileDevice = isMobileDevice;
            @event.Data.Browser        = browser;
            @event.Data.Platform       = platform;

            YafContext.Current.Vars["DontTrack"] = dontTrack;
        }
コード例 #2
0
        /// <summary>
        /// The current_ after init.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Current_AfterInit([NotNull] object sender, [NotNull] EventArgs e)
        {
            YafContext.Current.Vars["IsMobile"] = false;

            // see if this is a mobile device...
            if (!UserAgentHelper.IsMobileDevice(this.HttpRequestBase.UserAgent) &&
                !this.HttpRequestBase.Browser.IsMobileDevice)
            {
                // make sure to shut off mobile theme usage if the user agent is not mobile.
                if (this.YafSession.UseMobileTheme ?? false)
                {
                    this.YafSession.UseMobileTheme = false;
                }

                return;
            }

            if (!YafContext.Current.IsGuest)
            {
                // return if the user has mobile themes shut off in their profile.
                var userData = new CombinedUserDataHelper(YafContext.Current.PageUserID);
                if (!userData.UseMobileTheme)
                {
                    return;
                }
            }

            this.UpdateUseMobileThemeFromQueryString();

            // use the mobile theme?
            var useMobileTheme = this.YafSession.UseMobileTheme ?? true;

            // get the current mobile theme...
            var mobileTheme = YafContext.Current.BoardSettings.MobileTheme;

            if (mobileTheme.IsSet())
            {
                // create a new theme object...
                var theme = new YafTheme(mobileTheme);

                // make sure it's valid...
                if (YafTheme.IsValidTheme(theme.ThemeFile))
                {
                    YafContext.Current.Vars["IsMobile"] = true;

                    // set new mobile theme...
                    if (useMobileTheme)
                    {
                        YafContext.Current.Get <ThemeProvider>().Theme = theme;
                        this.YafSession.UseMobileTheme = true;
                    }

                    return;
                }
            }

            // make sure to shut off mobile theme usage if there was no valid mobile theme found...
            if (this.YafSession.UseMobileTheme ?? false)
            {
                this.YafSession.UseMobileTheme = false;
            }
        }
コード例 #3
0
        /// <summary>
        /// The bind data.
        /// </summary>
        private void BindData()
        {
            this.TimeZones.DataSource = StaticDataHelper.TimeZones();
            if (this.Get <YafBoardSettings>().AllowUserTheme)
            {
                this.Theme.DataSource     = StaticDataHelper.Themes();
                this.Theme.DataTextField  = "Theme";
                this.Theme.DataValueField = "FileName";
            }

            if (this.Get <YafBoardSettings>().AllowUserLanguage)
            {
                this.Culture.DataSource     = StaticDataHelper.Cultures();
                this.Culture.DataValueField = "CultureTag";
                this.Culture.DataTextField  = "CultureNativeName";
            }

            this.Country.DataSource     = StaticDataHelper.Country();
            this.Country.DataValueField = "Value";
            this.Country.DataTextField  = "Name";

            if (this.UserData.Profile.Country.IsSet())
            {
                this.LookForNewRegionsBind(this.UserData.Profile.Country);
            }

            if (this.Get <YafBoardSettings>().AllowUsersTextEditor)
            {
                this.ForumEditor.DataSource     = this.Get <IModuleManager <ForumEditor> >().ActiveAsDataTable("Editors");
                this.ForumEditor.DataValueField = "Value";
                this.ForumEditor.DataTextField  = "Name";
            }

            this.DataBind();

            if (this.Get <YafBoardSettings>().UseFarsiCalender&& this.CurrentCultureInfo.IsFarsiCulture())
            {
                this.Birthday.Text = this.UserData.Profile.Birthday > DateTimeHelper.SqlDbMinTime() ||
                                     this.UserData.Profile.Birthday.IsNullOrEmptyDBField()
                                         ? PersianDateConverter.ToPersianDate(this.UserData.Profile.Birthday)
                                     .ToString("d")
                                         : PersianDateConverter.ToPersianDate(PersianDate.MinValue).ToString("d");
            }
            else
            {
                this.Birthday.Text = this.UserData.Profile.Birthday > DateTimeHelper.SqlDbMinTime() ||
                                     this.UserData.Profile.Birthday.IsNullOrEmptyDBField()
                                         ? this.UserData.Profile.Birthday.Date.ToString(
                    this.CurrentCultureInfo.DateTimeFormat.ShortDatePattern,
                    CultureInfo.InvariantCulture)
                                         : DateTimeHelper.SqlDbMinTime()
                                     .Date.ToString(
                    this.CurrentCultureInfo.DateTimeFormat.ShortDatePattern,
                    CultureInfo.InvariantCulture);
            }

            this.Birthday.ToolTip = this.GetText("COMMON", "CAL_JQ_TT");

            this.DisplayName.Text    = this.UserData.DisplayName;
            this.City.Text           = this.UserData.Profile.City;
            this.Location.Text       = this.UserData.Profile.Location;
            this.HomePage.Text       = this.UserData.Profile.Homepage;
            this.Email.Text          = this.UserData.Email;
            this.Realname.Text       = this.UserData.Profile.RealName;
            this.Occupation.Text     = this.UserData.Profile.Occupation;
            this.Interests.Text      = this.UserData.Profile.Interests;
            this.Weblog.Text         = this.UserData.Profile.Blog;
            this.WeblogUrl.Text      = this.UserData.Profile.BlogServiceUrl;
            this.WeblogID.Text       = this.UserData.Profile.BlogServicePassword;
            this.WeblogUsername.Text = this.UserData.Profile.BlogServiceUsername;
            this.MSN.Text            = this.UserData.Profile.MSN;
            this.YIM.Text            = this.UserData.Profile.YIM;
            this.AIM.Text            = this.UserData.Profile.AIM;
            this.ICQ.Text            = this.UserData.Profile.ICQ;

            this.Facebook.Text = ValidationHelper.IsNumeric(this.UserData.Profile.Facebook)
                                     ? "https://www.facebook.com/profile.php?id={0}".FormatWith(
                this.UserData.Profile.Facebook)
                                     : this.UserData.Profile.Facebook;

            this.Twitter.Text         = this.UserData.Profile.Twitter;
            this.Google.Text          = this.UserData.Profile.Google;
            this.Xmpp.Text            = this.UserData.Profile.XMPP;
            this.Skype.Text           = this.UserData.Profile.Skype;
            this.Gender.SelectedIndex = this.UserData.Profile.Gender;

            if (this.UserData.Profile.Country.IsSet())
            {
                ListItem countryItem = this.Country.Items.FindByValue(this.UserData.Profile.Country.Trim());
                if (countryItem != null)
                {
                    countryItem.Selected = true;
                }
            }

            if (this.UserData.Profile.Region.IsSet())
            {
                ListItem regionItem = this.Region.Items.FindByValue(this.UserData.Profile.Region.Trim());
                if (regionItem != null)
                {
                    regionItem.Selected = true;
                }
            }

            ListItem timeZoneItem = this.TimeZones.Items.FindByValue(this.UserData.TimeZone.ToString());

            if (timeZoneItem != null)
            {
                timeZoneItem.Selected = true;
            }

            this.DSTUser.Checked = this.UserData.DSTUser;
            this.HideMe.Checked  = this.UserData.IsActiveExcluded &&
                                   (this.Get <YafBoardSettings>().AllowUserHideHimself || this.PageContext.IsAdmin);

            if (this.Get <YafBoardSettings>().MobileTheme.IsSet() &&
                UserAgentHelper.IsMobileDevice(HttpContext.Current.Request.UserAgent) ||
                HttpContext.Current.Request.Browser.IsMobileDevice)
            {
                this.UseMobileThemeRow.Visible = true;
                this.UseMobileTheme.Checked    = this.UserData.UseMobileTheme;
            }

            if (this.Get <YafBoardSettings>().AllowUserTheme&& this.Theme.Items.Count > 0)
            {
                // Allows to use different per-forum themes,
                // While "Allow User Change Theme" option in hostsettings is true
                string themeFile = this.Get <YafBoardSettings>().Theme;

                if (this.UserData.ThemeFile.IsSet())
                {
                    themeFile = this.UserData.ThemeFile;
                }

                ListItem themeItem = this.Theme.Items.FindByValue(themeFile);
                if (themeItem != null)
                {
                    themeItem.Selected = true;
                }
            }

            if (this.Get <YafBoardSettings>().AllowUsersTextEditor&& this.ForumEditor.Items.Count > 0)
            {
                // Text editor
                string textEditor = this.UserData.TextEditor.IsSet()
                                        ? this.UserData.TextEditor
                                        : this.Get <YafBoardSettings>().ForumEditor;

                ListItem editorItem = this.ForumEditor.Items.FindByValue(textEditor);
                if (editorItem != null)
                {
                    editorItem.Selected = true;
                }
            }

            if (!this.Get <YafBoardSettings>().AllowUserLanguage || this.Culture.Items.Count <= 0)
            {
                return;
            }

            // If 2-letter language code is the same we return Culture, else we return a default full culture from language file
            ListItem foundCultItem = this.Culture.Items.FindByValue(this.GetCulture(true));

            if (foundCultItem != null)
            {
                foundCultItem.Selected = true;
            }

            if (!Page.IsPostBack)
            {
                this.Realname.Focus();
            }
        }
コード例 #4
0
        /// <summary>
        /// The bind data.
        /// </summary>
        private void BindData()
        {
            this.TimeZones.DataSource = StaticDataHelper.TimeZones();
            if (this.PageContext.BoardSettings.AllowUserTheme)
            {
                this.Theme.DataSource     = StaticDataHelper.Themes();
                this.Theme.DataTextField  = "Theme";
                this.Theme.DataValueField = "FileName";
            }

            if (this.PageContext.BoardSettings.AllowUserLanguage)
            {
                this.Culture.DataSource     = StaticDataHelper.Cultures();
                this.Culture.DataValueField = "CultureTag";
                this.Culture.DataTextField  = "CultureNativeName";
            }

            this.DataBind();

            if (this.PageContext.BoardSettings.EnableDNACalendar)
            {
                this.datePicker.LocID = this.PageContext.Localization.GetText("COMMON", "CAL_JQ_CULTURE");
                this.datePicker.AnotherFormatString = this.PageContext.Localization.GetText("COMMON", "CAL_JQ_CULTURE_DFORMAT");
                this.datePicker.DateFormatString    = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;

                this.datePicker.Value = this.UserData.Profile.Birthday > DateTime.MinValue ? this.UserData.Profile.Birthday.Date : DateTime.MinValue.Date;

                this.datePicker.ToolTip           = this.PageContext.Localization.GetText("COMMON", "CAL_JQ_TT");
                this.datePicker.DefaultDateString = string.Empty;
            }
            else
            {
                this.datePicker.Enabled    = false;
                this.datePicker.Visible    = false;
                this.BirthdayLabel.Visible = false;
            }

            this.DisplayName.Text     = this.UserData.DisplayName;
            this.Location.Text        = this.UserData.Profile.Location;
            this.HomePage.Text        = this.UserData.Profile.Homepage;
            this.Email.Text           = this.UserData.Email;
            this.Realname.Text        = this.UserData.Profile.RealName;
            this.Occupation.Text      = this.UserData.Profile.Occupation;
            this.Interests.Text       = this.UserData.Profile.Interests;
            this.Weblog.Text          = this.UserData.Profile.Blog;
            this.WeblogUrl.Text       = this.UserData.Profile.BlogServiceUrl;
            this.WeblogID.Text        = this.UserData.Profile.BlogServicePassword;
            this.WeblogUsername.Text  = this.UserData.Profile.BlogServiceUsername;
            this.MSN.Text             = this.UserData.Profile.MSN;
            this.YIM.Text             = this.UserData.Profile.YIM;
            this.AIM.Text             = this.UserData.Profile.AIM;
            this.ICQ.Text             = this.UserData.Profile.ICQ;
            this.Xmpp.Text            = this.UserData.Profile.XMPP;
            this.Skype.Text           = this.UserData.Profile.Skype;
            this.Gender.SelectedIndex = this.UserData.Profile.Gender;

            ListItem timeZoneItem = this.TimeZones.Items.FindByValue(this.UserData.TimeZone.ToString());

            if (timeZoneItem != null)
            {
                timeZoneItem.Selected = true;
            }

            this.DSTUser.Checked = this.UserData.DSTUser;
            this.HideMe.Checked  = this.UserData.IsActiveExcluded && (this.PageContext.BoardSettings.AllowUserHideHimself || this.PageContext.IsAdmin);

            if (YafContext.Current.BoardSettings.MobileTheme.IsSet() && UserAgentHelper.IsMobileDevice(HttpContext.Current.Request.UserAgent) ||
                HttpContext.Current.Request.Browser.IsMobileDevice)
            {
                this.UseMobileThemeRow.Visible = true;


                this.UseMobileTheme.Checked = this.UserData.UseMobileTheme;
            }

            if (this.PageContext.BoardSettings.AllowUserTheme && this.Theme.Items.Count > 0)
            {
                // Allows to use different per-forum themes,
                // While "Allow User Change Theme" option in hostsettings is true
                string themeFile = this.PageContext.BoardSettings.Theme;

                if (!string.IsNullOrEmpty(this.UserData.ThemeFile))
                {
                    themeFile = this.UserData.ThemeFile;
                }

                ListItem themeItem = this.Theme.Items.FindByValue(themeFile);
                if (themeItem != null)
                {
                    themeItem.Selected = true;
                }
            }

            if (!this.PageContext.BoardSettings.AllowUserLanguage || this.Culture.Items.Count <= 0)
            {
                return;
            }

            string languageFile = this.PageContext.BoardSettings.Language;
            string culture4tag  = this.PageContext.BoardSettings.Culture;

            if (!string.IsNullOrEmpty(this.UserData.LanguageFile))
            {
                languageFile = this.UserData.LanguageFile;
            }

            if (!string.IsNullOrEmpty(this.UserData.CultureUser))
            {
                culture4tag = this.UserData.CultureUser;
            }

            // Get first default full culture from a language file tag.
            string langFileCulture = StaticDataHelper.CultureDefaultFromFile(languageFile);

            // If 2-letter language code is the same we return Culture, else we return a default full culture from language file
            ListItem foundCultItem = this.Culture.Items.FindByValue((langFileCulture.Substring(0, 2) == culture4tag.Substring(0, 2) ? culture4tag : langFileCulture));

            if (foundCultItem != null)
            {
                foundCultItem.Selected = true;
            }
        }