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

📄 helper.cs

📁 一个超强的在线WORD汉化版ASP程序5...
💻 CS
📖 第 1 页 / 共 2 页
字号:
		}

		/// <summary>
		/// 相对路径转为根路径格式"/UploadFile/..."
		/// </summary>
		/// <param name="path"></param>
		/// <returns></returns>
		static public string RelativePath2RootPath(string path)
		{
			string AbsolutenessPath = Context.Server.MapPath(path);
			string DummyDirectory = Context.Request.ApplicationPath;
			DummyDirectory = DummyDirectory.StartsWith("/")?DummyDirectory.Substring(1):DummyDirectory;
			string AbsolutenessRootPath = AbsolutenessPath.Substring(AbsolutenessPath.IndexOf(DummyDirectory));
			AbsolutenessRootPath = "/" + AbsolutenessRootPath.Replace("\\","/");
			AbsolutenessRootPath = AbsolutenessRootPath.EndsWith("/")?AbsolutenessRootPath:AbsolutenessRootPath+"/";
			return AbsolutenessRootPath;
		}

		/// <summary>
		/// 根路径转为带域名全路径格式
		/// </summary>
		/// <param name="path"></param>
		/// <returns></returns>
		static public string RootPath2DomainPath(string path)
		{
			string host = Context.Request.Url.Host;
			host = Context.Request.Url.Port==80?host:":"+Context.Request.Url.Port;
			return "http://" + host + RelativePath2RootPath(path);
		}

		/// <summary>
		/// 资源文件采用网站上的文件来路径
		/// </summary>
		/// <param name="path"></param>
		/// <returns></returns>
		static public string ResolveResourcePath(string path)
		{
			if(path==null)throw(new ArgumentNullException("path"));
			if(!path.StartsWith("/"))throw(new ArgumentException("path not starts with /","path"));
			return ResolvePath("/"
				+(AssemblyDateTime.Ticks)
				+"."+System.Globalization.CultureInfo.CurrentUICulture
				+"."+System.Globalization.CultureInfo.CurrentCulture
				+".aspx"+path);
		}

		static object asmdt;
		static public DateTime AssemblyDateTime
		{
			get
			{
				if(asmdt==null)
				{
					asmdt=File.GetLastWriteTime(typeof(Helper).Assembly.Location);
				}
				return (DateTime)asmdt;
			}
		}

		static bool IsFileExists(string filepath,byte[] bs)
		{
			byte[] fd;
			try
			{
				using(FileStream fs=new FileStream(filepath,FileMode.Open,FileAccess.Read))
				{
					fd=new byte[fs.Length];
					fs.Read(fd,0,fd.Length);
				}
			}
			catch
			{
				return false;
			}
			if(fd.Length!=bs.Length)return false;
			for(int i=0;i<fd.Length;i++)
			{
				if(fd[i]!=bs[i])
					return false;
			}
			return true;
		}

		static public string ResolvePath(string path)
		{
			string apppath=Context.Request.ApplicationPath;
			if(apppath.EndsWith("/"))
				apppath=apppath.Substring(0,apppath.Length-1);
			return apppath+"/lionsky_client/Lion.Data.Library.HtmlEditor."+Version+path;
		}

		static public HttpContext Context
		{
			get
			{
				HttpContext c=HttpContext.Current;
				if(c==null)
					throw(new Exception("HttpContext not found"));
				try
				{
					return c;
				}
				catch(Exception x)
				{
					throw(new Exception(x.Message));
				}
			}
		}

		/// <summary>
		/// 初始化 <see cref="Lion.Data.Library.HtmlEditor.HtmlEditor"/> 配置文件
		/// </summary>
		/// <param name="path">配置文件的路径</param>
		static public void InitConfigFile(string path)
		{
			InitConfigFile("Button.xml",path);	
			InitConfigFile("Style.xml",path);	
			InitConfigFile("ToolBar.xml",path);	
			
			Hashtable _urlargument = new Hashtable();
			
			//Button
			System.Xml.XmlDocument Buttondoc = new System.Xml.XmlDocument();
			Buttondoc.Load(Context.Server.MapPath(System.IO.Path.Combine(path,"Button.xml")));	
			_urlargument.Add("Button",Buttondoc);
			//Style
			System.Xml.XmlDocument Styledoc = new System.Xml.XmlDocument();
			Styledoc.Load(Context.Server.MapPath(System.IO.Path.Combine(path,"Style.xml")));	
			_urlargument.Add("Style",Styledoc);
			//ToolBar
			System.Xml.XmlDocument ToolBardoc = new System.Xml.XmlDocument();
			ToolBardoc.Load(Context.Server.MapPath(System.IO.Path.Combine(path,"ToolBar.xml")));	
			_urlargument.Add("ToolBar",ToolBardoc);

			if(Context.Application[path]==null)
			{
				Context.Application.Lock();
				Context.Application.Add(path,_urlargument);
				Context.Application.UnLock();
			}
			else
			{
				Context.Application.Lock();				
				Context.Application[path] = _urlargument;
				Context.Application.UnLock();
			}
		}

		/// <summary>
		/// 代码解释功能,目的是为了防止一些人恶意的提交一些代码,影响系统的安全使用,通过字符转换的方法,防止这种现象的发生
		/// </summary>
		/// <param name="html">要转换的数据字符串</param>
		/// <param name="filter">要过滤掉的单个格式</param>
		/// <returns>替换后的字符</returns>
		public static string DecodeFilter(string html, string filter)
		{
			string str = html;
			System.Text.RegularExpressions.Regex r;
			System.Text.RegularExpressions.Match m;
			switch(filter.ToUpper())
			{
				case "SCRIPT":
					//不允许使用javascript,vbscript等,事件onclick,ondlbclick等
					str = Regex.Replace(str,"</?script[^>]*>","");
					r = new Regex(@"</?script[^>]*>",RegexOptions.IgnoreCase);
					for (m = r.Match(str); m.Success; m = m.NextMatch()) 
					{
						str = str.Replace(m.Groups[0].ToString(),"");
					}
					r = new Regex(@"(javascript|jscript|vbscript|vbs):",RegexOptions.IgnoreCase);
					for (m = r.Match(str); m.Success; m = m.NextMatch()) 
					{
						str = str.Replace(m.Groups[0].ToString(), m.Groups[1].ToString()+":");
					}
					r = new Regex(@"on(mouse|exit|error|click|key)",RegexOptions.IgnoreCase);
					for (m = r.Match(str); m.Success; m = m.NextMatch()) 
					{
						str = str.Replace(m.Groups[0].ToString(), "<I>on"+ m.Groups[1].ToString() +"</I>");
					}
					r = new Regex(@"&#",RegexOptions.IgnoreCase);
					for (m = r.Match(str); m.Success; m = m.NextMatch()) 
					{
						str = str.Replace(m.Groups[0].ToString(), "<I>&#</I>");
					}
					break;
				case "TABLE":
					//不允许使用table,th,td,tr标签
					str = Regex.Replace(str,"</?table[^>]*>","");
					str = Regex.Replace(str,"</?tr[^>]*>","");
					str = Regex.Replace(str,"</?th[^>]*>","");
					str = Regex.Replace(str,"</?td[^>]*>","");
					break;
				case "CLASS":
					//不允许使用 class= 这样的标签
					r = new Regex(@"(<[^>]+) class=[^ |^>]*([^>]*>)",RegexOptions.IgnoreCase);
					for (m = r.Match(str); m.Success; m = m.NextMatch()) 
					{
						str = str.Replace(m.Groups[0].ToString(),m.Groups[0].ToString()+" "+m.Groups[1].ToString());
					}
					break;
				case "STYLE":
					//不允许使用 style= 这样的标签
					r = new Regex("(<[^>]+) style=\"[^\"]*\"([^>]*>)",RegexOptions.IgnoreCase);
					for (m = r.Match(str); m.Success; m = m.NextMatch()) 
					{
						str = str.Replace(m.Groups[0].ToString(),m.Groups[0].ToString()+" "+m.Groups[1].ToString());
					}
					break;
				case "XML":
					//不允许使用 xml 标签
					str = Regex.Replace(str,"<\\?xml[^>]*>","");
					break;
				case "NAMESPACE":
					//不允许使用 <o:p></o:p> 这种格式
					str = Regex.Replace(str,@"<\/?[a-z]+:[^>]*>","");
					break;
				case "FONT":
					//不允许使用 font 标签,不建议使用
					str = Regex.Replace(str,"</?font[^>]*>","");
					break;
				case "MARQUEE":
					//不允许使用 marquee 标签,也就没有移动滚动的特殊
					str = Regex.Replace(str,"</?marquee[^>]*>","");
					break;
				case "OBJECT":
					//不允许 object, param, embed 标签,不能嵌入对象
					str = Regex.Replace(str,"</?object[^>]*>","");
					str = Regex.Replace(str,"</?param[^>]*>","");
					str = Regex.Replace(str,"</?embed[^>]*>","");
					break;
			}
			return str;
		}
		

	}
}

⌨️ 快捷键说明

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