/// <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."); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { var endPoint = new Literal { Text = "." }; var isLoginAllowed = false; var isRegisterAllowed = false; if (Config.IsAnyPortal) { this.Visible = false; } else { if (Config.AllowLoginAndLogoff) { this.ConnectHolder.Controls.Add( new Literal { Text = this.GetText("TOOLBAR", "WELCOME_GUEST_CONNECT") }); // show login var loginLink = new ThemeButton { TextLocalizedTag = "LOGIN_CONNECT", TextLocalizedPage = "TOOLBAR", ParamText0 = this.Get<YafBoardSettings>().Name, TitleLocalizedTag = "LOGIN", TitleLocalizedPage = "TOOLBAR", CssClass = "yafcssbigbutton" }; if (this.Get<YafBoardSettings>().UseLoginBox && !(this.Get<IYafSession>().UseMobileTheme ?? false)) { loginLink.NavigateUrl = "javascript:void(0);"; loginLink.CssClass = "LoginLink"; } else { var returnUrl = this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("ReturnUrl").IsSet() ? "ReturnUrl={0}".FormatWith( this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("ReturnUrl")) : string.Empty; loginLink.NavigateUrl = !this.Get<YafBoardSettings>().UseSSLToLogIn ? YafBuildLink.GetLinkNotEscaped(ForumPages.login, returnUrl) : YafBuildLink.GetLinkNotEscaped(ForumPages.login, true, returnUrl) .Replace("http:", "https:"); } this.ConnectHolder.Controls.Add(loginLink); isLoginAllowed = true; } if (!this.Get<YafBoardSettings>().DisableRegistrations) { // show register link var registerLink = new ThemeButton { TextLocalizedTag = "REGISTER_CONNECT", TextLocalizedPage = "TOOLBAR", TitleLocalizedTag = "REGISTER", TitleLocalizedPage = "TOOLBAR", CssClass = "yafcssbigbutton", NavigateUrl = this.Get<YafBoardSettings>().ShowRulesForRegistration ? YafBuildLink.GetLink(ForumPages.rules) : (!this.Get<YafBoardSettings>().UseSSLToRegister ? YafBuildLink.GetLink(ForumPages.register) : YafBuildLink.GetLink( ForumPages.register, true).Replace("http:", "https:")) }; this.ConnectHolder.Controls.Add(registerLink); this.ConnectHolder.Controls.Add(endPoint); isRegisterAllowed = true; } else { this.ConnectHolder.Controls.Add(endPoint); this.ConnectHolder.Controls.Add(new Literal { Text = this.GetText("TOOLBAR", "DISABLED_REGISTER") }); } // If both disallowed if (!isLoginAllowed && !isRegisterAllowed) { this.ConnectHolder.Controls.Clear(); this.ConnectHolder.Visible = false; return; } if (this.Get<YafBoardSettings>().AllowSingleSignOn && (Config.FacebookAPIKey.IsSet() || Config.TwitterConsumerKey.IsSet() || Config.GoogleClientID.IsSet())) { this.ConnectHolder.Controls.Add( new Literal { Text = " {0} ".FormatWith(this.GetText("LOGIN", "CONNECT_VIA")) }); if (Config.FacebookAPIKey.IsSet() && Config.FacebookSecretKey.IsSet()) { var linkButton = new LinkButton { Text = "Facebook", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Facebook"), ID = "FacebookRegister", CssClass = "authLogin facebookLogin" }; linkButton.Click += this.FacebookFormClick; this.ConnectHolder.Controls.Add(linkButton); } this.ConnectHolder.Controls.Add(new Literal { Text = " " }); if (Config.TwitterConsumerKey.IsSet() && Config.TwitterConsumerSecret.IsSet()) { var linkButton = new LinkButton { Text = "Twitter", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Twitter"), ID = "TwitterRegister", CssClass = "authLogin twitterLogin" }; linkButton.Click += this.TwitterFormClick; this.ConnectHolder.Controls.Add(linkButton); } this.ConnectHolder.Controls.Add(new Literal { Text = " " }); if (Config.GoogleClientID.IsSet() && Config.GoogleClientSecret.IsSet()) { var linkButton = new LinkButton { Text = "Google", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Google"), ID = "GoogleRegister", CssClass = "authLogin googleLogin" }; linkButton.Click += this.GoogleFormClick; this.ConnectHolder.Controls.Add(linkButton); } } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { var endPoint = new Literal { Text = "." }; var isLoginAllowed = false; var isRegisterAllowed = false; if (Config.IsAnyPortal) { this.Visible = false; } else { if (Config.AllowLoginAndLogoff) { this.ConnectHolder.Controls.Add( new Literal { Text = this.GetText("TOOLBAR", "WELCOME_GUEST_CONNECT") }); // show login var loginLink = new ThemeButton { TextLocalizedTag = "LOGIN_CONNECT", TextLocalizedPage = "TOOLBAR", ParamText0 = this.Get <YafBoardSettings>().Name, TitleLocalizedTag = "LOGIN", TitleLocalizedPage = "TOOLBAR", // CssClass = "yaflittlebutton" }; if (this.Get <YafBoardSettings>().UseLoginBox&& !(this.Get <IYafSession>().UseMobileTheme ?? false)) { loginLink.NavigateUrl = "javascript:void(0);"; loginLink.CssClass = "LoginLink"; } else { var returnUrl = this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("ReturnUrl").IsSet() ? "ReturnUrl={0}".FormatWith( this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("ReturnUrl")) : string.Empty; loginLink.NavigateUrl = !this.Get <YafBoardSettings>().UseSSLToLogIn ? YafBuildLink.GetLinkNotEscaped(ForumPages.login, returnUrl) : YafBuildLink.GetLinkNotEscaped(ForumPages.login, true, returnUrl) .Replace("http:", "https:"); } this.ConnectHolder.Controls.Add(loginLink); isLoginAllowed = true; } if (!this.Get <YafBoardSettings>().DisableRegistrations) { // show register link var registerLink = new ThemeButton { TextLocalizedTag = "REGISTER_CONNECT", TextLocalizedPage = "TOOLBAR", TitleLocalizedTag = "REGISTER", TitleLocalizedPage = "TOOLBAR", // CssClass = "yaflittlebutton", NavigateUrl = this.Get <YafBoardSettings>().ShowRulesForRegistration ? YafBuildLink.GetLink(ForumPages.rules) : (!this.Get <YafBoardSettings>().UseSSLToRegister ? YafBuildLink.GetLink(ForumPages.register) : YafBuildLink.GetLink( ForumPages.register, true).Replace("http:", "https:")) }; this.ConnectHolder.Controls.Add(new Literal { Text = ", " }); this.ConnectHolder.Controls.Add(registerLink); this.ConnectHolder.Controls.Add(endPoint); isRegisterAllowed = true; } else { this.ConnectHolder.Controls.Add(endPoint); this.ConnectHolder.Controls.Add(new Literal { Text = this.GetText("TOOLBAR", "DISABLED_REGISTER") }); } // If both disallowed if (!isLoginAllowed && !isRegisterAllowed) { this.ConnectHolder.Controls.Clear(); this.ConnectHolder.Visible = false; return; } if (this.Get <YafBoardSettings>().AllowSingleSignOn && (Config.FacebookAPIKey.IsSet() || Config.TwitterConsumerKey.IsSet() || Config.GoogleClientID.IsSet())) { this.ConnectHolder.Controls.Add( new Literal { Text = " {0} ".FormatWith(this.GetText("LOGIN", "CONNECT_VIA")) }); if (Config.FacebookAPIKey.IsSet() && Config.FacebookSecretKey.IsSet()) { var linkButton = new LinkButton { Text = "Facebook", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Facebook"), ID = "FacebookRegister", CssClass = "authLogin facebookLogin" }; linkButton.Click += this.FacebookFormClick; this.ConnectHolder.Controls.Add(linkButton); } this.ConnectHolder.Controls.Add(new Literal { Text = " " }); if (Config.TwitterConsumerKey.IsSet() && Config.TwitterConsumerSecret.IsSet()) { var linkButton = new LinkButton { Text = "Twitter", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Twitter"), ID = "TwitterRegister", CssClass = "authLogin twitterLogin" }; linkButton.Click += this.TwitterFormClick; this.ConnectHolder.Controls.Add(linkButton); } this.ConnectHolder.Controls.Add(new Literal { Text = " " }); if (Config.GoogleClientID.IsSet() && Config.GoogleClientSecret.IsSet()) { var linkButton = new LinkButton { Text = "Google", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Google"), ID = "GoogleRegister", CssClass = "authLogin googleLogin" }; linkButton.Click += this.GoogleFormClick; this.ConnectHolder.Controls.Add(linkButton); } } } }
/// <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 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.GetLink( ForumPages.Posts, "m={0}#post{0}", activity.MessageID.Value), Type = ButtonAction.None, Text = this.GetRepository <Topic>().GetById(activity.TopicID.Value).TopicName, Icon = "comment" }; if (activity.ActivityFlags.ReceivedThanks) { var userLink = new UserLink { UserID = activity.FromUserID.Value }; icon = "heart"; message = this.GetTextFormatted( "RECEIVED_THANKS_MSG", userLink.RenderToString(), topicLink.RenderToString()); } if (activity.ActivityFlags.WasMentioned) { var userLink = new UserLink { UserID = activity.FromUserID.Value }; icon = "at"; message = this.GetTextFormatted( "WAS_MENTIONED_MSG", userLink.RenderToString(), topicLink.RenderToString()); } if (activity.ActivityFlags.WasQuoted) { var userLink = new UserLink { UserID = activity.FromUserID.Value }; icon = "quote-left"; message = this.GetTextFormatted( "WAS_QUOTED_MSG", userLink.RenderToString(), topicLink.RenderToString()); } var notify = activity.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.Created; messageHolder.Controls.Add(new Literal { Text = message }); if (!activity.Notification) { return; } markRead.CommandArgument = activity.MessageID.Value.ToString(); markRead.Visible = true; }
/// <summary> /// Setup the popup menu. /// </summary> private void SetupPopupMenu() { this.UserDropHolder.Controls.Add( new ThemeButton { Type = ButtonStyle.None, Icon = "th-list", TextLocalizedPage = "PAGE", TextLocalizedTag = "SEARCHUSER", CssClass = "dropdown-item", NavigateUrl = BuildLink.GetLink( ForumPages.Search, "postedby={0}", this.DataRow[this.Get <BoardSettings>().EnableDisplayName ? "DisplayName" : "UserName"]) }); this.UserDropHolder2.Controls.Add( new ThemeButton { Type = ButtonStyle.None, Icon = "th-list", TextLocalizedPage = "PAGE", TextLocalizedTag = "SEARCHUSER", CssClass = "dropdown-item", NavigateUrl = BuildLink.GetLink( ForumPages.Search, "postedby={0}", this.DataRow[this.Get <BoardSettings>().EnableDisplayName ? "DisplayName" : "UserName"]) }); if (this.PageContext.IsAdmin) { this.UserDropHolder.Controls.Add( new ThemeButton { Type = ButtonStyle.None, Icon = "cogs", TextLocalizedPage = "POSTS", TextLocalizedTag = "EDITUSER", CssClass = "dropdown-item", NavigateUrl = BuildLink.GetLink(ForumPages.Admin_EditUser, "u={0}", this.PostData.UserId) }); this.UserDropHolder2.Controls.Add( new ThemeButton { Type = ButtonStyle.None, Icon = "cogs", TextLocalizedPage = "POSTS", TextLocalizedTag = "EDITUSER", CssClass = "dropdown-item", NavigateUrl = BuildLink.GetLink(ForumPages.Admin_EditUser, "u={0}", this.PostData.UserId) }); } if (this.PageContext.PageUserID != this.PostData.UserId) { if (this.Get <IUserIgnored>().IsIgnored(this.PostData.UserId)) { var showButton = new ThemeButton { Type = ButtonStyle.None, Icon = "eye", TextLocalizedPage = "POSTS", TextLocalizedTag = "TOGGLEUSERPOSTS_SHOW", CssClass = "dropdown-item" }; showButton.Click += (sender, args) => { this.Get <IUserIgnored>().RemoveIgnored(this.PostData.UserId); this.Get <HttpResponseBase>().Redirect(this.Get <HttpRequestBase>().RawUrl); }; this.UserDropHolder.Controls.Add(showButton); } else { var hideButton = new ThemeButton { Type = ButtonStyle.None, Icon = "eye-slash", TextLocalizedPage = "POSTS", TextLocalizedTag = "TOGGLEUSERPOSTS_HIDE", CssClass = "dropdown-item" }; hideButton.Click += (sender, args) => { this.Get <IUserIgnored>().AddIgnored(this.PostData.UserId); this.Get <HttpResponseBase>().Redirect(this.Get <HttpRequestBase>().RawUrl); }; this.UserDropHolder.Controls.Add(hideButton); } } if (this.Get <BoardSettings>().EnableBuddyList&& this.PageContext.PageUserID != this.PostData.UserId) { var userBlockFlags = new UserBlockFlags(this.DataRow.Field <int>("BlockFlags")); // Should we add the "Add Buddy" item? if (!this.Get <IFriends>().IsBuddy(this.PostData.UserId, false) && !this.PageContext.IsGuest && !userBlockFlags .BlockFriendRequests) { var addFriendButton = new ThemeButton { Type = ButtonStyle.None, Icon = "user-plus", TextLocalizedPage = "BUDDY", TextLocalizedTag = "ADDBUDDY", CssClass = "dropdown-item" }; addFriendButton.Click += (sender, args) => { var strBuddyRequest = this.Get <IFriends>().AddRequest(this.PostData.UserId); if (Convert.ToBoolean(strBuddyRequest[1].ToType <int>())) { this.PageContext.AddLoadMessage( this.GetTextFormatted("NOTIFICATION_BUDDYAPPROVED_MUTUAL", strBuddyRequest[0]), MessageTypes.success); this.Get <HttpResponseBase>().Redirect(this.Get <HttpRequestBase>().RawUrl); } else { this.PageContext.AddLoadMessage( this.GetText("NOTIFICATION_BUDDYREQUEST"), MessageTypes.success); } }; this.UserDropHolder.Controls.Add(addFriendButton); } else if (this.Get <IFriends>().IsBuddy(this.PostData.UserId, true) && !this.PageContext.IsGuest) { // Are the users approved buddies? Add the "Remove buddy" item. var removeFriendButton = new ThemeButton { Type = ButtonStyle.None, Icon = "user-times", TextLocalizedPage = "BUDDY", TextLocalizedTag = "REMOVEBUDDY", CssClass = "dropdown-item", ReturnConfirmText = this.GetText( "FRIENDS", "NOTIFICATION_REMOVE") }; removeFriendButton.Click += (sender, args) => { this.Get <IFriends>().Remove(this.PostData.UserId); this.Get <HttpResponseBase>().Redirect(this.Get <HttpRequestBase>().RawUrl); this.PageContext.AddLoadMessage( this.GetTextFormatted( "REMOVEBUDDY_NOTIFICATION", this.Get <IFriends>().Remove(this.PostData.UserId)), MessageTypes.success); }; this.UserDropHolder.Controls.Add(removeFriendButton); } } this.UserDropHolder.Controls.Add(new Panel { CssClass = "dropdown-divider" }); this.UserDropHolder2.Controls.Add(new Panel { CssClass = "dropdown-divider" }); }
protected void SetupThemeButtonWithLink( ThemeButton thisButton, string linkUrl ) { if ( !String.IsNullOrEmpty( linkUrl ) ) { string link = linkUrl.Replace( "\"", "" ); if ( !link.ToLower().StartsWith( "http" ) ) { link = "http://" + link; } thisButton.NavigateUrl = link; thisButton.Attributes.Add( "target", "_blank" ); if ( PageContext.BoardSettings.UseNoFollowLinks ) thisButton.Attributes.Add( "rel", "nofollow" ); } else { thisButton.NavigateUrl = ""; } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { var endPoint = new Literal { Text = "." }; var isLoginAllowed = false; var isRegisterAllowed = false; if (Config.IsAnyPortal) { this.Visible = false; } else { if (Config.AllowLoginAndLogoff) { this.ConnectHolder.Controls.Add( new Literal { Text = $"<strong>{this.GetText("TOOLBAR", "WELCOME_GUEST_CONNECT")}</strong>" }); // show login var loginLink = new ThemeButton { TextLocalizedTag = "LOGIN_CONNECT", TextLocalizedPage = "TOOLBAR", ParamText0 = this.Get <YafBoardSettings>().Name, TitleLocalizedTag = "LOGIN", TitleLocalizedPage = "TOOLBAR", Type = ButtonAction.Link, Icon = "sign-in-alt", NavigateUrl = "javascript:void(0);", CssClass = "LoginLink" }; this.ConnectHolder.Controls.Add(loginLink); isLoginAllowed = true; } if (!this.Get <YafBoardSettings>().DisableRegistrations) { // show register link var registerLink = new ThemeButton { TextLocalizedTag = "REGISTER_CONNECT", TextLocalizedPage = "TOOLBAR", TitleLocalizedTag = "REGISTER", TitleLocalizedPage = "TOOLBAR", Type = ButtonAction.Link, Icon = "user-plus", NavigateUrl = this.Get <YafBoardSettings>().ShowRulesForRegistration ? YafBuildLink.GetLink(ForumPages.rules) : !this.Get <YafBoardSettings>().UseSSLToRegister ? YafBuildLink.GetLink(ForumPages.register) : YafBuildLink.GetLink( ForumPages.register, true).Replace("http:", "https:") }; this.ConnectHolder.Controls.Add(registerLink); isRegisterAllowed = true; } else { this.ConnectHolder.Controls.Add(endPoint); this.ConnectHolder.Controls.Add(new Literal { Text = this.GetText("TOOLBAR", "DISABLED_REGISTER") }); } // If both disallowed if (!isLoginAllowed && !isRegisterAllowed) { this.ConnectHolder.Controls.Clear(); this.ConnectHolder.Visible = false; return; } if (this.Get <YafBoardSettings>().AllowSingleSignOn && (Config.FacebookAPIKey.IsSet() || Config.TwitterConsumerKey.IsSet() || Config.GoogleClientID.IsSet())) { this.ConnectHolder.Controls.Add( new Literal { Text = $" {this.GetText("LOGIN", "CONNECT_VIA")} " }); if (Config.FacebookAPIKey.IsSet() && Config.FacebookSecretKey.IsSet()) { var linkButton = new LinkButton { Text = "Facebook", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Facebook"), ID = "FacebookRegister", CssClass = "authLogin facebookLogin" }; linkButton.Click += this.FacebookFormClick; this.ConnectHolder.Controls.Add(linkButton); } this.ConnectHolder.Controls.Add(new Literal { Text = " " }); if (Config.TwitterConsumerKey.IsSet() && Config.TwitterConsumerSecret.IsSet()) { var linkButton = new LinkButton { Text = "Twitter", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Twitter"), ID = "TwitterRegister", CssClass = "authLogin twitterLogin" }; linkButton.Click += this.TwitterFormClick; this.ConnectHolder.Controls.Add(linkButton); } this.ConnectHolder.Controls.Add(new Literal { Text = " " }); if (Config.GoogleClientID.IsSet() && Config.GoogleClientSecret.IsSet()) { var linkButton = new LinkButton { Text = "Google", ToolTip = this.GetTextFormatted("AUTH_CONNECT_HELP", "Google"), ID = "GoogleRegister", CssClass = "authLogin googleLogin" }; linkButton.Click += this.GoogleFormClick; this.ConnectHolder.Controls.Add(linkButton); } } } }
/// <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 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 }); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { var endPoint = new Literal { Text = "." }; var isLoginAllowed = false; var isRegisterAllowed = false; if (Config.IsAnyPortal) { this.Visible = false; return; } if (Config.AllowLoginAndLogoff) { this.ConnectHolder.Controls.Add( new Literal { Text = $"<strong>{this.GetText("TOOLBAR", "WELCOME_GUEST_CONNECT")}</strong>" }); // show login var loginLink = new ThemeButton { TextLocalizedTag = "LOGIN_CONNECT", TextLocalizedPage = "TOOLBAR", ParamText0 = this.PageContext.BoardSettings.Name, TitleLocalizedTag = "LOGIN", TitleLocalizedPage = "TOOLBAR", Type = ButtonStyle.Link, Icon = "sign-in-alt", NavigateUrl = "javascript:void(0);", CssClass = "LoginLink" }; this.ConnectHolder.Controls.Add(loginLink); isLoginAllowed = true; } if (!this.PageContext.BoardSettings.DisableRegistrations) { // show register link var registerLink = new ThemeButton { TextLocalizedTag = "REGISTER_CONNECT", TextLocalizedPage = "TOOLBAR", TitleLocalizedTag = "REGISTER", TitleLocalizedPage = "TOOLBAR", Type = ButtonStyle.Link, Icon = "user-plus", NavigateUrl = this.PageContext.BoardSettings.ShowRulesForRegistration ? BuildLink.GetLink(ForumPages.RulesAndPrivacy) : !this.PageContext.BoardSettings.UseSSLToRegister ? BuildLink.GetLink(ForumPages.Account_Register) : BuildLink.GetLink(ForumPages.Account_Register, true).Replace("http:", "https:") }; this.ConnectHolder.Controls.Add(registerLink); isRegisterAllowed = true; } else { this.ConnectHolder.Controls.Add(endPoint); this.ConnectHolder.Controls.Add(new Literal { Text = this.GetText("TOOLBAR", "DISABLED_REGISTER") }); } // If both disallowed if (isLoginAllowed || isRegisterAllowed) { return; } this.ConnectHolder.Controls.Clear(); this.ConnectHolder.Visible = false; }
/// <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 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 = BuildLink.GetLink( ForumPages.posts, "m={0}#post{0}", activity.MessageID.Value), Type = ButtonAction.None, Text = this.GetRepository <Topic>().GetById(activity.TopicID.Value).TopicName, Icon = "comment" }; if (activity.ActivityFlags.CreatedTopic) { topicLink.NavigateUrl = BuildLink.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()); } var notify = activity.Notification ? "text-success" : "text-secondary"; card.CssClass = activity.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.Created; messageHolder.Controls.Add(new Literal { Text = message }); if (!activity.Notification) { return; } markRead.CommandArgument = activity.MessageID.Value.ToString(); markRead.Visible = true; }
/// <summary> /// Render Li and a Item /// </summary> /// <param name="holder"> /// The holder. /// </param> /// <param name="cssClass"> /// The CSS class. /// </param> /// <param name="linkText"> /// The link text. /// </param> /// <param name="linkToolTip"> /// The link tool tip. /// </param> /// <param name="linkUrl"> /// The link URL. /// </param> /// <param name="noFollow"> /// Add no follow to the link /// </param> /// <param name="showUnread"> /// The show unread. /// </param> /// <param name="unread"> /// The unread. /// </param> /// <param name="unreadText"> /// The unread text. /// </param> /// <param name="isActive"> /// The is Active. /// </param> /// <param name="icon"> /// The icon. /// </param> private static void RenderMenuItem( Control holder, string cssClass, string linkText, string linkToolTip, string linkUrl, bool noFollow, bool showUnread, string unread, string unreadText, bool isActive, string icon = "") { var element = new HtmlGenericControl("li"); if (cssClass.IsSet()) { element.Attributes.Add("class", "nav-item"); } if (isActive) { cssClass = $"{cssClass} active"; } if (linkToolTip.IsNotSet()) { linkToolTip = linkText; } var link = new ThemeButton { TitleLocalizedTag = linkToolTip, Type = ButtonAction.None, TitleLocalizedPage = "TOOLBAR", NavigateUrl = linkUrl, Text = icon.IsSet() ? $"<i class=\"fa fa-{icon} fa-fw\"></i> {linkText}" : linkText, CssClass = cssClass }; if (noFollow) { link.Attributes.Add("rel", "nofollow"); } link.DataToggle = "tooltip"; if (showUnread) { /*link.Controls.Add(new LiteralControl(icon.IsSet() * ? $"<i class=\"fa fa-{icon} fa-fw\"></i> {linkText} " * : $"{linkText} "));*/ var unreadLabel = new Label { CssClass = "badge badge-danger ml-1", ToolTip = unreadText, Text = unread }; unreadLabel.Attributes.Add("data-toggle", "tooltip"); var unreadLabelText = new Label { CssClass = "sr-only", Text = unreadText }; link.Controls.Add(unreadLabel); link.Controls.Add(unreadLabelText); } if (cssClass.Equals("nav-link")) { element.Controls.Add(link); holder.Controls.Add(element); } else { holder.Controls.Add(link); } }
/// <summary> /// Attaches the specified theme button. /// </summary> /// <param name="themeButton">The theme button.</param> public void Attach(ThemeButton themeButton) { this.ButtonId = themeButton.ClientID; }
/// <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>().GetSingle(t => t.ID == 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 }); }