Esempio n. 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());
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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;
      }
    }
Esempio n. 5
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;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// The page_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            this.Get<StartupInitializeDb>().Run();

            var token = this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("token");

            if (token.IsNotSet() || !token.Equals(YafContext.Current.BoardSettings.WebServiceToken))
            {
                if (this.ShowErrors)
                {
                    this.OutputError(
                      "Invalid Web Service Token. Please go into your host settings and save them committing a unique web service token to the database.");
                }

                this.Response.End();
                return;
            }

            if (Config.BaseUrlMask.IsNotSet())
            {
                // fail... BaseUrlMask required for Digest.
                if (this.ShowErrors)
                {
                    this.OutputError(
                      "Cannot generate digest unless YAF.BaseUrlMask AppSetting is specified in your app.config (default). Please specify the full forward-facing url to this forum in the YAF.BaseUrlMask key.");
                }

                this.Response.End();
                return;
            }

            if (Config.ForceScriptName.IsNotSet())
            {
                // fail... ForceScriptName required for Digest.
                if (this.ShowErrors)
                {
                    this.OutputError(
                      @"Cannot generate digest unless YAF.ForceScriptName AppSetting is specified in your app.config (default). Please specify the full page name for YAF.NET -- usually ""default.aspx"".");
                }

                this.Response.End();
                return;
            }

            if (this.CurrentUserID == 0)
            {
                this.CurrentUserID = this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("UserID").ToType<int>();
            }

            if (this.BoardID == 0)
            {
                this.BoardID = this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("BoardID").ToType<int>();
            }

            // get topic hours...
            this._topicHours = -YafContext.Current.BoardSettings.DigestSendEveryXHours;

            this._forumData = this.Get<YafDbBroker>().GetSimpleForumTopic(
              this.BoardID, this.CurrentUserID, DateTime.Now.AddHours(this._topicHours), 9999);

            if (!this.NewTopics.Any() && !this.ActiveTopics.Any())
            {
                if (this.ShowErrors)
                {
                    this.OutputError(
                      "No topics for the last {0} hours.".FormatWith(YafContext.Current.BoardSettings.DigestSendEveryXHours));

                    //this.Response.Write(GetDebug());
                }

                this.Response.End();
                return;
            }

            this._languageFile = UserHelper.GetUserLanguageFile(this.CurrentUserID);
            this._theme = new YafTheme(UserHelper.GetUserThemeFile(this.CurrentUserID));

            string subject = this.GetText("SUBJECT").FormatWith(YafContext.Current.BoardSettings.Name);

            string digestHead = this._theme.GetItem("THEME", "DIGESTHEAD", null);

            if (digestHead.IsSet())
            {
                this.YafHead.Controls.Add(new LiteralControl(digestHead));
            }

            if (subject.IsSet())
            {
                this.YafHead.Title = subject;
            }
        }