コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check license
        if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, string.Empty) != string.Empty)
        {
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.Friends);
        }

        userId      = QueryHelper.GetInteger("userid", 0);
        currentUser = MembershipContext.AuthenticatedUser;

        // Check if request is for current user or another user with permission to manage it
        if (currentUser.IsPublic() || ((currentUser.UserID != userId) && !currentUser.IsAuthorizedPerResource("CMS.Friends", "Manage")))
        {
            RedirectToAccessDenied("CMS.Friends", "Manage");
        }

        int requestedUserId = QueryHelper.GetInteger("requestid", 0);

        PageTitle.TitleText            = GetString("friends.addnewfriend");
        FriendsRequest.UserID          = userId;
        FriendsRequest.RequestedUserID = requestedUserId;
        FriendsRequest.IsLiveSite      = true;

        if (requestedUserId != 0)
        {
            string fullUserName = String.Empty;

            UserInfo requestedUser = UserInfoProvider.GetUserInfo(requestedUserId);
            if (requestedUser != null)
            {
                fullUserName = Functions.GetFormattedUserName(requestedUser.UserName, requestedUser.FullName, requestedUser.UserNickName, true);
            }

            Page.Title          = string.Format(GetString("friends.requestfriendshipwith"), HTMLHelper.HTMLEncode(fullUserName));
            PageTitle.TitleText = Page.Title;
        }
    }
コード例 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check license
        if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, string.Empty) != string.Empty)
        {
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.Friends);
        }

        userId = QueryHelper.GetInteger("userid", 0);
        currentUser = MembershipContext.AuthenticatedUser;

        // Check if request is for current user or another user with permission to manage it
        if (currentUser.IsPublic() || ((currentUser.UserID != userId) && !currentUser.IsAuthorizedPerResource("CMS.Friends", "Manage")))
        {
            RedirectToAccessDenied("CMS.Friends", "Manage");
        }

        int requestedUserId = QueryHelper.GetInteger("requestid", 0);
        PageTitle.TitleText = GetString("friends.addnewfriend");
        FriendsRequest.UserID = userId;
        FriendsRequest.RequestedUserID = requestedUserId;
        FriendsRequest.IsLiveSite = true;

        if (requestedUserId != 0)
        {
            string fullUserName = String.Empty;

            UserInfo requestedUser = UserInfoProvider.GetUserInfo(requestedUserId);
            if (requestedUser != null)
            {
                fullUserName = Functions.GetFormattedUserName(requestedUser.UserName, requestedUser.FullName, requestedUser.UserNickName, true);
            }

            Page.Title = string.Format(GetString("friends.requestfriendshipwith"), HTMLHelper.HTMLEncode(fullUserName));
            PageTitle.TitleText = Page.Title;
        }
    }
コード例 #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check license
        if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, string.Empty) != string.Empty)
        {
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.Friends);
        }

        userId = QueryHelper.GetInteger("userid", 0);
        currentUser = MembershipContext.AuthenticatedUser;
        int requestedId = QueryHelper.GetInteger("requestid", 0);
        int friendshipId = 0;

        // Check if request is for current user or another user with permission to manage it
        if (currentUser.IsPublic() || ((currentUser.UserID != userId) && !currentUser.IsAuthorizedPerResource("CMS.Friends", "Manage")))
        {
            RedirectToAccessDenied("CMS.Friends", "Manage");
        }

        FriendsReject.SelectedFriends = null;
        FriendsReject.IsLiveSite = true;

        PageTitle.TitleText = GetString("friends.rejectfriendship");
        // Multiple selection
        if (Request["ids"] != null)
        {
            string[] items = Request["ids"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            if (items.Length > 0)
            {
                ArrayList friends = new ArrayList();
                foreach (string item in items)
                {
                    friends.Add(ValidationHelper.GetInteger(item, 0));
                }
                FriendsReject.SelectedFriends = friends;
                if (friends.Count == 1)
                {
                    friendshipId = Convert.ToInt32(friends[0]);
                }
            }
        }
        // For one user
        else
        {
            FriendsReject.RequestedUserID = requestedId;
        }

        FriendInfo fi = null;
        if (friendshipId != 0)
        {
            fi = FriendInfoProvider.GetFriendInfo(friendshipId);
            // Set edited object
            EditedObject = fi;
        }
        else if (requestedId != 0)
        {
            fi = FriendInfoProvider.GetFriendInfo(userId, requestedId);
            // Set edited object
            EditedObject = fi;
        }

        if (fi != null)
        {
            UserInfo requestedUser = (userId == fi.FriendRequestedUserID) ? UserInfoProvider.GetFullUserInfo(fi.FriendUserID) : UserInfoProvider.GetFullUserInfo(fi.FriendRequestedUserID);
            string fullUserName = Functions.GetFormattedUserName(requestedUser.UserName, requestedUser.FullName, requestedUser.UserNickName, true);
            Page.Title = GetString("friends.rejectfriendshipwith") + " " + HTMLHelper.HTMLEncode(fullUserName);
            PageTitle.TitleText = Page.Title;
        }

        // Set current user
        FriendsReject.UserID = userId;
    }
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData()
    {
        requestedGroupId = ValidationHelper.GetInteger(ContextMenu.Parameter, 0);

        DataTable table = new DataTable();

        table.Columns.Add("ActionDisplayName");
        table.Columns.Add("ActionScript");

        // Add only if community is present
        if (CommunityPresent)
        {
            // Get resource strings prefix
            string resourcePrefix = ContextMenu.ResourcePrefix;

            // View group profile
            string profileUrl = "";

            // Get group profile URL
            GeneralizedInfo infoObj = ModuleCommands.CommunityGetGroupInfo(requestedGroupId);
            if (infoObj != null)
            {
                profileUrl = ResolveUrl(DocumentURLProvider.GetUrl(ModuleCommands.CommunityGetGroupProfilePath(infoObj.ObjectCodeName, SiteContext.CurrentSiteName)));
            }

            table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".viewgroup|group.viewgroup"), "window.location.replace('" + profileUrl + "');" });
            if (!currentUser.IsGroupMember(requestedGroupId))
            {
                table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".joingroup|group.joingroup"), !currentUser.IsPublic() ? "ContextJoinTheGroup(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });
            }
            else
            {
                table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".leavegroup|group.leavegroup"), !currentUser.IsPublic() ? "ContextLeaveTheGroup(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });
            }

            if (infoObj != null)
            {
                // Display Manage the group link if user is logged as group administrator and user is visiting a group page
                if (currentUser.IsGroupAdministrator(requestedGroupId) || currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
                {
                    string managementUrl = ResolveUrl(DocumentURLProvider.GetUrl(ModuleCommands.CommunityGetGroupManagementPath(infoObj.ObjectCodeName, SiteContext.CurrentSiteName)));

                    table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".managegroup|group.managegroup"), !currentUser.IsPublic() ? " window.location.replace('" + managementUrl + "');" : "ContextRedirectToSignInUrl()" });
                }
            }
        }

        // Add count column
        DataColumn countColumn = new DataColumn();

        countColumn.ColumnName   = "Count";
        countColumn.DefaultValue = table.Rows.Count;

        table.Columns.Add(countColumn);
        repItem.DataSource = table;
        repItem.DataBind();
    }
コード例 #5
0
ファイル: Shortcuts.ascx.cs プロジェクト: v-jli/jean0407large
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            // Initialize properties
            string script = "";

            // Set current user
            currentUser = CMSContext.CurrentUser;

            // Get Enable Friends setting
            bool friendsEnabled = UIHelper.IsFriendsModuleEnabled(CMSContext.CurrentSiteName);

            // Initialize strings
            lnkSignIn.Text = SignInText;
            lnkJoinCommunity.Text = JoinCommunityText;
            lnkMyProfile.Text = MyProfileText;
            lnkEditMyProfile.Text = EditMyProfileText;
            btnSignOut.Text = SignOutText;
            lnkCreateNewGroup.Text = CreateNewGroupText;
            lnkCreateNewBlog.Text = CreateNewBlogText;
            lnkJoinGroup.Text = JoinGroupText;
            lnkLeaveGroup.Text = LeaveGroupText;
            lnkRejectFriendship.Text = RejectFriendshipText;
            requestFriendshipElem.LinkText = RequestFriendshipText;
            lnkSendMessage.Text = SendMessageText;
            lnkAddToContactList.Text = AddToContactListText;
            lnkAddToIgnoreList.Text = AddToIgnoreListText;
            lnkInviteToGroup.Text = InviteGroupText;
            lnkManageGroup.Text = ManageGroupText;
            lnkMyMessages.Text = MyMessagesText;
            lnkMyFriends.Text = MyFriendsText;
            lnkMyInvitations.Text = MyInvitationsText;
            lnkMyTasks.Text = MyTasksText;

            // If current user is public...
            if (currentUser.IsPublic())
            {
                // Display Sign In link if set so
                if (DisplaySignIn)
                {
                    // SignInPath returns URL - because of settings value
                    lnkSignIn.NavigateUrl = CMSContext.ResolveCurrentPath(SignInPath);
                    pnlSignIn.Visible = true;
                    pnlSignInOut.Visible = true;
                }

                // Display Join the community link if set so
                if (DisplayJoinCommunity)
                {
                    lnkJoinCommunity.NavigateUrl = GetUrl(JoinCommunityPath);
                    pnlJoinCommunity.Visible = true;
                    pnlPersonalLinks.Visible = true;
                }
            }
            // If user is logged in
            else
            {
                // Display Sign out link if set so
                if (DisplaySignOut && !RequestHelper.IsWindowsAuthentication())
                {
                    pnlSignOut.Visible = true;
                    pnlSignInOut.Visible = true;
                }

                // Display Edit my profile link if set so
                if (DisplayEditMyProfileLink)
                {
                    lnkEditMyProfile.NavigateUrl = URLHelper.ResolveUrl(TreePathUtils.GetUrl(GroupMemberInfoProvider.GetMemberManagementPath(currentUser.UserName, CMSContext.CurrentSiteName)));
                    pnlEditMyProfile.Visible = true;
                    pnlProfileLinks.Visible = true;
                }

                // Display My profile link if set so
                if (DisplayMyProfileLink)
                {
                    lnkMyProfile.NavigateUrl = URLHelper.ResolveUrl(TreePathUtils.GetUrl(GroupMemberInfoProvider.GetMemberProfilePath(currentUser.UserName, CMSContext.CurrentSiteName)));
                    pnlMyProfile.Visible = true;
                    pnlProfileLinks.Visible = true;
                }

                // Display Create new group link if set so
                if (DisplayCreateNewGroup)
                {
                    lnkCreateNewGroup.NavigateUrl = GetUrl(CreateNewGroupPath);
                    pnlCreateNewGroup.Visible = true;
                    pnlGroupLinks.Visible = true;
                }

                // Display Create new blog link if set so
                if (DisplayCreateNewBlog)
                {
                    // Check that Community Module is present
                    ModuleEntry entry = ModuleEntry.GetModuleEntry(ModuleEntry.BLOGS);
                    if (entry != null)
                    {
                        lnkCreateNewBlog.NavigateUrl = GetUrl(CreateNewBlogPath);
                        pnlCreateNewBlog.Visible = true;
                        pnlBlogLinks.Visible = true;
                    }
                }

                // Display My messages link
                if (DisplayMyMessages)
                {
                    lnkMyMessages.NavigateUrl = GetUrl(MyMessagesPath);
                    pnlMyMessages.Visible = true;
                    pnlPersonalLinks.Visible = true;
                }

                // Display My friends link
                if (DisplayMyFriends && friendsEnabled)
                {
                    lnkMyFriends.NavigateUrl = GetUrl(MyFriendsPath);
                    pnlMyFriends.Visible = true;
                    pnlPersonalLinks.Visible = true;
                }

                // Display My invitations link
                if (DisplayMyInvitations)
                {
                    lnkMyInvitations.NavigateUrl = GetUrl(MyInvitationsPath);
                    pnlMyInvitations.Visible = true;
                    pnlPersonalLinks.Visible = true;
                }

                // Display My tasks link
                if (DisplayMyTasks)
                {
                    lnkMyTasks.NavigateUrl = GetUrl(MyTasksPath);
                    pnlMyTasks.Visible = true;
                    pnlPersonalLinks.Visible = true;
                }

                GroupMemberInfo gmi = null;

                if (CommunityContext.CurrentGroup != null)
                {
                    // Get group info from community context
                    GroupInfo currentGroup = CommunityContext.CurrentGroup;

                    if (DisplayGroupLinks)
                    {
                        script += "function ReloadPage(){" + ControlsHelper.GetPostBackEventReference(this, "") + "}";

                        // Display Join group link if set so and user is visiting a group page
                        gmi = GetGroupMember(CMSContext.CurrentUser.UserID, currentGroup.GroupID);
                        if (gmi == null)
                        {
                            if (String.IsNullOrEmpty(JoinGroupPath))
                            {
                                script += "function JoinToGroupRequest() {\n" +
                                "modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/JoinTheGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','requestJoinToGroup', 500, 180); \n" +
                                " } \n";

                                lnkJoinGroup.Attributes.Add("onclick", "JoinToGroupRequest();return false;");
                                lnkJoinGroup.NavigateUrl = URLHelper.CurrentURL;
                            }
                            else
                            {
                                lnkJoinGroup.NavigateUrl = GetUrl(JoinGroupPath);
                            }
                            pnlJoinGroup.Visible = true;
                            pnlGroupLinks.Visible = true;
                        }
                        else if ((gmi.MemberStatus == GroupMemberStatus.Approved) || (CMSContext.CurrentUser.IsGlobalAdministrator))
                        // Display Leave the group link if user is the group member
                        {
                            if (String.IsNullOrEmpty(LeaveGroupPath))
                            {
                                script += "function LeaveTheGroupRequest() {\n" +
                                "modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/LeaveTheGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','requestLeaveThGroup', 500, 180); \n" +
                                " } \n";

                                lnkLeaveGroup.Attributes.Add("onclick", "LeaveTheGroupRequest();return false;");
                                lnkLeaveGroup.NavigateUrl = URLHelper.CurrentURL;
                            }
                            else
                            {
                                lnkLeaveGroup.NavigateUrl = GetUrl(LeaveGroupPath);
                            }

                            pnlLeaveGroup.Visible = true;
                            pnlGroupLinks.Visible = true;
                        }
                    }

                    // Display Manage the group link if set so and user is logged as group administrator and user is visiting a group page
                    if (DisplayManageGroup && (currentUser.IsGroupAdministrator(currentGroup.GroupID) || (currentUser.IsGlobalAdministrator)))
                    {
                        lnkManageGroup.NavigateUrl = ResolveUrl(TreePathUtils.GetUrl(GroupInfoProvider.GetGroupManagementPath(currentGroup.GroupName, CMSContext.CurrentSiteName)));
                        pnlManageGroup.Visible = true;
                        pnlGroupLinks.Visible = true;
                    }
                }

                if (DisplayInviteToGroup)
                {
                    // Get group info from community context
                    GroupInfo currentGroup = CommunityContext.CurrentGroup;
                    // Get user info from site context
                    UserInfo siteContextUser = SiteContext.CurrentUser;

                    // Display invite to group link for user who is visiting a group page
                    if (currentGroup != null)
                    {
                        // Get group user
                        if (gmi == null)
                        {
                            gmi = GetGroupMember(CMSContext.CurrentUser.UserID, currentGroup.GroupID);
                        }

                        if (((gmi != null) && (gmi.MemberStatus == GroupMemberStatus.Approved)) || (CMSContext.CurrentUser.IsGlobalAdministrator))
                        {
                            pnlInviteToGroup.Visible = true;

                            if (String.IsNullOrEmpty(InviteGroupPath))
                            {
                                script += "function InviteToGroup() {\n modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/InviteToGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','inviteToGroup', 500, 345); \n } \n";
                                lnkInviteToGroup.Attributes.Add("onclick", "InviteToGroup();return false;");
                                lnkInviteToGroup.NavigateUrl = URLHelper.CurrentURL;
                            }
                            else
                            {
                                lnkInviteToGroup.NavigateUrl = GetUrl(InviteGroupPath);
                            }
                        }
                    }
                    // Display invite to group link for user who is visiting another user's page
                    else if ((siteContextUser != null) && (siteContextUser.UserName != currentUser.UserName) && (GroupInfoProvider.GetUserGroupsCount(currentUser, CMSContext.CurrentSite) != 0))
                    {
                        pnlInviteToGroup.Visible = true;

                        if (String.IsNullOrEmpty(InviteGroupPath))
                        {
                            script += "function InviteToGroup() {\n modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/InviteToGroup.aspx") + "?invitedid=" + siteContextUser.UserID + "','inviteToGroup', 500, 310); \n } \n";
                            lnkInviteToGroup.Attributes.Add("onclick", "InviteToGroup();return false;");
                            lnkInviteToGroup.NavigateUrl = URLHelper.CurrentURL;
                        }
                        else
                        {
                            lnkInviteToGroup.NavigateUrl = GetUrl(InviteGroupPath);
                        }
                    }
                }

                if (SiteContext.CurrentUser != null)
                {
                    // Get user info from site context
                    UserInfo siteContextUser = SiteContext.CurrentUser;

                    // Display Friendship link if set so and user is visiting an user's page
                    if (DisplayFriendshipLinks && (currentUser.UserID != siteContextUser.UserID) && friendsEnabled)
                    {
                        FriendshipStatusEnum status = CMSContext.CurrentUser.HasFriend(siteContextUser.UserID);
                        switch (status)
                        {
                            case FriendshipStatusEnum.Approved:
                                // Friendship rejection
                                script += "function ShortcutFriendshipReject(id) { \n" +
                                        "modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Friends/CMSPages/Friends_Reject.aspx") + "?userid=" + currentUser.UserID + "&requestid=' + id , 'rejectFriend', 410, 270); \n" +
                                        " } \n";

                                lnkRejectFriendship.Attributes.Add("onclick", "ShortcutFriendshipReject('" + siteContextUser.UserID + "');return false;");
                                lnkRejectFriendship.NavigateUrl = URLHelper.CurrentURL;
                                pnlRejectFriendship.Visible = true;
                                pnlFriendshipLinks.Visible = true;
                                break;

                            case FriendshipStatusEnum.None:
                                requestFriendshipElem.UserID = currentUser.UserID;
                                requestFriendshipElem.RequestedUserID = siteContextUser.UserID;
                                pnlFriendshipLink.Visible = true;
                                pnlFriendshipLinks.Visible = true;
                                break;
                        }
                    }

                    // Show messaging links if enabled
                    if (MessagingPresent && (currentUser.UserID != siteContextUser.UserID))
                    {
                        // Display Send message link if user is visiting an user's page
                        if (DisplaySendMessage)
                        {
                            // Send private message
                            script += "function ShortcutPrivateMessage(id) { \n" +
                                    "modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Messaging/CMSPages/SendMessage.aspx") + "?userid=" + currentUser.UserID + "&requestid=' + id , 'sendMessage', 390, 390); \n" +
                                    " } \n";

                            lnkSendMessage.Attributes.Add("onclick", "ShortcutPrivateMessage('" + siteContextUser.UserID + "');return false;");
                            lnkSendMessage.NavigateUrl = URLHelper.CurrentURL;
                            pnlSendMessage.Visible = true;
                            pnlMessageLinks.Visible = true;
                        }

                        // Display Add to contact list link if user is visiting an user's page
                        if (DisplayAddToContactList)
                        {
                            // Check if user is in contact list
                            bool isInContactList = ModuleCommands.MessagingIsInContactList(currentUser.UserID, siteContextUser.UserID);

                            // Add to actions
                            if (!isInContactList)
                            {
                                lnkAddToContactList.Attributes.Add("onclick", "return ShortcutAddToContactList('" + siteContextUser.UserID + "')");
                                lnkAddToContactList.NavigateUrl = URLHelper.CurrentURL;
                                pnlAddToContactList.Visible = true;
                                pnlMessageLinks.Visible = true;

                                // Add to contact list
                                script += "function ShortcutAddToContactList(usertoadd) { \n" +
                                        "var confirmation = confirm(" + ScriptHelper.GetString(GetString("messaging.contactlist.addconfirmation")) + ");" +
                                        "if(confirmation)" +
                                        "{" +
                                        "selectedIdElem = document.getElementById('" + hdnSelectedId.ClientID + "'); \n" +
                                        "if (selectedIdElem != null) { selectedIdElem.value = usertoadd;}" +
                                        ControlsHelper.GetPostBackEventReference(this, "addtocontactlist", false) +
                                        "} return false;}\n";
                            }
                        }

                        // Display Add to ignore list link if user is visiting an user's page
                        if (DisplayAddToIgnoreList)
                        {
                            // Check if user is in ignore list
                            bool isInIgnoreList = ModuleCommands.MessagingIsInIgnoreList(currentUser.UserID, siteContextUser.UserID);

                            // Add to ignore list
                            if (!isInIgnoreList)
                            {
                                lnkAddToIgnoreList.Attributes.Add("onclick", "return ShortcutAddToIgnoretList('" + siteContextUser.UserID + "')");
                                lnkAddToIgnoreList.NavigateUrl = URLHelper.CurrentURL;
                                pnlAddToIgnoreList.Visible = true;
                                pnlMessageLinks.Visible = true;

                                // Add to ignore list
                                script += "function ShortcutAddToIgnoretList(usertoadd) { \n" +
                                        "var confirmation = confirm(" + ScriptHelper.GetString(GetString("messaging.ignorelist.addconfirmation")) + ");" +
                                        "if(confirmation)" +
                                        "{" +
                                        "selectedIdElem = document.getElementById('" + hdnSelectedId.ClientID + "'); \n" +
                                        "if (selectedIdElem != null) { selectedIdElem.value = usertoadd;}" +
                                        ControlsHelper.GetPostBackEventReference(this, "addtoignorelist", false) +
                                        "} return false; } \n";
                            }
                        }
                    }
                }
            }

            // Register menu management scripts
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Shortcuts_" + ClientID, ScriptHelper.GetScript(script));

            // Register the dialog script
            ScriptHelper.RegisterDialogScript(this.Page);
        }
    }
コード例 #6
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Let the parent control now new message is being saved
        if (OnBeforeMessageSaved != null)
        {
            OnBeforeMessageSaved();
        }

        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("General.BannedIP");
            return;
        }

        // Validate form
        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            // Check flooding when message being inserted through the LiveSite
            if (this.CheckFloodProtection && this.IsLiveSite && FloodProtectionHelper.CheckFlooding(CMSContext.CurrentSiteName, CMSContext.CurrentUser))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("General.FloodProtection");
                return;
            }

            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            BoardMessageInfo messageInfo = null;

            if (MessageID > 0)
            {
                // Get message info
                messageInfo    = BoardMessageInfoProvider.GetBoardMessageInfo(MessageID);
                MessageBoardID = messageInfo.MessageBoardID;
            }
            else
            {
                // Create new info
                messageInfo = new BoardMessageInfo();

                // User IP adress
                messageInfo.MessageUserInfo.IPAddress = Request.UserHostAddress;
                // User agent
                messageInfo.MessageUserInfo.Agent = Request.UserAgent;
            }

            // Setup message info
            messageInfo.MessageEmail = txtEmail.Text.Trim();
            messageInfo.MessageText  = txtMessage.Text.Trim();

            // Handle message URL
            string url = txtURL.Text.Trim();
            if ((url != "http://") && (url != "https://") && (url != ""))
            {
                if ((!url.ToLower().StartsWith("http://")) && (!url.ToLower().StartsWith("https://")))
                {
                    url = "http://" + url;
                }
            }
            else
            {
                url = "";
            }
            messageInfo.MessageURL = url;
            messageInfo.MessageURL = messageInfo.MessageURL.ToLower().Replace("javascript", "_javascript");

            messageInfo.MessageUserName = this.txtUserName.Text.Trim();
            if (!currentUser.IsPublic())
            {
                messageInfo.MessageUserID = currentUser.UserID;
            }

            messageInfo.MessageIsSpam = ValidationHelper.GetBoolean(this.chkSpam.Checked, false);

            if (this.BoardProperties.EnableContentRating && (ratingControl != null) &&
                (ratingControl.GetCurrentRating() > 0))
            {
                messageInfo.MessageRatingValue = ratingControl.CurrentRating;
            }

            BoardInfo boardInfo = null;

            // If there is message board
            if (MessageBoardID > 0)
            {
                // Load message board
                boardInfo = Board;
            }
            else
            {
                // Create new message board according to webpart properties
                boardInfo = new BoardInfo(this.BoardProperties);
                BoardInfoProvider.SetBoardInfo(boardInfo);

                // Update information on current message board
                this.MessageBoardID = boardInfo.BoardID;

                // Set board-role relationship
                BoardRoleInfoProvider.SetBoardRoles(this.MessageBoardID, this.BoardProperties.BoardRoles);

                // Set moderators
                BoardModeratorInfoProvider.SetBoardModerators(this.MessageBoardID, this.BoardProperties.BoardModerators);
            }

            if (boardInfo != null)
            {
                // If the very new message is inserted
                if (this.MessageID == 0)
                {
                    // If creating message set inserted to now and assign to board
                    messageInfo.MessageInserted = currentUser.DateTimeNow;
                    messageInfo.MessageBoardID  = MessageBoardID;

                    // Handle auto approve action
                    bool isAuthorized = BoardInfoProvider.IsUserAuthorizedToManageMessages(boardInfo);
                    if (isAuthorized)
                    {
                        messageInfo.MessageApprovedByUserID = currentUser.UserID;
                        messageInfo.MessageApproved         = true;
                    }
                    else
                    {
                        // Is board moderated ?
                        messageInfo.MessageApprovedByUserID = 0;
                        messageInfo.MessageApproved         = !boardInfo.BoardModerated;
                    }
                }
                else
                {
                    if (this.chkApproved.Checked)
                    {
                        // Set current user as approver
                        messageInfo.MessageApproved         = true;
                        messageInfo.MessageApprovedByUserID = currentUser.UserID;
                    }
                    else
                    {
                        messageInfo.MessageApproved         = false;
                        messageInfo.MessageApprovedByUserID = 0;
                    }
                }

                if (!AdvancedMode)
                {
                    if (!BadWordInfoProvider.CanUseBadWords(CMSContext.CurrentUser, CMSContext.CurrentSiteName))
                    {
                        // Columns to check
                        Dictionary <string, int> collumns = new Dictionary <string, int>();
                        collumns.Add("MessageText", 0);
                        collumns.Add("MessageUserName", 250);

                        // Perform bad words check
                        errorMessage = BadWordsHelper.CheckBadWords(messageInfo, collumns, "MessageApproved", "MessageApprovedByUserID",
                                                                    messageInfo.MessageText, currentUser.UserID);

                        // Additionaly check empty fields
                        if (errorMessage == string.Empty)
                        {
                            if (!ValidateMessage(messageInfo))
                            {
                                errorMessage = GetString("board.messageedit.emptybadword");
                            }
                        }
                    }
                }

                // Subscribe this user to message board
                if (chkSubscribe.Checked)
                {
                    string email = messageInfo.MessageEmail;

                    // Check for duplicit e-mails
                    DataSet ds = BoardSubscriptionInfoProvider.GetSubscriptions("SubscriptionBoardID=" + this.MessageBoardID +
                                                                                " AND SubscriptionEmail='" + SqlHelperClass.GetSafeQueryString(email, false) + "'", null);
                    if (DataHelper.DataSourceIsEmpty(ds))
                    {
                        BoardSubscriptionInfo bsi = new BoardSubscriptionInfo();
                        bsi.SubscriptionBoardID = this.MessageBoardID;
                        bsi.SubscriptionEmail   = email;
                        if (!currentUser.IsPublic())
                        {
                            bsi.SubscriptionUserID = currentUser.UserID;
                        }
                        BoardSubscriptionInfoProvider.SetBoardSubscriptionInfo(bsi);
                        ClearForm();
                        LogSubscribingActivity(bsi, boardInfo);
                    }
                    else
                    {
                        errorMessage = GetString("board.subscription.emailexists");
                    }
                }

                if (errorMessage == "")
                {
                    try
                    {
                        // Save message info
                        BoardMessageInfoProvider.SetBoardMessageInfo(messageInfo);

                        LogCommentActivity(messageInfo, boardInfo);

                        // If the board is moderated let the user know message is waiting for approval
                        if (boardInfo.BoardModerated && (messageInfo.MessageApproved == false))
                        {
                            this.lblInfo.Text    = GetString("board.messageedit.waitingapproval");
                            this.lblInfo.Visible = true;
                        }

                        // Rise after message saved event
                        if (OnAfterMessageSaved != null)
                        {
                            OnAfterMessageSaved(messageInfo);
                        }

                        // Clear form content
                        ClearForm();
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                    }
                }
            }
        }


        if (errorMessage != "")
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
        }
        else
        {
            // Regenerate new captcha
            captchaElem.GenerateNew();
        }
    }
コード例 #7
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            // Initialize properties
            string script = "";

            // Set current user
            currentUser = MembershipContext.AuthenticatedUser;

            // Get Enable Friends setting
            bool friendsEnabled = UIHelper.IsFriendsModuleEnabled(SiteContext.CurrentSiteName);

            // Initialize strings
            lnkSignIn.Text                 = SignInText;
            lnkJoinCommunity.Text          = JoinCommunityText;
            lnkMyProfile.Text              = MyProfileText;
            lnkEditMyProfile.Text          = EditMyProfileText;
            btnSignOut.Text                = SignOutText;
            lnkCreateNewGroup.Text         = CreateNewGroupText;
            lnkCreateNewBlog.Text          = CreateNewBlogText;
            lnkJoinGroup.Text              = JoinGroupText;
            lnkLeaveGroup.Text             = LeaveGroupText;
            lnkRejectFriendship.Text       = RejectFriendshipText;
            requestFriendshipElem.LinkText = RequestFriendshipText;
            lnkSendMessage.Text            = SendMessageText;
            lnkAddToContactList.Text       = AddToContactListText;
            lnkAddToIgnoreList.Text        = AddToIgnoreListText;
            lnkInviteToGroup.Text          = InviteGroupText;
            lnkManageGroup.Text            = ManageGroupText;
            lnkMyMessages.Text             = MyMessagesText;
            lnkMyFriends.Text              = MyFriendsText;
            lnkMyInvitations.Text          = MyInvitationsText;
            lnkMyTasks.Text                = MyTasksText;

            // If current user is public...
            if (currentUser.IsPublic())
            {
                // Display Sign In link if set so
                if (DisplaySignIn)
                {
                    // SignInPath returns URL - because of settings value
                    lnkSignIn.NavigateUrl = MacroResolver.ResolveCurrentPath(SignInPath);
                    pnlSignIn.Visible     = true;
                    pnlSignInOut.Visible  = true;
                }

                // Display Join the community link if set so
                if (DisplayJoinCommunity)
                {
                    lnkJoinCommunity.NavigateUrl = GetUrl(JoinCommunityPath);
                    pnlJoinCommunity.Visible     = true;
                    pnlPersonalLinks.Visible     = true;
                }
            }
            // If user is logged in
            else
            {
                // Display Sign out link if set so
                if (DisplaySignOut && !RequestHelper.IsWindowsAuthentication())
                {
                    pnlSignOut.Visible   = true;
                    pnlSignInOut.Visible = true;
                }

                // Display Edit my profile link if set so
                if (DisplayEditMyProfileLink)
                {
                    lnkEditMyProfile.NavigateUrl = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(GroupMemberInfoProvider.GetMemberManagementPath(currentUser.UserName, SiteContext.CurrentSiteName)));
                    pnlEditMyProfile.Visible     = true;
                    pnlProfileLinks.Visible      = true;
                }

                // Display My profile link if set so
                if (DisplayMyProfileLink)
                {
                    lnkMyProfile.NavigateUrl = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(GroupMemberInfoProvider.GetMemberProfilePath(currentUser.UserName, SiteContext.CurrentSiteName)));
                    pnlMyProfile.Visible     = true;
                    pnlProfileLinks.Visible  = true;
                }

                // Display Create new group link if set so
                if (DisplayCreateNewGroup)
                {
                    lnkCreateNewGroup.NavigateUrl = GetUrl(CreateNewGroupPath);
                    pnlCreateNewGroup.Visible     = true;
                    pnlGroupLinks.Visible         = true;
                }

                // Display Create new blog link if set so
                if (DisplayCreateNewBlog)
                {
                    // Check that Community Module is present
                    var entry = ModuleManager.GetModule(ModuleName.BLOGS);
                    if (entry != null)
                    {
                        lnkCreateNewBlog.NavigateUrl = GetUrl(CreateNewBlogPath);
                        pnlCreateNewBlog.Visible     = true;
                        pnlBlogLinks.Visible         = true;
                    }
                }

                // Display My messages link
                if (DisplayMyMessages)
                {
                    lnkMyMessages.NavigateUrl = GetUrl(MyMessagesPath);
                    pnlMyMessages.Visible     = true;
                    pnlPersonalLinks.Visible  = true;
                }

                // Display My friends link
                if (DisplayMyFriends && friendsEnabled)
                {
                    lnkMyFriends.NavigateUrl = GetUrl(MyFriendsPath);
                    pnlMyFriends.Visible     = true;
                    pnlPersonalLinks.Visible = true;
                }

                // Display My invitations link
                if (DisplayMyInvitations)
                {
                    lnkMyInvitations.NavigateUrl = GetUrl(MyInvitationsPath);
                    pnlMyInvitations.Visible     = true;
                    pnlPersonalLinks.Visible     = true;
                }

                // Display My tasks link
                if (DisplayMyTasks)
                {
                    lnkMyTasks.NavigateUrl   = GetUrl(MyTasksPath);
                    pnlMyTasks.Visible       = true;
                    pnlPersonalLinks.Visible = true;
                }

                GroupMemberInfo gmi = null;

                if (CommunityContext.CurrentGroup != null)
                {
                    // Get group info from community context
                    GroupInfo currentGroup = CommunityContext.CurrentGroup;

                    if (DisplayGroupLinks)
                    {
                        script += "function ReloadPage(){" + ControlsHelper.GetPostBackEventReference(this, "") + "}";

                        // Display Join group link if set so and user is visiting a group page
                        gmi = GetGroupMember(MembershipContext.AuthenticatedUser.UserID, currentGroup.GroupID);
                        if (gmi == null)
                        {
                            if (String.IsNullOrEmpty(JoinGroupPath))
                            {
                                script += "function JoinToGroupRequest() {\n" +
                                          "modalDialog('" + AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/JoinTheGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','requestJoinToGroup', 500, 180); \n" +
                                          " } \n";

                                lnkJoinGroup.Attributes.Add("onclick", "JoinToGroupRequest();return false;");
                                lnkJoinGroup.NavigateUrl = RequestContext.CurrentURL;
                            }
                            else
                            {
                                lnkJoinGroup.NavigateUrl = GetUrl(JoinGroupPath);
                            }
                            pnlJoinGroup.Visible  = true;
                            pnlGroupLinks.Visible = true;
                        }
                        else if ((gmi.MemberStatus == GroupMemberStatus.Approved) || (MembershipContext.AuthenticatedUser.IsGlobalAdministrator))
                        // Display Leave the group link if user is the group member
                        {
                            if (String.IsNullOrEmpty(LeaveGroupPath))
                            {
                                script += "function LeaveTheGroupRequest() {\n" +
                                          "modalDialog('" + AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/LeaveTheGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','requestLeaveThGroup', 500, 180); \n" +
                                          " } \n";

                                lnkLeaveGroup.Attributes.Add("onclick", "LeaveTheGroupRequest();return false;");
                                lnkLeaveGroup.NavigateUrl = RequestContext.CurrentURL;
                            }
                            else
                            {
                                lnkLeaveGroup.NavigateUrl = GetUrl(LeaveGroupPath);
                            }

                            pnlLeaveGroup.Visible = true;
                            pnlGroupLinks.Visible = true;
                        }
                    }

                    // Display Manage the group link if set so and user is logged as group administrator and user is visiting a group page
                    if (DisplayManageGroup && (currentUser.IsGroupAdministrator(currentGroup.GroupID) || (currentUser.IsGlobalAdministrator)))
                    {
                        lnkManageGroup.NavigateUrl = ResolveUrl(DocumentURLProvider.GetUrl(GroupInfoProvider.GetGroupManagementPath(currentGroup.GroupName, SiteContext.CurrentSiteName)));
                        pnlManageGroup.Visible     = true;
                        pnlGroupLinks.Visible      = true;
                    }
                }

                if (DisplayInviteToGroup)
                {
                    // Get group info from community context
                    GroupInfo currentGroup = CommunityContext.CurrentGroup;

                    // Get user info from site context
                    UserInfo siteContextUser = MembershipContext.CurrentUserProfile;

                    // Display invite to group link for user who is visiting a group page
                    if (currentGroup != null)
                    {
                        // Get group user
                        if (gmi == null)
                        {
                            gmi = GetGroupMember(MembershipContext.AuthenticatedUser.UserID, currentGroup.GroupID);
                        }

                        if (((gmi != null) && (gmi.MemberStatus == GroupMemberStatus.Approved)) || (MembershipContext.AuthenticatedUser.IsGlobalAdministrator))
                        {
                            pnlInviteToGroup.Visible = true;

                            if (String.IsNullOrEmpty(InviteGroupPath))
                            {
                                script += "function InviteToGroup() {\n modalDialog('" + AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/InviteToGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','inviteToGroup', 800, 450); \n } \n";
                                lnkInviteToGroup.Attributes.Add("onclick", "InviteToGroup();return false;");
                                lnkInviteToGroup.NavigateUrl = RequestContext.CurrentURL;
                            }
                            else
                            {
                                lnkInviteToGroup.NavigateUrl = GetUrl(InviteGroupPath);
                            }
                        }
                    }
                    // Display invite to group link for user who is visiting another user's page
                    else if ((siteContextUser != null) && (siteContextUser.UserName != currentUser.UserName) && (GroupInfoProvider.GetUserGroupsCount(currentUser, SiteContext.CurrentSite) != 0))
                    {
                        pnlInviteToGroup.Visible = true;

                        if (String.IsNullOrEmpty(InviteGroupPath))
                        {
                            script += "function InviteToGroup() {\n modalDialog('" + AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/InviteToGroup.aspx") + "?invitedid=" + siteContextUser.UserID + "','inviteToGroup', 700, 400); \n } \n";
                            lnkInviteToGroup.Attributes.Add("onclick", "InviteToGroup();return false;");
                            lnkInviteToGroup.NavigateUrl = RequestContext.CurrentURL;
                        }
                        else
                        {
                            lnkInviteToGroup.NavigateUrl = GetUrl(InviteGroupPath);
                        }
                    }
                }

                if (SiteContext.CurrentUser != null)
                {
                    // Get user info from site context
                    UserInfo siteContextUser = MembershipContext.CurrentUserProfile;

                    // Display Friendship link if set so and user is visiting an user's page
                    if (DisplayFriendshipLinks && (currentUser.UserID != siteContextUser.UserID) && friendsEnabled)
                    {
                        FriendshipStatusEnum status = MembershipContext.AuthenticatedUser.HasFriend(siteContextUser.UserID);
                        switch (status)
                        {
                        case FriendshipStatusEnum.Approved:
                            // Friendship rejection
                            script += "function ShortcutFriendshipReject(id) { \n" +
                                      "modalDialog('" + AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Friends/CMSPages/Friends_Reject.aspx") + "?userid=" + currentUser.UserID + "&requestid=' + id , 'rejectFriend', 410, 270); \n" +
                                      " } \n";

                            lnkRejectFriendship.Attributes.Add("onclick", "ShortcutFriendshipReject('" + siteContextUser.UserID + "');return false;");
                            lnkRejectFriendship.NavigateUrl = RequestContext.CurrentURL;
                            pnlRejectFriendship.Visible     = true;
                            pnlFriendshipLinks.Visible      = true;
                            break;

                        case FriendshipStatusEnum.None:
                            requestFriendshipElem.UserID          = currentUser.UserID;
                            requestFriendshipElem.RequestedUserID = siteContextUser.UserID;
                            pnlFriendshipLink.Visible             = true;
                            pnlFriendshipLinks.Visible            = true;
                            break;
                        }
                    }

                    // Show messaging links if enabled
                    if (MessagingPresent && (currentUser.UserID != siteContextUser.UserID))
                    {
                        // Display Send message link if user is visiting an user's page
                        if (DisplaySendMessage)
                        {
                            // Send private message
                            script += "function ShortcutPrivateMessage(id) { \n" +
                                      "modalDialog('" + AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Messaging/CMSPages/SendMessage.aspx") + "?userid=" + currentUser.UserID + "&requestid=' + id , 'sendMessage', 390, 390); \n" +
                                      " } \n";

                            lnkSendMessage.Attributes.Add("onclick", "ShortcutPrivateMessage('" + siteContextUser.UserID + "');return false;");
                            lnkSendMessage.NavigateUrl = RequestContext.CurrentURL;
                            pnlSendMessage.Visible     = true;
                            pnlMessageLinks.Visible    = true;
                        }

                        // Display Add to contact list link if user is visiting an user's page
                        if (DisplayAddToContactList)
                        {
                            // Check if user is in contact list
                            bool isInContactList = ModuleCommands.MessagingIsInContactList(currentUser.UserID, siteContextUser.UserID);

                            // Add to actions
                            if (!isInContactList)
                            {
                                lnkAddToContactList.Attributes.Add("onclick", "return ShortcutAddToContactList('" + siteContextUser.UserID + "')");
                                lnkAddToContactList.NavigateUrl = RequestContext.CurrentURL;
                                pnlAddToContactList.Visible     = true;
                                pnlMessageLinks.Visible         = true;

                                // Add to contact list
                                script += "function ShortcutAddToContactList(usertoadd) { \n" +
                                          "var confirmation = confirm(" + ScriptHelper.GetString(GetString("messaging.contactlist.addconfirmation")) + ");" +
                                          "if(confirmation)" +
                                          "{" +
                                          "selectedIdElem = document.getElementById('" + hdnSelectedId.ClientID + "'); \n" +
                                          "if (selectedIdElem != null) { selectedIdElem.value = usertoadd;}" +
                                          ControlsHelper.GetPostBackEventReference(this, "addtocontactlist", false) +
                                          "} return false;}\n";
                            }
                        }

                        // Display Add to ignore list link if user is visiting an user's page
                        if (DisplayAddToIgnoreList)
                        {
                            // Check if user is in ignore list
                            bool isInIgnoreList = ModuleCommands.MessagingIsInIgnoreList(currentUser.UserID, siteContextUser.UserID);

                            // Add to ignore list
                            if (!isInIgnoreList)
                            {
                                lnkAddToIgnoreList.Attributes.Add("onclick", "return ShortcutAddToIgnoretList('" + siteContextUser.UserID + "')");
                                lnkAddToIgnoreList.NavigateUrl = RequestContext.CurrentURL;
                                pnlAddToIgnoreList.Visible     = true;
                                pnlMessageLinks.Visible        = true;

                                // Add to ignore list
                                script += "function ShortcutAddToIgnoretList(usertoadd) { \n" +
                                          "var confirmation = confirm(" + ScriptHelper.GetString(GetString("messaging.ignorelist.addconfirmation")) + ");" +
                                          "if(confirmation)" +
                                          "{" +
                                          "selectedIdElem = document.getElementById('" + hdnSelectedId.ClientID + "'); \n" +
                                          "if (selectedIdElem != null) { selectedIdElem.value = usertoadd;}" +
                                          ControlsHelper.GetPostBackEventReference(this, "addtoignorelist", false) +
                                          "} return false; } \n";
                            }
                        }
                    }
                }
            }

            // Register menu management scripts
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Shortcuts_" + ClientID, ScriptHelper.GetScript(script));

            // Register the dialog script
            ScriptHelper.RegisterDialogScript(Page);
        }
    }
コード例 #8
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Let the parent control now new message is being saved
        if (OnBeforeMessageSaved != null)
        {
            OnBeforeMessageSaved();
        }

        // Check banned IP
        if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            ShowError(GetString("General.BannedIP"));
            return;
        }

        // Validate form
        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            // Check flooding when message being inserted through the LiveSite
            if (CheckFloodProtection && IsLiveSite && FloodProtectionHelper.CheckFlooding(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser))
            {
                ShowError(GetString("General.FloodProtection"));
                return;
            }

            CurrentUserInfo currentUser = MembershipContext.AuthenticatedUser;

            BoardMessageInfo messageInfo = null;

            if (MessageID > 0)
            {
                // Get message info
                messageInfo    = BoardMessageInfoProvider.GetBoardMessageInfo(MessageID);
                MessageBoardID = messageInfo.MessageBoardID;
            }
            else
            {
                // Create new info
                messageInfo = new BoardMessageInfo();

                // User IP address
                messageInfo.MessageUserInfo.IPAddress = RequestContext.UserHostAddress;
                // User agent
                messageInfo.MessageUserInfo.Agent = Request.UserAgent;
            }

            // Setup message info
            messageInfo.MessageEmail = txtEmail.Text.Trim();
            messageInfo.MessageText  = txtMessage.Text.Trim();

            // Handle message URL
            string url = txtURL.Text.Trim();
            if ((url != "http://") && (url != "https://") && (url != ""))
            {
                if ((!url.ToLowerCSafe().StartsWithCSafe("http://")) && (!url.ToLowerCSafe().StartsWithCSafe("https://")))
                {
                    url = "http://" + url;
                }
            }
            else
            {
                url = "";
            }
            messageInfo.MessageURL = url;
            messageInfo.MessageURL = messageInfo.MessageURL.ToLowerCSafe().Replace("javascript", "_javascript");

            messageInfo.MessageUserName = txtUserName.Text.Trim();
            if ((MessageID <= 0) && (!currentUser.IsPublic()))
            {
                messageInfo.MessageUserID = currentUser.UserID;
            }

            messageInfo.MessageIsSpam = ValidationHelper.GetBoolean(chkSpam.Checked, false);

            if (BoardProperties.EnableContentRating && (ratingControl != null) &&
                (ratingControl.GetCurrentRating() > 0))
            {
                messageInfo.MessageRatingValue = ratingControl.CurrentRating;

                // Remember rating in cookie
                string docs = CookieHelper.GetValue(CookieName.RatedDocuments) ?? "|";
                if (!docs.Contains("|" + DocumentContext.CurrentDocument.DocumentID + "|"))
                {
                    docs += DocumentContext.CurrentDocument.DocumentID + "|";

                    // Actualize the cookie
                    CookieHelper.SetValue(CookieName.RatedDocuments, docs, DateTime.Now.AddYears(1));
                }
            }

            BoardInfo boardInfo = null;

            // If there is message board
            if (MessageBoardID > 0)
            {
                // Load message board
                boardInfo = Board;
            }
            else
            {
                // Create new message board according to webpart properties
                boardInfo = new BoardInfo(BoardProperties);
                BoardInfoProvider.SetBoardInfo(boardInfo);

                // Update information on current message board
                MessageBoardID = boardInfo.BoardID;

                // Set board-role relationship
                BoardRoleInfoProvider.SetBoardRoles(MessageBoardID, BoardProperties.BoardRoles);

                // Set moderators
                BoardModeratorInfoProvider.SetBoardModerators(MessageBoardID, BoardProperties.BoardModerators);
            }

            if (boardInfo != null)
            {
                // If the very new message is inserted
                if (MessageID == 0)
                {
                    // If creating message set inserted to now and assign to board
                    messageInfo.MessageInserted = currentUser.DateTimeNow;
                    messageInfo.MessageBoardID  = MessageBoardID;

                    // Handle auto approve action
                    bool isAuthorized = BoardInfoProvider.IsUserAuthorizedToManageMessages(boardInfo);
                    if (isAuthorized)
                    {
                        messageInfo.MessageApprovedByUserID = currentUser.UserID;
                        messageInfo.MessageApproved         = true;
                    }
                    else
                    {
                        // Is board moderated ?
                        messageInfo.MessageApprovedByUserID = 0;
                        messageInfo.MessageApproved         = !boardInfo.BoardModerated;
                    }
                }
                else
                {
                    if (chkApproved.Checked)
                    {
                        // Set current user as approver
                        messageInfo.MessageApproved         = true;
                        messageInfo.MessageApprovedByUserID = currentUser.UserID;
                    }
                    else
                    {
                        messageInfo.MessageApproved         = false;
                        messageInfo.MessageApprovedByUserID = 0;
                    }
                }

                if (!AdvancedMode)
                {
                    if (!BadWordInfoProvider.CanUseBadWords(MembershipContext.AuthenticatedUser, SiteContext.CurrentSiteName))
                    {
                        // Columns to check
                        Dictionary <string, int> collumns = new Dictionary <string, int>();
                        collumns.Add("MessageText", 0);
                        collumns.Add("MessageUserName", 250);

                        // Perform bad words check
                        errorMessage = BadWordsHelper.CheckBadWords(messageInfo, collumns, "MessageApproved", "MessageApprovedByUserID",
                                                                    messageInfo.MessageText, currentUser.UserID, () => { return(ValidateMessage(messageInfo)); });

                        // Additionally check empty fields
                        if (errorMessage == string.Empty)
                        {
                            if (!ValidateMessage(messageInfo))
                            {
                                errorMessage = GetString("board.messageedit.emptybadword");
                            }
                        }
                    }
                }

                // Subscribe this user to message board
                if (chkSubscribe.Checked)
                {
                    string email = messageInfo.MessageEmail;

                    // Check for duplicate e-mails
                    DataSet ds = BoardSubscriptionInfoProvider.GetSubscriptions("((SubscriptionApproved = 1) OR (SubscriptionApproved IS NULL)) AND SubscriptionBoardID=" + MessageBoardID +
                                                                                " AND SubscriptionEmail='" + SecurityHelper.GetSafeQueryString(email, false) + "'", null);
                    if (DataHelper.DataSourceIsEmpty(ds))
                    {
                        BoardSubscriptionInfo bsi = new BoardSubscriptionInfo();
                        bsi.SubscriptionBoardID = MessageBoardID;
                        bsi.SubscriptionEmail   = email;
                        if (!currentUser.IsPublic())
                        {
                            bsi.SubscriptionUserID = currentUser.UserID;
                        }
                        BoardSubscriptionInfoProvider.Subscribe(bsi, DateTime.Now, true, true);
                        ClearForm();

                        if (bsi.SubscriptionApproved)
                        {
                            LogSubscribingActivity(bsi, boardInfo);
                        }
                    }
                    else
                    {
                        errorMessage = GetString("board.subscription.emailexists");
                    }
                }

                if (errorMessage == "")
                {
                    try
                    {
                        // Save message info
                        BoardMessageInfoProvider.SetBoardMessageInfo(messageInfo);

                        LogCommentActivity(messageInfo, boardInfo);

                        if (BoardProperties.EnableContentRating && (ratingControl != null) && (ratingControl.GetCurrentRating() > 0))
                        {
                            LogRatingActivity(ratingControl.CurrentRating);
                        }

                        // If the message is not approved let the user know message is waiting for approval
                        if (messageInfo.MessageApproved == false)
                        {
                            ShowError(GetString("board.messageedit.waitingapproval"));
                        }

                        // Rise after message saved event
                        if (OnAfterMessageSaved != null)
                        {
                            OnAfterMessageSaved(messageInfo);
                        }

                        // Hide message form if user has rated and empty rating is not allowed
                        if (!BoardProperties.AllowEmptyRating && TreeProvider.HasRated(DocumentContext.CurrentDocument))
                        {
                            pnlMessageEdit.Visible  = false;
                            lblAlreadyrated.Visible = true;
                        }
                        else
                        {
                            // Hide rating form if user has rated
                            if (BoardProperties.EnableContentRating && (ratingControl != null) && ratingControl.GetCurrentRating() > 0)
                            {
                                plcRating.Visible = false;
                            }
                        }

                        // Clear form content
                        ClearForm();
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                    }
                }
            }
        }


        if (!String.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
        }
    }
コード例 #9
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData()
    {
        requestedUserId = ValidationHelper.GetInteger(ContextMenu.Parameter, 0);

        DataTable table = new DataTable();

        table.Columns.Add("ActionDisplayName");
        table.Columns.Add("ActionScript");

        // Get resource strings prefix
        string resourcePrefix = ContextMenu.ResourcePrefix;

        // Add only if community is present
        if (CommunityPresent)
        {
            // Friendship request
            if ((requestedUserId != currentUser.UserID) && UIHelper.IsFriendsModuleEnabled(SiteContext.CurrentSiteName))
            {
                FriendshipStatusEnum status = currentUser.HasFriend(requestedUserId);
                bool authenticated          = AuthenticationHelper.IsAuthenticated();

                // If friendship exists add reject action or request friendship
                if (status == FriendshipStatusEnum.Approved)
                {
                    table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".rejectfriendship|friends.rejectfriendship"), authenticated ? "ContextFriendshipReject(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });
                }
                else if ((status == FriendshipStatusEnum.None) || currentUser.IsPublic())
                {
                    table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".requestfriendship|friends.requestfriendship"), authenticated ? "ContextFriendshipRequest(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });
                }

                // Group invitation
                table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".invite|groupinvitation.invite"), authenticated ? "ContextGroupInvitation(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });
            }
        }

        // Add only if messaging is present
        if (MessagingPresent)
        {
            // Check if user is in ignore list
            isInIgnoreList = ModuleCommands.MessagingIsInIgnoreList(currentUser.UserID, requestedUserId);

            // Check if user is in contact list
            isInContactList = ModuleCommands.MessagingIsInContactList(currentUser.UserID, requestedUserId);
            bool authenticated = AuthenticationHelper.IsAuthenticated();

            table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".sendmessage|sendmessage.sendmessage"), authenticated ? "ContextPrivateMessage(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });

            // Not for the same user
            if (requestedUserId != currentUser.UserID)
            {
                // Add to ignore list or add to contact list actions
                if (!isInIgnoreList)
                {
                    table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".addtoignorelist|messsaging.addtoignorelist"), authenticated ? "ContextAddToIgnoretList(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });
                }

                if (!isInContactList)
                {
                    table.Rows.Add(new object[] { ResHelper.GetString(resourcePrefix + ".addtocontactlist|messsaging.addtocontactlist"), authenticated ? "ContextAddToContactList(GetContextMenuParameter('" + ContextMenu.MenuID + "'))" : "ContextRedirectToSignInUrl()" });
                }
            }
        }

        // Add count column
        DataColumn countColumn = new DataColumn();

        countColumn.ColumnName   = "Count";
        countColumn.DefaultValue = table.Rows.Count;

        table.Columns.Add(countColumn);
        repItem.DataSource = table;
        repItem.DataBind();
    }
コード例 #10
0
    /// <summary>
    /// Checks whether user is authorized per project access.
    /// </summary>
    public bool IsAuthorizedPerProjectAccess()
    {
        // Keep current user
        CurrentUserInfo cui = CMSContext.CurrentUser;

        // Switch by create project option
        switch (ProjectAccess.ToLowerCSafe())
        {
        // All users
        case "all":
            return(true);

        // Authenticated users
        case "authenticated":
            if (!cui.IsPublic())
            {
                return(true);
            }
            break;

        // Group members
        case "groupmember":
            if (CommunityGroupID > 0)
            {
                return(cui.IsGroupMember(CommunityGroupID));
            }
            break;

        // Authorized roles
        case "authorized":
            // Check whether roles are defined
            if (!String.IsNullOrEmpty(AuthorizedRoles))
            {
                // Check whether user is valid group member if current project is assigned to some group
                if (CommunityGroupID > 0)
                {
                    if (!cui.IsGroupMember(CommunityGroupID))
                    {
                        return(false);
                    }
                }

                // Keep site name
                string siteName = CMSContext.CurrentSiteName;
                // Split roles by semicolon
                string[] roles = AuthorizedRoles.Split(';');

                // Loop thru all roles and check if user is assigned at leat to one role
                foreach (string role in roles)
                {
                    // If user is in role, break current cycle and return true
                    if (cui.IsInRole(role, siteName))
                    {
                        return(true);
                    }
                }
            }
            break;

        // Nobody
        case "nobody":
        default:
            return(false);
        }

        return(false);
    }
コード例 #11
0
    /// <summary>
    /// Adds product to the shopping cart.
    /// </summary>
    private void AddProductToShoppingCart()
    {
        // Validate input data
        if (!IsValid() || (this.SKU == null))
        {
            // Do not proces
            return;
        }

        if (this.RedirectToDetailsEnabled)
        {
            if (!this.ShowProductOptions && !this.ShowDonationProperties)
            {
                // Does product have some enabled product option categories?
                bool hasOptions = !DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetSKUOptionCategories(this.SKUID, true));

                // Is product a customizable donation?
                bool isCustomizableDonation = ((this.SKU != null) &&
                                               (this.SKU.SKUProductType == SKUProductTypeEnum.Donation) &&
                                               (!((this.SKU.SKUPrice == this.SKU.SKUMinPrice) && (this.SKU.SKUPrice == this.SKU.SKUMaxPrice)) || this.SKU.SKUPrivateDonation));

                if (hasOptions || isCustomizableDonation)
                {
                    // Redirect to product details
                    URLHelper.Redirect("~/CMSPages/GetProduct.aspx?productid=" + this.SKUID);
                }
            }
        }

        // Get cart item parameters
        ShoppingCartItemParameters cartItemParams = this.GetShoppingCartItemParameters();

        // Check if it is possible to add this item to shopping cart
        if (!ShoppingCartInfoProvider.CheckNewShoppingCartItems(this.ShoppingCart, cartItemParams))
        {
            // Show error message and cancel adding the product to shopping cart
            string error = String.Format(this.GetString("ecommerce.cartcontent.productdisabled"), this.SKU.SKUName);
            ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "ShoppingCartAddItemErrorAlert", ScriptHelper.GetAlertScript(error));
            return;
        }

        // If donation properties are used and donation properties form is not valid
        if (this.donationProperties.Visible && !String.IsNullOrEmpty(this.donationProperties.Validate()))
        {
            return;
        }

        // Fire on add to shopping cart event
        CancelEventArgs eventArgs = new CancelEventArgs();

        if (this.OnAddToShoppingCart != null)
        {
            this.OnAddToShoppingCart(this, eventArgs);
        }

        // If adding to shopping cart was cancelled
        if (eventArgs.Cancel)
        {
            return;
        }

        // Get cart item parameters in case something changed
        cartItemParams = this.GetShoppingCartItemParameters();

        // Log activity
        LogProductAddedToSCActivity(this.SKUID, this.SKU.SKUName, this.Quantity);

        if (this.ShoppingCart != null)
        {
            bool updateCart = false;

            // Assign current shopping cart to current user
            CurrentUserInfo ui = CMSContext.CurrentUser;
            if (!ui.IsPublic())
            {
                this.ShoppingCart.UserInfoObj = ui;
                updateCart = true;
            }

            // Shopping cart is not saved yet
            if (this.ShoppingCart.ShoppingCartID == 0)
            {
                updateCart = true;
            }

            // Update shopping cart when required
            if (updateCart)
            {
                ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCart);
            }

            // Add item to shopping cart
            ShoppingCartItemInfo addedItem = this.ShoppingCart.SetShoppingCartItem(cartItemParams);

            if (addedItem != null)
            {
                // Update shopping cart item in database
                ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(addedItem);

                // Update product options in database
                foreach (ShoppingCartItemInfo option in addedItem.ProductOptions)
                {
                    ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
                }

                // Update bundle items in database
                foreach (ShoppingCartItemInfo bundleItem in addedItem.BundleItems)
                {
                    ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(bundleItem);
                }

                // Track 'Add to shopping cart' conversion
                ECommerceHelper.TrackAddToShoppingCartConversion(addedItem);

                // If user has to be redirected to shopping cart
                if (this.RedirectToShoppingCart)
                {
                    // Set shopping cart referrer
                    SessionHelper.SetValue("ShoppingCartUrlReferrer", URLHelper.CurrentURL);

                    // Ensure shopping cart update
                    SessionHelper.SetValue("checkinventory", true);

                    // Redirect to shopping cart
                    URLHelper.Redirect(this.ShoppingCartUrl);
                }
                else
                {
                    // Localize SKU name
                    string skuName = (addedItem.SKUObj != null) ? ResHelper.LocalizeString(addedItem.SKUObj.SKUName) : "";

                    // Check inventory
                    string checkInventoryMessage = ShoppingCartInfoProvider.CheckShoppingCart(this.ShoppingCart).Replace(";", "\n");

                    // Get prodcut added message
                    string message = String.Format(this.GetString("com.productadded"), skuName);

                    // Add inventory check message
                    if (!String.IsNullOrEmpty(checkInventoryMessage))
                    {
                        message += "\n\n" + checkInventoryMessage;
                    }

                    // Count and show total price with options
                    CalculateTotalPrice();

                    // Register the call of JS handler informing about added product
                    ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "ShoppingCartItemAddedHandler", "if (typeof ShoppingCartItemAddedHandler == 'function') { ShoppingCartItemAddedHandler(" + ScriptHelper.GetString(message) + "); }", true);
                }
            }
        }
    }
コード例 #12
0
    /// <summary>
    /// Sets product in the shopping cart.
    /// </summary>
    /// <param name="itemParams">Shoppping cart item parameters</param>
    protected void AddProducts(ShoppingCartItemParameters itemParams)
    {
        // Get main product info
        int productId = itemParams.SKUID;
        int quantity  = itemParams.Quantity;

        if ((productId > 0) && (quantity > 0))
        {
            // Check product/options combination
            if (ShoppingCartInfoProvider.CheckNewShoppingCartItems(ShoppingCartInfoObj, itemParams))
            {
                // Get requested SKU info object from database
                SKUInfo skuObj = SKUInfoProvider.GetSKUInfo(productId);
                if (skuObj != null)
                {
                    // On the live site
                    if (!ShoppingCartControl.IsInternalOrder)
                    {
                        bool updateCart = false;

                        // Assign current shopping cart to current user
                        CurrentUserInfo ui = CMSContext.CurrentUser;
                        if (!ui.IsPublic())
                        {
                            this.ShoppingCartInfoObj.UserInfoObj = ui;
                            updateCart = true;
                        }

                        // Shopping cart is not saved yet
                        if (ShoppingCartInfoObj.ShoppingCartID == 0)
                        {
                            updateCart = true;
                        }

                        // Update shopping cart when required
                        if (updateCart)
                        {
                            ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCartInfoObj);
                        }

                        // Set item in the shopping cart
                        ShoppingCartItemInfo product = this.ShoppingCartInfoObj.SetShoppingCartItem(itemParams);

                        // Update shopping cart item in database
                        ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(product);

                        // Update product options in database
                        foreach (ShoppingCartItemInfo option in product.ProductOptions)
                        {
                            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
                        }

                        // Update bundle items in database
                        foreach (ShoppingCartItemInfo bundleItem in product.BundleItems)
                        {
                            ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(bundleItem);
                        }

                        // Track add to shopping cart conversion
                        ECommerceHelper.TrackAddToShoppingCartConversion(product);
                    }
                    // In CMSDesk
                    else
                    {
                        // Set item in the shopping cart
                        this.ShoppingCartInfoObj.SetShoppingCartItem(itemParams);
                    }
                }
            }

            // Avoid adding the same product after page refresh
            if (lblError.Text == "")
            {
                string url = URLRewriter.CurrentURL;

                if (!string.IsNullOrEmpty(URLHelper.GetUrlParameter(url, "productid")) ||
                    !string.IsNullOrEmpty(URLHelper.GetUrlParameter(url, "quantity")) ||
                    !string.IsNullOrEmpty(URLHelper.GetUrlParameter(url, "options")))
                {
                    // Remove parameters from URL
                    url = URLHelper.RemoveParameterFromUrl(url, "productid");
                    url = URLHelper.RemoveParameterFromUrl(url, "quantity");
                    url = URLHelper.RemoveParameterFromUrl(url, "options");
                    URLHelper.Redirect(url);
                }
            }
        }
    }
コード例 #13
0
    public void PerformAction()
    {
        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("General.BannedIP");
            return;
        }

        if (OnBeforeCommentSaved != null)
        {
            OnBeforeCommentSaved();
        }

        BlogCommentInfo bci = null;

        // Validate form
        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            // Check flooding when message being inserted through the LiveSite
            if (IsLiveSite && FloodProtectionHelper.CheckFlooding(CMSContext.CurrentSiteName, CMSContext.CurrentUser))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("General.FloodProtection");
                return;
            }

            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            // Create new comment
            if (IsInsertMode)
            {
                bci                       = new BlogCommentInfo();
                bci.CommentDate           = DateTime.Now;
                bci.CommentPostDocumentID = mPostDocumentId;

                // User IP address
                bci.CommentInfo.IPAddress = HTTPHelper.UserHostAddress;
                // User agent
                bci.CommentInfo.Agent = Request.UserAgent;

                if (!currentUser.IsPublic())
                {
                    bci.CommentUserID = currentUser.UserID;
                }
                bci.CommentIsTrackback = false;
            }
            // Get existing comment
            else
            {
                bci = BlogCommentInfoProvider.GetBlogCommentInfo(mCommentId);
            }

            // Update basic comment properties
            if (bci != null)
            {
                // Add http:// if needed
                string url = txtUrl.Text.Trim();
                if (url != "")
                {
                    if ((!url.ToLowerCSafe().StartsWithCSafe("http://")) && (!url.ToLowerCSafe().StartsWithCSafe("https://")))
                    {
                        url = "http://" + url;
                    }
                }

                bci.CommentIsSpam   = chkSpam.Checked;
                bci.CommentApproved = chkApproved.Checked;
                bci.CommentUserName = txtName.Text.Trim();
                bci.CommentUrl      = url;
                bci.CommentText     = txtComments.Text.Trim();
                bci.CommentUrl      = bci.CommentUrl.ToLowerCSafe().Replace("javascript", "_javascript");
                bci.CommentEmail    = txtEmail.Text.Trim();
            }

            if (IsInsertMode)
            {
                // Auto approve owner comments
                if (bci != null)
                {
                    TreeNode blogNode = BlogHelper.GetParentBlog(bci.CommentPostDocumentID, false);
                    if ((currentUser != null) && (blogNode != null))
                    {
                        bool isAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode);
                        if (isAuthorized)
                        {
                            bci.CommentApprovedByUserID = blogNode.NodeOwner;
                            bci.CommentApproved         = true;
                        }
                        else
                        {
                            // Is blog moderated ?
                            bool moderated = ValidationHelper.GetBoolean(blogNode.GetValue("BlogModerateComments"), false);

                            bci.CommentApprovedByUserID = 0;
                            bci.CommentApproved         = !moderated;
                        }
                    }
                }
            }

            // Perform bad words check
            if (!BadWordInfoProvider.CanUseBadWords(CMSContext.CurrentUser, CMSContext.CurrentSiteName))
            {
                if (bci != null)
                {
                    // Prepare columns to check
                    Dictionary <string, int> columns = new Dictionary <string, int>();
                    columns.Add("CommentText", 0);
                    columns.Add("CommentUserName", 200);

                    // Perform bad words to check
                    errorMessage = BadWordsHelper.CheckBadWords(bci, columns, "CommentApproved", "CommentApprovedByUserID", bci.CommentText, CMSContext.CurrentUser.UserID, () => { return(ValidateComment(bci)); });
                }
            }

            if (errorMessage == string.Empty)
            {
                if (bci != null)
                {
                    if (!ValidateComment(bci))
                    {
                        // Show error message
                        lblError.Visible = true;
                        lblError.Text    = GetString("Blog.CommentEdit.EmptyBadWord");
                    }
                    else
                    {
                        // Subscribe new subscriber
                        if (chkSubscribe.Checked)
                        {
                            BlogPostSubscriptionInfo bpsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(txtEmail.Text, mPostDocumentId);

                            // Check for duplicit subscriptions
                            if ((bpsi == null) || !bpsi.SubscriptionApproved)
                            {
                                bpsi = new BlogPostSubscriptionInfo();
                                bpsi.SubscriptionEmail          = txtEmail.Text;
                                bpsi.SubscriptionPostDocumentID = mPostDocumentId;
                                bpsi.SubscriptionUserID         = bci.CommentUserID;
                                BlogPostSubscriptionInfoProvider.Subscribe(bpsi, DateTime.Now, true, true);

                                if (bpsi.SubscriptionApproved)
                                {
                                    LogRegistrationActivity(bpsi);
                                }
                            }
                            else
                            {
                                errorMessage = GetString("blog.subscription.emailexists");
                            }
                        }

                        if (errorMessage == "")
                        {
                            // Save changes to database
                            BlogCommentInfoProvider.SetBlogCommentInfo(bci);

                            if (!bci.CommentApproved)
                            {
                                CommentSavedText = GetString("blog.comments.requiresmoderationafteraction");
                            }

                            // Inform user
                            lblInfo.Visible = true;
                            lblInfo.Text    = CommentSavedText;

                            // Clear form when required
                            if (mClearFormAfterSave)
                            {
                                txtComments.Text  = "";
                                txtUrl.Text       = "";
                                ctrlCaptcha.Value = "";
                            }

                            LogCommentActivity(bci, PostNodeId, PostCulture);

                            if (OnAfterCommentSaved != null)
                            {
                                OnAfterCommentSaved(bci);
                            }
                        }
                    }
                }
            }
        }

        if (errorMessage != "")
        {
            // Show error message
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
        else
        {
            // Regenerate captcha code when comment saved successfully
            ctrlCaptcha.GenerateNew();
        }
    }
コード例 #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        mOkButtonText     = GetString("general.add");
        mCommentSavedText = GetString("Blog.CommentEdit.CommentSaved");

        // Basic control initialization
        lblName.Text     = GetString("Blog.CommentEdit.lblName");
        lblUrl.Text      = GetString("Blog.CommentEdit.lblUrl");
        lblComments.Text = GetString("Blog.CommentEdit.lblComments");
        btnOk.Text       = mOkButtonText;

        // Validators initialization
        rfvComments.ErrorMessage   = GetString("Blog.CommentEdit.CommentEmpty");
        rfvName.ErrorMessage       = GetString("Blog.CommentEdit.NameEmpty");
        revEmailValid.ErrorMessage = GetString("general.correctemailformat");
        rfvEmail.ErrorMessage      = GetString("blog.commentedit.rfvemail");
        rfvEmail.Enabled           = RequireEmails;

        // Show or hide security code control
        plcCaptcha.Visible = mUseCaptcha;

        lblApproved.Text = GetString("Blog.CommentEdit.Approved");
        lblSpam.Text     = GetString("Blog.CommentEdit.Spam");
        lblInserted.Text = GetString("Blog.CommentEdit.Inserted");

        revEmailValid.ValidationExpression = ValidationHelper.EmailRegExp.ToString();

        plcChkSubscribe.Visible = EnableSubscriptions;

        revEmailValid.ValidationGroup = ValidationGroup;
        rfvComments.ValidationGroup   = ValidationGroup;
        rfvEmail.ValidationGroup      = ValidationGroup;
        rfvName.ValidationGroup       = ValidationGroup;
        btnOk.ValidationGroup         = ValidationGroup;

        if (!RequestHelper.IsPostBack())
        {
            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            // New comment
            if (IsInsertMode)
            {
                // Prefill current user fullname
                if ((currentUser != null) && (!currentUser.IsPublic()))
                {
                    txtName.Text  = currentUser.UserNickName != "" ? currentUser.UserNickName : currentUser.FullName;
                    txtEmail.Text = currentUser.Email;
                }
            }
            // Existing comment
            else
            {
                LoadCommentData();
            }

            // Advaced mode in CMSDesk
            if (AdvancedMode)
            {
                plcAdvancedMode.Visible = true;
            }
        }

        // Ensure information is displayed to the user
        bool savedRequiresApprove = QueryHelper.GetBoolean("saveda", false);
        bool saved = QueryHelper.GetBoolean("saved", false);

        if (saved || savedRequiresApprove)
        {
            if (savedRequiresApprove)
            {
                CommentSavedText = GetString("blog.comments.requiresmoderationafteraction");
            }

            lblInfo.Text    = CommentSavedText;
            lblInfo.Visible = true;
        }
    }
コード例 #15
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public void ReloadData()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            // WAI validation
            lblText.AssociatedControlClientID = ucBBEditor.TextArea.ClientID;

            // Default settings
            pnlSendMessage.Visible = true;
            pnlNoUser.Visible      = false;

            if (currentUser.IsAuthenticated() || AllowAnonymousUsers)
            {
                // Decide if the user is anonymous
                isAnonymousUser = currentUser.IsPublic();

                // Change controls
                if (isAnonymousUser)
                {
                    lblFrom.Visible = false;
                    txtFrom.Visible = true;
                }
                else
                {
                    lblFrom.Visible = true;
                    lblFrom.Text    = HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(currentUser.UserName, currentUser.FullName, currentUser.UserNickName, IsLiveSite));
                    txtFrom.Visible = false;
                }

                // Reacting on the message
                // Get message
                if (Message != null)
                {
                    UserInfo sender = UserInfoProvider.GetUserInfo(Message.MessageSenderUserID);
                    // Reply
                    switch (SendMessageMode)
                    {
                    case MessageActionEnum.Reply:
                        if (sender != null)
                        {
                            hdnUserId.Value = sender.UserID.ToString();

                            // Check if postback wasn't caused by send button to avoid overriding values
                            if (ControlsHelper.GetPostBackControl(Page) != btnSendMessage)
                            {
                                // Set message subject
                                MessageSubject += Message.MessageSubject;
                                // Set message body
                                if (currentUser.UserSignature.Trim() != string.Empty)
                                {
                                    MessageBody += "\n\n\n" + currentUser.UserSignature;
                                }
                                if (PasteOriginalMessage)
                                {
                                    MessageBody += "\n\n// " + Message.MessageBody.Replace("\n", "\n// ");
                                }
                            }

                            // Set recipient
                            lblTo.Text    = HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(sender.UserName, sender.FullName, sender.UserNickName, IsLiveSite));
                            lblTo.Visible = true;
                            ucMessageUserSelector.Visible = false;
                        }
                        else
                        {
                            pnlNoUser.Visible      = true;
                            pnlSendMessage.Visible = false;
                            lblNoUser.Text         = GetString("SendMessage.NoUser");
                        }
                        break;

                    case MessageActionEnum.Forward:
                        // Check if postback wasn't caused by send button to avoid overriding values
                        if (ControlsHelper.GetPostBackControl(Page) != btnSendMessage)
                        {
                            MessageSubject += Message.MessageSubject;
                            string signature = (currentUser.UserSignature.Trim() != "") ? "\n\n\n" + currentUser.UserSignature : "";
                            MessageBody += signature + "\n\n// " + Message.MessageBody.Replace("\n", "\n//");
                        }

                        lblTo.Visible = false;
                        ucMessageUserSelector.Visible = true;
                        break;
                    }
                }
                // New message
                else if (SendMessageMode == MessageActionEnum.New)
                {
                    if (DefaultRecipient != "")
                    {
                        lblTo.Visible = true;
                        ucMessageUserSelector.Visible = false;

                        // Get default recipient name
                        string userName = UserInfoProvider.GetUserNameById(ValidationHelper.GetInteger(DefaultRecipient, 0));
                        userName = Functions.GetFormattedUserName(userName, IsLiveSite);

                        lblTo.Text      = HTMLHelper.HTMLEncode(userName);
                        hdnUserId.Value = DefaultRecipient;
                    }
                    else
                    {
                        lblTo.Visible = false;
                        if (isAnonymousUser)
                        {
                            ucMessageUserSelector.Visible = AllowAnonymousRecipientSelection;
                        }
                        else
                        {
                            ucMessageUserSelector.Visible = true;
                        }
                    }

                    // Add signature
                    if (!isAnonymousUser)
                    {
                        if (currentUser.UserSignature.Trim() != "")
                        {
                            MessageBody += "\n\n\n" + currentUser.UserSignature;
                        }
                    }
                }

                // Initialize subject and body
                if (txtSubject.Text == string.Empty)
                {
                    txtSubject.Text = MessageSubject;
                }
                if (ucBBEditor.Text == string.Empty)
                {
                    ucBBEditor.Text = MessageBody;
                }
            }
            else
            {
                Visible = false;
            }
        }
    }
コード例 #16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check license
        if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, string.Empty) != string.Empty)
        {
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.Friends);
        }

        userId      = QueryHelper.GetInteger("userid", 0);
        currentUser = MembershipContext.AuthenticatedUser;
        int requestedId  = QueryHelper.GetInteger("requestid", 0);
        int friendshipId = 0;

        // Check if request is for current user or another user with permission to manage it
        if (currentUser.IsPublic() || ((currentUser.UserID != userId) && !currentUser.IsAuthorizedPerResource("CMS.Friends", "Manage")))
        {
            RedirectToAccessDenied("CMS.Friends", "Manage");
        }

        FriendsApprove.SelectedFriends = null;
        FriendsApprove.IsLiveSite      = true;

        PageTitle.TitleText = GetString("friends.approvefriendship");
        // Multiple selection
        if (Request["ids"] != null)
        {
            string[] items = Request["ids"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            if (items.Length > 0)
            {
                ArrayList friends = new ArrayList();
                foreach (string item in items)
                {
                    friends.Add(ValidationHelper.GetInteger(item, 0));
                }
                FriendsApprove.SelectedFriends = friends;
                if (friends.Count == 1)
                {
                    friendshipId = Convert.ToInt32(friends[0]);
                }
            }
        }
        // For one user
        else
        {
            FriendsApprove.RequestedUserID = requestedId;
        }

        FriendInfo fi = null;

        if (friendshipId != 0)
        {
            fi = FriendInfoProvider.GetFriendInfo(friendshipId);
            // Set edited object
            EditedObject = fi;
        }
        else if (requestedId != 0)
        {
            fi = FriendInfoProvider.GetFriendInfo(userId, requestedId);
            // Set edited object
            EditedObject = fi;
        }

        if (fi != null)
        {
            UserInfo requestedUser = (userId == fi.FriendRequestedUserID) ? UserInfoProvider.GetFullUserInfo(fi.FriendUserID) : UserInfoProvider.GetFullUserInfo(fi.FriendRequestedUserID);
            string   fullUserName  = Functions.GetFormattedUserName(requestedUser.UserName, requestedUser.FullName, requestedUser.UserNickName, true);
            Page.Title          = GetString("friends.approvefriendshipwith") + " " + HTMLHelper.HTMLEncode(fullUserName);
            PageTitle.TitleText = Page.Title;
        }

        // Set current user
        FriendsApprove.UserID = userId;
    }
コード例 #17
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            // Initialize properties
            string script = "";

            // Set current user
            currentUser = MembershipContext.AuthenticatedUser;

            // Initialize strings
            lnkSignIn.Text         = SignInText;
            lnkJoinCommunity.Text  = JoinCommunityText;
            lnkMyProfile.Text      = MyProfileText;
            lnkEditMyProfile.Text  = EditMyProfileText;
            btnSignOut.Text        = SignOutText;
            lnkCreateNewGroup.Text = CreateNewGroupText;
            lnkCreateNewBlog.Text  = CreateNewBlogText;
            lnkJoinGroup.Text      = JoinGroupText;
            lnkLeaveGroup.Text     = LeaveGroupText;
            lnkInviteToGroup.Text  = InviteGroupText;
            lnkManageGroup.Text    = ManageGroupText;
            lnkMyInvitations.Text  = MyInvitationsText;

            // If current user is public...
            if (currentUser.IsPublic())
            {
                // Display Sign In link if set so
                if (DisplaySignIn)
                {
                    // SignInPath returns URL - because of settings value
                    lnkSignIn.NavigateUrl = MacroResolver.ResolveCurrentPath(SignInPath);
                    pnlSignIn.Visible     = true;
                    pnlSignInOut.Visible  = true;
                }

                // Display Join the community link if set so
                if (DisplayJoinCommunity)
                {
                    lnkJoinCommunity.NavigateUrl = GetUrl(JoinCommunityPath);
                    pnlJoinCommunity.Visible     = true;
                    pnlPersonalLinks.Visible     = true;
                }
            }
            // If user is logged in
            else
            {
                // Display Sign out link if set so
                if (DisplaySignOut && !AuthenticationMode.IsWindowsAuthentication())
                {
                    pnlSignOut.Visible   = true;
                    pnlSignInOut.Visible = true;
                }

                // Display Edit my profile link if set so
                if (DisplayEditMyProfileLink)
                {
                    lnkEditMyProfile.NavigateUrl = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(GroupMemberInfoProvider.GetMemberManagementPath(currentUser.UserName, SiteContext.CurrentSiteName)));
                    pnlEditMyProfile.Visible     = true;
                    pnlProfileLinks.Visible      = true;
                }

                // Display My profile link if set so
                if (DisplayMyProfileLink)
                {
                    lnkMyProfile.NavigateUrl = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(GroupMemberInfoProvider.GetMemberProfilePath(currentUser.UserName, SiteContext.CurrentSiteName)));
                    pnlMyProfile.Visible     = true;
                    pnlProfileLinks.Visible  = true;
                }

                // Display Create new group link if set so
                if (DisplayCreateNewGroup)
                {
                    lnkCreateNewGroup.NavigateUrl = GetUrl(CreateNewGroupPath);
                    pnlCreateNewGroup.Visible     = true;
                    pnlGroupLinks.Visible         = true;
                }

                // Display Create new blog link if set so
                if (DisplayCreateNewBlog)
                {
                    // Check that Community Module is present
                    var entry = ModuleManager.GetModule(ModuleName.BLOGS);
                    if (entry != null)
                    {
                        lnkCreateNewBlog.NavigateUrl = GetUrl(CreateNewBlogPath);
                        pnlCreateNewBlog.Visible     = true;
                        pnlBlogLinks.Visible         = true;
                    }
                }

                // Display My invitations link
                if (DisplayMyInvitations)
                {
                    lnkMyInvitations.NavigateUrl = GetUrl(MyInvitationsPath);
                    pnlMyInvitations.Visible     = true;
                    pnlPersonalLinks.Visible     = true;
                }

                GroupMemberInfo gmi = null;

                if (CommunityContext.CurrentGroup != null)
                {
                    // Get group info from community context
                    GroupInfo currentGroup = CommunityContext.CurrentGroup;

                    if (DisplayGroupLinks)
                    {
                        // Display Join group link if set so and user is visiting a group page
                        gmi = GetGroupMember(MembershipContext.AuthenticatedUser.UserID, currentGroup.GroupID);
                        if (gmi == null)
                        {
                            if (String.IsNullOrEmpty(JoinGroupPath))
                            {
                                script += "function JoinToGroupRequest() {\n" +
                                          "modalDialog('" + ApplicationUrlHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/JoinTheGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','requestJoinToGroup', 500, 180); \n" +
                                          " } \n";

                                lnkJoinGroup.Attributes.Add("onclick", "JoinToGroupRequest();return false;");
                                lnkJoinGroup.NavigateUrl = RequestContext.CurrentURL;
                            }
                            else
                            {
                                lnkJoinGroup.NavigateUrl = GetUrl(JoinGroupPath);
                            }
                            pnlJoinGroup.Visible  = true;
                            pnlGroupLinks.Visible = true;
                        }
                        else if ((gmi.MemberStatus == GroupMemberStatus.Approved) || (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)))
                        // Display Leave the group link if user is the group member
                        {
                            if (String.IsNullOrEmpty(LeaveGroupPath))
                            {
                                script += "function LeaveTheGroupRequest() {\n" +
                                          "modalDialog('" + ApplicationUrlHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/LeaveTheGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','requestLeaveThGroup', 500, 180); \n" +
                                          " } \n";

                                lnkLeaveGroup.Attributes.Add("onclick", "LeaveTheGroupRequest();return false;");
                                lnkLeaveGroup.NavigateUrl = RequestContext.CurrentURL;
                            }
                            else
                            {
                                lnkLeaveGroup.NavigateUrl = GetUrl(LeaveGroupPath);
                            }

                            pnlLeaveGroup.Visible = true;
                            pnlGroupLinks.Visible = true;
                        }
                    }

                    // Display Manage the group link if set so and user is logged as group administrator and user is visiting a group page
                    if (DisplayManageGroup && (currentUser.IsGroupAdministrator(currentGroup.GroupID) || (currentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))))
                    {
                        lnkManageGroup.NavigateUrl = ResolveUrl(DocumentURLProvider.GetUrl(GroupInfoProvider.GetGroupManagementPath(currentGroup.GroupName, SiteContext.CurrentSiteName)));
                        pnlManageGroup.Visible     = true;
                        pnlGroupLinks.Visible      = true;
                    }
                }

                // Get user info from site context
                UserInfo siteContextUser = MembershipContext.CurrentUserProfile;

                if (DisplayInviteToGroup)
                {
                    // Get group info from community context
                    GroupInfo currentGroup = CommunityContext.CurrentGroup;

                    // Display invite to group link for user who is visiting a group page
                    if (currentGroup != null)
                    {
                        // Get group user
                        if (gmi == null)
                        {
                            gmi = GetGroupMember(MembershipContext.AuthenticatedUser.UserID, currentGroup.GroupID);
                        }

                        if (((gmi != null) && (gmi.MemberStatus == GroupMemberStatus.Approved)) || (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)))
                        {
                            pnlInviteToGroup.Visible = true;

                            if (String.IsNullOrEmpty(InviteGroupPath))
                            {
                                script += "function InviteToGroup() {\n modalDialog('" + ApplicationUrlHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/InviteToGroup.aspx") + "?groupid=" + currentGroup.GroupID + "','inviteToGroup', 800, 450); \n } \n";
                                lnkInviteToGroup.Attributes.Add("onclick", "InviteToGroup();return false;");
                                lnkInviteToGroup.NavigateUrl = RequestContext.CurrentURL;
                            }
                            else
                            {
                                lnkInviteToGroup.NavigateUrl = GetUrl(InviteGroupPath);
                            }
                        }
                    }
                    // Display invite to group link for user who is visiting another user's page
                    else if ((siteContextUser != null) && (siteContextUser.UserName != currentUser.UserName) && (GroupInfoProvider.GetUserGroupsCount(currentUser, SiteContext.CurrentSite) != 0))
                    {
                        pnlInviteToGroup.Visible = true;

                        if (String.IsNullOrEmpty(InviteGroupPath))
                        {
                            script += "function InviteToGroup() {\n modalDialog('" + ApplicationUrlHelper.ResolveDialogUrl("~/CMSModules/Groups/CMSPages/InviteToGroup.aspx") + "?invitedid=" + siteContextUser.UserID + "','inviteToGroup', 700, 400); \n } \n";
                            lnkInviteToGroup.Attributes.Add("onclick", "InviteToGroup();return false;");
                            lnkInviteToGroup.NavigateUrl = RequestContext.CurrentURL;
                        }
                        else
                        {
                            lnkInviteToGroup.NavigateUrl = GetUrl(InviteGroupPath);
                        }
                    }
                }
            }

            // Register menu management scripts
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Shortcuts_" + ClientID, ScriptHelper.GetScript(script));

            // Register the dialog script
            ScriptHelper.RegisterDialogScript(Page);
        }
    }