Exemple #1
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)
        {
            // check if this feature is disabled
            if (!this.Get <YafBoardSettings>().AllowPrivateMessages)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Disabled);
            }

            if (this.IsPostBack)
            {
                return;
            }

            if (this.Request.QueryString.GetFirstOrDefault("v").IsSet())
            {
                this.View = PmViewConverter.FromQueryString(this.Request.QueryString.GetFirstOrDefault("v"));

                this.hidLastTab.Value = $"View{(int)this.View}";
            }

            this.PageLinks.AddRoot();
            this.PageLinks.AddLink(
                this.Get <YafBoardSettings>().EnableDisplayName
                    ? this.PageContext.CurrentUserData.DisplayName
                    : this.PageContext.PageUserName,
                YafBuildLink.GetLink(ForumPages.cp_profile));
            this.PageLinks.AddLink(this.GetText("TITLE"));

            this.NewPM.NavigateUrl  = YafBuildLink.GetLinkNotEscaped(ForumPages.pmessage);
            this.NewPM2.NavigateUrl = this.NewPM.NavigateUrl;
        }
Exemple #2
0
        /// <summary>
        /// Check if the user needs to be unsuspended or redirected to the info page
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void _preLoadPage_HandleEvent(
            [NotNull] object sender,
            [NotNull] EventConverterArgs <ForumPagePreLoadEvent> e)
        {
            // check for suspension if enabled...
            if (!this.PageContext.Globals.IsSuspendCheckEnabled)
            {
                return;
            }

            if (!this.PageContext.IsSuspended)
            {
                return;
            }

            if (this.Get <IDateTime>().GetUserDateTime(this.PageContext.SuspendedUntil)
                <= this.Get <IDateTime>().GetUserDateTime(DateTime.UtcNow))
            {
                LegacyDb.user_suspend(this.PageContext.PageUserID, null);

                this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.PageContext.PageUserID));
            }
            else
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Suspended);
            }
        }
        /// <summary>
        /// The forum control_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ForumControl_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            bool accessDenied = false;

            switch (this.ForumPageType)
            {
            case ForumPages.login:
                if (!HttpContext.Current.Request.IsSecureConnection & this.PageContext.BoardSettings.UseSSLToLogIn)
                {
                    accessDenied = true;
                }

                break;

            case ForumPages.register:
                if (!HttpContext.Current.Request.IsSecureConnection & this.PageContext.BoardSettings.UseSSLToRegister)
                {
                    accessDenied = true;
                }

                break;
            }

            if (accessDenied)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }
        }
Exemple #4
0
        /// <summary>
        /// Handles the Load event of the AdminPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void AdminPageLoad([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.CreatePageLinks();
            }

            // not admins are forbidden
            if (!this.PageContext.IsAdmin)
            {
                YafBuildLink.AccessDenied();
            }

            // host admins are not checked
            if (this.PageContext.IsHostAdmin)
            {
                return;
            }

            // Load the page access list.
            var dt = this.GetRepository <AdminPageUserAccess>().List(
                this.PageContext.PageUserID, this.PageContext.ForumPageType.ToString().ToLowerInvariant());

            // Check access rights to the page.
            if (!this.PageContext.ForumPageType.ToString().IsSet() || dt == null || !dt.HasRows())
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.HostAdminPermissionsAreRequired);
            }
        }
Exemple #5
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)
        {
            // check if this feature is disabled
            if (!this.Get <YafBoardSettings>().AllowPrivateMessages)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Disabled);
            }

            if (this.IsPostBack)
            {
                return;
            }

            if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("pm").IsNotSet())
            {
                YafBuildLink.AccessDenied();
            }

            this.PageLinks.AddRoot();
            this.PageLinks.AddLink(
                this.Get <YafBoardSettings>().EnableDisplayName
                    ? this.PageContext.CurrentUserData.DisplayName
                    : this.PageContext.PageUserName,
                YafBuildLink.GetLink(ForumPages.cp_profile));

            // handle custom YafBBCode javascript or CSS...
            this.Get <IBBCode>().RegisterCustomBBCodePageElements(this.Page, this.GetType());

            this.BindData();
        }
Exemple #6
0
        /// <summary>
        /// Checks access rights for the page
        /// </summary>
        private void CheckAccess()
        {
            if (this._boardId > 0 || this._categoryId > 0)
            {
                // invalid category
                var categoryVars = this._categoryId > 0 &&
                                   (this._topicId > 0 || this._editTopicId > 0 || this._editMessageId > 0 ||
                                    this.editForumId > 0 || this._editBoardId > 0 || this._forumId > 0 ||
                                    this._boardId > 0);

                // invalid board vars
                var boardVars = this._boardId > 0 &&
                                (this._topicId > 0 || this._editTopicId > 0 || this._editMessageId > 0 ||
                                 this.editForumId > 0 || this._editBoardId > 0 || this._forumId > 0 ||
                                 this._categoryId > 0);
                if (!categoryVars || !boardVars)
                {
                    YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);
                }
            }
            else if (this._forumId > 0 && !this.PageContext.ForumPollAccess)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }
        }
        /// <summary>
        /// Check if the user needs to be unsuspended or redirected to the info page
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void _preLoadPage_HandleEvent(
            [NotNull] object sender,
            [NotNull] EventConverterArgs <ForumPagePreLoadEvent> e)
        {
            // check for suspension if enabled...
            if (!this.PageContext.Globals.IsSuspendCheckEnabled)
            {
                return;
            }

            if (!this.PageContext.IsSuspended)
            {
                return;
            }

            if (this.Get <IDateTime>().GetUserDateTime(this.PageContext.SuspendedUntil)
                <= this.Get <IDateTime>().GetUserDateTime(DateTime.UtcNow))
            {
                LegacyDb.user_suspend(this.PageContext.PageUserID);

                this.Get <ISendNotification>()
                .SendUserSuspensionEndedNotification(
                    this.PageContext.CurrentUserData.Email,
                    this.PageContext.BoardSettings.EnableDisplayName
                            ? this.PageContext.CurrentUserData.DisplayName
                            : this.PageContext.CurrentUserData.UserName);

                this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.PageContext.PageUserID));
            }
            else
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Suspended);
            }
        }
        /// <summary>
        /// The init i ds.
        /// </summary>
        /// <param name="idNames">
        /// The id names.
        /// </param>
        /// <param name="errorOnInvalid">
        /// The error on invalid.
        /// </param>
        /// <exception cref="Exception">
        /// </exception>
        private void InitIDs([NotNull] string[] idNames, [NotNull] bool[] errorOnInvalid)
        {
            CodeContracts.VerifyNotNull(idNames, "idNames");
            CodeContracts.VerifyNotNull(errorOnInvalid, "errorOnInvalid");

            if (idNames.Length != errorOnInvalid.Length)
            {
                throw new Exception("idNames and errorOnInvalid variables must be the same array length.");
            }

            for (var i = 0; i < idNames.Length; i++)
            {
                if (this.Params.ContainsKey(idNames[i]))
                {
                    continue;
                }

                if (HttpContext.Current.Request.QueryString.GetFirstOrDefault(idNames[i]).IsSet() && long.TryParse(HttpContext.Current.Request.QueryString.GetFirstOrDefault(idNames[i]), out var idConverted))
                {
                    this.Params.Add(idNames[i], idConverted);
                }
                else if (errorOnInvalid[i])
                {
                    // fail, see if it should be valid...
                    YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);
                }
            }
        }
        /// <summary>
        /// Handles the CreatedUser event of the CreateUserWizard1 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 CreateUserWizard1_CreatedUser([NotNull] object sender, [NotNull] EventArgs e)
        {
            SitecoreMembershipUser user = UserMembershipHelper.GetUser(this.CreateUserWizard1.UserName);

            // setup inital roles (if any) for this user
            RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, this.CreateUserWizard1.UserName);

            var displayName = user.UserName;

            if (this.Get <YafBoardSettings>().EnableDisplayName)
            {
                displayName = this.CreateUserStepContainer.FindControlAs <TextBox>("DisplayName").Text.Trim();
            }

            // create the user in the YAF DB as well as sync roles...
            int?userID = RoleMembershipHelper.CreateForumUser(user, displayName, YafContext.Current.PageBoardID);

            // create empty profile just so they have one
            YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName);

            // setup their inital profile information
            userProfile.Save();

            if (userID == null)
            {
                // something is seriously wrong here -- redirect to failure...
                YafBuildLink.RedirectInfoPage(InfoMessage.Failure);
            }

            // handle e-mail verification if needed
            if (this.Get <YafBoardSettings>().EmailVerification)
            {
                // get the user email
                var emailTextBox =
                    (TextBox)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");
                var email = emailTextBox.Text.Trim();

                this.Get <ISendNotification>().SendVerificationEmail(user, email, userID);
            }
            else
            {
                // Send welcome mail/pm to user
                this.Get <ISendNotification>().SendUserWelcomeNotification(user, userID.Value);
            }

            if (this.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet())
            {
                // send user register notification to the following admin users...
                this.Get <ISendNotification>().SendRegistrationNotificationEmail(user, userID.Value);
            }

            if (this.IsPossibleSpamBot)
            {
                this.Get <ISendNotification>().SendSpamBotNotificationToAdmins(user, userID.Value);
            }
        }
Exemple #10
0
        public static DataRow GetFirstRowOrInvalid([NotNull] this DataTable dt)
        {
            DataRow row = dt.GetFirstRow();

            if (row != null)
            {
                return(row);
            }

            // fail...
            YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);

            return(null);
        }
Exemple #11
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.PollList.Visible     = this.PageContext.BoardSettings.BoardPollID > 0;
            this.PollList.PollGroupId = this.PageContext.BoardSettings.BoardPollID;
            this.PollList.BoardId     = this.PageContext.Settings.BoardID;

            if (!this.IsPostBack)
            {
                // vzrus: needs testing, potentially can cause problems
                if (!(UserAgentHelper.IsSearchEngineSpider(HttpContext.Current.Request.UserAgent)))
                {
                    if (!HttpContext.Current.Request.Browser.Cookies)
                    {
                        YafBuildLink.RedirectInfoPage(InfoMessage.RequiresCookies);
                    }

                    Version ecmaVersion = HttpContext.Current.Request.Browser.EcmaScriptVersion;

                    if (ecmaVersion != null)
                    {
                        if (!(ecmaVersion.Major > 0))
                        {
                            YafBuildLink.RedirectInfoPage(InfoMessage.EcmaScriptVersionUnsupported);
                        }
                    }
                    else
                    {
                        YafBuildLink.RedirectInfoPage(InfoMessage.RequiresEcmaScript);
                    }
                }

                this.ShoutBox1.Visible         = this.PageContext.BoardSettings.ShowShoutbox;
                this.ForumStats.Visible        = this.PageContext.BoardSettings.ShowForumStatistics;
                this.ActiveDiscussions.Visible = this.PageContext.BoardSettings.ShowActiveDiscussions;


                if (this.PageContext.Settings.LockedForum == 0)
                {
                    this.PageLinks.AddLink(this.PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum));
                    if (this.PageContext.PageCategoryID != 0)
                    {
                        this.PageLinks.AddLink(
                            this.PageContext.PageCategoryName,
                            YafBuildLink.GetLink(ForumPages.forum, "c={0}", this.PageContext.PageCategoryID));
                        this.Welcome.Visible = false;
                    }
                }
            }
        }
Exemple #12
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)
        {
            // check if this feature is disabled
            if (!this.Get <YafBoardSettings>().AllowPrivateMessages)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Disabled);
            }

            if (this.IsPostBack)
            {
                return;
            }

            if (this.Request.QueryString.GetFirstOrDefault("v").IsSet())
            {
                this._view = PMViewConverter.FromQueryString(this.Request.QueryString.GetFirstOrDefault("v"));

                this.hidLastTab.Value = ((int)this._view).ToString();
            }

            // if (_view == PMView.Inbox)
            // this.PMTabs.ActiveTab = this.InboxTab;
            // else if (_view == PMView.Outbox)
            // this.PMTabs.ActiveTab = this.OutboxTab;
            // else if (_view == PMView.Archive)
            // this.PMTabs.ActiveTab = this.ArchiveTab;
            this.PageLinks.AddRoot();
            this.PageLinks.AddLink(
                this.Get <YafBoardSettings>().EnableDisplayName
                    ? this.PageContext.CurrentUserData.DisplayName
                    : this.PageContext.PageUserName,
                YafBuildLink.GetLink(ForumPages.cp_profile));
            this.PageLinks.AddLink(this.GetText("TITLE"));

            // InboxTab.HeaderText = GetText("INBOX");
            // OutboxTab.HeaderText = GetText("SENTITEMS");
            // ArchiveTab.HeaderText = GetText("ARCHIVE");
            this.NewPM.NavigateUrl  = YafBuildLink.GetLinkNotEscaped(ForumPages.pmessage);
            this.NewPM2.NavigateUrl = this.NewPM.NavigateUrl;

            // inbox tab
            // ScriptManager.RegisterClientScriptBlock(InboxTabUpdatePanel, typeof(UpdatePanel), "InboxTabRefresh", String.Format("function InboxTabRefresh() {1}\n__doPostBack('{0}', '');\n{2}", InboxTabUpdatePanel.ClientID, '{', '}'), true);
            // sent tab
            // ScriptManager.RegisterClientScriptBlock(SentTabUpdatePanel, typeof(UpdatePanel), "SentTabRefresh", String.Format("function SentTabRefresh() {1}\n__doPostBack('{0}', '');\n{2}", SentTabUpdatePanel.ClientID, '{', '}'), true);
            // archive tab
            // ScriptManager.RegisterClientScriptBlock(ArchiveTabUpdatePanel, typeof(UpdatePanel), "ArchiveTabRefresh", String.Format("function ArchiveTabRefresh() {1}\n__doPostBack('{0}', '');\n{2}", ArchiveTabUpdatePanel.ClientID, '{', '}'), true);
        }
Exemple #13
0
        /// <summary>
        /// The create user wizard 1_ created user.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            MembershipUser user = UserMembershipHelper.GetUser(this.CreateUserWizard1.UserName);

            // setup inital roles (if any) for this user
            RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, this.CreateUserWizard1.UserName);

            string displayName = user.UserName;

            if (this.PageContext.BoardSettings.EnableDisplayName)
            {
                displayName = this.CreateUserStepContainer.FindControlAs <TextBox>("DisplayName").Text.Trim();
            }

            // create the user in the YAF DB as well as sync roles...
            int?userID = RoleMembershipHelper.CreateForumUser(user, displayName, YafContext.Current.PageBoardID);

            // create empty profile just so they have one
            YafUserProfile userProfile = YafUserProfile.GetProfile(this.CreateUserWizard1.UserName);

            // setup their inital profile information
            userProfile.Save();

            if (userID == null)
            {
                // something is seriously wrong here -- redirect to failure...
                YafBuildLink.RedirectInfoPage(InfoMessage.Failure);
            }

            // handle e-mail verification if needed
            if (this.PageContext.BoardSettings.EmailVerification)
            {
                // get the user email
                this.SendVerificationEmail(user, userID);
            }

            if (this.PageContext.BoardSettings.NotificationOnUserRegisterEmailList.IsSet())
            {
                // send user register notification to the following admin users...
                this.SendRegistrationNotificationEmail(user);
            }
        }
Exemple #14
0
        /// <summary>
        /// The admin page_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void AdminPage_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            // not admins are forbidden
            if (!this.PageContext.IsAdmin)
            {
                YafBuildLink.AccessDenied();
            }

            // host admins are not checked
            if (this.PageContext.IsHostAdmin)
            {
                return;
            }

            // Load the page access list.
            var dt = LegacyDb.adminpageaccess_list(
                this.PageContext.PageUserID, this.PageContext.ForumPageType.ToString().ToLowerInvariant());

            // Check access rights to the page.
            if (!this.PageContext.ForumPageType.ToString().IsSet() || dt == null || dt.Rows.Count <= 0)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.HostAdminPermissionsAreRequired);
            }
        }
Exemple #15
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)
        {
            // check if this feature is disabled
            if (!this.PageContext.BoardSettings.AllowPrivateMessages)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Disabled);
            }

            if (!this.IsPostBack)
            {
                if (this.Request.QueryString.GetFirstOrDefault("pm").IsNotSet())
                {
                    YafBuildLink.AccessDenied();
                }

                this.PageLinks.AddLink(this.PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum));
                this.PageLinks.AddLink(this.PageContext.PageUserName, YafBuildLink.GetLink(ForumPages.cp_profile));

                // handle custom YafBBCode javascript or CSS...
                YafBBCode.RegisterCustomBBCodePageElements(this.Page, this.GetType());

                this.BindData();
            }
        }
Exemple #16
0
        /// <summary>
        /// the page load event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.Get <YafBoardSettings>().EnableAlbum)
            {
                YafBuildLink.AccessDenied();
            }

            if (this.IsPostBack)
            {
                return;
            }

            var sigData = this.GetRepository <User>().AlbumsDataAsDataTable(
                this.PageContext.PageUserID,
                YafContext.Current.PageBoardID);

            var usrAlbumsAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbums", null);

            var albumSize = this.GetRepository <UserAlbum>().CountUserAlbum(this.PageContext.PageUserID);
            int userID;

            switch (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a"))
            {
            // A new album is being created. check the permissions.
            case "new":

                // Is album feature enabled?
                if (!this.Get <YafBoardSettings>().EnableAlbum)
                {
                    YafBuildLink.AccessDenied();
                }

                // Has the user created maximum number of albums?
                if (usrAlbumsAllowed.HasValue && usrAlbumsAllowed > 0)
                {
                    // Albums count. If we reached limit then we go to info page.
                    if (usrAlbumsAllowed > 0 && albumSize >= usrAlbumsAllowed)
                    {
                        YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                    }
                }

                /* if (this.Get<YafBoardSettings>().AlbumsMax > 0 &&
                 *                  albumSize[0] > this.Get<YafBoardSettings>().AlbumsMax - 1)
                 *        {
                 *            YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                 *        }*/
                userID = this.PageContext.PageUserID;
                break;

            default:
                userID = this.GetRepository <UserAlbum>().List(
                    Security.StringToIntOrRedirect(
                        this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("a")))
                         .FirstOrDefault().UserID;

                if (userID != this.PageContext.PageUserID)
                {
                    YafBuildLink.AccessDenied();
                }

                break;
            }

            var displayName = YafContext.Current.Get <YafBoardSettings>().EnableDisplayName
                                  ? UserMembershipHelper.GetDisplayNameFromID(userID)
                                  : UserMembershipHelper.GetUserNameFromID(userID);

            // Add the page links.
            this.PageLinks.AddRoot();
            this.PageLinks.AddLink(
                displayName,
                YafBuildLink.GetLink(ForumPages.profile, "u={0}&name={1}", userID.ToString(), displayName));
            this.PageLinks.AddLink(
                this.GetText("ALBUMS"),
                YafBuildLink.GetLink(ForumPages.albums, "u={0}", userID.ToString()));
            this.PageLinks.AddLink(this.GetText("TITLE"), string.Empty);

            this.BindData();

            var usrAlbumImagesAllowed = sigData.GetFirstRowColumnAsValue <int?>("UsrAlbumImages", null);

            // Has the user uploaded maximum number of images?
            // vzrus: changed for DB check The default number of album images is 0. In the case albums are disabled.
            if (usrAlbumImagesAllowed.HasValue && usrAlbumImagesAllowed > 0)
            {
                if (this.List.Items.Count >= usrAlbumImagesAllowed)
                {
                    this.uploadtitletr.Visible = false;
                    this.selectfiletr.Visible  = false;
                }
                else
                {
                    this.uploadtitletr.Visible = true;
                    this.selectfiletr.Visible  = true;
                }

                this.imagesInfo.Text = this.GetTextFormatted(
                    "IMAGES_INFO",
                    this.List.Items.Count,
                    usrAlbumImagesAllowed,
                    this.Get <YafBoardSettings>().AlbumImagesSizeMax / 1024);
            }
            else
            {
                this.uploadtitletr.Visible = false;
                this.selectfiletr.Visible  = false;
            }
        }
Exemple #17
0
        /// <summary>
        /// The return to page.
        /// </summary>
        private void ReturnToPage()
        {
            if (this._topicUnapproved)
            {
                // Tell user that his message will have to be approved by a moderator
                var url = YafBuildLink.GetLink(ForumPages.topics, "f={0}", this._returnForum);

                if (Config.IsRainbow)
                {
                    YafBuildLink.Redirect(ForumPages.info, "i=1");
                }
                else
                {
                    YafBuildLink.Redirect(ForumPages.info, "i=1&url={0}", this.Server.UrlEncode(url));
                }
            }

            // YafBuildLink.Redirect(ForumPages.posts, "m={0}#{0}", this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("m"));
            this.ParamsToSend(out var retliterals, out var retvalue);

            switch (retliterals)
            {
            case "t":
                YafBuildLink.Redirect(ForumPages.posts, "t={0}", retvalue);
                break;

            case "em":

                YafBuildLink.Redirect(ForumPages.postmessage, "m={0}", retvalue);
                break;

            case "f":

                YafBuildLink.Redirect(ForumPages.topics, "f={0}", retvalue);
                break;

            case "ef":
                YafBuildLink.Redirect(ForumPages.admin_editforum, "f={0}", retvalue);
                break;

            case "c":
                YafBuildLink.Redirect(ForumPages.forum, "c={0}", retvalue);
                break;

            case "ec":
                YafBuildLink.Redirect(ForumPages.admin_editcategory, "c={0}", retvalue);
                break;

            case "b":
                YafBuildLink.Redirect(ForumPages.forum);
                break;

            case "eb":
                YafBuildLink.Redirect(ForumPages.admin_editboard, "b={0}", retvalue);
                break;

            default:
                YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);
                break;
            }
        }
Exemple #18
0
        /// <summary>
        /// The init poll ui.
        /// </summary>
        /// <param name="pollID">
        /// The poll ID.
        /// </param>
        private void InitPollUI(int?pollID)
        {
            // we should get the schema anyway
            this._choices = this.GetRepository <Poll>().StatsAsDataTable(pollID);
            this._choices.Columns.Add("ChoiceOrderID", typeof(int));

            // First existing values alway 1!
            var existingRowsCount    = 1;
            var allExistingRowsCount = this._choices.Rows.Count;

            // we edit existing poll
            if (this._choices.HasRows())
            {
                if (this._choices.Rows[0]["UserID"].ToType <int>() != this.PageContext.PageUserID &&
                    !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess)
                {
                    YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);
                }

                this.IsBoundCheckBox.Checked              = this._choices.Rows[0]["IsBound"].ToType <bool>();
                this.IsClosedBoundCheckBox.Checked        = this._choices.Rows[0]["IsClosedBound"].ToType <bool>();
                this.AllowMultipleChoicesCheckBox.Checked = this._choices.Rows[0]["AllowMultipleChoices"].ToType <bool>();
                this.AllowSkipVoteCheckBox.Checked        = this._choices.Rows[0]["AllowSkipVote"].ToType <bool>();
                this.ShowVotersCheckBox.Checked           = this._choices.Rows[0]["ShowVoters"].ToType <bool>();
                this.Question.Text           = this._choices.Rows[0]["Question"].ToString();
                this.QuestionObjectPath.Text = this._choices.Rows[0]["QuestionObjectPath"].ToString();

                if (this._choices.Rows[0]["Closes"] != DBNull.Value)
                {
                    var closing = (DateTime)this._choices.Rows[0]["Closes"] - DateTime.UtcNow;

                    this.PollExpire.Text = (closing.TotalDays + 1).ToType <int>().ToString();
                }
                else
                {
                    this.PollExpire.Text = null;
                }

                foreach (DataRow choiceRow in this._choices.Rows)
                {
                    choiceRow["ChoiceOrderID"] = existingRowsCount;

                    existingRowsCount++;
                }
            }
            else
            {
                // A new topic is created
                // below check currently if works for topics only, but will do as some things are not enabled
                if (!this.CanCreatePoll())
                {
                    YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                }

                // Get isBound value using page variables. They are initialized here.
                var pgidt = 0;

                // If a topic poll is edited or new topic created
                if (this._topicId > 0 && this.topicInfo != null)
                {
                    // topic id should not be null here
                    if (this.topicInfo.PollID != null)
                    {
                        pgidt = this.topicInfo.PollID.Value;

                        var pollGroupData = this.GetRepository <Poll>().PollGroupStatsAsDataTable(pgidt);

                        this.IsBoundCheckBox.Checked = pollGroupData.Rows[0]["IsBound"].ToType <bool>();
                    }
                }
                else if (this._forumId > 0 && (!(this._topicId > 0) || !(this._editTopicId > 0)))
                {
                    // forum id should not be null here
                    pgidt = this.GetRepository <Forum>().List(this.PageContext.PageBoardID, this._forumId).FirstOrDefault().PollGroupID.Value;
                }
                else if (this._categoryId > 0)
                {
                    // category id should not be null here
                    pgidt =
                        this.GetRepository <Category>()
                        .Listread(this.PageContext.PageUserID, this._categoryId)
                        .GetFirstRowColumnAsValue("PollGroupID", 0);
                }

                if (pgidt > 0)
                {
                    if (this.GetRepository <Poll>().PollGroupStatsAsDataTable(pgidt).Rows[0]["IsBound"].ToType <int>() == 2)
                    {
                        this.IsBoundCheckBox.Checked = true;
                    }

                    if (this.GetRepository <Poll>().PollGroupStatsAsDataTable(pgidt).Rows[0]["IsClosedBound"].ToType <int>() == 4)
                    {
                        this.IsClosedBoundCheckBox.Checked = true;
                    }
                }

                // clear the fields...
                this.PollExpire.Text = string.Empty;
                this.Question.Text   = string.Empty;
            }

            // we add dummy rows to data table to fill in repeater empty fields
            var dummyRowsCount = this.Get <YafBoardSettings>().AllowedPollChoiceNumber - allExistingRowsCount - 1;

            for (var i = 0; i <= dummyRowsCount; i++)
            {
                var drow = this._choices.NewRow();
                drow["ChoiceOrderID"] = existingRowsCount + i;
                this._choices.Rows.Add(drow);
            }

            // Bind choices repeater
            this.ChoiceRepeater.DataSource = this._choices;
            this.ChoiceRepeater.DataBind();
            this.ChoiceRepeater.Visible = true;

            // Show controls
            this.SavePoll.Visible                = true;
            this.Cancel.Visible                  = true;
            this.PollRow1.Visible                = true;
            this.PollRowExpire.Visible           = true;
            this.IsClosedBound.Visible           =
                this.IsBound.Visible             = this.Get <YafBoardSettings>().AllowUsersHidePollResults || this.PageContext.IsAdmin || this.PageContext.IsForumModerator;
            this.tr_AllowMultipleChoices.Visible = this.Get <YafBoardSettings>().AllowMultipleChoices || this.PageContext.IsAdmin ||
                                                   this.PageContext.ForumModeratorAccess;
            this.tr_ShowVoters.Visible    = true;
            this.tr_AllowSkipVote.Visible = false;
        }
Exemple #19
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)
        {
            if (!this.PageContext.IsGuest)
            {
                // Register Ajax Pro.
                Utility.RegisterTypeForAjax(typeof(YafFavoriteTopic));

                // The html code for "Favorite Topic" theme buttons.
                string tagButtonHTML =
                    "'<a class=\"yafcssbigbutton rightItem\" href=\"javascript:addFavoriteTopic(' + res.value + ');\" onclick=\"blur();\" title=\"{0}\"><span>{1}</span></a>'"
                    .FormatWith(
                        this.PageContext.Localization.GetText("BUTTON_TAGFAVORITE_TT"),
                        this.PageContext.Localization.GetText("BUTTON_TAGFAVORITE"));
                string untagButtonHTML =
                    "'<a class=\"yafcssbigbutton rightItem\" href=\"javascript:removeFavoriteTopic(' + res.value + ');\" onclick=\"blur();\" title=\"{0}\"><span>{1}</span></a>'"
                    .FormatWith(
                        this.PageContext.Localization.GetText("BUTTON_UNTAGFAVORITE_TT"),
                        this.PageContext.Localization.GetText("BUTTON_UNTAGFAVORITE"));

                // Register the client side script for the "Favorite Topic".
                YafContext.Current.PageElements.RegisterJsBlockStartup(
                    "addFavoriteTopicJs", JavaScriptBlocks.addFavoriteTopicJs(untagButtonHTML));
                YafContext.Current.PageElements.RegisterJsBlockStartup(
                    "removeFavoriteTopicJs", JavaScriptBlocks.removeFavoriteTopicJs(tagButtonHTML));
                YafContext.Current.PageElements.RegisterJsBlockStartup(
                    "asynchCallFailedJs", JavaScriptBlocks.asynchCallFailedJs);

                // Has the user already tagged this topic as favorite?
                if (this.Get <YafFavoriteTopic>().IsFavoriteTopic(this.PageContext.PageTopicID))
                {
                    // Generate the "Untag" theme button with appropriate JS calls for onclick event.
                    this.TagFavorite1.NavigateUrl       = "javascript:removeFavoriteTopic(" + this.PageContext.PageTopicID + ");";
                    this.TagFavorite2.NavigateUrl       = "javascript:removeFavoriteTopic(" + this.PageContext.PageTopicID + ");";
                    this.TagFavorite1.TextLocalizedTag  = "BUTTON_UNTAGFAVORITE";
                    this.TagFavorite1.TitleLocalizedTag = "BUTTON_UNTAGFAVORITE_TT";
                    this.TagFavorite2.TextLocalizedTag  = "BUTTON_UNTAGFAVORITE";
                    this.TagFavorite2.TitleLocalizedTag = "BUTTON_UNTAGFAVORITE_TT";
                }
                else
                {
                    // Generate the "Tag" theme button with appropriate JS calls for onclick event.
                    this.TagFavorite1.NavigateUrl       = "javascript:addFavoriteTopic(" + this.PageContext.PageTopicID + ");";
                    this.TagFavorite2.NavigateUrl       = "javascript:addFavoriteTopic(" + this.PageContext.PageTopicID + ");";
                    this.TagFavorite1.TextLocalizedTag  = "BUTTON_TAGFAVORITE";
                    this.TagFavorite1.TitleLocalizedTag = "BUTTON_TAGFAVORITE_TT";
                    this.TagFavorite2.TextLocalizedTag  = "BUTTON_TAGFAVORITE";
                    this.TagFavorite2.TitleLocalizedTag = "BUTTON_TAGFAVORITE_TT";
                }
            }
            else
            {
                this.TagFavorite1.Visible = false;
                this.TagFavorite2.Visible = false;
            }

            this._quickReplyEditor.BaseDir    = YafForumInfo.ForumClientFileRoot + "editors";
            this._quickReplyEditor.StyleSheet = this.PageContext.Theme.BuildThemePath("theme.css");

            this._topic = DB.topic_info(this.PageContext.PageTopicID);

            // in case topic is deleted or not existant
            if (this._topic == null)
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);
            }

            // get topic flags
            this._topicFlags = new TopicFlags(this._topic["Flags"]);

            using (DataTable dt = DB.forum_list(this.PageContext.PageBoardID, this.PageContext.PageForumID))
            {
                this._forum = dt.Rows[0];
            }

            this._forumFlags = new ForumFlags(this._forum["Flags"]);

            if (this.PageContext.IsGuest && !this.PageContext.ForumReadAccess)
            {
                // attempt to get permission by redirecting to login...
                this.Get <YafPermissions>().HandleRequest(ViewPermissions.RegisteredUsers);
            }
            else if (!this.PageContext.ForumReadAccess)
            {
                YafBuildLink.AccessDenied();
            }

            if (!this.IsPostBack)
            {
                if (this.PageContext.Settings.LockedForum == 0)
                {
                    this.PageLinks.AddLink(this.PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum));
                    this.PageLinks.AddLink(
                        this.PageContext.PageCategoryName,
                        YafBuildLink.GetLink(ForumPages.forum, "c={0}", this.PageContext.PageCategoryID));
                }

                this.QuickReply.Text         = this.GetText("POSTMESSAGE", "SAVE");
                this.DataPanel1.TitleText    = this.GetText("QUICKREPLY");
                this.DataPanel1.ExpandText   = this.GetText("QUICKREPLY_SHOW");
                this.DataPanel1.CollapseText = this.GetText("QUICKREPLY_HIDE");

                this.PageLinks.AddForumLinks(this.PageContext.PageForumID);
                this.PageLinks.AddLink(
                    this.Get <YafBadWordReplace>().Replace(this.Server.HtmlDecode(this.PageContext.PageTopicName)), string.Empty);

                this.TopicTitle.Text = this.Get <YafBadWordReplace>().Replace(this.HtmlEncode((string)this._topic["Topic"]));

                this.ViewOptions.Visible     = this.PageContext.BoardSettings.AllowThreaded;
                this.ForumJumpHolder.Visible = this.PageContext.BoardSettings.ShowForumJump &&
                                               this.PageContext.Settings.LockedForum == 0;

                this.RssTopic.NavigateUrl = YafBuildLink.GetLinkNotEscaped(
                    ForumPages.rsstopic,
                    "pg={0}&t={1}",
                    this.Request.QueryString.GetFirstOrDefault("g"),
                    this.PageContext.PageTopicID);
                this.RssTopic.Visible = this.PageContext.BoardSettings.ShowRSSLink;

                this.QuickReplyPlaceHolder.Visible = this.PageContext.BoardSettings.ShowQuickAnswer;

                if ((this.PageContext.IsGuest && this.PageContext.BoardSettings.EnableCaptchaForGuests) ||
                    (this.PageContext.BoardSettings.EnableCaptchaForPost && !this.PageContext.IsCaptchaExcluded))
                {
                    this.imgCaptcha.ImageUrl = "{0}resource.ashx?c=1".FormatWith(YafForumInfo.ForumClientFileRoot);
                    this.CaptchaDiv.Visible  = true;
                }

                if (!this.PageContext.ForumPostAccess || (this._forumFlags.IsLocked && !this.PageContext.ForumModeratorAccess))
                {
                    this.NewTopic1.Visible = false;
                    this.NewTopic2.Visible = false;
                }

                // Ederon : 9/9/2007 - moderators can reply in locked topics
                if (!this.PageContext.ForumReplyAccess ||
                    ((this._topicFlags.IsLocked || this._forumFlags.IsLocked) && !this.PageContext.ForumModeratorAccess))
                {
                    this.PostReplyLink1.Visible        = this.PostReplyLink2.Visible = false;
                    this.QuickReplyPlaceHolder.Visible = false;
                }

                if (this.PageContext.ForumModeratorAccess)
                {
                    this.MoveTopic1.Visible = true;
                    this.MoveTopic2.Visible = true;
                }
                else
                {
                    this.MoveTopic1.Visible = false;
                    this.MoveTopic2.Visible = false;
                }

                if (!this.PageContext.ForumModeratorAccess)
                {
                    this.LockTopic1.Visible   = false;
                    this.UnlockTopic1.Visible = false;
                    this.DeleteTopic1.Visible = false;
                    this.LockTopic2.Visible   = false;
                    this.UnlockTopic2.Visible = false;
                    this.DeleteTopic2.Visible = false;
                }
                else
                {
                    this.LockTopic1.Visible   = !this._topicFlags.IsLocked;
                    this.UnlockTopic1.Visible = !this.LockTopic1.Visible;
                    this.LockTopic2.Visible   = this.LockTopic1.Visible;
                    this.UnlockTopic2.Visible = !this.LockTopic2.Visible;
                }
            }

            // Mark topic read
            YafContext.Current.Get <YafSession>().SetTopicRead(this.PageContext.PageTopicID, DateTime.UtcNow);

            this.BindData();
        }
Exemple #20
0
        /// <summary>
        /// The init poll ui.
        /// </summary>
        /// <param name="pollID">
        /// The poll ID.
        /// </param>
        private void InitPollUI(int?pollID)
        {
            // we should get the schema anyway
            this._choices = DB.poll_stats(pollID);
            this._choices.Columns.Add("ChoiceOrderID", typeof(int));

            // First existing values alway 1!
            int existingRowsCount    = 1;
            int allExistingRowsCount = this._choices.Rows.Count;

            // we edit existing poll
            if (this._choices.Rows.Count > 0)
            {
                if ((Convert.ToInt32(this._choices.Rows[0]["UserID"]) != this.PageContext.PageUserID) &&
                    (!this.PageContext.IsAdmin) && (!this.PageContext.IsForumModerator))
                {
                    YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);
                }


                this.IsBoundCheckBox.Checked              = this._choices.Rows[0]["IsBound"].ToType <bool>();
                this.IsClosedBoundCheckBox.Checked        = this._choices.Rows[0]["IsClosedBound"].ToType <bool>();
                this.AllowMultipleChoicesCheckBox.Checked = this._choices.Rows[0]["AllowMultipleChoices"].ToType <bool>();

                this.Question.Text           = this._choices.Rows[0]["Question"].ToString();
                this.QuestionObjectPath.Text = this._choices.Rows[0]["QuestionObjectPath"].ToString();

                if (this._choices.Rows[0]["Closes"] != DBNull.Value)
                {
                    TimeSpan closing = (DateTime)this._choices.Rows[0]["Closes"] - DateTime.UtcNow;

                    this.PollExpire.Text = SqlDataLayerConverter.VerifyInt32(closing.TotalDays + 1).ToString();
                }
                else
                {
                    this.PollExpire.Text = null;
                }

                foreach (DataRow choiceRow in this._choices.Rows)
                {
                    choiceRow["ChoiceOrderID"] = existingRowsCount;

                    existingRowsCount++;
                }
            }
            else
            {
                // A new topic is created
                // below check currently if works for topics only, but will do as some things are not enabled
                if (!CanCreatePoll())
                {
                    YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                }
                // Get isBound value using page variables. They are initialized here.
                int pgidt = 0;

                // If a topic poll is edited or new topic created
                if (this._topicId > 0 && this._topicInfo != null)
                {
                    // topicid should not be null here
                    if (!this._topicInfo["PollID"].IsNullOrEmptyDBField())
                    {
                        pgidt = (int)this._topicInfo["PollID"];

                        DataTable pollGroupData = DB.pollgroup_stats(pgidt);

                        this.IsBoundCheckBox.Checked = Convert.ToBoolean(pollGroupData.Rows[0]["IsBound"]);
                        // this.IsClosedBoundCheckBox.Checked = Convert.ToBoolean(DB.pollgroup_stats(pgidt).Rows[0]["IsClosedBound"]);
                    }
                }
                else if (this._forumId > 0 && (!(this._topicId > 0) || (!(this._editTopicId > 0))))
                {
                    // forumid should not be null here
                    pgidt = (int)DB.forum_list(this.PageContext.PageBoardID, this._forumId).Rows[0]["PollGroupID"];
                }
                else if (this._categoryId > 0)
                {
                    // categoryid should not be null here
                    pgidt =
                        (int)
                        DB.category_listread(this.PageContext.PageBoardID, this.PageContext.PageUserID, this._categoryId).Rows[0][
                            "PollGroupID"];
                }

                if (pgidt > 0)
                {
                    if (Convert.ToInt32(DB.pollgroup_stats(pgidt).Rows[0]["IsBound"]) == 2)
                    {
                        this.IsBoundCheckBox.Checked = true;
                    }

                    if (Convert.ToInt32(DB.pollgroup_stats(pgidt).Rows[0]["IsClosedBound"]) == 4)
                    {
                        this.IsClosedBoundCheckBox.Checked = true;
                    }
                }

                // clear the fields...
                this.PollExpire.Text = string.Empty;
                this.Question.Text   = string.Empty;
            }

            // we add dummy rows to data table to fill in repeater empty fields
            int dummyRowsCount = this.PageContext.BoardSettings.AllowedPollChoiceNumber - allExistingRowsCount - 1;

            for (int i = 0; i <= dummyRowsCount; i++)
            {
                DataRow drow = this._choices.NewRow();
                drow["ChoiceOrderID"] = existingRowsCount + i;
                this._choices.Rows.Add(drow);
            }

            // Bind choices repeater
            this.ChoiceRepeater.DataSource = this._choices;
            this.ChoiceRepeater.DataBind();
            this.ChoiceRepeater.Visible = true;

            // Show controls
            this.SavePoll.Visible                = true;
            this.Cancel.Visible                  = true;
            this.PollRow1.Visible                = true;
            this.PollRowExpire.Visible           = true;
            this.IsClosedBound.Visible           = this.IsBound.Visible = PageContext.BoardSettings.AllowUsersHidePollResults || PageContext.IsAdmin || PageContext.IsForumModerator;
            this.tr_AllowMultipleChoices.Visible = PageContext.BoardSettings.AllowMultipleChoices || PageContext.IsAdmin || PageContext.IsForumModerator;
        }
Exemple #21
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)
        {
            // Put user code to initialize the page here
            if (!(this.Get <YafBoardSettings>().ShowRSSLink || this.Get <YafBoardSettings>().ShowAtomLink))
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }

            // Atom feed as variable
            var atomFeedByVar = this.Request.QueryString.GetFirstOrDefault("ft")
                                == YafSyndicationFormats.Atom.ToInt().ToString();

            YafSyndicationFeed feed = null;

            // var syndicationItems = new List<SyndicationItem>();
            var lastPostIcon = BaseUrlBuilder.BaseUrl
                               + this.PageContext.CurrentForumPage.GetThemeContents("ICONS", "ICON_NEWEST");
            var lastPostName = this.GetText("DEFAULT", "GO_LAST_POST");

            YafRssFeeds feedType;

            try
            {
                feedType = this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("pg").ToEnum <YafRssFeeds>(true);
            }
            catch
            {
                // default to Forum Feed.
                feedType = YafRssFeeds.Forum;
            }

            switch (feedType)
            {
            // Latest posts feed
            case YafRssFeeds.LatestPosts:
                if (
                    !(this.Get <YafBoardSettings>().ShowActiveDiscussions &&
                      this.Get <IPermissions>().Check(this.Get <YafBoardSettings>().PostLatestFeedAccess)))
                {
                    YafBuildLink.AccessDenied();
                }

                this.GetPostLatestFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName);
                break;

            // Latest Announcements feed
            case YafRssFeeds.LatestAnnouncements:
                if (!this.Get <IPermissions>().Check(this.Get <YafBoardSettings>().ForumFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }

                this.GetLatestAnnouncementsFeed(ref feed, feedType, atomFeedByVar);
                break;

            // Posts Feed
            case YafRssFeeds.Posts:
                if (
                    !(this.PageContext.ForumReadAccess &&
                      this.Get <IPermissions>().Check(this.Get <YafBoardSettings>().PostsFeedAccess)))
                {
                    YafBuildLink.AccessDenied();
                }

                if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("t") != null)
                {
                    int topicId;
                    if (int.TryParse(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("t"), out topicId))
                    {
                        this.GetPostsFeed(ref feed, feedType, atomFeedByVar, topicId);
                    }
                }

                break;

            // Forum Feed
            case YafRssFeeds.Forum:
                if (!this.Get <IPermissions>().Check(this.Get <YafBoardSettings>().ForumFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }

                object categoryId = null;

                if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("c") != null)
                {
                    int icategoryId;
                    if (int.TryParse(
                            this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("c"), out icategoryId))
                    {
                        categoryId = icategoryId;
                    }
                }

                this.GetForumFeed(ref feed, feedType, atomFeedByVar, categoryId);
                break;

            // Topics Feed
            case YafRssFeeds.Topics:
                if (
                    !(this.PageContext.ForumReadAccess &&
                      this.Get <IPermissions>().Check(this.Get <YafBoardSettings>().TopicsFeedAccess)))
                {
                    YafBuildLink.AccessDenied();
                }

                if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f") != null)
                {
                    int forumId;
                    if (int.TryParse(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f"), out forumId))
                    {
                        this.GetTopicsFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName, forumId);
                    }
                }

                break;

            // Active Topics
            case YafRssFeeds.Active:
                if (!this.Get <IPermissions>().Check(this.Get <YafBoardSettings>().ActiveTopicFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }

                int    categoryActiveIntId;
                object categoryActiveId = null;
                if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f") != null
                    &&
                    int.TryParse(
                        this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f"), out categoryActiveIntId))
                {
                    categoryActiveId = categoryActiveIntId;
                }

                this.GetActiveFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName, categoryActiveId);

                break;

            case YafRssFeeds.Favorite:
                if (!this.Get <IPermissions>().Check(this.Get <YafBoardSettings>().FavoriteTopicFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }

                int    categoryFavIntId;
                object categoryFavId = null;
                if (this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f") != null
                    &&
                    int.TryParse(
                        this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f"), out categoryFavIntId))
                {
                    categoryFavId = categoryFavIntId;
                }

                this.GetFavoriteFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName, categoryFavId);
                break;

            default:
                YafBuildLink.AccessDenied();
                break;
            }

            // update the feed with the item list...
            // the list should be added after all other feed properties are set
            if (feed != null)
            {
                var writer = new XmlTextWriter(this.Response.OutputStream, Encoding.UTF8);
                writer.WriteStartDocument();

                // write the feed to the response writer);
                if (!atomFeedByVar)
                {
                    var rssFormatter = new Rss20FeedFormatter(feed);
                    rssFormatter.WriteTo(writer);
                    this.Response.ContentType = "application/rss+xml";
                }
                else
                {
                    var atomFormatter = new Atom10FeedFormatter(feed);
                    atomFormatter.WriteTo(writer);

                    this.Response.ContentType = "application/atom+xml";
                }

                writer.WriteEndDocument();
                writer.Close();

                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.Cache.SetCacheability(HttpCacheability.Public);

                this.Response.End();
            }
            else
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }
        }
Exemple #22
0
        /// <summary>
        /// The handle.
        /// </summary>
        /// <param name="event">
        /// The event.
        /// </param>
        /// <exception cref="ApplicationException">Failed to find guest user.</exception>
        /// <exception cref="ApplicationException">Failed to create new user.</exception>
        /// <exception cref="ApplicationException">Unable to find the Guest User!</exception>
        public void Handle([NotNull] InitPageLoadEvent @event)
        {
            try
            {
                object userKey = null;

                if (YafContext.Current.User != null)
                {
                    userKey = YafContext.Current.User.ProviderUserKey;
                }

                int     tries = 0;
                DataRow pageRow;
                string  forumPage = this.Get <HttpRequestBase>().QueryString.ToString();
                string  location  = this.Get <HttpRequestBase>().FilePath;

                // resources are not handled by ActiveLocation control so far.
                if (location.Contains("resource.ashx"))
                {
                    forumPage = string.Empty;
                    location  = string.Empty;
                }

                do
                {
                    pageRow = LegacyDb.pageload(
                        this.Get <HttpSessionStateBase>().SessionID,
                        YafContext.Current.PageBoardID,
                        userKey,
                        this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                        location,
                        forumPage,
                        @event.Data.Browser,
                        @event.Data.Platform,
                        @event.Data.CategoryID,
                        @event.Data.ForumID,
                        @event.Data.TopicID,
                        @event.Data.MessageID,
                        // don't track if this is a search engine
                        @event.Data.IsSearchEngine,
                        @event.Data.IsMobileDevice,
                        @event.Data.DontTrack);

                    // if the user doesn't exist...
                    if (userKey != null && pageRow == null)
                    {
                        // create the user...
                        if (
                            !RoleMembershipHelper.DidCreateForumUser(
                                YafContext.Current.User, YafContext.Current.PageBoardID))
                        {
                            throw new ApplicationException("Failed to create new user.");
                        }
                    }

                    if (tries++ < 2)
                    {
                        continue;
                    }

                    if (userKey != null && pageRow == null)
                    {
                        // probably no permissions, use guest user instead...
                        userKey = null;
                        continue;
                    }

                    // fail...
                    break;
                }while (pageRow == null && userKey != null);

                if (pageRow == null)
                {
                    throw new ApplicationException("Unable to find the Guest User!");
                }

                // add all loaded page data into our data dictionary...
                @event.DataDictionary.AddRange(pageRow.ToDictionary());

                // clear active users list
                if (@event.DataDictionary["ActiveUpdate"].ToType <bool>())
                {
                    // purge the cache if something has changed...
                    this.DataCache.Remove(Constants.Cache.UsersOnlineStatus);
                }
            }
            catch (Exception x)
            {
#if !DEBUG
                // log the exception...
                this.Logger.Fatal(
                    x,
                    "Failure Initializing User/Page (URL: {0}).",
                    this.Get <HttpRequestBase>().Url.ToString());

                // log the user out...
                //FormsAuthentication.SignOut();

                if (YafContext.Current.ForumPageType != ForumPages.info)
                {
                    // show a failure notice since something is probably up with membership...
                    YafBuildLink.RedirectInfoPage(InfoMessage.Failure);
                }
                else
                {
                    // totally failing... just re-throw the exception...
                    throw;
                }
#else
                // re-throw exception...
                throw;
#endif
            }
        }
        /// <summary>
        /// the page load event.
        /// </summary>
        /// <param name="sender">
        /// the sender.
        /// </param>
        /// <param name="e">
        /// the e.
        /// </param>
        protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.PageContext.BoardSettings.EnableAlbum)
            {
                YafBuildLink.AccessDenied();
            }

            if (!this.IsPostBack)
            {
                DataTable sigData = DB.user_getalbumsdata(this.PageContext.PageUserID, YafContext.Current.PageBoardID);


                var usrAlbumsAllowed =
                    sigData.GetFirstRowColumnAsValue <int?>(
                        "UsrAlbums", null);

                int[] albumSize = DB.album_getstats(this.PageContext.PageUserID, null);
                int   userID;
                switch (this.Request.QueryString.GetFirstOrDefault("a"))
                {
                // A new album is being created. check the permissions.
                case "new":

                    // Is album feature enabled?
                    if (!this.PageContext.BoardSettings.EnableAlbum)
                    {
                        YafBuildLink.AccessDenied();
                    }

                    // Has the user created maximum number of albums?
                    if (usrAlbumsAllowed.HasValue && usrAlbumsAllowed > 0)
                    {
                        // Albums count. If we reached limit then we go to info page.
                        if (usrAlbumsAllowed > 0 &&
                            (albumSize[0] >= usrAlbumsAllowed))
                        {
                            YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                        }
                    }

                    /* if (this.PageContext.BoardSettings.AlbumsMax > 0 &&
                     *                      albumSize[0] > this.PageContext.BoardSettings.AlbumsMax - 1)
                     *            {
                     *                YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                     *            }*/
                    userID = this.PageContext.PageUserID;
                    break;

                default:
                    userID =
                        Convert.ToInt32(
                            DB.album_list(null, Security.StringToLongOrRedirect(this.Request.QueryString.GetFirstOrDefault("a"))).
                            Rows[0]["UserID"]);
                    if (userID != this.PageContext.PageUserID)
                    {
                        YafBuildLink.AccessDenied();
                    }

                    break;
                }

                string displayName = UserMembershipHelper.GetDisplayNameFromID(userID);

                // Add the page links.
                this.PageLinks.AddLink(this.PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum));
                this.PageLinks.AddLink(
                    !string.IsNullOrEmpty(displayName) ? displayName : UserMembershipHelper.GetUserNameFromID(userID),
                    YafBuildLink.GetLink(ForumPages.profile, "u={0}", userID.ToString()));
                this.PageLinks.AddLink(
                    this.GetText("ALBUMS"), YafBuildLink.GetLink(ForumPages.albums, "u={0}", userID.ToString()));
                this.PageLinks.AddLink(this.GetText("TITLE"), string.Empty);

                this.Back.Text   = this.GetText("BACK");
                this.Upload.Text = this.GetText("UPLOAD");

                this.BindData();

                var usrAlbumImagesAllowed =
                    sigData.GetFirstRowColumnAsValue <int?>(
                        "UsrAlbumImages", null);
                // Has the user uploaded maximum number of images?
                // vzrus: changed for DB check The default number of album images is 0. In the case albums are disabled.
                if (usrAlbumImagesAllowed.HasValue && usrAlbumImagesAllowed > 0)
                {
                    if (List.Items.Count >= usrAlbumImagesAllowed)
                    {
                        this.uploadtitletr.Visible = false;
                        this.selectfiletr.Visible  = false;
                    }
                    else
                    {
                        this.uploadtitletr.Visible = true;
                        this.selectfiletr.Visible  = true;
                    }

                    this.imagesInfo.Text = this.PageContext.Localization.GetTextFormatted("IMAGES_INFO",
                                                                                          List.Items.Count, usrAlbumImagesAllowed);
                }
                else
                {
                    this.uploadtitletr.Visible = false;
                    this.selectfiletr.Visible  = false;
                }
            }
        }