/// <summary> /// The render. /// </summary> /// <param name="writer"> /// The writer. /// </param> protected override void Render(HtmlTextWriter writer) { var userName = Parameters["inner"]; if (userName.IsNotSet() || userName.Length > 50) { return; } var userId = this.Get<IUserDisplayName>().GetId(userName.Trim()); if (userId.HasValue) { var stringBuilder = new StringBuilder(); var userLink = new UserLink { UserID = (int)userId, CssClass = "UserLinkBBCode", BlankTarget = true, ID = "UserLinkBBCodeFor{0}".FormatWith(userId) }; var showOnlineStatusImage = this.Get<YafBoardSettings>().ShowUserOnlineStatus && !UserMembershipHelper.IsGuestUser(userId); var onlineStatusImage = new OnlineStatusImage { ID = "OnlineStatusImage", Style = "vertical-align: bottom", UserID = (int)userId }; stringBuilder.AppendLine("<!-- BEGIN userlink -->"); stringBuilder.AppendLine(@"<span class=""userLinkContainer"">"); stringBuilder.AppendLine(userLink.RenderToString()); if (showOnlineStatusImage) { stringBuilder.AppendLine(onlineStatusImage.RenderToString()); } stringBuilder.AppendLine("</span>"); stringBuilder.AppendLine("<!-- END userlink -->"); writer.Write(stringBuilder.ToString()); } else { writer.Write(this.HtmlEncode(userName)); } }
/// <summary> /// Render The User related Links /// </summary> private void RenderUserContainer() { if (this.PageContext.IsGuest) { return; } this.UserContainer.Visible = true; // My Profile this.MyProfile.ToolTip = this.GetText("TOOLBAR", "MYPROFILE_TITLE"); this.MyProfile.NavigateUrl = YafBuildLink.GetLink(ForumPages.cp_profile); this.MyProfile.Text = this.GetText("TOOLBAR", "MYPROFILE"); // My Inbox if (this.Get<YafBoardSettings>().AllowPrivateMessages) { RenderMenuItem( this.MyInboxItem, "menuMy myPm", null, this.GetText("TOOLBAR", "INBOX"), this.GetText("TOOLBAR", "INBOX_TITLE"), YafBuildLink.GetLink(ForumPages.cp_pm), false, this.PageContext.UnreadPrivate > 0, this.PageContext.UnreadPrivate.ToString(), this.GetText("TOOLBAR", "NEWPM").FormatWith(this.PageContext.UnreadPrivate)); } // My Buddies if (this.Get<YafBoardSettings>().EnableBuddyList && this.PageContext.UserHasBuddies) { RenderMenuItem( this.MyBuddiesItem, "menuMy myBuddies", null, this.GetText("TOOLBAR", "BUDDIES"), this.GetText("TOOLBAR", "BUDDIES_TITLE"), YafBuildLink.GetLink(ForumPages.cp_editbuddies), false, this.PageContext.PendingBuddies > 0, this.PageContext.PendingBuddies.ToString(), this.GetText("TOOLBAR", "BUDDYREQUEST").FormatWith(this.PageContext.PendingBuddies)); } // My Albums if (this.Get<YafBoardSettings>().EnableAlbum && (this.PageContext.UsrAlbums > 0 || this.PageContext.NumAlbums > 0)) { RenderMenuItem( this.MyAlbumsItem, "menuMy myAlbums", null, this.GetText("TOOLBAR", "MYALBUMS"), this.GetText("TOOLBAR", "MYALBUMS_TITLE"), YafBuildLink.GetLinkNotEscaped(ForumPages.albums, "u={0}", this.PageContext.PageUserID), false, false, null, null); } bool unread = this.PageContext.UnreadPrivate > 0 || this.PageContext.PendingBuddies > 0/* || this.PageContext.UnreadTopics > 0*/; // My Topics RenderMenuItem( this.MyTopicItem, "menuMy myTopics", null, this.GetText("TOOLBAR", "MYTOPICS"), this.GetText("TOOLBAR", "MYTOPICS"), YafBuildLink.GetLink(ForumPages.mytopics), false, false,//this.PageContext.UnreadTopics > 0, string.Empty,//this.PageContext.UnreadTopics.ToString(), string.Empty);//this.GetText("TOOLBAR", "UNREADTOPICS").FormatWith(this.PageContext.UnreadTopics)); // Logout if (!Config.IsAnyPortal && Config.AllowLoginAndLogoff) { this.LogoutItem.Visible = true; this.LogOutButton.Text = this.GetText("TOOLBAR", "LOGOUT"); this.LogOutButton.ToolTip = this.GetText("TOOLBAR", "LOGOUT"); } // Logged in as : username this.LoggedInUserPanel.Visible = true; if (unread) { this.LoggedInUserPanel.CssClass = "loggedInUser unread"; } this.LoggedInUserPanel.Controls.Add( new Label { Text = this.GetText("TOOLBAR", "LOGGED_IN_AS").FormatWith(" ") }); var userLink = new UserLink { ID = "UserLoggedIn", UserID = this.PageContext.PageUserID, CssClass = "currentUser", EnableHoverCard = false }; this.LoggedInUserPanel.Controls.Add(userLink); }
/// <summary> /// Raises PreRender event and prepares control for rendering by creating links to active users. /// </summary> /// <param name="e"> /// The e. /// </param> protected override void OnPreRender([NotNull] EventArgs e) { // IMPORTANT : call base implementation, raises PreRender event base.OnPreRender(e); // we shall continue only if there are active user data available if (this.ActiveUserTable == null) { return; } // add style column if there is no such column in the table // style column defines how concrete user's link should be styled if (!this.ActiveUserTable.Columns.Contains("Style")) { this.ActiveUserTable.Columns.Add("Style", typeof(string)); this.ActiveUserTable.AcceptChanges(); } var crawlers = new List<string>(); // go through the table and process each row foreach (DataRow row in this.ActiveUserTable.Rows) { UserLink userLink; bool isCrawler = row["IsCrawler"].ToType<int>() > 0; // create new link and set its parameters if (isCrawler) { if (crawlers.Contains(row["Browser"].ToString())) { continue; } crawlers.Add(row["Browser"].ToString()); userLink = new UserLink { CrawlerName = row["Browser"].ToString(), UserID = row["UserID"].ToType<int>(), Style = this.Get<YafBoardSettings>().UseStyledNicks ? this.Get<IStyleTransform>().DecodeStyleByString(row["Style"].ToString(), false) : string.Empty }; userLink.ID += userLink.CrawlerName; } else { userLink = new UserLink { UserID = row["UserID"].ToType<int>(), Style = this.Get<YafBoardSettings>().UseStyledNicks ? this.Get<IStyleTransform>().DecodeStyleByString(row["Style"].ToString(), false) : string.Empty, ReplaceName = this.Get<YafBoardSettings>().EnableDisplayName ? row["UserDisplayName"].ToString() : row["UserName"].ToString() }; userLink.ID = "UserLink{0}{1}".FormatWith(this.InstantId, userLink.UserID); } // how many users of this type is present (valid for guests, others have it 1) int userCount = row["UserCount"].ToType<int>(); if (userCount > 1 && (!isCrawler || !this.Get<YafBoardSettings>().ShowCrawlersInActiveList)) { // add postfix if there is more the one user of this name userLink.PostfixText = " ({0})".FormatWith(userCount); } // indicates whether user link should be added or not bool addControl = true; // we might not want to add this user link if user is marked as hidden if (Convert.ToBoolean(row["IsHidden"]) || // or if user is guest and guest should be hidden (this.TreatGuestAsHidden && Convert.ToBoolean(row["IsGuest"]))) { // hidden user are always visible to admin and himself) if (this.PageContext.IsAdmin || userLink.UserID == this.PageContext.PageUserID) { // but use css style to distinguish such users userLink.CssClass = "active_hidden"; // and also add postfix userLink.PostfixText = " ({0})".FormatWith(this.GetText("HIDDEN")); } else { // user is hidden from this user... addControl = false; } } // add user link if it's not supressed if (!addControl) { continue; } // vzrus: if guests or crawlers there can be a control with the same id. var ul = this.FindControlRecursiveAs<UserLink>(userLink.ID); if (ul != null) { this.Controls.Remove(ul); } this.Controls.Add(userLink); } }