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

📄 transforms.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 4 页
字号:
			//
			encodedString = Regex.Replace(encodedString, @"\[wmv(?:\s*)\]((.|\n)*?)\[/wmv(?:\s*)\]", "<embed src=\"$1\" width=\"314\" height=\"256\" autostart=\"0\"></embed>", options);
			encodedString = Regex.Replace(encodedString, @"\[wmv=((.|\n)*?)x((.|\n)*?)(?:\s*)\]((.|\n)*?)\[/wmv(?:\s*)\]", "<embed src=\"$5\" autostart=\"0\" width=\"$1\" height=\"$3\"></embed>", options );
 
			// mid
			//
			encodedString = Regex.Replace(encodedString, @"\[mid(?:\s*)\]((.|\n)*?)\[/mid(?:\s*)\]", "<embed src=\"$1\" width=\"314\" height=\"45\" autostart=\"0\"></embed>", options);
 
			// ra
			//
			encodedString = Regex.Replace(encodedString, @"\[ra(?:\s*)\]((.|\n)*?)\[/ra(?:\s*)\]", "<object classid=\"clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA\" id=\"RAOCX\" width=\"253\" height=\"60\"><param name=\"_ExtentX\" value=\"6694\"><param name=\"_ExtentY\" value=\"1588\"><param name=\"AUTOSTART\" value=\"0\"><param name=\"SHUFFLE\" value=\"0\"><param name=\"PREFETCH\" value=\"0\"><param name=\"NOLABELS\" value=\"0\"><param name=\"SRC\" value=\"$1\"><param name=\"CONTROLS\" value=\"StatusBar,ControlPanel\"><param name=\"LOOP\" value=\"0\"><param name=\"NUMLOOP\" value=\"0\"><param name=\"CENTER\" value=\"0\"><param name=\"MAINTAINASPECT\" value=\"0\"><param name=\"BACKGROUNDCOLOR\" value=\"#000000\"><embed src=\"$1\" width=\"253\" autostart=\"true\" height=\"60\"></embed></object>", options);
 
			// rm
			//
			encodedString = Regex.Replace(encodedString, @"\[rm(?:\s*)\]((.|\n)*?)\[/rm(?:\s*)\]", "<object classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" height=\"241\" id=\"Player\" width=\"316\" viewastext><param name=\"_ExtentX\" value=\"12726\"><param name=\"_ExtentY\" value=\"8520\"><param name=\"AUTOSTART\" value=\"0\"><param name=\"SHUFFLE\" value=\"0\"><param name=\"PREFETCH\" value=\"0\"><param name=\"NOLABELS\" value=\"0\"><param name=\"CONTROLS\" value=\"ImageWindow\"><param name=\"CONSOLE\" value=\"_master\"><param name=\"LOOP\" value=\"0\"><param name=\"NUMLOOP\" value=\"0\"><param name=\"CENTER\" value=\"0\"><param name=\"MAINTAINASPECT\" value=\"316\"><param name=\"BACKGROUNDCOLOR\" value=\"#000000\"></object><br><object classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" height=\"32\" id=\"Player\" width=\"316\" VIEWASTEXT><param name=\"_ExtentX\" value=\"18256\"><param name=\"_ExtentY\" value=\"794\"><param name=\"AUTOSTART\" value=\"-1\"><param name=\"SHUFFLE\" value=\"0\"><param name=\"PREFETCH\" value=\"0\"><param name=\"NOLABELS\" value=\"0\"><param name=\"CONTROLS\" value=\"controlpanel\"><param name=\"CONSOLE\" value=\"_master\"><param name=\"LOOP\" value=\"0\"><param name=\"NUMLOOP\" value=\"0\"><param name=\"CENTER\" value=\"0\"><param name=\"MAINTAINASPECT\" value=\"0\"><param name=\"BACKGROUNDCOLOR\" value=\"#000000\"><param name=\"SRC\" value=\"$1\"></object>", options);
			encodedString = Regex.Replace(encodedString, @"\[rm=((.|\n)*?)x((.|\n)*?)(?:\s*)\]((.|\n)*?)\[/rm(?:\s*)\]", "<object classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" height=\"$3\" id=\"Player\" width=\"$1\" viewastext><param name=\"_ExtentX\" value=\"12726\"><param name=\"_ExtentY\" value=\"8520\"><param name=\"AUTOSTART\" value=\"0\"><param name=\"SHUFFLE\" value=\"0\"><param name=\"PREFETCH\" value=\"0\"><param name=\"NOLABELS\" value=\"0\"><param name=\"CONTROLS\" value=\"ImageWindow\"><param name=\"CONSOLE\" value=\"_master\"><param name=\"LOOP\" value=\"0\"><param name=\"NUMLOOP\" value=\"0\"><param name=\"CENTER\" value=\"0\"><param name=\"MAINTAINASPECT\" value=\"$5\"><param name=\"BACKGROUNDCOLOR\" value=\"#000000\"></object><br><object classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" height=\"32\" id=\"Player\" width=\"$1\" VIEWASTEXT><param name=\"_ExtentX\" value=\"18256\"><param name=\"_ExtentY\" value=\"794\"><param name=\"AUTOSTART\" value=\"-1\"><param name=\"SHUFFLE\" value=\"0\"><param name=\"PREFETCH\" value=\"0\"><param name=\"NOLABELS\" value=\"0\"><param name=\"CONTROLS\" value=\"controlpanel\"><param name=\"CONSOLE\" value=\"_master\"><param name=\"LOOP\" value=\"0\"><param name=\"NUMLOOP\" value=\"0\"><param name=\"CENTER\" value=\"0\"><param name=\"MAINTAINASPECT\" value=\"0\"><param name=\"BACKGROUNDCOLOR\" value=\"#000000\"><param name=\"SRC\" value=\"$5\"></object>", options );
 

			// Color
			//
			encodedString = Regex.Replace(encodedString, @"\[color=((.|\n)*?)(?:\s*)\]((.|\n)*?)\[/color(?:\s*)\]", "<span style=\"color=$1;\">$3</span>", options);
 
			// Horizontal Rule
			//
			//            encodedString = Regex.Replace(encodedString, @"\[hr(?:\s*)\]", "<hr />", options);
        
			// Email
			//
			encodedString = Regex.Replace(encodedString, @"\[email(?:\s*)\]((.|\n)*?)\[/email(?:\s*)\]", "<a href=\"mailto:$1\">$1</a>", options);
 
			// Font size
			//
			encodedString = Regex.Replace(encodedString, @"\[size=((.|\n)*?)(?:\s*)\]((.|\n)*?)\[/size(?:\s*)\]", "<span style=\"font-size:$1\">$3</span>", options);
			encodedString = Regex.Replace(encodedString, @"\[font=((.|\n)*?)(?:\s*)\]((.|\n)*?)\[/font(?:\s*)\]", "<span style=\"font-family:$1;\">$3</span>", options );
			encodedString = Regex.Replace(encodedString, @"\[align=((.|\n)*?)(?:\s*)\]((.|\n)*?)\[/align(?:\s*)\]", "<div style=\"text-align:$1;\">$3</span>", options );
			encodedString = Regex.Replace(encodedString, @"\[float=((.|\n)*?)(?:\s*)\]((.|\n)*?)\[/float(?:\s*)\]", "<div style=\"float:$1;\">$3</div>", options );
 
			string sListFormat = "<ol class=\"anf_list\" style=\"list-style:{0};\">$1</ol>";
			// Lists
			encodedString = Regex.Replace(encodedString, @"\[\*(?:\s*)]\s*([^\[]*)", "<li>$1</li>", options );
			encodedString = Regex.Replace(encodedString, @"\[list(?:\s*)\]((.|\n)*?)\[/list(?:\s*)\]", "<ul class=\"anf_list\">$1</ul>", options );
			encodedString = Regex.Replace(encodedString, @"\[list=1(?:\s*)\]((.|\n)*?)\[/list(?:\s*)\]", string.Format( sListFormat, "decimal" ), options );
			encodedString = Regex.Replace(encodedString, @"\[list=i(?:\s*)\]((.|\n)*?)\[/list(?:\s*)\]", string.Format( sListFormat, "lower-roman" ), RegexOptions.Compiled );
			encodedString = Regex.Replace(encodedString, @"\[list=I(?:\s*)\]((.|\n)*?)\[/list(?:\s*)\]", string.Format( sListFormat, "upper-roman" ), RegexOptions.Compiled );
			encodedString = Regex.Replace(encodedString, @"\[list=a(?:\s*)\]((.|\n)*?)\[/list(?:\s*)\]", string.Format( sListFormat, "lower-alpha" ), RegexOptions.Compiled );
			encodedString = Regex.Replace(encodedString, @"\[list=A(?:\s*)\]((.|\n)*?)\[/list(?:\s*)\]", string.Format( sListFormat, "upper-alpha" ), RegexOptions.Compiled );
 
			return encodedString;
		}
		#endregion

		#region Strip Tags
        public static string StripForPreview (string content) {
            content = Regex.Replace(content, "<br>", "\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
			content = Regex.Replace(content, "<br/>", "\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
			content = Regex.Replace(content, "<br />", "\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            content = Regex.Replace(content, "<p>", "\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            content = content.Replace("'", "&#39;");

            return StripHtmlXmlTags(content);
        }

        public static string StripHtmlXmlTags (string content) {
            return Regex.Replace(content, "<[^>]+>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);
        }

        // *********************************************************************
        //  StripScriptTags
        //
        /// <summary>
        /// Helper function used to ensure we don't inject script into the db.
        /// </summary>
        /// <param name="dirtyText">Text to be cleaned for script tags</param>
        /// <returns>Clean text with no script tags.</returns>
        /// 
        // ********************************************************************/
        public static string StripScriptTags(string content) {
            string cleanText;

            // Perform RegEx
            content = Regex.Replace(content, "<script((.|\n)*?)</script>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            cleanText = Regex.Replace(content, "\"javascript:", "", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            return cleanText;
        }
		#endregion

		#region Emoticon & User Transforms
        public static string EmoticonTransforms (string formattedPost) {

            // remove some overhead if this is turned off
            if (!CSContext.Current.SiteSettings.EnableEmoticons)
                return formattedPost;

            try {
                // Load the emoticon transform table
                //
				ArrayList emoticonTxTable = Smilies.GetSmilies();
				
				const string imgFormat = "<img src=\"{0}{1}\" alt=\"{2}\" />";

				// EAD 6/27/2004: Changed to loop through twice.
				// Once for brackets first, so to capture the Party emoticon
				// (special emoticons that REQUIRE brackets), so not to replace
				// with other non-bracket icons. Less efficient yes, but captures 
				// all emoticons properly.
				//
				string smileyPattern	= "";
				string replacePattern	= "";
				RegexOptions options	= RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Multiline ;
                string forumHomePath = Globals.GetSiteUrls().Emoticon;

				foreach ( Smiley smiley in emoticonTxTable ) {
					smileyPattern	= string.Format(@"\[{0}\]", Regex.Escape(smiley.SmileyCode) );
					replacePattern	= string.Format(imgFormat, forumHomePath, smiley.SmileyUrl, smiley.SmileyText + " [[SmileyCode]]");

					formattedPost = Regex.Replace( formattedPost, smileyPattern, replacePattern, options );
			
					if ( smiley.IsSafeWithoutBrackets() )
					{
						formattedPost = Regex.Replace( formattedPost, Regex.Escape(smiley.SmileyCode), 
								replacePattern, 
								options ); 
					}

					// If the smiley code contains a < or >, check to see if it was HtmlEncoded in the body
					if(smiley.SmileyCode.IndexOfAny( new char[] { '<', '>', '&' }) != -1)
					{
						try
						{
							smileyPattern	= string.Format(@"\[{0}\]", Regex.Escape(HttpContext.Current.Server.HtmlEncode(smiley.SmileyCode)) );
							formattedPost = Regex.Replace( formattedPost, smileyPattern, replacePattern, options );

							if(smiley.IsSafeWithoutBrackets())
							{
								formattedPost = Regex.Replace( formattedPost, Regex.Escape(HttpContext.Current.Server.HtmlEncode(smiley.SmileyCode)), 
									replacePattern, 
									options ); 
							}
						}
						catch(NullReferenceException) { }	// If we are outside of a web-context, referencing HttpContext.Current could throw a null ref.
					}

					// Finally, look for [SmileyCode] to place the smiley's code back in there (mostly for in the alt tags)
					// If the smiley was actually there, it could end up getting mistaken for another smiley... ie, [:)]
					// would get an alt tag of "Smile [:)]", it'll then search for the non-bracket version, and see :) and treat it as another instance
					formattedPost = Regex.Replace( formattedPost, @"\[SmileyCode\]", smiley.SmileyCode, options );

				}

				return formattedPost;
            } catch( Exception e ) {
                CSException ex = new CSException( CSExceptionType.UnknownError, "Could not transform smilies in the post.", e );
				ex.Log();

				return formattedPost;
            }
        }

        // *********************************************************************
        //  PerformUserTransforms
        //
        /// <summary>
        /// Performs the user defined transforms
        /// </summary>
        /// 
        // ********************************************************************/
        static string PerformUserTransforms(string stringToTransform, ArrayList userDefinedTransforms) {
            int iLoop = 0;			

            while (iLoop < userDefinedTransforms.Count) {		
		        
                // Special work for anchors
                stringToTransform = Regex.Replace(stringToTransform, userDefinedTransforms[iLoop].ToString(), userDefinedTransforms[iLoop+1].ToString(), RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Multiline);

                iLoop += 2;
            }

            return stringToTransform;
        }


        // *********************************************************************
        //  LoadTransformFile
        //
        /// <summary>
        /// Returns an array list containing transforms that the user defined in a transform file.
        /// </summary>
        /// 
        // ********************************************************************/
        private static ArrayList LoadTransformFile (string filename) {
            string cacheKey = "transformTable-" + filename;
            ArrayList tranforms;
            string filenameOfTransformFile;

            // read the transformation hashtable from the cache
            //
            tranforms = CSCache.Get(cacheKey) as ArrayList;

            if (tranforms == null) {

                tranforms = new ArrayList();

                // Grab the transform file
                //
                filenameOfTransformFile = CSContext.Current.Context.Request.MapPath("~/" + filename);

                if (filenameOfTransformFile.Length > 0) {

                    StreamReader sr = File.OpenText( filenameOfTransformFile );

                    // Read through each set of lines in the text file
                    //
                    string line = sr.ReadLine(); 
                    string replaceLine = "";

                    while (line != null) {

                        line = Regex.Escape(line);
                        replaceLine = sr.ReadLine();

                        // make sure replaceLine != null
                        //
                        if (replaceLine == null) 
                            break;
					
                        line = line.Replace("<CONTENTS>", "((.|\n)*?)");
                        line = line.Replace("<WORDBOUNDARY>", "\\b");
                        line = line.Replace("<", "&lt;");
                        line = line.Replace(">", "&gt;");
                        line = line.Replace("\"", "&quot;");

                        replaceLine = replaceLine.Replace("<CONTENTS>", "$1");					
					
                        tranforms.Add(line);
                        tranforms.Add(replaceLine);

                        line = sr.ReadLine();

                    }

                    // close the streamreader
                    //
                    sr.Close();		

                    // slap the ArrayList into the cache and set its dependency to the transform file.
                    //
                    CSCache.Insert(cacheKey, tranforms, new CacheDependency(filenameOfTransformFile));

⌨️ 快捷键说明

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