//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using CommunityServer.Components;
using Group = System.Text.RegularExpressions.Group;

namespace CommunityServer.Discussions.Components
{
	/// <summary>
	/// Summary description for ForumFormatter.
	/// </summary>
	public class ForumFormatter
	{
        #region static predefined values
        static string forumStatusIcon = "<img title=\"{0}\" alt=\"{0}\" src=\"{1}\"/>";
        static string threadStatusIcon = "<a href=\"{0}\"><img title=\"{1}\" src=\"{2}\" border=\"0\" /></a>";
        #endregion

		private ForumFormatter()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        #region ForumFormatter
        
        #region Format Private Message Recipients
        public static string FormatPrivateMessageRecipients (PrivateMessage message) 
        {
            if (message.Recipients == null)
                // LN 5/31/04 : returns "Not available"
                return ResourceManager.GetString("NotAvailable"); //string.Empty;

            CSContext csContext = CSContext.Current;
            StringBuilder s = new StringBuilder();

            for (int i = 0; i < message.Recipients.Count; i++) 
            {
                User user = (User) message.Recipients[i];

                // LN 5/31/04 : Workaround to keep stored procedures as they are now.
                // Check out if recipient's ID is AuthorID.
                // If yes, then the real recipient is current user.
                if (user.UserID != message.AuthorID)
                    s.Append( Formatter.FormatUsername( user.UserID, user.Username ) );
                else
                    s.Append( Formatter.FormatUsername( csContext.User.UserID, csContext.User.Username ) );

                if ((i+1) < message.Recipients.Count)
                    s.Append(", ");

            }

            // LN 5/31/04 : returns "Not available"
            if (s.Length > 0)
                return s.ToString();
            else
                return ResourceManager.GetString("NotAvailable");

        }
        #endregion

        
        #region Format Forum Name in ThreadView
        public static string ForumNameInThreadView (Thread thread) 
        {
            CSContext csContext = CSContext.Current;

            if (thread.SectionID != csContext.SectionID)
                return "<span class=\"inlineLink\" onclick=\"window.open('" + ForumUrls.Instance().Forum(thread.SectionID) + "')\"> in " + thread.Section.Name + "</span>";
            
            return string.Empty;

        }
        #endregion

        
        #region Format User Location
        public static string FormatLocation ( string encodedString ) 
        {
            return FormatLocation ( encodedString, true );
        }


        public static string FormatLocation ( string encodedString, bool createLink) 
        {
            string urlName;
            ForumPost p;
            Forum f;
            CommunityServer.Components.Group fg;
            SiteUrls.ForumLocation location = SiteUrls.GetForumLocation(encodedString);
            string url = "";

            if ( createLink )
                url = "<a href=\"{0}\">{1}</a>";
            else
                url = "{1}";

            // Check if we have a comma separated key value in UrlName
            //
            string[] keys = location.UrlName.Split( ',' );
            if (keys != null &&
                keys.GetLength( 0 ) > 0)
            {
                urlName = keys[0];
            }
            else
            {
                urlName = location.UrlName;
            }

            switch (urlName) 
            {
                case "/":
                case "/default.aspx":
                    location.Description = string.Format(url, Globals.GetSiteUrls().Home, ResourceManager.GetString("Location_Home"));
                    break;

                case "faq":
                    location.Description = string.Format(url, Globals.GetSiteUrls().FAQ, ResourceManager.GetString("Location_Faq"));
                    break;

                case "user_List":
                    location.Description = string.Format(url, Globals.GetSiteUrls().UserList, ResourceManager.GetString("Location_MemberList"));
                    break;

                case "user":
					User u = Users.GetUser(location.UserID, false);
                    location.Description = string.Format(ResourceManager.GetString("Location_MemberProfile"), string.Format(url, Globals.GetSiteUrls().UserProfile(u.Username), u.DisplayName));
                    break;

                case "forum":
                case "forumshome":
                    try 
                    {
                        f = Forums.GetForum(location.ForumID);
                        location.Description = string.Format(ResourceManager.GetString("Location_Forum"), string.Format(url, ForumUrls.Instance().Forum(location.ForumID), f.Name));
                    } 
                    catch 
                    {
                        location.Description = string.Format(url, Globals.GetSiteUrls().ForumsHome, ResourceManager.GetString("Location_ForumsHome") );
                    }
                    break;

                case "webloghome":
                    location.Description = string.Format(url, Globals.GetSiteUrls().WeblogsHome, ResourceManager.GetString("Location_WeblogsHome") );
                    break;

                case "galleryhome":
                    location.Description = string.Format(url, Globals.GetSiteUrls().GalleriesHome, ResourceManager.GetString("Location_GalleriesHome") );
                    break;

                case "searchFriendlyForum":
                    try 
                    {
                        f = Forums.GetForum(location.ForumID);
                        location.Description = string.Format(ResourceManager.GetString("Location_Forum"), string.Format(url, ForumUrls.Instance().Forum(location.ForumID), f.Name));
                    } 
                    catch 
                    {
                        location.Description = ResourceManager.GetString("Location_Hidden");
                    }
                    break;

                case "post":
                    try 
                    {
                        p = Posts.GetPost(location.PostID, CSContext.Current.User.UserID);

                        location.Description = string.Format(ResourceManager.GetString("Location_PostView"), string.Format(url, Globals.GetSiteUrls().Post(location.PostID), p.Subject));
                    } 
                    catch 
                    {
                        location.Description = ResourceManager.GetString("Location_Hidden");
                    }
                    break;

                case "searchFriendlyPost":
                    try 
                    {
                        p = Posts.GetPost(location.PostID, CSContext.Current.User.UserID);

                        location.Description = string.Format(ResourceManager.GetString("Location_PostView"), string.Format(url, Globals.GetSiteUrls().Post(location.PostID), p.Subject));
                    } 
                    catch 
                    {
                        location.Description = ResourceManager.GetString("Location_Hidden");
                    }
                    break;

                case "forumGroup":
                    try 
                    {
                        fg = ForumGroups.GetForumGroup(location.ForumGroupID);
                        location.Description = string.Format(ResourceManager.GetString("Location_ForumGroup"), string.Format(url, Globals.GetSiteUrls().ForumGroup(location.ForumGroupID), fg.Name));
                    } 
                    catch 
                    {
                        location.Description = ResourceManager.GetString("Location_Hidden");
                    }
                    break;

                case "searchFriendlyForumGroup":
                    try 
                    {
                        fg = ForumGroups.GetForumGroup(location.ForumGroupID);
                        location.Description = string.Format(ResourceManager.GetString("Location_ForumGroup"), string.Format(url, Globals.GetSiteUrls().ForumGroup(location.ForumGroupID), fg.Name));
                    } 
                    catch 
                    {
                        location.Description = ResourceManager.GetString("Location_Hidden");
                    }
                    break;

                case "post_Reply":
                    try 
                    {
                        p = Posts.GetPost(location.PostID, CSContext.Current.User.UserID);

                        location.Description = string.Format(ResourceManager.GetString("Location_PostReply"), string.Format(url, Globals.GetSiteUrls().Post(location.PostID), p.Subject));
                    } 
                    catch 
                    {
                        location.Description = ResourceManager.GetString("Location_Hidden");
                    }
                    break;

                case "post_Create":
                    try 
                    {
                        f = Forums.GetForum(location.ForumID);
                        location.Description = string.Format(ResourceManager.GetString("Location_PostNew"), string.Format(url, ForumUrls.Instance().Forum(location.ForumID), f.Name));
                    } 
                    catch 
                    {
                        location.Description = ResourceManager.GetString("Location_Hidden");
                    }
                    break;

                case "whoIsOnline":
                    location.Description = string.Format(url, Globals.GetSiteUrls().WhoIsOnline, ResourceManager.GetString("Location_WhoIsOnline"));
                    break;

                case "post_Active":
                    location.Description = string.Format(url, ForumUrls.Instance().PostsActive, ResourceManager.GetString("Location_ActiveTopics"));
                    break;

                case "post_Unanswered":
                    location.Description = string.Format(url, ForumUrls.Instance().PostsUnanswered, ResourceManager.GetString("Location_UnansweredTopics"));
                    break;

                case "user_ForgotPassword":
                    location.Description = string.Format(url, Globals.GetSiteUrls().UserForgotPassword, ResourceManager.GetString("Location_Login"));
                    break;

                case "user_Register":
                    location.Description = ResourceManager.GetString("Location_Hidden");
                    break;

                case "user_EditProfile":
                case "user_EditProfile_Clean":
                    location.Description = ResourceManager.GetString("Location_Hidden");
                    break;

                case "logout":
                    location.Description = string.Format(url, Globals.GetSiteUrls().Logout, ResourceManager.GetString("Location_Logout"));
                    break;

                case "login":
                    location.Description = string.Format(url, Globals.GetSiteUrls().Login, ResourceManager.GetString("Location_Login"));
                    break;

                case "search":
                case "search_ForText":
                case "search_ByUser":
                    location.Description = ResourceManager.GetString("Location_Hidden");
                    break;

                case "user_MyForums":
                    location.Description = ResourceManager.GetString("Location_Hidden");
                    break;

                case "user_ChangePassword":
                    location.Description = ResourceManager.GetString("Location_Hidden");
                    break;

                case "user_ChangePasswordAnswer":
                    location.Description = ResourceManager.GetString("Location_Hidden");
                    break;

                default:
                    location.Description = ResourceManager.GetString("Location_NotFound");
                    break;
            }

            return location.Description;
        }
        #endregion


        
        #region Format sub-forum listings
        public static string FormatSubForum (Forum forum) 
        {
            string stringToFormat = "<br><b>" + ResourceManager.GetString("Subforums") + "</b>";
            string subForumSeparator = ResourceManager.GetString("CommaSeperator");

            // If there are no sub forums, return
            //
            if (forum.Sections.Count == 0)
                return null;

			// Sort subforums by name
			forum.Sections.Sort(new SectionSorter(SectionSortBy.Name));

            foreach (Forum f in forum.Sections) 
            {
                stringToFormat = stringToFormat + " <a href=\"" + ForumUrls.Instance().Forum(f.SectionID) + "\">" + f.Name + "</a>" + subForumSeparator;
            }

            stringToFormat = stringToFormat.Remove( stringToFormat.LastIndexOf(subForumSeparator), 1);

            return stringToFormat;
        }

        public static string FormatSubForumAdmin( Section section ) 
        {
            string stringToFormat = "<br><b>" + ResourceManager.GetString("Subforums") + "</b>";
            string subForumSeparator = ResourceManager.GetString("CommaSeperator");

            // If there are no sub forums, return
            //
            if (section.Sections.Count == 0)
                return null;

            Forum forum = section as Forum;
            if(forum != null || section.Sections.Count == 0)
            {
                return null;
            }

			// Sort subforums by name
			forum.Sections.Sort(new SectionSorter(SectionSortBy.Name));

            foreach (Forum f in section.Sections) 
            {
                stringToFormat = stringToFormat + " <a href=\"" + ForumUrls.Instance().ControlPanel_EditForum(f.SectionID) + "\">" + f.Name + "</a>" + subForumSeparator;
            }

            stringToFormat = stringToFormat.Remove( stringToFormat.LastIndexOf(subForumSeparator), 1);

            return stringToFormat;
        }
        #endregion

        
        #region Formatting for read/unread status icon for Forums & Threads
        public static string StatusIcon (int status) 
        {
            string imagePath = Globals.GetSkinPath() +"/images/";
            string imageName = "";
            string imageTitle = "";
            string openWindow = "javascript:OpenWindow('" + Globals.GetSiteUrls().HelpThreadIcons + "')";

            switch (status) 
            {
                case 1:
                    imageName = "topic-announce.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicAnnounce");
                    break;

                case 2:
                    imageName = "topic-announce_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicAnnounceNotRead");
                    break;

                case 3:
                    imageName = "topic-pinned_popular.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                    break;

                case 4:
                    imageName = "topic-pinned_popular_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                    break;

                case 5:
                    imageName = "topic-pinned.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicPinned");
                    break;

                case 6:
                    imageName = "topic-pinned_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicPinnedNotRead");
                    break;

                case 7:
                    imageName = "topic-locked.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicNoReplies");
                    break;

                case 8:
                    imageName = "topic-locked_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicNoRepliesNotRead");
                    break;

                case 9:
                    imageName = "topic-popular.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                    break;

                case 10:
                    imageName = "topic-popular_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                    break;

                case 11:
                    imageName = "topic.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_Topic");
                    break;

                case 12:
                    imageName = "topic_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicNotRead");
                    break;

            }

            imageName = imagePath + imageName;

            return String.Format(threadStatusIcon, openWindow, imageTitle, imageName);
        }

		public static bool HasRead(Thread thread)
		{
			return thread.HasRead || CSContext.Current.User.IsAnonymous;
		}

        public static string StatusIcon (Thread thread) 
        {
            string imagePath = Globals.GetSkinPath() +"/images/";
            string imageName = "";
            string imageTitle = "";
            string openWindow = "javascript:OpenWindow('" + Globals.GetSiteUrls().HelpThreadIcons + "')";
			bool hasRead = HasRead(thread);

            if (thread.IsAnnouncement) 
            {
                if (hasRead) 
                {
                    imageName = "topic-announce.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicAnnounce");
                } 
                else 
                {
                    imageName = "topic-announce_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicAnnounceNotRead");
                }
            } 
            else if ((thread.IsSticky) && (thread.IsPopular)) 
            {
                if (hasRead) 
                {
                    imageName = "topic-pinned_popular.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                } 
                else 
                {
                    imageName = "topic-pinned_popular_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                }
            } 
            else if (thread.IsSticky) 
            {
                if (hasRead) 
                {
                    imageName = "topic-pinned.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicPinned");
                } 
                else 
                {
                    imageName = "topic-pinned_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicPinnedNotRead");
                }
            } 
            else if (thread.IsLocked) 
            {
                if (hasRead) 
                {
                    imageName = "topic-locked.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicNoReplies");
                } 
                else 
                {
                    imageName = "topic-locked_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicNoRepliesNotRead");
                }
            } 
            else if (thread.IsPopular) 
            {
                if (hasRead) 
                {
                    imageName = "topic-popular.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                } 
                else 
                {
                    imageName = "topic-popular_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_PopularPost");
                }
            } 
            else 
            {
                if (hasRead) 
                {
                    imageName = "topic.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_Topic");
                } 
                else 
                {
                    imageName = "topic_notread.gif";
                    imageTitle = ResourceManager.GetString("IconAlt_TopicNotRead");
                }
            }

            imageName = imagePath + imageName;

            return String.Format(threadStatusIcon, openWindow, imageTitle, imageName);
            
        }

		public static bool HasRead(Forum forum)
		{
			User u = CSContext.Current.User;

			// Setup the read/unread status
			if (!u.IsAnonymous) 
			{
				HybridDictionary d = Sections.GetSectionsRead(u.UserID, false);

				if (d[forum.SectionID] != null) 
				{
					DateTime lastActivity = (DateTime) d[forum.SectionID];

					if (forum.MostRecentPostDate <= lastActivity)
						return true;

				}

				if (forum.TotalPosts == 0)
					return true;

				if(forum.MostRecentPostDate <= DateTime.Now.AddDays(-ForumConfiguration.Instance().DaysPostMarkedAsRead))
					return true;

				return false;
			}
			else
				return true;
		}

		public static string StatusIcon (Forum forum) 
        {
            string imagePath = Globals.GetSkinPath() +"/images/";
            string icon = string.Empty;
            string alt = string.Empty;
			bool unreadPosts = !HasRead(forum);    
			User u = CSContext.Current.User;

			switch (forum.ForumType) 
            {

                case ForumType.KB:
                    if (u.IsAnonymous) 
                    {
                        icon = "forum_kb.gif";
                        alt = ResourceManager.GetString("IconAlt_KB");
                        break;
                    }

                    if (unreadPosts) 
                    {
                        icon = "forum_kb_new.gif";
                        alt = ResourceManager.GetString("IconAlt_KBNewPosts");
                    } 
                    else 
                    {
                        icon = "forum_kb.gif";
                        alt = ResourceManager.GetString("IconAlt_KB");
                    }
                    break;

                case ForumType.Newsletter:
                    if (u.IsAnonymous) 
                    {
                        icon = "forum_newsletter.gif";
                        alt = ResourceManager.GetString("IconAlt_PrivateForums");
                        break;
                    }

                    if (unreadPosts) 
                    {
                        icon = "forum_newsletter.gif";
                        alt = ResourceManager.GetString("IconAlt_PrivateForumsNewPosts");
                    } 
                    else 
                    {
                        icon = "forum_newsletter.gif";
                        alt = ResourceManager.GetString("IconAlt_PrivateForums");
                    }
                    break;

                case ForumType.Link:
                    icon = "forum_link.gif";
                    alt = ResourceManager.GetString("IconAlt_Link");
                    break;

                default:
                    if (u.IsAnonymous) 
                    {
                        icon = "forum_status.gif";
                        alt = ResourceManager.GetString("NoUnreadPosts");
                        break;
                    }

                    if (forum.IsPrivate) 
                    {

                        if (unreadPosts) 
                        {
                            icon = "forum_private_newposts.gif";
                            alt = ResourceManager.GetString("IconAlt_PrivateForumsNewPosts");
                        } 
                        else 
                        {
                            icon = "forum_private.gif";
                            alt = ResourceManager.GetString("IconAlt_PrivateForums");
                        }
                        
                    } 
                    else 
                    {
                        if (unreadPosts) 
                        {
                            icon = "forum_status_new.gif";
                            alt = ResourceManager.GetString("IconAlt_NewPosts");
                        } 
                        else 
                        {
                            icon = "forum_status.gif";
                            alt = ResourceManager.GetString("NoUnreadPosts");
                        }
                    }

                    break;
            }
				
            return String.Format(forumStatusIcon, alt, imagePath + icon);
        }
        #endregion
       
        #region Format last post display
        public static string FormatLastPost (Thread thread) 
		{
			return FormatLastPost(thread, false);           
        }

		public static string FormatLastPost (Thread thread, bool useLongFormat)
		{
			string author = thread.MostRecentPostAuthor;
			User u = Users.FindUserByUsername(author);
			if (u != null && u.UserID > 0)
				author = u.DisplayName;

			return FormatLastPost(thread.MostRecentPostID, thread.Replies, thread.ThreadDate, thread.MostRecentPostAuthorID, author, thread.Subject, false, useLongFormat);
		}

        public static string FormatLastPost (Forum forum) 
        {

            return FormatLastPost( forum, false );
        }

        public static string FormatLastPost (Forum forum, bool displaySubject) 
        {
			string author = forum.MostRecentPostAuthor;
			User u = Users.FindUserByUsername(author);
			if (u != null && u.UserID > 0)
				author = u.DisplayName;
				
            return FormatLastPost( forum.MostRecentPostID, forum.MostRecentThreadReplies, forum.MostRecentPostDate, forum.MostRecentPostAuthorID, author, forum.MostRecentPostSubject, displaySubject, false );
        }

        public static string FormatLastPost (int postID, int replies, DateTime postDate, int authorID, string author, string subject, bool displaySubject, bool useLongFormat) 
        {
            string postToday;
            string postYesterday;
            string postTodayAnonymous;
            string postYesterdayAnonymous;
            string formatString = "";
            object[] formatElements = new object[6];
            string temp = "";
	
            postToday = "<b>" + ResourceManager.GetString("TodayAt") + " {0}</b>";
            postYesterday = "<b>" + ResourceManager.GetString("YesterdayAt") + " {0}</b>";
            postTodayAnonymous = "<b>" + ResourceManager.GetString("TodayAt") + " {0}</b>";
            postYesterdayAnonymous = "<b>" + ResourceManager.GetString("YesterdayAt") + " {0}</b>";

            // Do we have an author
            //
            if (author == string.Empty)
                author = ResourceManager.GetString("DefaultAnonymousUsername");
		
            // Populate the object array for the string formatter
            //
            formatElements[0] = postDate;
            formatElements[1] = Globals.GetSiteUrls().UserProfile( authorID);
            formatElements[2] = Formatter.CheckStringLength(author, 16);

			// Attempt to get the currently signed in user
			//
        	CSContext cntx = CSContext.Current;
        	User user = cntx.User;

            if (replies >= ForumConfiguration.Instance().PostsPerPage) 
            {
                int page;
				
				if (user.PostSortOrder == SortOrder.Descending)
					page = 1;
				else
	                page = 1 + replies / ForumConfiguration.Instance().PostsPerPage;

				formatElements[3] = ForumUrls.Instance().PostPaged(postID, page);
            } 
            else 
            {
                formatElements[3] = ForumUrls.Instance().PostInPage(postID, postID);
            }
			
            if (postDate < DateTime.Now.AddYears(-20))
                return ResourceManager.GetString("NumberWhenZero");
            
            // Do we have a signed in user?  If so, adjust it.
            //
            if (!user.IsAnonymous)
            {
                postDate = user.GetTimezone(postDate);
                formatElements[0] = postDate;
            }

            // prefix the formatString with the subject if asked
            //
			if (!useLongFormat)
			{
				if (displaySubject) 
				{
					// Used to grab the subject of the postID.
					//
					formatString = "<b><a title=\"{5}\" href=\"{3}\">{4}</a></b><br/>" + ResourceManager.GetString("ForumGroupView_Legend_LastPostBy") + "<a href=\"{1}\">{2}</a><br/>";
				
					// We have the subject html encoded
					//
					formatElements[4] =   Formatter.CheckStringLength( subject, 25 ) ;
				} 
				else 
				{
					formatString = ResourceManager.GetString("ForumGroupView_Legend_LastPostBy") + "<a href=\"{1}\">{2}</a>&nbsp;<a href=\"{3}\"><img alt=\"{5}\" border=\"0\" src=\"" + Globals.GetSkinPath() + "/images/icon_mini_topic.gif\"></a><br/>";
					formatElements[4] = "";
				}
			}
			else
			{
				if (displaySubject) 
				{
					// Used to grab the subject of the postID.
					//
					formatString = string.Format(ResourceManager.GetString("ForumGroupView_Legend_LastPostBy_Long_WithTitle"), "{3}", "{4}", "{1}", "{2}");
				
					// We have the subject html encoded
					//
					formatElements[4] =   Formatter.CheckStringLength( subject, 25 ) ;
				} 
				else 
				{
                    if(replies == 0)
                        formatString = string.Format(ResourceManager.GetString("ForumGroupView_Legend_LastPostBy_Long_WithNoReplies"), "{3}", "{1}", "{2}");
                    else
					    formatString = string.Format(ResourceManager.GetString("ForumGroupView_Legend_LastPostBy_Long"), "{3}", "{1}", "{2}");
					
                    formatElements[4] = "";
				}
			}

            // Always display the post's subject as a tool tip
            //
            formatElements[5] = subject;

            // Format the post if it occurred today
            //
            DateTime userLocalTime = user.GetTimezone(DateTime.Now); 
            
            if ((postDate.DayOfYear == userLocalTime.DayOfYear) && 
                (postDate.Year == userLocalTime.Year)) 
            {
                if (authorID > 0)
                    formatString += postToday;
                else
                    formatString += postTodayAnonymous;

                formatElements[0] = ((DateTime) formatElements[0]).ToString(cntx.SiteSettings.TimeFormat);

            } 
            else if ((postDate.DayOfYear == (userLocalTime.DayOfYear - 1)) && 
                (postDate.Year == userLocalTime.Year)) 
            {
                if (authorID > 0) 
                    formatString += postYesterday;
                else
                    formatString += postYesterdayAnonymous;

                formatElements[0] = ((DateTime) formatElements[0]).ToString(cntx.SiteSettings.TimeFormat);

            } 
            else 
            {
                formatString += "{0}";					

                formatElements[0] = ((DateTime) formatElements[0]).ToString(user.Profile.DateFormat) + " " + ((DateTime) formatElements[0]).ToString(cntx.SiteSettings.TimeFormat);
            }

            // add a table
            //
            if (displaySubject)
                temp = String.Format(formatString, formatElements);
            else
                temp = String.Format(formatString, formatElements);

            return temp;            
        }
        #endregion

        #endregion

        #region Format Users Viewing Forum
        public static string FormatUsersViewingForum (Forum forum) 
        {
//            SiteUrls.ForumLocation location;
//            ArrayList users;
//            int viewing = 0;
//
//            users = Users.GetUsersOnline(CSContext.Current.SiteSettings.UserOnlineTimeWindow);
//
//            foreach (User user in users) 
//            {
//                location = SiteUrls.GetForumLocation(user.LastAction);
//
//                if (location.ForumID == forum.SectionID)
//                    viewing++;
//            }
//
//            if (viewing > 0)
//                return string.Format(ResourceManager.GetString("ForumGroupView_Viewing"), viewing);

            return "";
        }
        #endregion
	}
}
