function.asp

来自「ZD-BS是一个基于asp+access的个人blog系统 程序特点: 1.」· ASP 代码 · 共 765 行 · 第 1/2 页

ASP
765
字号
			chr1 = chr2 = chr3 = "";
			enc1 = enc2 = enc3 = enc4 = "";
		} while (i < input.length);
		return output;
	};

	this.decode64=function(input) {
		if(!str||str.constructor!=String) return "";
		var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
		var output = "";
		var chr1, chr2, chr3 = "";
		var enc1, enc2, enc3, enc4 = "";
		var i = 0;
		var base64test = /[^A-Za-z0-9\+\/\=]/g;
		if (base64test.exec(input)) {
			return "";
		}
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		do {
			enc1 = keyStr.indexOf(input.charAt(i++));
			enc2 = keyStr.indexOf(input.charAt(i++));
			enc3 = keyStr.indexOf(input.charAt(i++));
			enc4 = keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
			chr1 = chr2 = chr3 = "";
			enc1 = enc2 = enc3 = enc4 = "";
		} while (i < input.length);
		return unescape(output);
	};
	
	this.searchArr=function(arr,strItem,value){
		var arrResult=null;
		var tmp0=0;
		if(arr){
			arrResult=new Array();
			for(var i=0;i<arr.length;i++){
				if(arr[i][strItem]==value){
					arrResult[tmp0]=arr[i];
					tmp0++;
				}
			}
			if(tmp0==0) arrResult=null;
		}
		return arrResult;
	};

	this.existKey=function(arr,strKey){
		if(!arr) return false;
		for(var key in arr){
			if(strKey==key) return true;
		}
		return false;
	};

	this.getKey=function(arr){
		var arrResult=new Array(),i=0;
		for(var key in arr){
			arrResult[i]=key;
			i++;
		}
		if(i>0){
			return arrResult;
		}else{
			return null;
		}
	};
	
	this.randomStr=function(intLength,strSeed){
		if(!intLength) intLength=16;
		if(!strSeed) strSeed="0123456789abcdef";
		var seedLength=strSeed.length;
		var strResult="",i=0,intKey;
		while(i<intLength){
			intKey=Math.round((Math.random()*seedLength));
			if(intKey>=0&&intKey<seedLength){
				strResult+=strSeed.charAt(intKey);
				i++;
			}
		}
		return strResult;
	};

	this.stringToRegExp=function(str){
		if(str==undefined){ return ""; }
		str=str.replace(/\\/g,"\\");
		str=str.replace(/\^/g,"\\^");
		str=str.replace(/\*/g,"\\*");
		str=str.replace(/\?/g,"\\?");
		str=str.replace(/\+/g,"\\+");
		str=str.replace(/\./g,"\\.");
		str=str.replace(/\|/g,"\\|");
		str=str.replace(/\[/g,"\\[");
		str=str.replace(/\]/g,"\\]");
		str=str.replace(/\(/g,"\\(");
		str=str.replace(/\)/g,"\\)");
		str=str.replace(/\{/g,"\\{");
		str=str.replace(/\}/g,"\\}");
		return str;
	};

	this.trimText=function(str,strStart,strEnd){
		if(str==undefined){ return ""; }
		if(strStart){
			str=str.replace(new RegExp("^[^"+func.stringToRegExp(strStart)+"]+","g"),"");
		}
		if(strEnd){
			str=str.replace(new RegExp("[^"+func.stringToRegExp(strEnd)+"]+$","g"),"");
		}
		str=str.replace(/(^\s*|\s*$)/g,"");
		str=str.replace(/(\r*\n){3,}/g,"\r\n\r\n");
		return str;
	};
	
	//format example//////////////////////////
	//yyyy: year
	//YY:   short year
	//mm:   month
	//ME:   english month long
	//me:   english month short
	//dd:   date
	//HH:   hours
	//MM:   minutes
	//SS:   seconds
	//ww:   weeks
	//WE:   english week long
	//we:   english week short
	//WZ:   chinese week long
	//wz:   chinese week short
	//MS:   milliseconds
	//ms:   the time showed milliseconds
	//Z :   full TimeZone Offset
	///////////////////////////////////////////
	this.dateStr=function(objDate,strFormat){
		if(objDate==undefined){
		  objDate=new Date();
		}else{
		  objDate=new Date(objDate);
		}
		var W=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
		var WZ=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
		var w=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
		var wz=["日","一","二","三","四","五","六"];
		var M=["January","February","March","April","May","June","July","August","Sebtember","October","November","December"];
		var MZ=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];
		var m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Seb","Oct","Nov","Dec"];
		if(!strFormat) strFormat="yyyy-mm-dd HH:MM:SS";
		var strYear=objDate.getFullYear();
		var strMonth=objDate.getMonth()+1;
		var strDate=objDate.getDate();
		var strHours=objDate.getHours();
		var strMinutes=objDate.getMinutes();
		var strSeconds=objDate.getSeconds();
		var strWeeks=objDate.getDay()+1;
		var strMilliSeconds=objDate.getMilliseconds();
		var strMS=objDate.getTime();
		var strZone=objDate.getTimezoneOffset();
		if(strZone==0){
			strZone="Z";
		}else{
			strZone = Math.abs(Math.round(strZone/60));
			strZone = (objDate.getTimezoneOffset() <0 ? "+":"-") + (strZone<10 ? "0"+strZone : strZone);
		}
		strFormat=strFormat.replace(/yyyy/g,strYear);
		strFormat=strFormat.replace(/YY/g,String(strYear).substr(2,4));
		strFormat=strFormat.replace(/mm/g,strMonth);
		strFormat=strFormat.replace(/ME/g,M[Number(strMonth)-1]);
		strFormat=strFormat.replace(/MZ/g,MZ[Number(strMonth)-1]);
		strFormat=strFormat.replace(/me/g,m[Number(strMonth)-1]);
		strFormat=strFormat.replace(/dd/g,strDate);
		strFormat=strFormat.replace(/HH/g,strHours);
		strFormat=strFormat.replace(/MM/g,strMinutes);
		strFormat=strFormat.replace(/SS/g,strSeconds);
		strFormat=strFormat.replace(/ww/g,strWeeks);
		strFormat=strFormat.replace(/WE/g,W[Number(strWeeks)-1]);
		strFormat=strFormat.replace(/WZ/g,WZ[Number(strWeeks)-1]);
		strFormat=strFormat.replace(/we/g,w[Number(strWeeks)-1]);
		strFormat=strFormat.replace(/wz/g,wz[Number(strWeeks)-1]);
		strFormat=strFormat.replace(/MS/g,strMilliSeconds);
		strFormat=strFormat.replace(/ms/g,strMS);
		strFormat=strFormat.replace(/Z/g,strZone+"00");
		return strFormat;
	};

	//enample: 2006-4-8 20:12:34
	this.getDate=function(strDateTime){
		var theDate=new Date();
		var iNum=0;
		var strDate;
		var strTime;
		strDateTime=strDateTime.split(" ");
		if(strDateTime.length==2){
			strDate=strDateTime[0];
			strTime=strDateTime[1];
		}else if(strDateTime.length=1){
			strDate=strDateTime[0];
			strTime="";
		}else{
			return null;
		}
		strDate=strDate.split("-");
		if(strDate.length!=3){
			return null;
		}else{
			theDate.setFullYear(this.checkInt(strDate[0]));
			theDate.setMonth(this.checkInt(strDate[1])-1);
			theDate.setDate(this.checkInt(strDate[2]));
		}
		strTime=strTime.split(":");
		if(strTime.length==3){
			theDate.setHours(this.checkInt(strTime[0]));
			theDate.setMinutes(this.checkInt(strTime[1]));
			theDate.setSeconds(this.checkInt(strTime[2]));
		}
		return theDate;
	};

	this.remoteRequest=function(strURL,strMode,value,arrHeader,bAsync,intWait,getType){
		var result;
		try{
			objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP");
		}
		catch(e){return false;}
		try{
			objXMLHTTP.open(strMode, strURL, bAsync);
		}
		catch(e){return false;}
		if(arrHeader!=null){
			for(var n in arrHeader){
				try{
					objXMLHTTP.setRequestHeader(n,arrHeader[n]);
				}
				catch(e){return false;}
			}
		}
		try{
			result=objXMLHTTP.send(value);
		}
		catch(e){return false;}
		if(objXMLHTTP.readyState!=4){
			try{
				objXMLHTTP.waitForResponse(intWait);
			}
			catch(e){return false;}
		}
		if(objXMLHTTP.readyState!=4||objXMLHTTP.status!=200){
			objXMLHTTP.abort();
			return false;
		}else if(getType=="xml"){
			result=objXMLHTTP.responseXml;
		}else if(getType=="header"){
			result=objXMLHTTP.getAllResponseHeaders();
		}else if(getType=="obj"){
			result=objXMLHTTP;
		}else{
			result=objXMLHTTP.responseText;
		}
		delete objXMLHTTP;
		return result;
	};
	
	this.getIp=function(){
		var strIP=String(Request.ServerVariables("HTTP_X_FORWARDED_FOR")).replace(/[^0-9\.,]/g,"");
		if(strIP.length<7) strIP=String(Request.ServerVariables("REMOTE_ADDR")).replace(/[^0-9\.,]/g,"");
		if(strIP.indexOf(",")>7) strIP=strIP.substr(0,strIP.indexOf(","));
		return strIP;
	};

	this.getAgent=function(){
		var strUA=String(Request.ServerVariables("HTTP_USER_AGENT"));
		if(strUA=="undefined") strUA="";
		var arrInfo={"name": "Unkown","os": "Unkown"};
		var idx, idxCol;
		var strType="";
		strUA = strUA.toLowerCase();
		strUA = strUA.replace(/^\s+/,"");
		strUA = strUA.replace(/\s+$/,"");
		strUA = strUA.replace(/\n/,"");
		if(strUA.length<10) return arrInfo;
		if(strUA.indexOf("mozilla")>-1) arrInfo["name"]="Mozilla";
		if(strUA.indexOf("icab")>-1) arrInfo["name"]="iCab";
		if(strUA.indexOf("lynx")>-1) arrInfo["name"]="Lynx";
		if(strUA.indexOf("links")>-1) arrInfo["name"]="Links";
		if(strUA.indexOf("elinks")>-1) arrInfo["name"]="ELinks";
		if(strUA.indexOf("jbrowser")>-1) arrInfo["name"]="JBrowser";
		if(strUA.indexOf("gecko")>-1){
			strType="[Gecko]";
			arrInfo["name"]="Mozilla";
			if(strUA.indexOf("aol")>-1) arrInfo["name"]="AOL";
			if(strUA.indexOf("netscape")>-1) arrInfo["name"]="Netscape";
			if(strUA.indexOf("firefox")>-1) arrInfo["name"]="FireFox";
			if(strUA.indexOf("chimera")>-1) arrInfo["name"]="Chimera";
			if(strUA.indexOf("camino")>-1) arrInfo["name"]="Camino";
			if(strUA.indexOf("galeon")>-1) arrInfo["name"]="Galeon";
			if(strUA.indexOf("k-meleon")>-1) arrInfo["name"]="K-Meleon";
			arrInfo["name"]+=strType;
		}
		if(strUA.indexOf("konqueror")>-1){
			arrInfo["name"]="Konqueror";
		}
		if(strUA.indexOf("bot")>-1||strUA.indexOf("crawl")>-1){
			strType="[Bot/Crawler]";
			arrInfo["name"]="";
			if(strUA.indexOf("grub")>-1) arrInfo["name"]="Grub";
			if(strUA.indexOf("googlebot")>-1) arrInfo["name"]="GoogleBot";
			if(strUA.indexOf("msnbot")>-1) arrInfo["name"]="MSN Bot";
			if(strUA.indexOf("slurp")>-1) arrInfo["name"]="Yahoo! Slurp";
			arrInfo["name"]+=strType;
		}
		if(strUA.indexOf("wget")>-1){
			arrInfo["name"]="Wget";
		}
		if(strUA.indexOf("ask jeeves")>-1||strUA.indexOf("teoma")>-1){
			arrInfo["name"]="Ask Jeeves/Teoma";
		}
		if(strUA.indexOf("msie")>-1){
			strType="[IE";
			idx=strUA.indexOf("msie") ;
			idxCol=strUA.indexOf(";",idx) 
			strType+= " "+strUA.substr(idx+5, idxCol-idx-5)+"]";
			arrInfo["name"]="IE";
			if(strUA.indexOf("msn")>-1) arrInfo["name"]="MSN";
			if(strUA.indexOf("aol")>-1) arrInfo["name"]="AOL";
			if(strUA.indexOf("webtv")>-1) arrInfo["name"]="WebTV";
			if(strUA.indexOf("myie2")>-1) arrInfo["name"]="MyIE2";
			if(strUA.indexOf("maxthon")>-1) arrInfo["name"]="Maxthon";
			if(strUA.indexOf("gosurf")>-1) arrInfo["name"]="GoSurf";
			if(strUA.indexOf("netcaptor")>-1) arrInfo["name"]="NetCaptor";
			if(strUA.indexOf("sleipnir")>-1) arrInfo["name"]="Sleipnir";
			if(strUA.indexOf("avant browser")>-1) arrInfo["name"]="AvantBrowser";
			if(strUA.indexOf("greenbrowser")>-1) arrInfo["name"]="GreenBrowser";
			if(strUA.indexOf("slimbrowser")>-1) arrInfo["name"]="SlimBrowser";
			arrInfo["name"]+=strType;
		}
		if(strUA.indexOf("opera")>-1){
			idx=strUA.indexOf("opera") ;
			arrInfo["name"]="Opera "+strUA.substr(idx+6, idx+9);
		}
		if(strUA.indexOf("applewebkit")>-1){
			strType="[AppleWebKit]";
			arrInfo["name"]="";
			if(strUA.indexOf("omniweb")>-1) arrInfo["name"]="OmniWeb";
			if(strUA.indexOf("safari")>-1) arrInfo["name"]="Safari";
			arrInfo["name"]+=strType;
		}
		if(strUA.indexOf("windows")>-1) arrInfo["os"]="Windows";
		if(strUA.indexOf("windows ce")>-1) arrInfo["os"]="Windows CE";
		if(strUA.indexOf("windows 95")>-1) arrInfo["os"]="Windows 95";
		if(strUA.indexOf("win98")>-1) arrInfo["os"]="Windows 98";
		if(strUA.indexOf("windows 98")>-1) arrInfo["os"]="Windows 98";
		if(strUA.indexOf("windows 2000")>-1) arrInfo["os"]="Windows 2000";
		if(strUA.indexOf("windows xp")>-1) arrInfo["os"]="Windows XP";
		if(strUA.indexOf("windows nt")>-1){
			arrInfo["os"]="Windows NT";
			if(strUA.indexOf("windows nt 5.0")>-1) arrInfo["os"]="Windows 2000";
			if(strUA.indexOf("windows nt 5.1")>-1) arrInfo["os"]="Windows XP";
			if(strUA.indexOf("windows nt 5.2")>-1) arrInfo["os"]="Windows 2003";
		}
		if(strUA.indexOf("x11")>-1||strUA.indexOf("unix")>-1) arrInfo["os"]="Unix";
		if(strUA.indexOf("sunos")>-1||strUA.indexOf("sun os")>-1) arrInfo["os"]="SUN OS";
		if(strUA.indexOf("powerpc")>-1||strUA.indexOf("ppc")>-1) arrInfo["os"]="PowerPC";
		if(strUA.indexOf("macintosh")>-1) arrInfo["os"]="Mac";
		if(strUA.indexOf("mac osx")>-1) arrInfo["os"]="MacOSX";
		if(strUA.indexOf("freebsd")>-1) arrInfo["os"]="FreeBSD";
		if(strUA.indexOf("linux")>-1) arrInfo["os"]="Linux";
		if(strUA.indexOf("palmsource")>-1||strUA.indexOf("palmos")>-1) arrInfo["os"]="PalmOS";
		if(strUA.indexOf("wap ")>-1) arrInfo["os"]="WAP";
		return arrInfo;
	};
	
}

</script>

⌨️ 快捷键说明

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