mirror of
https://github.com/friendica/friendica
synced 2024-12-27 03:20:15 +00:00
10 lines
No EOL
43 KiB
JavaScript
10 lines
No EOL
43 KiB
JavaScript
/*!
|
|
* jSmart Javascript template engine (v2.15.0)
|
|
* https://github.com/umakantp/jsmart
|
|
* http://opensource.org/licenses/LGPL-3.0
|
|
*
|
|
* Copyright 2011-2015, Max Miroshnikov <miroshnikov at gmail dot com>
|
|
* Umakant Patil <me @ umakantpatil dot com>
|
|
*/
|
|
!function(){function obMerge(a){for(var b=1;b<arguments.length;++b)for(var c in arguments[b])a[c]=arguments[b][c];return a}function countProperties(a){var b=0;for(var c in a)a.hasOwnProperty(c)&&b++;return b}function findInArray(a,b){if(Array.prototype.indexOf)return a.indexOf(b);for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}function evalString(a){return a.replace(/\\t/," ").replace(/\\n/,"\n").replace(/\\(['"\\])/g,"$1")}function trimQuotes(a){return evalString(a.replace(/^['"](.*)['"]$/,"$1")).replace(/^\s+|\s+$/g,"")}function findTag(a,b){for(var c=0,d=0,e=jSmart.prototype.left_delimiter,f=jSmart.prototype.right_delimiter,g=jSmart.prototype.auto_literal,h=/^\s*(.+)\s*$/i,i=a?new RegExp("^\\s*("+a+")\\s*$","i"):h,j=0;j<b.length;++j)if(b.substr(j,e.length)==e){if(g&&j+1<b.length&&b.substr(j+1,1).match(/\s/))continue;c||(b=b.slice(j),d+=parseInt(j),j=0),++c}else if(b.substr(j,f.length)==f){if(g&&j-1>=0&&b.substr(j-1,1).match(/\s/))continue;if(!--c){var k=b.slice(e.length,j).replace(/[\r\n]/g," "),l=k.match(i);if(l)return l.index=d,l[0]=b.slice(0,j+f.length),l}0>c&&(c=0)}return null}function findCloseTag(a,b,c){var d="",e=null,f=null,g=0;do{if(e&&(g+=e[0].length),e=findTag(a,c),!e)throw new Error("Unclosed {"+b+"}");d+=c.slice(0,e.index),g+=e.index,c=c.slice(e.index+e[0].length),f=findTag(b,d),f&&(d=d.slice(f.index+f[0].length))}while(f);return e.index=g,e}function findElseTag(a,b,c,d){for(var e=0,f=findTag(c,d);f;f=findTag(c,d)){var g=findTag(a,d);if(!g||g.index>f.index)return f.index+=e,f;d=d.slice(g.index+g[0].length),e+=g.index+g[0].length;var h=findCloseTag(b,a,d);d=d.slice(h.index+h[0].length),e+=h.index+h[0].length}return null}function execute(code,data){if("string"==typeof code)with({__code:code})with(modifiers)with(data)try{return eval(__code)}catch(e){throw new Error(e.message+" in \n"+code)}return code}function executeByFuncObject(a,b){try{return a.apply(this,b)}catch(c){throw new Error(c.message)}}function assignVar(a,b,c){a.match(/\[\]$/)?c[a.replace(/\[\]$/,"")].push(b):c[a]=b}function parse(a,b){for(var c=findTag("",a);c;c=findTag("",a)){c.index&&parseText(a.slice(0,c.index),b),a=a.slice(c.index+c[0].length);var d=c[1].match(/^\s*(\w+)(.*)$/);if(d){var e=d[1],f=d.length>2?d[2].replace(/^\s+|\s+$/g,""):"";if(e in buildInFunctions){var g=buildInFunctions[e],h=("parseParams"in g?g.parseParams:parseParams)(f);if("block"==g.type){a=a.replace(/^\n/,"");var i=findCloseTag("/"+e,e+" +[^}]*",a);g.parse(h,b,a.slice(0,i.index)),a=a.slice(i.index+i[0].length)}else g.parse(h,b),"extends"==e&&(b=[]);a=a.replace(/^\n/,"")}else if(e in plugins){var j=plugins[e];if("block"==j.type){var i=findCloseTag("/"+e,e+" +[^}]*",a);parsePluginBlock(e,parseParams(f),b,a.slice(0,i.index)),a=a.slice(i.index+i[0].length)}else"function"==j.type&&parsePluginFunc(e,parseParams(f),b);("append"==e||"assign"==e||"capture"==e||"eval"==e||"include"==e)&&(a=a.replace(/^\n/,""))}else buildInFunctions.expression.parse(c[1],b)}else{var k=buildInFunctions.expression.parse(c[1],b);"build-in"==k.type&&"operator"==k.name&&"="==k.op&&(a=a.replace(/^\n/,""))}}return a&&parseText(a,b),b}function parseText(a,b){if(parseText.parseEmbeddedVars)for(var c=/([$][\w@]+)|`([^`]*)`/,d=c.exec(a);d;d=c.exec(a))b.push({type:"text",data:a.slice(0,d.index)}),b.push(parseExpression(d[1]?d[1]:d[2]).tree),a=a.slice(d.index+d[0].length);return b.push({type:"text",data:a}),b}function parseFunc(a,b,c){return b.__parsed.name=parseText(a,[])[0],c.push({type:"plugin",name:"__func",params:b}),c}function parseOperator(a,b,c,d){d.push({type:"build-in",name:"operator",op:a,optype:b,precedence:c,params:{}})}function parseVar(a,b,c){for(var d=b.token,e=[{type:"text",data:c.replace(/^(\w+)@(key|index|iteration|first|last|show|total)/gi,"$1__$2")}],f=/^(?:\.|\s*->\s*|\[\s*)/,g=a.match(f);g;g=a.match(f)){b.token+=g[0],a=a.slice(g[0].length);var h={value:"",tree:[]};if(g[0].match(/\[/)){h=parseExpression(a),h&&(b.token+=h.value,e.push(h.tree),a=a.slice(h.value.length));var i=a.match(/\s*\]/);i&&(b.token+=i[0],a=a.slice(i[0].length))}else{var j=parseModifiers.stop;if(parseModifiers.stop=!0,lookUp(a,h)){b.token+=h.value;var k=h.tree[0];"plugin"==k.type&&"__func"==k.name&&(k.hasOwner=!0),e.push(k),a=a.slice(h.value.length)}else h=!1;parseModifiers.stop=j}h||e.push({type:"text",data:""})}return b.tree.push({type:"var",parts:e}),b.value+=b.token.substr(d.length),onParseVar(b.token),a}function onParseVar(){}function parseModifiers(a,b){if(!parseModifiers.stop){var c=a.match(/^\|(\w+)/);if(c){b.value+=c[0];var d="default"==c[1]?"defaultValue":c[1];a=a.slice(c[0].length).replace(/^\s+/,""),parseModifiers.stop=!0;for(var e=[],f=a.match(/^\s*:\s*/);f;f=a.match(/^\s*:\s*/)){b.value+=a.slice(0,f[0].length),a=a.slice(f[0].length);var g={value:"",tree:[]};lookUp(a,g)?(b.value+=g.value,e.push(g.tree[0]),a=a.slice(g.value.length)):parseText("",e)}parseModifiers.stop=!1,e.unshift(b.tree.pop()),b.tree.push(parseFunc(d,{__parsed:e},[])[0]),parseModifiers(a,b)}}}function lookUp(a,b){if(!a)return!1;if(a.substr(0,jSmart.prototype.left_delimiter.length)==jSmart.prototype.left_delimiter){var c=findTag("",a);if(c)return b.token=c[0],b.value+=c[0],parse(c[0],b.tree),parseModifiers(a.slice(b.value.length),b),!0}for(var d=0;d<tokens.length;++d)if(a.match(tokens[d].re))return b.token=RegExp.lastMatch,b.value+=RegExp.lastMatch,tokens[d].parse(b,a.slice(b.token.length)),!0;return!1}function bundleOp(a,b,c){var d=b[a];if("operator"==d.name&&d.precedence==c&&!d.params.__parsed){if("binary"==d.optype)return d.params.__parsed=[b[a-1],b[a+1]],b.splice(a-1,3,d),!0;if("post-unary"==d.optype)return d.params.__parsed=[b[a-1]],b.splice(a-1,2,d),!0;d.params.__parsed=[b[a+1]],b.splice(a,2,d)}return!1}function composeExpression(a){var b=0;for(b=0;b<a.length;++b)a[b]instanceof Array&&(a[b]=composeExpression(a[b]));for(var c=1;14>c;++c)if(2==c||10==c)for(b=a.length;b>0;--b)b-=bundleOp(b-1,a,c);else for(b=0;b<a.length;++b)b-=bundleOp(b,a,c);return a[0]}function parseExpression(a){for(var b={value:"",tree:[]};lookUp(a.slice(b.value.length),b););return b.tree.length?(b.tree=composeExpression(b.tree),b):!1}function parseParams(a,b,c){var d=a.replace(/\n/g," ").replace(/^\s+|\s+$/g,""),e=[];e.__parsed=[];var a="";if(!d)return e;for(b||(b=/^\s+/,c=/^(\w+)\s*=\s*/);d;){var f=null;if(c){var g=d.match(c);g&&(f=trimQuotes(g[1]),a+=d.slice(0,g[0].length),d=d.slice(g[0].length))}var h=parseExpression(d);if(!h)break;f?(e[f]=h.value,e.__parsed[f]=h.tree):(e.push(h.value),e.__parsed.push(h.tree)),a+=d.slice(0,h.value.length),d=d.slice(h.value.length);var i=d.match(b);if(!i)break;a+=d.slice(0,i[0].length),d=d.slice(i[0].length)}return e.toString=function(){return a},e}function parsePluginBlock(a,b,c,d){c.push({type:"plugin",name:a,params:b,subTree:parse(d,[])})}function parsePluginFunc(a,b,c){c.push({type:"plugin",name:a,params:b})}function getActualParamValues(a,b){var c=[];for(var d in a.__parsed)if(a.__parsed.hasOwnProperty(d)){var e=process([a.__parsed[d]],b);c[d]=e}return c.__get=function(a,b,d){if(a in c&&"undefined"!=typeof c[a])return c[a];if("undefined"!=typeof d&&"undefined"!=typeof c[d])return c[d];if(null===b)throw new Error("The required attribute '"+a+"' is missing");return b},c}function isEmptyObject(a){for(var b in a)if(a.hasOwnProperty(b))return!1;return!0}function getVarValue(a,b,c){for(var d=b,e="",f=0;f<a.parts.length;++f){var g=a.parts[f];if("plugin"==g.type&&"__func"==g.name&&g.hasOwner)b.__owner=d,d=process([a.parts[f]],b),delete b.__owner;else if(e=process([g],b),e in b.smarty.section&&"text"==g.type&&"smarty"!=process([a.parts[0]],b)&&(e=b.smarty.section[e].index),!e&&"undefined"!=typeof c&&d instanceof Array&&(e=d.length),"undefined"!=typeof c&&f==a.parts.length-1&&(d[e]=c),"object"==typeof d&&null!==d&&e in d)d=d[e];else{if("undefined"==typeof c)return c;d[e]={},d=d[e]}}return d}function process(a,b){for(var c="",d=0;d<a.length;++d){var e="",f=a[d];if("text"==f.type)e=f.data;else if("var"==f.type)e=getVarValue(f,b);else if("build-in"==f.type)e=buildInFunctions[f.name].process(f,b);else if("plugin"==f.type){var g=plugins[f.name];if("block"==g.type){var h={value:!0};for(g.process(getActualParamValues(f.params,b),"",b,h);h.value;)h.value=!1,e+=g.process(getActualParamValues(f.params,b),process(f.subTree,b),b,h)}else"function"==g.type&&(e=g.process(getActualParamValues(f.params,b),b))}if("boolean"==typeof e&&(e=e?"1":""),1==a.length)return e;if(c+=e,b.smarty["continue"]||b.smarty["break"])return c}return c}function getTemplate(a,b,c){if(!c&&a in files)b=files[a];else{var d=jSmart.prototype.getTemplate(a);if("string"!=typeof d)throw new Error("No template for "+a);parse(applyFilters(jSmart.prototype.filters_global.pre,stripComments(d.replace(/\r\n/g,"\n"))),b),files[a]=b}return b}function stripComments(a){for(var b="",c=a.match(/{\*/);c;c=a.match(/{\*/)){b+=a.slice(0,c.index),a=a.slice(c.index+c[0].length);var d=a.match(/\*}/);if(!d)throw new Error("Unclosed {*");a=a.slice(d.index+d[0].length)}return b+a}function applyFilters(a,b){for(var c=0;c<a.length;++c)b=a[c](b);return b}var buildInFunctions={expression:{parse:function(a,b){var c=parseExpression(a);return b.push({type:"build-in",name:"expression",expression:c.tree,params:parseParams(a.slice(c.value.length).replace(/^\s+|\s+$/g,""))}),c.tree},process:function(a,b){var c=getActualParamValues(a.params,b),d=process([a.expression],b);if(findInArray(c,"nofilter")<0){for(var e=0;e<default_modifiers.length;++e){var f=default_modifiers[e];f.params.__parsed[0]={type:"text",data:d},d=process([f],b)}escape_html&&(d=modifiers.escape(d)),d=applyFilters(varFilters,d),tpl_modifiers.length&&(__t=function(){return d},d=process(tpl_modifiers,b))}return d}},operator:{process:function(a,b){var c=getActualParamValues(a.params,b),d=c[0];if("binary"!=a.optype){if("!"==a.op)return!d;var e="var"==a.params.__parsed[0].type;e&&(d=getVarValue(a.params.__parsed[0],b));var f=d;if("pre-unary"==a.optype){switch(a.op){case"-":f=-d;break;case"++":f=++d;break;case"--":f=--d}e&&getVarValue(a.params.__parsed[0],b,d)}else{switch(a.op){case"++":d++;break;case"--":d--}getVarValue(a.params.__parsed[0],b,d)}return f}var g=c[1];if("="==a.op)return getVarValue(a.params.__parsed[0],b,g),"";if(a.op.match(/(\+=|-=|\*=|\/=|%=)/)){switch(d=getVarValue(a.params.__parsed[0],b),a.op){case"+=":d+=g;break;case"-=":d-=g;break;case"*=":d*=g;break;case"/=":d/=g;break;case"%=":d%=g}return getVarValue(a.params.__parsed[0],b,d)}if(a.op.match(/div/))return"div"!=a.op^d%g==0;if(a.op.match(/even/))return"even"!=a.op^d/g%2==0;if(a.op.match(/xor/))return(d||g)&&!(d&&g);switch(a.op){case"==":return d==g;case"!=":return d!=g;case"+":return Number(d)+Number(g);case"-":return Number(d)-Number(g);case"*":return Number(d)*Number(g);case"/":return Number(d)/Number(g);case"%":return Number(d)%Number(g);case"&&":return d&&g;case"||":return d||g;case"<":return g>d;case"<=":return g>=d;case">":return d>g;case">=":return d>=g;case"===":return d===g;case"!==":return d!==g}}},section:{type:"block",parse:function(a,b,c){var d=[],e=[];b.push({type:"build-in",name:"section",params:a,subTree:d,subTreeElse:e});var f=findElseTag("section [^}]+","/section","sectionelse",c);f?(parse(c.slice(0,f.index),d),parse(c.slice(f.index+f[0].length).replace(/^[\r\n]/,""),e)):parse(c,d)},process:function(a,b){var c=getActualParamValues(a.params,b),d={};b.smarty.section[c.__get("name",null,0)]=d;var e=c.__get("show",!0);if(d.show=e,!e)return process(a.subTreeElse,b);var f=parseInt(c.__get("start",0)),g=c.loop instanceof Object?countProperties(c.loop):isNaN(c.loop)?0:parseInt(c.loop),h=parseInt(c.__get("step",1)),i=parseInt(c.__get("max"));isNaN(i)&&(i=Number.MAX_VALUE),0>f?(f+=g,0>f&&(f=0)):f>=g&&(f=g?g-1:0);for(var j=0,k=0,l=f;l>=0&&g>l&&i>j;l+=h,++j)k=l;d.total=j,d.loop=j,j=0;var m="";for(l=f;l>=0&&g>l&&i>j&&!b.smarty["break"];l+=h,++j)d.first=l==f,d.last=0>l+h||l+h>=g,d.index=l,d.index_prev=l-h,d.index_next=l+h,d.iteration=d.rownum=j+1,m+=process(a.subTree,b),b.smarty["continue"]=!1;return b.smarty["break"]=!1,j?m:process(a.subTreeElse,b)}},setfilter:{type:"block",parseParams:function(a){return[parseExpression("__t()|"+a).tree]},parse:function(a,b,c){b.push({type:"build-in",name:"setfilter",params:a,subTree:parse(c,[])})},process:function(a,b){tpl_modifiers=a.params;var c=process(a.subTree,b);return tpl_modifiers=[],c}},"for":{type:"block",parseParams:function(a){var b=a.match(/^\s*\$(\w+)\s*=\s*([^\s]+)\s*to\s*([^\s]+)\s*(?:step\s*([^\s]+))?\s*(.*)$/);if(!b)throw new Error("Invalid {for} parameters: "+a);return parseParams("varName='"+b[1]+"' from="+b[2]+" to="+b[3]+" step="+(b[4]?b[4]:"1")+" "+b[5])},parse:function(a,b,c){var d=[],e=[];b.push({type:"build-in",name:"for",params:a,subTree:d,subTreeElse:e});var f=findElseTag("for\\s[^}]+","/for","forelse",c);f?(parse(c.slice(0,f.index),d),parse(c.slice(f.index+f[0].length),e)):parse(c,d)},process:function(a,b){var c=getActualParamValues(a.params,b),d=parseInt(c.__get("from")),e=parseInt(c.__get("to")),f=parseInt(c.__get("step"));isNaN(f)&&(f=1);var g=parseInt(c.__get("max"));isNaN(g)&&(g=Number.MAX_VALUE);for(var h=0,i="",j=Math.min(Math.ceil(((f>0?e-d:d-e)+1)/Math.abs(f)),g),k=parseInt(c.from);j>h&&!b.smarty["break"];k+=f,++h)b[c.varName]=k,i+=process(a.subTree,b),b.smarty["continue"]=!1;return b.smarty["break"]=!1,h||(i=process(a.subTreeElse,b)),i}},"if":{type:"block",parse:function(a,b,c){var d=[],e=[];b.push({type:"build-in",name:"if",params:a,subTreeIf:d,subTreeElse:e});var f=findElseTag("if\\s+[^}]+","/if","else[^}]*",c);if(f){parse(c.slice(0,f.index),d),c=c.slice(f.index+f[0].length);var g=f[1].match(/^else\s*if(.*)/);g?buildInFunctions["if"].parse(parseParams(g[1]),e,c.replace(/^\n/,"")):parse(c.replace(/^\n/,""),e)}else parse(c,d)},process:function(a,b){var c=getActualParamValues(a.params,b)[0];return c&&!(c instanceof Array&&0==c.length||"object"==typeof c&&isEmptyObject(c))?process(a.subTreeIf,b):process(a.subTreeElse,b)}},foreach:{type:"block",parseParams:function(a){var b=a.match(/^\s*([$].+)\s*as\s*[$](\w+)\s*(=>\s*[$](\w+))?\s*$/i);return b&&(a="from="+b[1]+" item="+(b[4]||b[2]),b[4]&&(a+=" key="+b[2])),parseParams(a)},parse:function(a,b,c){var d=[],e=[];b.push({type:"build-in",name:"foreach",params:a,subTree:d,subTreeElse:e});var f=findElseTag("foreach\\s[^}]+","/foreach","foreachelse",c);f?(parse(c.slice(0,f.index),d),parse(c.slice(f.index+f[0].length).replace(/^[\r\n]/,""),e)):parse(c,d)},process:function(a,b){var c=getActualParamValues(a.params,b),d=c.from;d instanceof Object||(d=[d]);var e=countProperties(d);b[c.item+"__total"]=e,"name"in c&&(b.smarty.foreach[c.name]={},b.smarty.foreach[c.name].total=e);var f="",g=0;for(var h in d)if(d.hasOwnProperty(h)){if(b.smarty["break"])break;b[c.item+"__key"]=isNaN(h)?h:parseInt(h),"key"in c&&(b[c.key]=b[c.item+"__key"]),b[c.item]=d[h],b[c.item+"__index"]=parseInt(g),b[c.item+"__iteration"]=parseInt(g+1),b[c.item+"__first"]=0===g,b[c.item+"__last"]=g==e-1,"name"in c&&(b.smarty.foreach[c.name].index=parseInt(g),b.smarty.foreach[c.name].iteration=parseInt(g+1),b.smarty.foreach[c.name].first=0===g?1:"",b.smarty.foreach[c.name].last=g==e-1?1:""),++g,f+=process(a.subTree,b),b.smarty["continue"]=!1}return b.smarty["break"]=!1,b[c.item+"__show"]=g>0,c.name&&(b.smarty.foreach[c.name].show=g>0?1:""),g>0?f:process(a.subTreeElse,b)}},"function":{type:"block",parse:function(a,b,c){var d=[];plugins[trimQuotes(a.name?a.name:a[0])]={type:"function",subTree:d,defautParams:a,process:function(a,b){var c=getActualParamValues(this.defautParams,b);return delete c.name,process(this.subTree,obMerge({},b,c,a))}},parse(c,d)}},php:{type:"block",parse:function(){}},"extends":{type:"function",parse:function(a,b){b.splice(0,b.length),getTemplate(trimQuotes(a.file?a.file:a[0]),b)}},block:{type:"block",parse:function(a,b,c){b.push({type:"build-in",name:"block",params:a}),a.append=findInArray(a,"append")>=0,a.prepend=findInArray(a,"prepend")>=0,a.hide=findInArray(a,"hide")>=0,a.hasChild=a.hasParent=!1,onParseVar=function(b){b.match(/^\s*[$]smarty.block.child\s*$/)&&(a.hasChild=!0),b.match(/^\s*[$]smarty.block.parent\s*$/)&&(a.hasParent=!0)};var b=parse(c,[]);onParseVar=function(){};var d=trimQuotes(a.name?a.name:a[0]);d in blocks||(blocks[d]=[]),blocks[d].push({tree:b,params:a})},process:function(a,b){b.smarty.block.parent=b.smarty.block.child="";var c=trimQuotes(a.params.name?a.params.name:a.params[0]);return this.processBlocks(blocks[c],blocks[c].length-1,b),b.smarty.block.child},processBlocks:function(a,b,c){if(!b&&a[b].params.hide)return void(c.smarty.block.child="");for(var d=!0,e=!1;b>=0;--b){if(a[b].params.hasParent){var f=c.smarty.block.child;c.smarty.block.child="",this.processBlocks(a,b-1,c),c.smarty.block.parent=c.smarty.block.child,c.smarty.block.child=f}var f=c.smarty.block.child,g=process(a[b].tree,c);c.smarty.block.child=f,a[b].params.hasChild?c.smarty.block.child=g:d?c.smarty.block.child=g+c.smarty.block.child:e&&(c.smarty.block.child+=g),d=a[b].params.append,e=a[b].params.prepend}}},strip:{type:"block",parse:function(a,b,c){parse(c.replace(/[ \t]*[\r\n]+[ \t]*/g,""),b)}},literal:{type:"block",parse:function(a,b,c){parseText(c,b)}},ldelim:{type:"function",parse:function(a,b){parseText(jSmart.prototype.left_delimiter,b)}},rdelim:{type:"function",parse:function(a,b){parseText(jSmart.prototype.right_delimiter,b)}},"while":{type:"block",parse:function(a,b,c){b.push({type:"build-in",name:"while",params:a,subTree:parse(c,[])})},process:function(a,b){for(var c="";getActualParamValues(a.params,b)[0]&&!b.smarty["break"];)c+=process(a.subTree,b),b.smarty["continue"]=!1;return b.smarty["break"]=!1,c}}},plugins={},modifiers={},files={},blocks=null,scripts=null,tpl_modifiers=[],tokens=[{re:/^\$([\w@]+)/,parse:function(a,b){parseModifiers(parseVar(b,a,RegExp.$1),a)}},{re:/^(true|false)/i,parse:function(a){parseText(a.token.match(/true/i)?"1":"",a.tree)}},{re:/^'([^'\\]*(?:\\.[^'\\]*)*)'/,parse:function(a,b){parseText(evalString(RegExp.$1),a.tree),parseModifiers(b,a)}},{re:/^"([^"\\]*(?:\\.[^"\\]*)*)"/,parse:function(a,b){var c=evalString(RegExp.$1),d=c.match(tokens[0].re);if(d){var e={token:d[0],tree:[]};if(parseVar(c,e,d[1]),e.token.length==c.length)return void a.tree.push(e.tree[0])}parseText.parseEmbeddedVars=!0,a.tree.push({type:"plugin",name:"__quoted",params:{__parsed:parse(c,[])}}),parseText.parseEmbeddedVars=!1,parseModifiers(b,a)}},{re:/^(\w+)\s*[(]([)]?)/,parse:function(a,b){var c=RegExp.$1,d=RegExp.$2,e=parseParams(d?"":b,/^\s*,\s*/);parseFunc(c,e,a.tree),a.value+=e.toString(),parseModifiers(b.slice(e.toString().length),a)}},{re:/^\s*\(\s*/,parse:function(a){var b=[];a.tree.push(b),b.parent=a.tree,a.tree=b}},{re:/^\s*\)\s*/,parse:function(a){a.tree.parent&&(a.tree=a.tree.parent)}},{re:/^\s*(\+\+|--)\s*/,parse:function(a){a.tree.length&&"var"==a.tree[a.tree.length-1].type?parseOperator(RegExp.$1,"post-unary",1,a.tree):parseOperator(RegExp.$1,"pre-unary",1,a.tree)}},{re:/^\s*(===|!==|==|!=)\s*/,parse:function(a){parseOperator(RegExp.$1,"binary",6,a.tree)}},{re:/^\s+(eq|ne|neq)\s+/i,parse:function(a){var b=RegExp.$1.replace(/ne(q)?/,"!=").replace(/eq/,"==");parseOperator(b,"binary",6,a.tree)}},{re:/^\s*!\s*/,parse:function(a){parseOperator("!","pre-unary",2,a.tree)}},{re:/^\s+not\s+/i,parse:function(a){parseOperator("!","pre-unary",2,a.tree)}},{re:/^\s*(=|\+=|-=|\*=|\/=|%=)\s*/,parse:function(a){parseOperator(RegExp.$1,"binary",10,a.tree)}},{re:/^\s*(\*|\/|%)\s*/,parse:function(a){parseOperator(RegExp.$1,"binary",3,a.tree)}},{re:/^\s+mod\s+/i,parse:function(a){parseOperator("%","binary",3,a.tree)}},{re:/^\s*(\+|-)\s*/,parse:function(a){a.tree.length&&"operator"!=a.tree[a.tree.length-1].name?parseOperator(RegExp.$1,"binary",4,a.tree):parseOperator(RegExp.$1,"pre-unary",4,a.tree)}},{re:/^\s*(<=|>=|<>|<|>)\s*/,parse:function(a){parseOperator(RegExp.$1.replace(/<>/,"!="),"binary",5,a.tree)}},{re:/^\s+(lt|lte|le|gt|gte|ge)\s+/i,parse:function(a){var b=RegExp.$1.replace(/lt/,"<").replace(/l(t)?e/,"<=").replace(/gt/,">").replace(/g(t)?e/,">=");parseOperator(b,"binary",5,a.tree)}},{re:/^\s+(is\s+(not\s+)?div\s+by)\s+/i,parse:function(a){parseOperator(RegExp.$2?"div_not":"div","binary",7,a.tree)}},{re:/^\s+is\s+(not\s+)?(even|odd)(\s+by\s+)?\s*/i,parse:function(a){var b=RegExp.$1?"odd"==RegExp.$2?"even":"even_not":"odd"==RegExp.$2?"even_not":"even";parseOperator(b,"binary",7,a.tree),RegExp.$3||parseText("1",a.tree)}},{re:/^\s*(&&)\s*/,parse:function(a){parseOperator(RegExp.$1,"binary",8,a.tree)}},{re:/^\s*(\|\|)\s*/,parse:function(a){parseOperator(RegExp.$1,"binary",9,a.tree)}},{re:/^\s+and\s+/i,parse:function(a){parseOperator("&&","binary",11,a.tree)}},{re:/^\s+xor\s+/i,parse:function(a){parseOperator("xor","binary",12,a.tree)}},{re:/^\s+or\s+/i,parse:function(a){parseOperator("||","binary",13,a.tree)}},{re:/^#(\w+)#/,parse:function(a,b){var c={token:"$smarty",tree:[]};parseVar(".config."+RegExp.$1,c,"smarty"),a.tree.push(c.tree[0]),parseModifiers(b,a)}},{re:/^\s*\[\s*/,parse:function(a,b){var c=parseParams(b,/^\s*,\s*/,/^('[^'\\]*(?:\\.[^'\\]*)*'|"[^"\\]*(?:\\.[^"\\]*)*"|\w+)\s*=>\s*/);parsePluginFunc("__array",c,a.tree),a.value+=c.toString();var d=b.slice(c.toString().length).match(/\s*\]/);d&&(a.value+=d[0])}},{re:/^[\d.]+/,parse:function(a,b){a.token=a.token.indexOf(".")>-1?parseFloat(a.token):parseInt(a.token,10),parseText(a.token,a.tree),parseModifiers(b,a)}},{re:/^\w+/,parse:function(a,b){parseText(a.token,a.tree),parseModifiers(b,a)}}];jSmart=function(a){this.tree=[],this.tree.blocks={},this.scripts={},this.default_modifiers=[],this.filters={variable:[],post:[]},this.smarty={smarty:{block:{},"break":!1,capture:{},"continue":!1,counter:{},cycle:{},foreach:{},section:{},now:Math.floor((new Date).getTime()/1e3),"const":{},config:{},current_dir:"/",template:"",ldelim:jSmart.prototype.left_delimiter,rdelim:jSmart.prototype.right_delimiter,version:"2.15.0"}},blocks=this.tree.blocks,parse(applyFilters(jSmart.prototype.filters_global.pre,stripComments(new String(a?a:"").replace(/\r\n/g,"\n"))),this.tree)},jSmart.prototype.fetch=function(a){blocks=this.tree.blocks,scripts=this.scripts,escape_html=this.escape_html,default_modifiers=jSmart.prototype.default_modifiers_global.concat(this.default_modifiers),this.data=obMerge("object"==typeof a?a:{},this.smarty),varFilters=jSmart.prototype.filters_global.variable.concat(this.filters.variable);var b=process(this.tree,this.data);return jSmart.prototype.debugging&&plugins.debug.process([],this.data),applyFilters(jSmart.prototype.filters_global.post.concat(this.filters.post),b)},jSmart.prototype.escape_html=!1,jSmart.prototype.registerPlugin=function(a,b,c){"modifier"==a?modifiers[b]=c:plugins[b]={type:a,process:c}},jSmart.prototype.registerFilter=function(a,b){(this.tree?this.filters:jSmart.prototype.filters_global)["output"==a?"post":a].push(b)},jSmart.prototype.filters_global={pre:[],variable:[],post:[]},jSmart.prototype.configLoad=function(a,b,c){c=c?c:this.data;for(var d=a.replace(/\r\n/g,"\n").replace(/^\s+|\s+$/g,""),e=/^\s*(?:\[([^\]]+)\]|(?:(\w+)[ \t]*=[ \t]*("""|'[^'\\\n]*(?:\\.[^'\\\n]*)*'|"[^"\\\n]*(?:\\.[^"\\\n]*)*"|[^\n]*)))/m,f="",g=d.match(e);g;g=d.match(e)){if(d=d.slice(g.index+g[0].length),g[1])f=g[1];else if((!f||f==b)&&"."!=f.substr(0,1))if('"""'==g[3]){var h=d.match(/"""/);h&&(c.smarty.config[g[2]]=d.slice(0,h.index),d=d.slice(h.index+h[0].length))}else c.smarty.config[g[2]]=trimQuotes(g[3]);var i=d.match(/\n+/);if(!i)break;d=d.slice(i.index+i[0].length)}},jSmart.prototype.clearConfig=function(a){a?delete this.data.smarty.config[a]:this.data.smarty.config={}},jSmart.prototype.addDefaultModifier=function(a){a instanceof Array||(a=[a]);for(var b=0;b<a.length;++b){var c={value:"",tree:[0]};parseModifiers("|"+a[b],c),(this.tree?this.default_modifiers:this.default_modifiers_global).push(c.tree[0])}},jSmart.prototype.default_modifiers_global=[],jSmart.prototype.getTemplate=function(a){throw new Error("No template for "+a)},jSmart.prototype.getFile=function(a){throw new Error("No file for "+a)},jSmart.prototype.getJavascript=function(a){throw new Error("No Javascript for "+a)},jSmart.prototype.getConfig=function(a){throw new Error("No config for "+a)},jSmart.prototype.auto_literal=!0,jSmart.prototype.left_delimiter="{",jSmart.prototype.right_delimiter="}",jSmart.prototype.debugging=!1,jSmart.prototype.PHPJS=function(fnm,modifier){if("function"==eval("typeof "+fnm))return"object"==typeof window?window:global;if("function"==typeof PHP_JS)return new PHP_JS;throw new Error("Modifier '"+modifier+"' uses JavaScript port of PHP function '"+fnm+"'. You can find one at http://phpjs.org")},jSmart.prototype.makeTimeStamp=function(a){if(!a)return Math.floor((new Date).getTime()/1e3);if(isNaN(a)){var b=jSmart.prototype.PHPJS("strtotime","date_format").strtotime(a);return-1==b||b===!1?Math.floor((new Date).getTime()/1e3):b}return a=new String(a),14==a.length?Math.floor(new Date(a.substr(0,4),a.substr(4,2)-1,a.substr(6,2),a.substr(8,2),a.substr(10,2)).getTime()/1e3):parseInt(a)},jSmart.prototype.registerPlugin("function","__array",function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&a[c]&&"function"!=typeof a[c]&&(b[c]=a[c]);return b}),jSmart.prototype.registerPlugin("function","__func",function(a,b){for(var c=[],d={},e=[],f=0;f<a.length;++f)c.push(a.name+"__p"+f),e.push(a[f]),d[a.name+"__p"+f]=a[f];var g,h=obMerge({},b,d);return"__owner"in b&&a.name in b.__owner?(g="__owner."+a.name,execute(g+"("+c.join(",")+")",h)):modifiers.hasOwnProperty(a.name)?(g=modifiers[a.name],executeByFuncObject(g,e,h)):(g=a.name,execute(g+"("+c.join(",")+")",h))}),jSmart.prototype.registerPlugin("function","__quoted",function(a){return a.join("")}),jSmart.prototype.registerPlugin("function","append",function(a,b){var c=a.__get("var",null,0);c in b&&b[c]instanceof Array||(b[c]=[]);var d=a.__get("index",!1),e=a.__get("value",null,1);return d===!1?b[c].push(e):b[c][d]=e,""}),jSmart.prototype.registerPlugin("function","assign",function(a,b){return assignVar(a.__get("var",null,0),a.__get("value",null,1),b),""}),jSmart.prototype.registerPlugin("function","break",function(a,b){return b.smarty["break"]=!0,""}),jSmart.prototype.registerPlugin("function","call",function(a,b){var c=a.__get("name",null,0);delete a.name;var d=a.__get("assign",!1);delete a.assign;var e=plugins[c].process(a,b);return d?(assignVar(d,e,b),""):e}),jSmart.prototype.registerPlugin("block","capture",function(a,b,c){if(b){b=b.replace(/^\n/,""),c.smarty.capture[a.__get("name","default",0)]=b,"assign"in a&&assignVar(a.assign,b,c);var d=a.__get("append",!1);d&&(d in c?c[d]instanceof Array&&c[d].push(b):c[d]=[b])}return""}),jSmart.prototype.registerPlugin("function","continue",function(a,b){return b.smarty["continue"]=!0,""}),jSmart.prototype.registerPlugin("function","counter",function(a,b){var c=a.__get("name","default");if(c in b.smarty.counter){var d=b.smarty.counter[c];"start"in a?d.value=parseInt(a.start):(d.value=parseInt(d.value),d.skip=parseInt(d.skip),"down"==d.direction?d.value-=d.skip:d.value+=d.skip),d.skip=a.__get("skip",d.skip),d.direction=a.__get("direction",d.direction),d.assign=a.__get("assign",d.assign)}else b.smarty.counter[c]={value:parseInt(a.__get("start",1)),skip:parseInt(a.__get("skip",1)),direction:a.__get("direction","up"),assign:a.__get("assign",!1)};return b.smarty.counter[c].assign?(b[b.smarty.counter[c].assign]=b.smarty.counter[c].value,""):a.__get("print",!0)?b.smarty.counter[c].value:""}),jSmart.prototype.registerPlugin("function","cycle",function(a,b){var c=a.__get("name","default"),d=a.__get("reset",!1);c in b.smarty.cycle||(b.smarty.cycle[c]={arr:[""],delimiter:a.__get("delimiter",","),index:0},d=!0),a.__get("delimiter",!1)&&(b.smarty.cycle[c].delimiter=a.delimiter);var e=a.__get("values",!1);if(e){var f=[];if(e instanceof Object)for(nm in e)f.push(e[nm]);else f=e.split(b.smarty.cycle[c].delimiter);(f.length!=b.smarty.cycle[c].arr.length||f[0]!=b.smarty.cycle[c].arr[0])&&(b.smarty.cycle[c].arr=f,b.smarty.cycle[c].index=0,d=!0)}return a.__get("advance","true")&&(b.smarty.cycle[c].index+=1),(b.smarty.cycle[c].index>=b.smarty.cycle[c].arr.length||d)&&(b.smarty.cycle[c].index=0),a.__get("assign",!1)?(assignVar(a.assign,b.smarty.cycle[c].arr[b.smarty.cycle[c].index],b),""):a.__get("print",!0)?b.smarty.cycle[c].arr[b.smarty.cycle[c].index]:""}),jSmart.prototype.print_r=function(a,b){if(a instanceof Object){var c=(a instanceof Array?"Array["+a.length+"]":"Object")+"<br>";for(var d in a)a.hasOwnProperty(d)&&(c+=b+" <strong>"+d+"</strong> : "+jSmart.prototype.print_r(a[d],b+" ")+"<br>");return c}return a},jSmart.prototype.registerPlugin("function","debug",function(a,b){"undefined"!=typeof dbgWnd&&dbgWnd.close(),dbgWnd=window.open("","","width=680,height=600,resizable,scrollbars=yes");var c="",d=0;for(var e in b)c+="<tr class="+(++d%2?"odd":"even")+"><td><strong>"+e+"</strong></td><td>"+jSmart.prototype.print_r(b[e],"")+"</td></tr>";return dbgWnd.document.write(" <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> <head> <title>jSmart Debug Console</title> <style type='text/css'> table {width: 100%;} td {vertical-align:top;width: 50%;} .even td {background-color: #fafafa;} </style> </head> <body> <h1>jSmart Debug Console</h1> <h2>assigned template variables</h2> <table>"+c+"</table> </body> </html> "),""}),jSmart.prototype.registerPlugin("function","eval",function(a,b){var c=[];parse(a.__get("var","",0),c);var d=process(c,b);return"assign"in a?(assignVar(a.assign,d,b),""):d}),jSmart.prototype.registerPlugin("function","fetch",function(a,b){var c=jSmart.prototype.getFile(a.__get("file",null,0));return"assign"in a?(assignVar(a.assign,c,b),""):c}),jSmart.prototype.registerPlugin("function","html_checkboxes",function(a,b){var c,d,e,f=a.__get("type","checkbox"),g=a.__get("name",f),h=a.__get("name",f),i=a.__get("values",a.options),j=a.__get("options",[]),k="options"in a,l=a.__get("selected",!1),m=a.__get("separator",""),n=Boolean(a.__get("labels",!0)),o=Boolean(a.__get("label_ids",!1)),p=[],q=0,r="";if("checkbox"==f&&(g+="[]"),!k)for(c in a.output)j.push(a.output[c]);for(c in i)i.hasOwnProperty(c)&&(d=k?c:i[c],e=h+"_"+d,r=n?o?'<label for="'+e+'">':"<label>":"",r+='<input type="'+f+'" name="'+g+'" value="'+d+'" ',o&&(r+='id="'+e+'" '),l==(k?c:i[c])&&(r+='checked="checked" '),r+="/>"+j[k?c:q++],r+=n?"</label>":"",r+=m,p.push(r));return"assign"in a?(assignVar(a.assign,p,b),""):p.join("\n")}),jSmart.prototype.registerPlugin("function","html_image",function(a){var b,c=a.__get("file",null),d=a.__get("width",!1),e=a.__get("height",!1),f=a.__get("alt",""),g=a.__get("href",a.__get("link",!1)),h=a.__get("path_prefix",""),i={file:1,width:1,height:1,alt:1,href:1,basedir:1,path_prefix:1,link:1},j='<img src="'+h+c+'" alt="'+f+'"'+(d?' width="'+d+'"':"")+(e?' height="'+e+'"':"");for(b in a)a.hasOwnProperty(b)&&"string"==typeof a[b]&&(b in i||(j+=" "+b+'="'+a[b]+'"'));return j+=" />",g?'<a href="'+g+'">'+j+"</a>":j}),jSmart.prototype.registerPlugin("function","html_options",function(a){var b,c=a.__get("values",a.options),d=a.__get("options",[]),e="options"in a;if(!e)for(b in a.output)d.push(a.output[b]);var f=a.__get("selected",!1),g=[],h="",i=0;for(b in c)c.hasOwnProperty(b)&&(h='<option value="'+(e?b:c[b])+'"',f==(e?b:c[b])&&(h+=' selected="selected"'),h+=">"+d[e?b:i++]+"</option>",g.push(h));var j=a.__get("name",!1);return(j?'<select name="'+j+'">\n'+g.join("\n")+"\n</select>":g.join("\n"))+"\n"}),jSmart.prototype.registerPlugin("function","html_radios",function(a,b){return a.type="radio",plugins.html_checkboxes.process(a,b)}),jSmart.prototype.registerPlugin("function","html_select_date",function(a){var b=a.__get("prefix","Date_"),c=["January","February","March","April","May","June","July","August","September","October","November","December"],d="";d+='<select name="'+b+'Month">\n';
|
|
var e=0;for(e=0;e<c.length;++e)d+='<option value="'+e+'">'+c[e]+"</option>\n";for(d+="</select>\n",d+='<select name="'+b+'Day">\n',e=0;31>e;++e)d+='<option value="'+e+'">'+e+"</option>\n";return d+="</select>\n"}),jSmart.prototype.registerPlugin("function","html_table",function(a){var b,c=[];if(a.loop instanceof Array)c=a.loop;else for(b in a.loop)a.loop.hasOwnProperty(b)&&c.push(a.loop[b]);var d=a.__get("rows",!1),e=a.__get("cols",!1);e||(e=d?Math.ceil(c.length/d):3);var f=[];if(isNaN(e)){if("object"==typeof e)for(b in e)e.hasOwnProperty(b)&&f.push(e[b]);else f=e.split(/\s*,\s*/);e=f.length}d=d?d:Math.ceil(c.length/e);var g=a.__get("inner","cols"),h=a.__get("caption",""),i=a.__get("table_attr",'border="1"'),j=a.__get("th_attr",!1);j&&"object"!=typeof j&&(j=[j]);var k=a.__get("tr_attr",!1);k&&"object"!=typeof k&&(k=[k]);var l=a.__get("td_attr",!1);l&&"object"!=typeof l&&(l=[l]);for(var m=a.__get("trailpad"," "),n=a.__get("hdir","right"),o=a.__get("vdir","down"),p="",q=0;d>q;++q){p+="<tr"+(k?" "+k[q%k.length]:"")+">\n";for(var r=0;e>r;++r){var s="cols"==g?("down"==o?q:d-1-q)*e+("right"==n?r:e-1-r):("right"==n?r:e-1-r)*d+("down"==o?q:d-1-q);p+="<td"+(l?" "+l[r%l.length]:"")+">"+(s<c.length?c[s]:m)+"</td>\n"}p+="</tr>\n"}var t="";if(f.length){t="\n<thead><tr>";for(var u=0;u<f.length;++u)t+="\n<th"+(j?" "+j[u%j.length]:"")+">"+f["right"==n?u:f.length-1-u]+"</th>";t+="\n</tr></thead>"}return"<table "+i+">"+(h?"\n<caption>"+h+"</caption>":"")+t+"\n<tbody>\n"+p+"</tbody>\n</table>\n"}),jSmart.prototype.registerPlugin("function","include",function(a,b){var c=a.__get("file",null,0),d=obMerge({},b,a);d.smarty.template=c;var e=process(getTemplate(c,[],findInArray(a,"nocache")>=0),d);return"assign"in a?(assignVar(a.assign,e,b),""):e}),jSmart.prototype.registerPlugin("function","include_javascript",function(a,b){var c=a.__get("file",null,0);if(a.__get("once",!0)&&c in scripts)return"";scripts[c]=!0;var d=execute(jSmart.prototype.getJavascript(c),{$this:b});return"assign"in a?(assignVar(a.assign,d,b),""):d}),jSmart.prototype.registerPlugin("function","include_php",function(a,b){return plugins.include_javascript.process(a,b)}),jSmart.prototype.registerPlugin("function","insert",function(params,data){var fparams={};for(var nm in params)params.hasOwnProperty(nm)&&isNaN(nm)&¶ms[nm]&&"string"==typeof params[nm]&&"name"!=nm&&"assign"!=nm&&"script"!=nm&&(fparams[nm]=params[nm]);var prefix="insert_";"script"in params&&(eval(jSmart.prototype.getJavascript(params.script)),prefix="smarty_insert_");var func=eval(prefix+params.__get("name",null,0)),s=func(fparams,data);return"assign"in params?(assignVar(params.assign,s,data),""):s}),jSmart.prototype.registerPlugin("block","javascript",function(a,b,c){return c.$this=c,execute(b,c),delete c.$this,""}),jSmart.prototype.registerPlugin("function","config_load",function(a,b){return jSmart.prototype.configLoad(jSmart.prototype.getConfig(a.__get("file",null,0)),a.__get("section","",1),b),""}),jSmart.prototype.registerPlugin("function","mailto",function(a){var b=a.__get("address",null),c=a.__get("encode","none"),d=a.__get("text",b),e=jSmart.prototype.PHPJS("rawurlencode","mailto").rawurlencode(a.__get("cc","")).replace("%40","@"),f=jSmart.prototype.PHPJS("rawurlencode","mailto").rawurlencode(a.__get("bcc","")).replace("%40","@"),g=jSmart.prototype.PHPJS("rawurlencode","mailto").rawurlencode(a.__get("followupto","")).replace("%40","@"),h=jSmart.prototype.PHPJS("rawurlencode","mailto").rawurlencode(a.__get("subject","")),i=jSmart.prototype.PHPJS("rawurlencode","mailto").rawurlencode(a.__get("newsgroups","")),j=a.__get("extra","");if(b+=e?"?cc="+e:"",b+=f?(e?"&":"?")+"bcc="+f:"",b+=h?(e||f?"&":"?")+"subject="+h:"",b+=i?(e||f||h?"&":"?")+"newsgroups="+i:"",b+=g?(e||f||h||i?"&":"?")+"followupto="+g:"",s='<a href="mailto:'+b+'" '+j+">"+d+"</a>","javascript"==c){s="document.write('"+s+"');";for(var k="",l=0;l<s.length;++l)k+="%"+jSmart.prototype.PHPJS("bin2hex","mailto").bin2hex(s.substr(l,1));return'<script type="text/javascript">eval(unescape(\''+k+"'))</script>"}if("javascript_charcode"==c){for(var m=[],l=0;l<s.length;++l)m.push(jSmart.prototype.PHPJS("ord","mailto").ord(s.substr(l,1)));return'<script type="text/javascript" language="javascript">\n<!--\n{document.write(String.fromCharCode('+m.join(",")+"))}\n//-->\n</script>\n"}if("hex"==c){if(b.match(/^.+\?.+$/))throw new Error("mailto: hex encoding does not work with extra attributes. Try javascript.");for(var n="",l=0;l<b.length;++l)n+=b.substr(l,1).match(/\w/)?"%"+jSmart.prototype.PHPJS("bin2hex","mailto").bin2hex(b.substr(l,1)):b.substr(l,1);for(var o="",l=0;l<d.length;++l)o+="&#x"+jSmart.prototype.PHPJS("bin2hex","mailto").bin2hex(d.substr(l,1))+";";return'<a href="mailto:'+n+'" '+j+">"+o+"</a>"}return s}),jSmart.prototype.registerPlugin("function","math",function(params,data){with(Math)with(params)var res=eval(params.__get("equation",null).replace(/pi\(\s*\)/g,"PI"));return"format"in params&&(res=jSmart.prototype.PHPJS("sprintf","math").sprintf(params.format,res)),"assign"in params?(assignVar(params.assign,res,data),""):res}),jSmart.prototype.registerPlugin("block","nocache",function(a,b){return b}),jSmart.prototype.registerPlugin("block","textformat",function(a,b,c){if(!b)return"";var d=a.__get("wrap",80),e=a.__get("wrap_char","\n"),f=a.__get("wrap_cut",!1),g=a.__get("indent_char"," "),h=a.__get("indent",0),i=new Array(h+1).join(g),j=a.__get("indent_first",0),k=new Array(j+1).join(g),l=a.__get("style","");"email"==l&&(d=72);for(var m=b.split(/[\r\n]{2}/),n=0;n<m.length;++n){var o=m[n];o&&(o=o.replace(/^\s+|\s+$/,"").replace(/\s+/g," "),j>0&&(o=k+o),o=modifiers.wordwrap(o,d-h,e,f),h>0&&(o=o.replace(/^/gm,i)),m[n]=o)}var p=m.join(e+e);return"assign"in a?(assignVar(a.assign,p,c),""):p}),jSmart.prototype.registerPlugin("modifier","capitalize",function(a,b,c){var d=new RegExp(b?"[^a-zA-Z_à-ü]+":"[^a-zA-Z0-9_à-ü]"),e=null,f="";for(c&&(a=a.toLowerCase()),e=a.match(d);e;e=a.match(d)){var g=a.slice(0,e.index);f+=g.match(/\d/)?g:g.charAt(0).toUpperCase()+g.slice(1),f+=a.slice(e.index,e.index+e[0].length),a=a.slice(e.index+e[0].length)}return a.match(/\d/)?f+a:f+a.charAt(0).toUpperCase()+a.slice(1)}),jSmart.prototype.registerPlugin("modifier","cat",function(a,b){return b=b?b:"",a+b}),jSmart.prototype.registerPlugin("modifier","count",function(a,b){if(null===a||"undefined"==typeof a)return 0;if(a.constructor!==Array&&a.constructor!==Object)return 1;b=Boolean(b);var c,d=0;for(c in a)a.hasOwnProperty(c)&&(d++,b&&a[c]&&(a[c].constructor===Array||a[c].constructor===Object)&&(d+=modifiers.count(a[c],!0)));return d}),jSmart.prototype.registerPlugin("modifier","count_characters",function(a,b){return b?a.length:a.replace(/\s/g,"").length}),jSmart.prototype.registerPlugin("modifier","count_paragraphs",function(a){var b=a.match(/\n+/g);return b?b.length+1:1}),jSmart.prototype.registerPlugin("modifier","count_sentences",function(a){var b=a.match(/[^\s]\.(?!\w)/g);return b?b.length:0}),jSmart.prototype.registerPlugin("modifier","count_words",function(a){var b=a.match(/\w+/g);return b?b.length:0}),jSmart.prototype.registerPlugin("modifier","date_format",function(a,b,c){return jSmart.prototype.PHPJS("strftime","date_format").strftime(b?b:"%b %e, %Y",jSmart.prototype.makeTimeStamp(a?a:c))}),jSmart.prototype.registerPlugin("modifier","defaultValue",function(a,b){return a&&"null"!=a&&"undefined"!=a?a:b?b:""}),jSmart.prototype.registerPlugin("modifier","unescape",function(a,b,c){switch(a=new String(a),b=b||"html",c=c||"UTF-8",b){case"html":return a.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,'"');case"entity":case"htmlall":return jSmart.prototype.PHPJS("html_entity_decode","unescape").html_entity_decode(a,0);case"url":return jSmart.prototype.PHPJS("rawurldecode","unescape").rawurldecode(a)}return a}),jSmart.prototype.registerPlugin("modifier","escape",function(a,b,c,d){switch(a=new String(a),b=b||"html",c=c||"UTF-8",d="undefined"!=typeof d?Boolean(d):!0,b){case"html":return d&&(a=a.replace(/&/g,"&")),a.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,""");case"htmlall":return jSmart.prototype.PHPJS("htmlentities","escape").htmlentities(a,3,c);case"url":return jSmart.prototype.PHPJS("rawurlencode","escape").rawurlencode(a);case"urlpathinfo":return jSmart.prototype.PHPJS("rawurlencode","escape").rawurlencode(a).replace(/%2F/g,"/");case"quotes":return a.replace(/(^|[^\\])'/g,"$1\\'");case"hex":for(var e="",f=0;f<a.length;++f)e+="%"+jSmart.prototype.PHPJS("bin2hex","escape").bin2hex(a.substr(f,1));return e;case"hexentity":for(var e="",f=0;f<a.length;++f)e+="&#x"+jSmart.prototype.PHPJS("bin2hex","escape").bin2hex(a.substr(f,1)).toLowerCase()+";";return e;case"decentity":for(var e="",f=0;f<a.length;++f)e+="&#"+jSmart.prototype.PHPJS("ord","escape").ord(a.substr(f,1))+";";return e;case"mail":return a.replace(/@/g," [AT] ").replace(/[.]/g," [DOT] ");case"nonstd":for(var e="",f=0;f<a.length;++f){var g=jSmart.prototype.PHPJS("ord","escape").ord(a.substr(f,1));e+=g>=126?"&#"+g+";":a.substr(f,1)}return e;case"javascript":return a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/<\//g,"</")}return a}),jSmart.prototype.registerPlugin("modifier","indent",function(a,b,c){b=b?b:4,c=c?c:" ";for(var d="";b--;)d+=c;var e=a.match(/\n+$/);return d+a.replace(/\n+$/,"").replace(/\n/g,"\n"+d)+(e?e[0]:"")}),jSmart.prototype.registerPlugin("modifier","lower",function(a){return a.toLowerCase()}),jSmart.prototype.registerPlugin("modifier","nl2br",function(a){return a.replace(/\n/g,"<br />\n")}),jSmart.prototype.registerPlugin("modifier","regex_replace",function(a,b,c){var d=b.match(/^ *\/(.*)\/(.*) *$/);return new String(a).replace(new RegExp(d[1],"g"+(d.length>1?d[2]:"")),c)}),jSmart.prototype.registerPlugin("modifier","replace",function(a,b,c){if(!b)return a;a=new String(a),b=new String(b),c=new String(c);var d="",e=-1;for(e=a.indexOf(b);e>=0;e=a.indexOf(b))d+=a.slice(0,e)+c,e+=b.length,a=a.slice(e);return d+a}),jSmart.prototype.registerPlugin("modifier","spacify",function(a,b){return b||(b=" "),a.replace(/(\n|.)(?!$)/g,"$1"+b)}),jSmart.prototype.registerPlugin("modifier","noprint",function(){return""}),jSmart.prototype.registerPlugin("modifier","string_format",function(a,b){return jSmart.prototype.PHPJS("sprintf","string_format").sprintf(b,a)}),jSmart.prototype.registerPlugin("modifier","strip",function(a,b){return b=b?b:" ",new String(a).replace(/[\s]+/g,b)}),jSmart.prototype.registerPlugin("modifier","strip_tags",function(a,b){return b=null==b?!0:b,new String(a).replace(/<[^>]*?>/g,b?" ":"")}),jSmart.prototype.registerPlugin("modifier","truncate",function(a,b,c,d,e){return b=b?b:80,c=null!=c?c:"...",a.length<=b?a:(b-=Math.min(b,c.length),e?a.slice(0,Math.floor(b/2))+c+a.slice(a.length-Math.floor(b/2)):(d||(a=a.slice(0,b+1).replace(/\s+?(\S+)?$/,"")),a.slice(0,b)+c))}),jSmart.prototype.registerPlugin("modifier","upper",function(a){return a.toUpperCase()}),jSmart.prototype.registerPlugin("modifier","wordwrap",function(a,b,c,d){b=b||80,c=c||"\n";for(var e=a.split("\n"),f=0;f<e.length;++f){for(var g=e[f],h="";g.length>b;){for(var i=0,j=g.slice(i).match(/\s+/);j&&i+j.index<=b;j=g.slice(i).match(/\s+/))i+=j.index+j[0].length;i=i||(d?b:j?j.index+j[0].length:g.length),h+=g.slice(0,i).replace(/\s+$/,""),i<g.length&&(h+=c),g=g.slice(i)}e[f]=h+g}return e.join("\n")}),String.prototype.fetch=function(a){var b=new jSmart(this);return b.fetch(a)},"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=jSmart:("undefined"!=typeof global&&(global.jSmart=jSmart),"function"==typeof define&&define.amd&&define("jSmart",[],function(){return jSmart}))}(); |