⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formatter.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 2 页
字号:

        public static string RemoveHtml(string html, int charLimit)
        {
            if(html == null || html.Trim().Length == 0)
                return string.Empty;

            string nonhtml =  Regex.Replace(html, "<[^>]+>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            if(charLimit <= 0 || charLimit >= nonhtml.Length)
                return nonhtml;

            int place = charLimit;
            int len = nonhtml.Length - 1;

            while(!Char.IsWhiteSpace(nonhtml[place]) && place < len)
            {
                place ++;
            }

            return nonhtml.Substring(0,place);


        }

		#endregion

		#region Format post emoticon
		public static string GetEmotionMarkup (int emoticonID) {

            const string imgFormat = "<img src=\"{0}{1}\" alt=\"{2}\" />";
            string forumHomePath = Globals.GetSiteUrls().Emoticon;

            // If we aren't using Emoticons, return an empty string.
            if ( (emoticonID == 0) || (!CSContext.Current.SiteSettings.EnableEmoticons) )
				return "";

            ArrayList emoticonTxTable = Smilies.GetSmilies();

            // EAD 2-9-2005: Removed try/catch block as this will return null if doesn't exist and changed
            // logic to detect the null returned.
            Smiley smiley = new Smiley();
            smiley = Smilies.GetSmiley( emoticonID );

            if (smiley != null)
                return string.Format(imgFormat, forumHomePath, smiley.SmileyUrl, smiley.SmileyText + " [" + smiley.SmileyCode + "]");
            else
                return "";

		}
		#endregion

        #region Format edit notes
        public static string EditNotes (string notes) {

            if (notes == null)
                return String.Empty;

            //string editNotesTable = "<table width=\"75%\" class=\"editTable\"><tr><td>{0}</td></tr></table>";
            //return string.Format(editNotesTable, Transforms.FormatPost(notes, PostType.HTML)) + Globals.HtmlNewLine + Globals.HtmlNewLine; 
			return Transforms.FormatPostText(notes, PostType.HTML);

        }
        #endregion

        #region Format Post IP Address
        public static string PostIPAddress (Post post) {

            if (post.UserHostAddress == "000.000.000.000")
                return string.Format(ResourceManager.GetString("PostFlatView_IPAddress"), ResourceManager.GetString("NotLogged"));

            if (CSContext.Current.SiteSettings.DisplayPostIP) {
                return string.Format(ResourceManager.GetString("PostFlatView_IPAddress"), post.UserHostAddress);
            } else if ((CSContext.Current.SiteSettings.DisplayPostIPAdminsModeratorsOnly) && ((CSContext.Current.User.IsForumAdministrator) || (CSContext.Current.User.IsModerator)) ){ 
                return string.Format(ResourceManager.GetString("PostFlatView_IPAddress"), post.UserHostAddress);
            } else {
                return string.Format(ResourceManager.GetString("PostFlatView_IPAddress"), ResourceManager.GetString("Logged"));
            }

        }
        #endregion

        #region Format Whitespace
        public static string Whitespace(int height, int width, bool preBreak, bool postBreak) {
            string imgTag = string.Format("<img width=\"{1}\" height=\"{0}\" src=\"" + Globals.ApplicationPath + "/Utility/1x1.gif\">", height, width);

            if (preBreak)
                imgTag = "<br>" + imgTag;

            if (postBreak)
                imgTag = imgTag + "<br>";

            return imgTag;

        }
        
        #endregion

        #region Format Username
        public static string FormatUsername (int userID, string username) {
            return FormatUsername( userID, username, false, true );
        }
        
        public static string FormatUsername (int userID, string username, bool showAsAnonymous) {
            return FormatUsername( userID, username, showAsAnonymous, true );
        }
        
        public static string FormatUsername (int userID, string username, bool showAsAnonymous, bool useSpanTag) {
            // Added actual param showAsAnonymous to display a normal user as anonymous
            // if it is required so.
            //
            if (username == "")
                username = ResourceManager.GetString("DefaultAnonymousUsername");

            if (userID == 0)
                return ResourceManager.GetString("DefaultAnonymousUsername");
            
            if (userID > 0 && showAsAnonymous) { 
                username = ResourceManager.GetString("DefaultAnonymousUsername");
                userID = Users.GetAnonymousUser().UserID;
            }

            if (useSpanTag)
            return "<span class=\"inlineLink\" onclick=\"window.open('" + Globals.GetSiteUrls().UserProfile(userID) + "')\">" + username + "</span>";
            else
                return "<a target=\"_blank\" href=\"" + Globals.GetSiteUrls().UserProfile(userID) + "\">" + username + "</a>";
        }
        #endregion
		
		public static string FormatIrcCommands (string postText, string postFrom) {
			return FormatIrcCommands (postText, postFrom, "");
		}

		public static string FormatIrcCommands (string postText, string postFrom, string postTo) {
			// This is for our pure enjoyment. - Terry & Eric
			//

			// /me slaps Terry with a big-mouth trout.
			//
			postText = Regex.Replace(postText, @"(>/me\b|\n>/me)(.*?|\n)(<|\n|<\n)", "><span class=\"txtIrcMe\">&nbsp;*&nbsp;" + postFrom + "$2</span><", RegexOptions.IgnoreCase | RegexOptions.Compiled);
			postText = Regex.Replace(postText, @"(\n/me\b)(.*?|\n)(\n)", "<span class=\"txtIrcMe\">&nbsp;*&nbsp;" + postFrom + "$2</span>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

			// /you
			//
			// TODO: when we figure out how to grab the "Replying To" from
			// create/edit post.


			return postText;
		}

        public static string FormatUserRank (Int32 postCount, bool showAsPicture) {
            ArrayList ranks = Ranks.GetRanks();
            return FormatUserRank( postCount, showAsPicture, ranks );
        }

        public static string FormatUserRank (Int32 postCount, bool showAsPicture, ArrayList ranks) { 
            string rankName = "";
            string rankUrlPicture = "";
            string imgHtmlTag = "<img src=\"{0}\" border=\"0\" alt=\"{1}\">";
            
            if (ranks == null)
                return ResourceManager.GetString( "Utility_UserRank_NotAvailable" );

            foreach (Rank rank in ranks) { 
                if (postCount >= rank.PostingCountMinimum && 
                    postCount <= rank.PostingCountMaximum) { 

                    rankName = rank.RankName.Trim();
                    rankUrlPicture = rank.RankIconUrl.Trim();
                    break;
                }
            }
            
            // Exit if there is an empty rank name
            //
            if (rankName.Length == 0) { 
                return ResourceManager.GetString( "Utility_UserRank_NotAvailable" );
            }
            
            // Do we need to display a pictured rank?
            //
            if (showAsPicture && rankUrlPicture.Length > 0) {
                string pictureUrl = Globals.GetSkinPath() + "/images/" + rankUrlPicture;

                // TODO: Check for picture availability ?!
                //

                return string.Format( imgHtmlTag, pictureUrl, rankName );
            } 
            
            return rankName;
        }

        #region Format Moderator Actions
        /// <summary>
        /// Gets a localized description for provided ModeratorAction.
        /// </summary>
        public static string FormatModeratorAction (ModeratorActions action) {
            return ResourceManager.GetString( "Utility_ModeratorActions_" + action.ToString() );
        }
        #endregion

        #region Format User Audit Counters
        /// <summary>
        /// Formats user moderation counters following this pattern "[message_actions] / [forum_actions]".
        /// If one of the ingredients are 0 then we will display a '-' character instead. 
        /// </summary>
        public static string FormatUserAuditCounters (int userID, AuditSummary summary) {
            string outString = "{0} / {1}";
            string counterLink = "<a href=\"{0}\">{1}</a>";
            int[] counters = Audit.GetUserAuditCounters( summary );

            if (counters == null) { 
                return string.Format( outString, "-", "-" );
            }

            
            if (counters[0] > 0 && counters[2] > 0)
                return string.Format( outString, string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[1] ), counters[0] ), string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[3] ), counters[2] ) );
            else {
                if (counters[0] == 0 && counters[2] > 0)
                    return string.Format( outString, "-", string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[3] ), counters[2] ) );
                else 
                    if (counters[0] > 0 && counters[2] == 0)
                        return string.Format( outString, string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[1] ), counters[0] ), "-" );
                    else
                        return string.Format( outString, "-", "-" );
            }
        }
        #endregion

        #region Format ban reason
        public static string FormatBanReason (UserBanReason banReason) { 
            return ResourceManager.GetString( "Utility_UserBanReason_" + banReason.ToString() );
        }
        #endregion
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -