Esempio n. 1
0
        /// <summary>
        /// Gets the user info as JSON string for the hover cards
        /// </summary>
        /// <param name="context">The context.</param>
        private void GetUserInfo([NotNull] HttpContext context)
        {
            try
            {
                var userId = context.Request.QueryString.GetFirstOrDefault("userinfo").ToType<int>();

                MembershipUser user = UserMembershipHelper.GetMembershipUserById(userId);

                if (user == null || user.ProviderUserKey.ToString() == "0")
                {
                    context.Response.Write(
                   "Error: Resource has been moved or is unavailable. Please contact the forum admin.");

                    return;
                }

                // Check if user has access
                if (!this.Get<IPermissions>().Check(this.Get<YafBoardSettings>().ProfileViewPermissions))
                {
                    context.Response.Write(string.Empty);

                    return;
                }

                var userData = new CombinedUserDataHelper(user, userId);

                context.Response.Clear();

                context.Response.ContentType = "application/json";
                context.Response.ContentEncoding = Encoding.UTF8;
                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.Cache.SetExpires(
                    DateTime.UtcNow.AddMilliseconds(YafContext.Current.Get<YafBoardSettings>().OnlineStatusCacheTimeout));
                context.Response.Cache.SetLastModified(DateTime.UtcNow);

                var avatarUrl = this.Get<IAvatars>().GetAvatarUrlForUser(userId);

                avatarUrl = avatarUrl.IsNotSet()
                           ? "{0}images/noavatar.gif".FormatWith(YafForumInfo.ForumClientFileRoot)
                           : avatarUrl;

                var activeUsers = this.Get<IDataCache>().GetOrSet(
                    Constants.Cache.UsersOnlineStatus,
                    () =>
                    this.Get<YafDbBroker>().GetActiveList(
                        false, YafContext.Current.Get<YafBoardSettings>().ShowCrawlersInActiveList),
                    TimeSpan.FromMilliseconds(YafContext.Current.Get<YafBoardSettings>().OnlineStatusCacheTimeout));

                var userIsOnline =
                    activeUsers.AsEnumerable().Any(
                        x => x.Field<int>("UserId").Equals(userId) && !x.Field<bool>("IsHidden"));

                var userName = this.Get<YafBoardSettings>().EnableDisplayName ? userData.DisplayName : userData.UserName;

                userName = HttpUtility.HtmlEncode(userName);

                var location = userData.Profile.Country.IsSet()
                                   ? YafContext.Current.Get<IHaveLocalization>().GetText(
                                       "COUNTRY", userData.Profile.Country.Trim())
                                   : userData.Profile.Location;

                if (userData.Profile.Region.IsSet() && userData.Profile.Country.IsSet())
                {
                    var tag = "RGN_{0}_{1}".FormatWith(userData.Profile.Country.Trim(), userData.Profile.Region);

                    location += ", {0}".FormatWith(YafContext.Current.Get<IHaveLocalization>().GetText("REGION", tag));
                }

                var forumUrl = HttpUtility.UrlDecode(context.Request.QueryString.GetFirstOrDefault("forumUrl"));

                if (Config.IsMojoPortal)
                {
                    forumUrl = forumUrl + "&g={0}&u={1}".FormatWith(ForumPages.pmessage, userId);
                }
                else
                {
                    forumUrl = forumUrl.Replace(".aspx", ".aspx?g={0}&u={1}".FormatWith(ForumPages.pmessage, userId));
                }

                var pmButton = new ThemeButton
                                   {
                                       ID = "PM",
                                       CssClass = "yafcssimagebutton",
                                       TextLocalizedPage = "POSTS",
                                       TextLocalizedTag = "PM",
                                       ImageThemeTag = "PM",
                                       TitleLocalizedTag = "PM_TITLE",
                                       TitleLocalizedPage = "POSTS",
                                       NavigateUrl = Config.IsAnyPortal ? forumUrl : YafBuildLink.GetLinkNotEscaped(ForumPages.pmessage, true, "u={0}", userId).Replace(
                                               "resource.ashx", "default.aspx"),
                                       ParamTitle0 = userName,
                                       Visible =
                                           !userData.IsGuest && this.Get<YafBoardSettings>().AllowPrivateMessages
                                           && !userId.Equals(YafContext.Current.PageUserID) && !YafContext.Current.IsGuest
                                   };

                var userInfo = new YafUserInfo
                                   {
                                       name = userName,
                                       realname = HttpUtility.HtmlEncode(userData.Profile.RealName),
                                       avatar = avatarUrl,
                                       /*profilelink =
                                           Config.IsAnyPortal ? userlinkUrl : YafBuildLink.GetLink(ForumPages.profile, true, "u={0}", userId).Replace(
                                               "resource.ashx", "default.aspx"),*/
                                       interests = HttpUtility.HtmlEncode(userData.Profile.Interests),
                                       homepage = userData.Profile.Homepage,
                                       posts = "{0:N0}".FormatWith(userData.NumPosts),
                                       rank = userData.RankName,
                                       location = location,
                                       joined = this.Get<IDateTime>().FormatDateLong(userData.Joined),
                                       online = userIsOnline,
                                       actionButtons = pmButton.RenderToString()
                                   };

                if (YafContext.Current.Get<YafBoardSettings>().EnableUserReputation)
                {
                    userInfo.points = (userData.Points.ToType<int>() > 0 ? "+" : string.Empty) + userData.Points;
                }

                context.Response.Write(userInfo.ToJson());

                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            catch (Exception x)
            {
                this.Get<ILogger>().Log(0, this, x, EventLogTypes.Information);

                context.Response.Write(
                    "Error: Resource has been moved or is unavailable. Please contact the forum admin.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The activity stream_ on item data bound.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void ActivityStream_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var activity = (Activity)e.Item.DataItem;

            var iconLabel       = e.Item.FindControlAs <Label>("Icon");
            var title           = e.Item.FindControlAs <Literal>("Title");
            var messageHolder   = e.Item.FindControlAs <PlaceHolder>("Message");
            var displayDateTime = e.Item.FindControlAs <DisplayDateTime>("DisplayDateTime");

            var message = string.Empty;
            var icon    = string.Empty;

            var topicLink = new ThemeButton
            {
                NavigateUrl =
                    YafBuildLink.GetLink(
                        ForumPages.posts,
                        "m={0}#post{0}",
                        activity.MessageID.Value),
                Type = ButtonAction.OutlineSecondary,
                Text = this.GetRepository <Topic>().GetById(activity.TopicID.Value)
                       .TopicName,
                Icon = "comment"
            };

            if (activity.ActivityFlags.CreatedTopic)
            {
                topicLink.NavigateUrl = YafBuildLink.GetLink(ForumPages.posts, "t={0}", activity.TopicID.Value);

                title.Text = this.GetText("CP_PROFILE", "CREATED_TOPIC");
                icon       = "comment";
                message    = this.GetTextFormatted("CREATED_TOPIC_MSG", topicLink.RenderToString());
            }

            if (activity.ActivityFlags.CreatedReply)
            {
                title.Text = this.GetText("CP_PROFILE", "CREATED_REPLY");
                icon       = "comment";
                message    = this.GetTextFormatted("CREATED_REPLY_MSG", topicLink.RenderToString());
            }

            if (activity.ActivityFlags.GivenThanks)
            {
                var userLink = new UserLink {
                    UserID = activity.FromUserID.Value
                };

                title.Text = this.GetText("CP_PROFILE", "GIVEN_THANKS");
                icon       = "heart";
                message    = this.GetTextFormatted("GIVEN_THANKS_MSG", userLink.RenderToString(), topicLink.RenderToString());
            }

            if (activity.ActivityFlags.ReceivedThanks)
            {
                var userLink = new UserLink {
                    UserID = activity.FromUserID.Value
                };

                title.Text = this.GetText("CP_PROFILE", "RECEIVED_THANKS");
                icon       = "heart";
                message    = this.GetTextFormatted("RECEIVED_THANKS_MSG", userLink.RenderToString(), topicLink.RenderToString());
            }

            if (activity.ActivityFlags.WasMentioned)
            {
                var userLink = new UserLink {
                    UserID = activity.FromUserID.Value
                };

                title.Text = this.GetText("CP_PROFILE", "WAS_MENTIONED");
                icon       = "at";
                message    = this.GetTextFormatted("WAS_MENTIONED_MSG", userLink.RenderToString(), topicLink.RenderToString());
            }

            if (activity.ActivityFlags.WasQuoted)
            {
                var userLink = new UserLink {
                    UserID = activity.FromUserID.Value
                };

                title.Text = this.GetText("CP_PROFILE", "WAS_QUOTED");
                icon       = "quote-left";
                message    = this.GetTextFormatted("WAS_QUOTED_MSG", userLink.RenderToString(), topicLink.RenderToString());
            }

            iconLabel.Text = $@"<i class=""fas fa-circle fa-stack-2x text-secondary""></i>
               <i class=""fas fa-{icon} fa-stack-1x fa-inverse""></i>;";

            displayDateTime.DateTime = activity.Created;

            messageHolder.Controls.Add(new Literal {
                Text = message
            });
        }
Esempio n. 3
0
        /// <summary>
        /// The activity stream_ on item data bound.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void ActivityStream_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var activity = (Tuple <Activity, Topic>)e.Item.DataItem;

            var card            = e.Item.FindControlAs <Panel>("Card");
            var iconLabel       = e.Item.FindControlAs <Label>("Icon");
            var title           = e.Item.FindControlAs <Literal>("Title");
            var messageHolder   = e.Item.FindControlAs <PlaceHolder>("Message");
            var displayDateTime = e.Item.FindControlAs <DisplayDateTime>("DisplayDateTime");
            var markRead        = e.Item.FindControlAs <ThemeButton>("MarkRead");

            var message = string.Empty;
            var icon    = string.Empty;

            var topicLink = new ThemeButton
            {
                NavigateUrl  = this.Get <LinkBuilder>().GetTopicLink(activity.Item2.ID, activity.Item2.TopicName),
                Type         = ButtonStyle.None,
                Text         = activity.Item2.TopicName,
                Icon         = "comment",
                IconCssClass = "far"
            };

            if (activity.Item1.ActivityFlags.CreatedTopic)
            {
                topicLink.NavigateUrl = this.Get <LinkBuilder>().GetTopicLink(activity.Item1.TopicID.Value, activity.Item2.TopicName);
                title.Text            = this.GetText("ACCOUNT", "CREATED_TOPIC");
                icon    = "comment";
                message = this.GetTextFormatted("CREATED_TOPIC_MSG", topicLink.RenderToString());
            }

            if (activity.Item1.ActivityFlags.CreatedReply)
            {
                title.Text = this.GetText("ACCOUNT", "CREATED_REPLY");
                icon       = "comment";
                message    = this.GetTextFormatted("CREATED_REPLY_MSG", topicLink.RenderToString());
            }

            if (activity.Item1.ActivityFlags.GivenThanks)
            {
                var user = this.GetRepository <User>().GetById(activity.Item1.FromUserID.Value);

                var userLink = new UserLink
                {
                    UserID      = activity.Item1.FromUserID.Value,
                    Suspended   = user.Suspended,
                    Style       = user.UserStyle,
                    ReplaceName = user.DisplayOrUserName()
                };

                title.Text = this.GetText("ACCOUNT", "GIVEN_THANKS");
                icon       = "heart";
                message    = this.GetTextFormatted(
                    "GIVEN_THANKS_MSG",
                    userLink.RenderToString(),
                    topicLink.RenderToString());
            }

            var notify = activity.Item1.Notification ? "text-success" : "text-secondary";

            card.CssClass = activity.Item1.Notification ? "card shadow" : "card";

            iconLabel.Text = $@"<i class=""fas fa-circle fa-stack-2x {notify}""></i>
               <i class=""fas fa-{icon} fa-stack-1x fa-inverse""></i>";

            displayDateTime.DateTime = activity.Item1.Created;

            messageHolder.Controls.Add(new Literal {
                Text = message
            });

            if (!activity.Item1.Notification)
            {
                return;
            }

            markRead.CommandArgument = activity.Item1.MessageID.Value.ToString();
            markRead.Visible         = true;
        }
Esempio n. 4
0
        /// <summary>
        /// The activity stream_ on item data bound.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void ActivityStream_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var activity = (Tuple <Activity, User, Topic>)e.Item.DataItem;

            var messageHolder   = e.Item.FindControlAs <PlaceHolder>("Message");
            var displayDateTime = e.Item.FindControlAs <DisplayDateTime>("DisplayDateTime");
            var markRead        = e.Item.FindControlAs <ThemeButton>("MarkRead");
            var iconLabel       = e.Item.FindControlAs <Label>("Icon");

            var message = string.Empty;
            var icon    = string.Empty;

            var topicLink = new ThemeButton
            {
                NavigateUrl = BuildLink.GetTopicLink(activity.Item1.MessageID.Value, activity.Item3.TopicName),
                Type        = ButtonStyle.None,
                Text        = activity.Item3.TopicName,
                Icon        = "comment"
            };

            if (activity.Item1.ActivityFlags.ReceivedThanks)
            {
                var userLink = new UserLink
                {
                    UserID      = activity.Item1.FromUserID.Value,
                    Suspended   = activity.Item2.Suspended,
                    Style       = activity.Item2.UserStyle,
                    ReplaceName = this.PageContext.BoardSettings.EnableDisplayName
                        ? activity.Item2.DisplayName
                        : activity.Item2.Name
                };

                icon    = "heart";
                message = this.GetTextFormatted(
                    "RECEIVED_THANKS_MSG",
                    userLink.RenderToString(),
                    topicLink.RenderToString());
            }

            if (activity.Item1.ActivityFlags.WasMentioned)
            {
                var userLink = new UserLink
                {
                    UserID      = activity.Item1.FromUserID.Value,
                    Suspended   = activity.Item2.Suspended,
                    Style       = activity.Item2.UserStyle,
                    ReplaceName = this.PageContext.BoardSettings.EnableDisplayName
                        ? activity.Item2.DisplayName
                        : activity.Item2.Name
                };

                icon    = "at";
                message = this.GetTextFormatted(
                    "WAS_MENTIONED_MSG",
                    userLink.RenderToString(),
                    topicLink.RenderToString());
            }

            if (activity.Item1.ActivityFlags.WasQuoted)
            {
                var userLink = new UserLink
                {
                    UserID      = activity.Item1.FromUserID.Value,
                    Suspended   = activity.Item2.Suspended,
                    Style       = activity.Item2.UserStyle,
                    ReplaceName = this.PageContext.BoardSettings.EnableDisplayName
                        ? activity.Item2.DisplayName
                        : activity.Item2.Name
                };

                icon    = "quote-left";
                message = this.GetTextFormatted(
                    "WAS_QUOTED_MSG",
                    userLink.RenderToString(),
                    topicLink.RenderToString());
            }

            var notify = activity.Item1.Notification ? "text-success" : "text-secondary";

            iconLabel.Text = $@"<i class=""fas fa-circle fa-stack-2x {notify}""></i>
               <i class=""fas fa-{icon} fa-stack-1x fa-inverse""></i>";

            displayDateTime.DateTime = activity.Item1.Created;

            messageHolder.Controls.Add(new Literal {
                Text = message
            });

            if (!activity.Item1.Notification)
            {
                return;
            }

            markRead.CommandArgument = activity.Item1.MessageID.Value.ToString();
            markRead.Visible         = true;
        }