Ejemplo n.º 1
0
    public string Handler_AddTo()
    {
        StringBuilder sbRet = new StringBuilder();
            ContentAPI apiContent = new ContentAPI();
            Ektron.Cms.Community.CommunityGroupAPI apiCommunityGroup = new Ektron.Cms.Community.CommunityGroupAPI();
            Ektron.Cms.Community.FavoritesAPI apiFavorites = new Ektron.Cms.Community.FavoritesAPI();
            Ektron.Cms.Community.FriendsAPI apiFriends = new Ektron.Cms.Community.FriendsAPI();
            long iObjID = 0;
            Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes sbObjType = Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes.Content;
            string sMode = "";
            string sMsg = "";
            string sKey = "";
            string sResult = "";
            int iIdx = 0;
            bool bIsMine = false;
            long bIsMyLinkID = 0;
            string sRetMsg = "";
            bool bAuth = false;
            int iLang = 0;
            string title = "";
            string link = "";
            string action = "";
            try
            {
                iObjID = Convert.ToInt64(Request.QueryString["oid"]);
                int oType = 0;
                int.TryParse(EkFunctions.HtmlEncode(Request.QueryString["otype"]), out oType);
                switch (oType)
                {
                    case 0:
                        sbObjType = Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes.Content;
                        break;
                    case 1:
                        sbObjType = Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes.User;
                        break;
                    case 19:
                        sbObjType = Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes.CommunityGroup;
                        break;
                }

                sMode = EkFunctions.HtmlEncode(Request.QueryString["mode"]);
                sKey = EkFunctions.HtmlEncode(Request.QueryString["key"]);
                iIdx = Convert.ToInt32(Request.QueryString["idx"]);
                title = EkFunctions.HtmlEncode(Request.QueryString["title"]);
                link = EkFunctions.HtmlEncode(Request.QueryString["link"]);

                if (iObjID > 0)
                {
                    sbRet.Append("  <method>AJAX_AddTo</method>").Append(Environment.NewLine);
                }
                else if (iObjID == 0)
                {
                    sbRet.Append("  <method>AJAX_AddLinkTo</method>").Append(Environment.NewLine);
                }

                bAuth = System.Convert.ToBoolean((apiContent.LoadPermissions(0, "users", 0)).IsLoggedIn);
                if (bAuth)
                {
                    if (sbObjType == Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes.CommunityGroup)
                    {
                        Ektron.Cms.Common.EkEnumeration.GroupMemberStatus mMemberStatus = Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.NotInGroup;
                        mMemberStatus = apiCommunityGroup.GetGroupMemberStatus(iObjID, apiContent.UserId);
                        if (mMemberStatus == Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.Approved)
                        {
                            if (sMode == "remove")
                            {
                                apiCommunityGroup.RemoveUserFromCommunityGroup(iObjID, apiContent.UserId);
                                Ektron.Cms.Common.Cache.ApplicationCache.Invalidate((string) ("GroupAccess_" + iObjID.ToString() + "_" + apiContent.UserId.ToString()));
                                sMsg = apiContent.EkMsgRef.GetMessage("lbl left group");
                                sRetMsg = apiContent.EkMsgRef.GetMessage("lbl join group");
                                sResult = "1";
                            }
                            else if (sMode == "add")
                            {
                                sMsg = apiContent.EkMsgRef.GetMessage("lbl already in group");
                                sRetMsg = apiContent.EkMsgRef.GetMessage("lbl leave group");
                                sResult = "-1";
                            }
                        }
                        else if (mMemberStatus == Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.Leader)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl leader of group");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl leader of group");
                            sResult = "-1";
                        }
                        else if (mMemberStatus == Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.NotInGroup)
                        {
                            if (sMode == "remove")
                            {
                                sMsg = apiContent.EkMsgRef.GetMessage("lbl not in group");
                                sRetMsg = apiContent.EkMsgRef.GetMessage("lbl join group");
                                sResult = "-1";
                            }
                            else if (sMode == "add")
                            {
                                apiCommunityGroup.AddUserToCommunityGroup(iObjID, apiContent.UserId);
                                Ektron.Cms.Common.Cache.ApplicationCache.Invalidate((string) ("GroupAccess_" + iObjID.ToString() + "_" + apiContent.UserId.ToString()));
                                mMemberStatus = apiCommunityGroup.GetGroupMemberStatus(iObjID, apiContent.UserId);
                                if (mMemberStatus == Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.Pending)
                                {
                                    sRetMsg = apiContent.EkMsgRef.GetMessage("lbl cgroup cancel join req");
                                    sMsg = apiContent.EkMsgRef.GetMessage("lbl leave group");
                                    sResult = "0";
                                }
                                else
                                {
                                    sRetMsg = apiContent.EkMsgRef.GetMessage("lbl leave group");
                                    sMsg = apiContent.EkMsgRef.GetMessage("lbl joined group");
                                    sResult = "0";
                                }
                            }
                        }
                        else if (mMemberStatus == Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.Pending)
                        {
                            if (sMode == "remove")
                            {
                                apiCommunityGroup.CancelJoinRequestForCommunityGroup(iObjID, apiContent.UserId);
                                Ektron.Cms.Common.Cache.ApplicationCache.Invalidate((string) ("GroupAccess_" + iObjID.ToString() + "_" + apiContent.UserId.ToString()));
                                sMsg = apiContent.EkMsgRef.GetMessage("lbl cancel group join");
                                sRetMsg = apiContent.EkMsgRef.GetMessage("lbl join group");
                                sResult = "1";
                            }
                            else if (sMode == "add")
                            {
                                sMsg = apiContent.EkMsgRef.GetMessage("lbl requested join group");
                                sRetMsg = apiContent.EkMsgRef.GetMessage("lbl cgroup cancel join req");
                                sResult = "-1";
                            }
                        }
                        else if (mMemberStatus == Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.InvitedMember)
                        {
                            apiCommunityGroup.AddUserToCommunityGroup(iObjID, apiContent.UserId);
                            Ektron.Cms.Common.Cache.ApplicationCache.Invalidate((string) ("GroupAccess_" + iObjID.ToString() + "_" + apiContent.UserId.ToString()));
                            mMemberStatus = apiCommunityGroup.GetGroupMemberStatus(iObjID, apiContent.UserId);
                            if (mMemberStatus == Ektron.Cms.Common.EkEnumeration.GroupMemberStatus.Pending)
                            {
                                sRetMsg = apiContent.EkMsgRef.GetMessage("lbl cgroup cancel join req");
                                sMsg = apiContent.EkMsgRef.GetMessage("lbl leave group");
                                sResult = "0";
                            }
                            else
                            {
                                sRetMsg = apiContent.EkMsgRef.GetMessage("lbl leave group");
                                sMsg = apiContent.EkMsgRef.GetMessage("lbl cgrp accept inv");
                                sResult = "0";
                            }
                        }
                    }
                    else if (sbObjType == Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes.Content)
                    {
                        if (Request.QueryString["lang"] != "" && Information.IsNumeric(Request.QueryString["lang"]))
                        {
                            iLang = Convert.ToInt32(Request.QueryString["lang"]);
                        }
                        if (iLang > 0)
                        {
                            apiFavorites.ContentLanguage = iLang;
                        }
                        if (iObjID > 0)
                        {
                            bIsMine = apiFavorites.IsMyContentFavorite(iObjID);
                        }
                        else
                        {
                            bIsMyLinkID = apiFavorites.GetFavoriteId(title, link, apiContent.UserId);
                        }

                        if (sMode == "remove" && bIsMine)
                        {
                            apiFavorites.DeleteMyContentFavorite(iObjID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl no longer fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add fav");
                            sResult = "1";
                            action = "addFavorite";
                        }
                        else if (sMode == "remove" && ! bIsMine)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl not fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add fav");
                            sResult = "-1";
                        }
                        else if (sMode == "add" && bIsMine)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl already fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove fav");
                            sResult = "-1";
                        }
                        else if (sMode == "add" && ! bIsMine)
                        {
                            apiFavorites.AddContentFavorite(iObjID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl now fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove fav");
                            sResult = "0";
                            action = "removeFavorite";
                        }
                        else if (sMode == "addlink" && bIsMyLinkID == 0)
                        {
                            if (title != "")
                            {
                                apiFavorites.AddFavoriteLink(apiContent.UserId, 0, iLang, title, link, "");
                            }
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl now fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove fav");
                            sResult = "0";
                        }
                        else if (sMode == "addlink" && bIsMyLinkID > 0)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl already fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove fav");
                            sResult = "-1";
                        }
                        else if (sMode == "removelink" && bIsMyLinkID > 0)
                        {
                            apiFavorites.DeleteFavoriteLink(bIsMyLinkID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl no longer fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add fav");
                            sResult = "1";
                        }
                        else if (sMode == "removelink" && bIsMyLinkID == 0)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl not fav");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add fav");
                            sResult = "-1";
                        }
                    }
                    else if (sbObjType == Ektron.Cms.Common.EkEnumeration.CMSSocialBarTypes.User)
                    {
                        Ektron.Cms.Common.EkEnumeration.FriendStatus fFriendStatus = Ektron.Cms.Common.EkEnumeration.FriendStatus.NotFriend;
                        // bIsMine = apiContent.IsMyFriend(iObjID)
                        fFriendStatus = apiFriends.GetFriendStatus(iObjID, apiContent.UserId);
                        if (sMode == "remove" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.Approved)
                        {
                            apiFriends.DeleteMyFriend(iObjID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl no longer friend");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add friend");
                            sResult = "1";
                        }
                        else if (sMode == "remove" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.NotFriend)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl not friend");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add friend");
                            sResult = "-1";
                        }
                        else if (sMode == "add" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.Approved)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl already friend");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove friend");
                            sResult = "-1";
                        }
                        else if (sMode == "add" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.NotFriend)
                        {
                            apiFriends.AddPendingFriend(iObjID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl now friend req");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove friend req");
                            sResult = "0";
                        }
                        else if (sMode == "remove" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.Pending)
                        {
                            apiFriends.DeletePendingFriendRequest(iObjID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl no longer pending friend");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add friend");
                            sResult = "1";
                        }
                        else if (sMode == "add" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.Pending)
                        {
                            apiFriends.AcceptPendingFriend(iObjID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl already request friend");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove friend");
                            sResult = "0";
                        }
                        else if (sMode == "remove" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.Invited)
                        {
                            apiFriends.DeleteSentFriendRequest(iObjID);
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl no longer pending friend");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl add friend");
                            sResult = "1";
                        }
                        else if (sMode == "add" && fFriendStatus == Ektron.Cms.Common.EkEnumeration.FriendStatus.Invited)
                        {
                            sMsg = apiContent.EkMsgRef.GetMessage("lbl already request friend");
                            sRetMsg = apiContent.EkMsgRef.GetMessage("lbl remove friend");
                            sResult = "0";
                        }
                    }
                }
                else
                {
                    sMsg = apiContent.EkMsgRef.GetMessage("lbl not logged in");
                    sRetMsg = apiContent.EkMsgRef.GetMessage("lbl not logged in");
                    sResult = "-1";
                }
                sbRet.Append("  <result>").Append(sResult).Append("</result>").Append(Environment.NewLine);
                sbRet.Append("  <returnmsg>").Append(sMsg).Append("</returnmsg>").Append(Environment.NewLine);
                sbRet.Append("  <oid>").Append(iObjID).Append("</oid>").Append(Environment.NewLine);
                sbRet.Append("  <otype>").Append(oType.ToString()).Append("</otype>").Append(Environment.NewLine);
                sbRet.Append("  <ilang>").Append(iLang.ToString()).Append("</ilang>").Append(Environment.NewLine);
                sbRet.Append("  <idx>").Append(iIdx).Append("</idx>").Append(Environment.NewLine);
                sbRet.Append("  <retmsg>").Append(sRetMsg).Append("</retmsg>").Append(Environment.NewLine);
                sbRet.Append("  <key>").Append(sKey).Append("</key>").Append(Environment.NewLine);
                sbRet.Append("  <action>").Append(action).Append("</action>").Append(Environment.NewLine);
                if (iObjID == 0)
                {
                    sbRet.Append("  <title>").Append(title.ToString()).Append("</title>").Append(Environment.NewLine);
                    sbRet.Append("  <link>").Append(link).Append("</link>").Append(Environment.NewLine);
                }
            }
            catch (Exception ex)
            {
                sbRet.Append("  <method>AJAX_AddTo</method>").Append(Environment.NewLine);
                sbRet.Append("  <result>error</result>").Append(Environment.NewLine);
                sbRet.Append("  <returnmsg>").Append(ex.Message).Append("</returnmsg>").Append(Environment.NewLine);
                sbRet.Append("  <oid>").Append(iObjID).Append("</oid>").Append(Environment.NewLine);
                sbRet.Append("  <otype>").Append(sbObjType).Append("</otype>").Append(Environment.NewLine);
                sbRet.Append("  <ilang>").Append(iLang.ToString()).Append("</ilang>").Append(Environment.NewLine);
                sbRet.Append("  <idx>").Append(iIdx).Append("</idx>").Append(Environment.NewLine);
                sbRet.Append("  <retmsg>").Append(sRetMsg).Append("</retmsg>").Append(Environment.NewLine);
                sbRet.Append("  <key>").Append(sKey).Append("</key>").Append(Environment.NewLine);
            }
            return sbRet.ToString();
    }
Ejemplo n.º 2
0
 protected void LoadFriendGroupList()
 {
     Ektron.Cms.UserAPI _userApi = new UserAPI();
     Ektron.Cms.Community.FriendsAPI _friendsApi = new Ektron.Cms.Community.FriendsAPI();
     Ektron.Cms.Community.CommunityGroupAPI _communityGroupApi = new Ektron.Cms.Community.CommunityGroupAPI();
     int totalpages = 0;
     int totalgroups = 0;
     userInfo = _userApi.GetUserById(_userApi.RequestInformationRef.UserId, false, false);
     friendList = _friendsApi.GetFriendsForUser(_friendsApi.RequestInformationRef.UserId);
     groupList = _communityGroupApi.GetCommunityGroupsForUser(_communityGroupApi.RequestInformationRef.UserId, 0, 1000, ref totalpages, ref totalgroups);
 }