Tools.js

/* HTML Encode/Decode: http://www.strictly-software.com/htmlencode */ Encoder={EncodeType:"entity",isEmpty:function(a){if(a){return((a===null)||a.length==0||/^\s+$/.test(a))}else{return true}},arr1:new Array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","&Aelig;","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","Ø","ù","ú","û","ü","ý","þ","ÿ",""","&","<",">","œ","œ","š","š","ÿ","ˆ","˜"," "," "," ","‌","‍","‎","‏","–","—","‘","’","‚","“","”","„","†","†","‰","‹","›","€","ƒ","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","σ","τ","υ","φ","χ","ψ","ω","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","ς","σ","τ","υ","φ","χ","ψ","ω","ϑ","ϒ","ϖ","•","…","′","′","‾","⁄","℘","ℑ","ℜ","™","ℵ","←","↑","→","↓","↔","↵","←","↑","→","↓","↔","∀","∂","∃","∅","∇","∈","∉","∋","∏","∑","−","∗","√","∝","∞","∠","∧","∨","∩","∪","∫","∴","∼","≅","≈","≠","≡","≤","≥","⊂","⊃","⊄","⊆","⊇","⊕","⊗","⊥","⋅","⌈","⌉","⌊","⌋","⟨","⟩","◊","♠","♣","♥","♦"),arr2:new Array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ",""","&","<",">","Œ","œ","Š","š","Ÿ","ˆ","˜"," "," "," ","‌","‍","‎","‏","–","—","‘","’","‚","“","”","„","†","‡","‰","‹","›","€","ƒ","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Ψ","Ω","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","ς","σ","τ","υ","φ","χ","ψ","ω","ϑ","ϒ","ϖ","•","…","′","″","‾","⁄","℘","ℑ","ℜ","™","ℵ","←","↑","→","↓","↔","↵","⇐","⇑","⇒","⇓","⇔","∀","∂","∃","∅","∇","∈","∉","∋","∏","∑","−","∗","√","∝","∞","∠","∧","∨","∩","∪","∫","∴","∼","≅","≈","≠","≡","≤","≥","⊂","⊃","⊄","⊆","⊇","⊕","⊗","⊥","⋅","⌈","⌉","⌊","⌋","〈","〉","◊","♠","♣","♥","♦"),HTML2Numerical:function(a){return this.swapArrayVals(a,this.arr1,this.arr2)},NumericalToHTML:function(a){return this.swapArrayVals(a,this.arr2,this.arr1)},numEncode:function(b){if(this.isEmpty(b)){return""}var d="";for(var a=0;a<b.length;a++){var f=b.charAt(a);if(f<" "||f>"~"){f="&#"+f.charCodeAt()+";"}d+=f}return d},htmlDecode:function(e){var g,b,f=e;if(this.isEmpty(f)){return""}f=this.HTML2Numerical(f);arr=f.match(/&#[0-9]{1,5};/g);if(arr!=null){for(var a=0;a<arr.length;a++){b=arr[a];g=b.substring(2,b.length-1);if(g>=-32768&&g<=65535){f=f.replace(b,String.fromCharCode(g))}else{f=f.replace(b,"")}}}return f},htmlEncode:function(a,b){if(this.isEmpty(a)){return""}b=b||false;if(b){if(this.EncodeType=="numerical"){a=a.replace(/&/g,"&")}else{a=a.replace(/&/g,"&")}}a=this.XSSEncode(a,false);if(this.EncodeType=="numerical"||!b){a=this.HTML2Numerical(a)}a=this.numEncode(a);if(!b){a=a.replace(/&#/g,"##AMPHASH##");if(this.EncodeType=="numerical"){a=a.replace(/&/g,"&")}else{a=a.replace(/&/g,"&")}a=a.replace(/##AMPHASH##/g,"&#")}a=a.replace(/&#\d*([^\d;]|$)/g,"$1");if(!b){a=this.correctEncoding(a)}if(this.EncodeType=="entity"){a=this.NumericalToHTML(a)}return a},XSSEncode:function(b,a){if(!this.isEmpty(b)){a=a||true;if(a){b=b.replace(/\'/g,"'");b=b.replace(/\"/g,""");b=b.replace(/</g,"<");b=b.replace(/>/g,">")}else{b=b.replace(/\'/g,"'");b=b.replace(/\"/g,""");b=b.replace(/</g,"<");b=b.replace(/>/g,">")}return b}else{return""}},hasEncoded:function(a){if(/&#[0-9]{1,5};/g.test(a)){return true}else{if(/&[A-Z]{2,6};/gi.test(a)){return true}else{return false}}},stripUnicode:function(a){return a.replace(/[^\x20-\x7E]/g,"")},correctEncoding:function(a){return a.replace(/(&)(amp;)+/,"$1")},swapArrayVals:function(f,c,b){if(this.isEmpty(f)){return""}var e;if(c&&b){if(c.length==b.length){for(var a=0,d=c.length;a<d;a++){e=new RegExp(c[a],"g");f=f.replace(e,b[a])}}}return f},inArray:function(d,b){for(var c=0,a=b.length;c<a;c++){if(b[c]===d){return c}}return -1}}; /* ParseURI: http://blog.stevenlevithan.com/archives/parseuri */ function parseUri(e){var d=parseUri.options,a=d.parser[d.strictMode?"strict":"loose"].exec(e),c={},b=14;while(b--){c[d.key[b]]=a[b]||""}c[d.q.name]={};c[d.key[12]].replace(d.q.parser,function(g,f,h){if(f){c[d.q.name][f]=h}});return c}parseUri.options={strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};
Parse URI script, and an HTML character encoder/decoder.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.