Beispiel #1
0
        /// <summary>
        /// The page_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Get <YafInitializeDb>().Run();

            var token = this.Request.QueryString.GetFirstOrDefault("token");

            if (token.IsNotSet() || !token.Equals(YafContext.Current.BoardSettings.WebServiceToken))
            {
                this.Response.End();
                return;
            }

            if (Config.BaseUrlMask.IsNotSet())
            {
                // fail... BaseUrlMask required for Digest.
                this.Response.End();
                return;
            }

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

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

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

            if (!this.NewTopics.Any() && !this.ActiveTopics.Any())
            {
                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;
            }
        }
        /// <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());
            }
        }
Beispiel #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)
        {
            var row = UserMembershipHelper.GetUserRowForID(userId, boardID);

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

            if (!YafTheme.IsValidTheme(themeFile))
            {
                themeFile = "yaf";
            }

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

            var themeFile = row != null && 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);
        }
Beispiel #6
0
        /// <summary>
        /// Sets the theme class up for usage
        /// </summary>
        /// <exception cref="CantLoadThemeException"><c>CantLoadThemeException</c>.</exception>
        private void InitTheme()
        {
            if (this.initTheme)
            {
                return;
            }

            this.BeforeInit?.Invoke(this, new EventArgs());

            string theme;

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

            if (!YafTheme.IsValidTheme(theme))
            {
                theme = "yaf";
            }

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

            this.AfterInit?.Invoke(this, new EventArgs());
        }
Beispiel #7
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;
            }
        }
    /// <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;
      }
    }
Beispiel #9
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.BoardID == 0)
            {
                this.BoardID = this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("BoardID").ToType <int>();
            }

            if (HttpContext.Current != null)
            {
                if (YafContext.Current.BoardSettings.BoardID.Equals(this.BoardID))
                {
                    this.BoardSettings = YafContext.Current.BoardSettings;
                }
            }
            else
            {
                this.BoardSettings = new YafLoadBoardSettings(this.BoardID);
            }

            this.Get <StartupInitializeDb>().Run();

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

            if (token.IsNotSet() || !token.Equals(this.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.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>();
            }

            // get topic hours...
            this._topicHours = -this.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(this.BoardSettings.DigestSendEveryXHours));

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

                this.Response.End();
                return;
            }

            this._languageFile = UserHelper.GetUserLanguageFile(
                this.CurrentUserID,
                this.BoardID,
                this.BoardSettings.AllowUserLanguage);

            this._theme =
                new YafTheme(
                    UserHelper.GetUserThemeFile(
                        this.CurrentUserID,
                        this.BoardID,
                        this.BoardSettings.AllowUserTheme,
                        this.BoardSettings.Theme));

            var subject = this.GetText("SUBJECT").FormatWith(this.BoardSettings.Name);

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

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

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