示例#1
0
        /// <summary>
        /// Sets the theme class up for usage
        /// </summary>
        /// <exception cref="CantLoadThemeException"><c>CantLoadThemeException</c>.</exception>
        private void InitTheme()
        {
            if (this._initTheme)
            {
                return;
            }

            if (this.BeforeInit != null)
            {
                this.BeforeInit(this, new EventArgs());
            }

            string themeFile;

            if (YafContext.Current.Page != null && YafContext.Current.Page["ThemeFile"] != null &&
                YafContext.Current.BoardSettings.AllowUserTheme)
            {
                // use user-selected theme
                themeFile = YafContext.Current.Page["ThemeFile"].ToString();
            }
            else if (YafContext.Current.Page != null && YafContext.Current.Page["ForumTheme"] != null)
            {
                themeFile = YafContext.Current.Page["ForumTheme"].ToString();
            }
            else
            {
                themeFile = YafContext.Current.BoardSettings.Theme;
            }

            if (!YafTheme.IsValidTheme(themeFile))
            {
                themeFile = StaticDataHelper.Themes().Rows[0][1].ToString();
            }

            // create the theme class
            this.Theme = new YafTheme(themeFile);

            // make sure it's valid again...
            if (!YafTheme.IsValidTheme(this.Theme.ThemeFile))
            {
                // can't load a theme... throw an exception.
                throw new CantLoadThemeException(
                          @"Unable to find a theme to load. Last attempted to load ""{0}"" but failed.".FormatWith(themeFile));
            }

            if (this.AfterInit != null)
            {
                this.AfterInit(this, new EventArgs());
            }
        }
示例#2
0
        /// <summary>
        /// Gets the user theme file.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns>Returns User theme</returns>
        public static string GetUserThemeFile(int userId)
        {
            DataRow row = UserMembershipHelper.GetUserRowForID(userId);

            string themeFile = row["ThemeFile"] != DBNull.Value && YafContext.Current.Get <YafBoardSettings>().AllowUserTheme
                                   ? row["ThemeFile"].ToString()
                                   : YafContext.Current.Get <YafBoardSettings>().Theme;

            if (!YafTheme.IsValidTheme(themeFile))
            {
                themeFile = StaticDataHelper.Themes().Rows[0][1].ToString();
            }

            return(themeFile);
        }
示例#3
0
        /// <summary>
        /// Gets the user theme file.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="boardID">The board identifier.</param>
        /// <param name="allowUserTheme">if set to <c>true</c> [allow user theme].</param>
        /// <param name="theme">The theme.</param>
        /// <returns>
        /// Returns User theme
        /// </returns>
        public static string GetUserThemeFile(int userId, int boardID, bool allowUserTheme, string theme)
        {
            DataRow row = UserMembershipHelper.GetUserRowForID(userId, boardID);

            var themeFile = (row != null && row["ThemeFile"] != DBNull.Value && allowUserTheme)
                                   ? row["ThemeFile"].ToString()
                                   : theme;

            if (!YafTheme.IsValidTheme(themeFile))
            {
                themeFile = StaticDataHelper.Themes().Rows[0][1].ToString();
            }

            return(themeFile);
        }
示例#4
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;
            }
        }