-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsmart.core.min.js
70 lines (67 loc) · 30.5 KB
/
smart.core.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
jSmart Javascript template engine, a port of Smarty PHP to Javascript
https://github.com/miroshnikov/jsmart
Copyright 2016, Max Miroshnikov <miroshnikov at gmail dot com>
jSmart is licensed under the MIT license
*/
(function(){function B(a,c){for(var b=1;b<arguments.length;++b)for(var d in arguments[b])a[d]=arguments[b][d];return a}function E(a){var c=0,b;for(b in a)a.hasOwnProperty(b)&&c++;return c}function C(a,c){if(Array.prototype.indexOf)return a.indexOf(c);for(var b=0;b<a.length;++b)if(a[b]===c)return b;return-1}function J(a){return a.replace(/\\t/,"\t").replace(/\\n/,"\n").replace(/\\(['"\\])/g,"$1")}function y(a){return J(a.replace(/^['"](.*)['"]$/,"$1")).replace(/^\s+|\s+$/g,"")}function u(a,c){for(var b=
0,d=0,e=f.prototype.left_delimiter,g=f.prototype.right_delimiter,h=f.prototype.auto_literal,K=/^\s*(.+)\s*$/i,K=a?RegExp("^\\s*("+a+")\\s*$","i"):K,l=0;l<c.length;++l)if(c.substr(l,e.length)==e)h&&l+1<c.length&&c.substr(l+1,1).match(/\s/)||(b||(c=c.slice(l),d+=parseInt(l),l=0),++b);else if(c.substr(l,g.length)==g&&!(h&&0<=l-1&&c.substr(l-1,1).match(/\s/))){if(!--b){var m=c.slice(e.length,l).replace(/[\r\n]/g," ").match(K);if(m)return m.index=d,m[0]=c.slice(0,l+g.length),m}0>b&&(b=0)}return null}function L(a,
c,b){var d="",e=null,g=null,h=0;do{e&&(h+=e[0].length);e=u(a,b);if(!e)throw Error("Unclosed {"+c+"}");d+=b.slice(0,e.index);h+=e.index;b=b.slice(e.index+e[0].length);(g=u(c,d))&&(d=d.slice(g.index+g[0].length))}while(g);e.index=h;return e}function F(a,c,b,d){for(var e=0,g=u(b,d);g;g=u(b,d)){var h=u(a,d);if(!h||h.index>g.index)return g.index+=e,g;d=d.slice(h.index+h[0].length);e+=h.index+h[0].length;g=L(c,a,d);d=d.slice(g.index+g[0].length);e+=g.index+g[0].length}return null}function R(a,c){if("string"==
typeof a)with({__code:a})with(M)with(c)try{return eval(__code)}catch(b){throw Error(b.message+" in \n"+a);}return a}function z(a,c,b){a.match(/\[\]$/)?b[a.replace(/\[\]$/,"")].push(c):b[a]=c}function k(a,c){for(var b=u("",a);b;b=u("",a)){b.index&&q(a.slice(0,b.index),c);a=a.slice(b.index+b[0].length);var d=b[1].match(/^\s*(\w+)(.*)$/);if(d){var e=d[1],d=2<d.length?d[2].replace(/^\s+|\s+$/g,""):"";if(e in A){var g=A[e],d=("parseParams"in g?g.parseParams:t)(d);"block"==g.type?(a=a.replace(/^\n/,""),
b=L("/"+e,e+" +[^}]*",a),g.parse(d,c,a.slice(0,b.index)),a=a.slice(b.index+b[0].length)):(g.parse(d,c),"extends"==e&&(c=[]));a=a.replace(/^\n/,"")}else if(e in v){if(b=v[e],"block"==b.type?(b=L("/"+e,e+" +[^}]*",a),d=t(d),g=a.slice(0,b.index),c.push({type:"plugin",name:e,params:d,subTree:k(g,[])}),a=a.slice(b.index+b[0].length)):"function"==b.type&&(b=t(d),c.push({type:"plugin",name:e,params:b})),"append"==e||"assign"==e||"capture"==e||"eval"==e||"include"==e)a=a.replace(/^\n/,"")}else A.expression.parse(b[1],
c)}else e=A.expression.parse(b[1],c),"build-in"==e.type&&"operator"==e.name&&"="==e.op&&(a=a.replace(/^\n/,""))}a&&q(a,c);return c}function q(a,c){if(q.parseEmbeddedVars)for(var b=/([$][\w@]+)|`([^`]*)`/,d=a.match(b);d;d=a.match(b))c.push({type:"text",data:a.slice(0,d.index)}),c.push(D(d[1]?d[1]:d[2]).tree),a=a.slice(d.index+d[0].length);c.push({type:"text",data:a});return c}function S(a,c,b){c.__parsed.name=q(a,[])[0];b.push({type:"plugin",name:"__func",params:c});return b}function n(a,c,b,d){d.push({type:"build-in",
name:"operator",op:a,optype:c,precedence:b,params:{}})}function N(a,c,b){var d=c.token;b=[{type:"text",data:b.replace(/^(\w+)@(key|index|iteration|first|last|show|total)/gi,"$1__$2")}];for(var e=/^(?:\.|\s*->\s*|\[\s*)/,g=a.match(e);g;g=a.match(e)){c.token+=g[0];a=a.slice(g[0].length);var h={value:"",tree:[]};if(g[0].match(/\[/)){if(h=D(a))c.token+=h.value,b.push(h.tree),a=a.slice(h.value.length);if(g=a.match(/\s*\]/))c.token+=g[0],a=a.slice(g[0].length)}else{g=p.stop;p.stop=!0;if(O(a,h)){c.token+=
h.value;var f=h.tree[0];"plugin"==f.type&&"__func"==f.name&&(f.hasOwner=!0);b.push(f);a=a.slice(h.value.length)}else h=!1;p.stop=g}h||b.push({type:"text",data:""})}c.tree.push({type:"var",parts:b});c.value+=c.token.substr(d.length);P(c.token);return a}function P(a){}function p(a,c){if(!p.stop){var b=a.match(/^\|(\w+)/);if(b){c.value+=b[0];var d="default"==b[1]?"__defaultValue":"__"+b[1];a=a.slice(b[0].length).replace(/^\s+/,"");p.stop=!0;for(var b=[],e=a.match(/^\s*:\s*/);e;e=a.match(/^\s*:\s*/))c.value+=
a.slice(0,e[0].length),a=a.slice(e[0].length),e={value:"",tree:[]},O(a,e)?(c.value+=e.value,b.push(e.tree[0]),a=a.slice(e.value.length)):q("",b);p.stop=!1;b.unshift(c.tree.pop());c.tree.push(S(d,{__parsed:b},[])[0]);p(a,c)}}}function O(a,c){if(!a)return!1;if(a.substr(0,f.prototype.left_delimiter.length)==f.prototype.left_delimiter){var b=u("",a);if(b)return c.token=b[0],c.value+=b[0],k(b[0],c.tree),p(a.slice(c.value.length),c),!0}for(b=0;b<G.length;++b)if(a.match(G[b].re))return c.token=RegExp.lastMatch,
c.value+=RegExp.lastMatch,G[b].parse(c,a.slice(c.token.length)),!0;return!1}function T(a,c,b){var d=c[a];if("operator"==d.name&&d.precedence==b&&!d.params.__parsed){if("binary"==d.optype)return d.params.__parsed=[c[a-1],c[a+1]],c.splice(a-1,3,d),!0;if("post-unary"==d.optype)return d.params.__parsed=[c[a-1]],c.splice(a-1,2,d),!0;d.params.__parsed=[c[a+1]];c.splice(a,2,d)}return!1}function U(a){for(var c=0,c=0;c<a.length;++c)a[c]instanceof Array&&(a[c]=U(a[c]));for(var b=1;14>b;++b)if(2==b||10==b)for(c=
a.length;0<c;--c)c-=T(c-1,a,b);else for(c=0;c<a.length;++c)c-=T(c,a,b);return a[0]}function D(a){for(var c={value:"",tree:[]};O(a.slice(c.value.length),c););if(!c.tree.length)return!1;c.tree=U(c.tree);return c}function t(a,c,b){var d=a.replace(/\n/g," ").replace(/^\s+|\s+$/g,""),e=[];e.__parsed=[];a="";if(!d)return e;c||(c=/^\s+/,b=/^(\w+)\s*=\s*/);for(;d;){var g=null;if(b){var h=d.match(b);h&&(g=y(h[1]),a+=d.slice(0,h[0].length),d=d.slice(h[0].length))}h=D(d);if(!h)break;g?(e[g]=h.value,e.__parsed[g]=
h.tree):(e.push(h.value),e.__parsed.push(h.tree));a+=d.slice(0,h.value.length);d=d.slice(h.value.length);if(g=d.match(c))a+=d.slice(0,g[0].length),d=d.slice(g[0].length);else break}e.toString=function(){return a};return e}function s(a,c){var b=[],d;for(d in a.__parsed)if(a.__parsed.hasOwnProperty(d)){var e=m([a.__parsed[d]],c);"string"==typeof e&&e.match(/^[1-9]\d{0,14}$/)&&!isNaN(e)&&(e=parseInt(e,10));b[d]=e}b.__get=function(a,c,d){if(a in b&&"undefined"!=typeof b[a]&&"function"!=typeof b[a])return b[a];
if("undefined"!=typeof d&&"undefined"!=typeof b[d])return b[d];if(null===c)throw Error("The required attribute '"+a+"' is missing");return c};return b}function w(a,c,b){for(var d=c,e="",g=0;g<a.parts.length;++g){var h=a.parts[g];if("plugin"==h.type&&"__func"==h.name&&h.hasOwner)c.__owner=d,d=m([a.parts[g]],c),delete c.__owner;else{e=m([h],c);e in c.smarty.section&&"text"==h.type&&"smarty"!=m([a.parts[0]],c)&&(e=c.smarty.section[e].index);!e&&"undefined"!=typeof b&&d instanceof Array&&(e=d.length);
"undefined"!=typeof b&&g==a.parts.length-1&&(d[e]=b);if(!("object"==typeof d&&null!==d&&e in d)){if("undefined"==typeof b)return b;d[e]={}}d=d[e]}}return d}function m(a,c){for(var b="",d=0;d<a.length;++d){var e="",g=a[d];if("text"==g.type)e=g.data;else if("var"==g.type)e=w(g,c);else if("build-in"==g.type)e=A[g.name].process(g,c);else if("plugin"==g.type){var h=v[g.name];if("block"==h.type){var f={value:!0};for(h.process(s(g.params,c),"",c,f);f.value;)f.value=!1,e+=h.process(s(g.params,c),m(g.subTree,
c),c,f)}else"function"==h.type&&(e=h.process(s(g.params,c),c))}"boolean"==typeof e&&(e=e?"1":"");if(1==a.length)return e;b+=null!==e?e:"";if(c.smarty["continue"]||c.smarty["break"])break}return b}function V(a,c,b){if(!b&&a in Q)c.length=0,B(c,Q[a]);else{var d=f.prototype.getTemplate(a);if("string"!=typeof d)throw Error("No template for "+a);k(H(f.prototype.filters_global.pre,W(d.replace(/\r\n/g,"\n"))),c);b||(Q[a]=c)}return c}function W(a){for(var c="",b=RegExp(f.prototype.left_delimiter+"\\*"),d=
RegExp("\\*"+f.prototype.right_delimiter),e=a.match(b);e;e=a.match(b)){c+=a.slice(0,e.index);a=a.slice(e.index+e[0].length);e=a.match(d);if(!e)throw Error("Unclosed "+f.left_delimiter+"*");a=a.slice(e.index+e[0].length)}return c+a}function H(a,c){for(var b=0;b<a.length;++b)c=a[b](c);return c}var A={expression:{parse:function(a,c){var b=D(a);c.push({type:"build-in",name:"expression",expression:b.tree,params:t(a.slice(b.value.length).replace(/^\s+|\s+$/g,""))});return b.tree},process:function(a,c){var b=
s(a.params,c),d=m([a.expression],c);if(0>C(b,"nofilter")){for(b=0;b<default_modifiers.length;++b){var e=default_modifiers[b];e.params.__parsed[0]={type:"text",data:d};d=m([e],c)}escape_html&&(d=M.__escape(d));d=H(varFilters,d);I.length&&(__t=function(){return d},d=m(I,c))}return d}},operator:{process:function(a,c){var b=s(a.params,c),d=b[0];if("binary"==a.optype){b=b[1];if("="==a.op)return w(a.params.__parsed[0],c,b),"";if(a.op.match(/(\+=|-=|\*=|\/=|%=)/)){d=w(a.params.__parsed[0],c);switch(a.op){case "+=":d+=
b;break;case "-=":d-=b;break;case "*=":d*=b;break;case "/=":d/=b;break;case "%=":d%=b}return w(a.params.__parsed[0],c,d)}if(a.op.match(/div/))return"div"!=a.op^0==d%b;if(a.op.match(/even/))return"even"!=a.op^0==d/b%2;if(a.op.match(/xor/))return(d||b)&&!(d&&b);switch(a.op){case "==":return d==b;case "!=":return d!=b;case "+":return d+b;case "-":return d-b;case "*":return d*b;case "/":return d/b;case "%":return d%b;case "&&":return d&&b;case "||":return d||b;case "<":return d<b;case "<=":return d<=
b;case ">":return d>b;case ">=":return d>=b;case "===":return d===b;case "!==":return d!==b}}else{if("!"==a.op)return d instanceof Array?!d.length:"object"==typeof d?!E(d):"0"===d?!0:!d;(b="var"==a.params.__parsed[0].type)&&(d=w(a.params.__parsed[0],c));var e=d;if("pre-unary"==a.optype){switch(a.op){case "-":e=-d;break;case "++":e=++d;break;case "--":e=--d}b&&w(a.params.__parsed[0],c,d)}else{switch(a.op){case "++":d++;break;case "--":d--}w(a.params.__parsed[0],c,d)}return e}}},section:{type:"block",
parse:function(a,c,b){var d=[],e=[];c.push({type:"build-in",name:"section",params:a,subTree:d,subTreeElse:e});(a=F("section [^}]+","/section","sectionelse",b))?(k(b.slice(0,a.index),d),k(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)):k(b,d)},process:function(a,c){var b=s(a.params,c),d={};c.smarty.section[b.__get("name",null,0)]=d;var e=b.__get("show",!0);d.show=e;if(!e)return m(a.subTreeElse,c);var e=parseInt(b.__get("start",0)),g=b.loop instanceof Object?E(b.loop):isNaN(b.loop)?0:parseInt(b.loop),
h=parseInt(b.__get("step",1)),b=parseInt(b.__get("max"));isNaN(b)&&(b=Number.MAX_VALUE);0>e?(e+=g,0>e&&(e=0)):e>=g&&(e=g?g-1:0);for(var f=0,l=e;0<=l&&l<g&&f<b;l+=h,++f);d.total=f;d.loop=f;for(var f=0,k="",l=e;0<=l&&l<g&&f<b&&!c.smarty["break"];l+=h,++f)d.first=l==e,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=f+1,k+=m(a.subTree,c),c.smarty["continue"]=!1;c.smarty["break"]=!1;return f?k:m(a.subTreeElse,c)}},setfilter:{type:"block",parseParams:function(a){return[D("__t()|"+
a).tree]},parse:function(a,c,b){c.push({type:"build-in",name:"setfilter",params:a,subTree:k(b,[])})},process:function(a,c){I=a.params;var b=m(a.subTree,c);I=[];return b}},"for":{type:"block",parseParams:function(a){var c=a.match(/^\s*\$(\w+)\s*=\s*([^\s]+)\s*to\s*([^\s]+)\s*(?:step\s*([^\s]+))?\s*(.*)$/);if(!c)throw Error("Invalid {for} parameters: "+a);return t("varName='"+c[1]+"' from="+c[2]+" to="+c[3]+" step="+(c[4]?c[4]:"1")+" "+c[5])},parse:function(a,c,b){var d=[],e=[];c.push({type:"build-in",
name:"for",params:a,subTree:d,subTreeElse:e});(a=F("for\\s[^}]+","/for","forelse",b))?(k(b.slice(0,a.index),d),k(b.slice(a.index+a[0].length),e)):k(b,d)},process:function(a,c){var b=s(a.params,c),d=parseInt(b.__get("from")),e=parseInt(b.__get("to")),g=parseInt(b.__get("step"));isNaN(g)&&(g=1);var h=parseInt(b.__get("max"));isNaN(h)&&(h=Number.MAX_VALUE);for(var f=0,l="",d=Math.min(Math.ceil(((0<g?e-d:d-e)+1)/Math.abs(g)),h),e=parseInt(b.from);f<d&&!c.smarty["break"];e+=g,++f)c[b.varName]=e,l+=m(a.subTree,
c),c.smarty["continue"]=!1;c.smarty["break"]=!1;f||(l=m(a.subTreeElse,c));return l}},"if":{type:"block",parse:function(a,c,b){var d=[],e=[];c.push({type:"build-in",name:"if",params:a,subTreeIf:d,subTreeElse:e});(a=F("if\\s+[^}]+","/if","else[^}]*",b))?(k(b.slice(0,a.index),d),b=b.slice(a.index+a[0].length),(d=a[1].match(/^else\s*if(.*)/))?A["if"].parse(t(d[1]),e,b.replace(/^\n/,"")):k(b.replace(/^\n/,""),e)):k(b,d)},process:function(a,c){var b=s(a.params,c)[0];return!b||b instanceof Array&&!b.length||
b instanceof Object&&!E(b)?m(a.subTreeElse,c):m(a.subTreeIf,c)}},foreach:{type:"block",parseParams:function(a){var c=a.match(/^\s*([$].+)\s*as\s*[$](\w+)\s*(=>\s*[$](\w+))?\s*$/i);c&&(a="from="+c[1]+" item="+(c[4]||c[2]),c[4]&&(a+=" key="+c[2]));return t(a)},parse:function(a,c,b){var d=[],e=[];c.push({type:"build-in",name:"foreach",params:a,subTree:d,subTreeElse:e});(a=F("foreach\\s[^}]+","/foreach","foreachelse",b))?(k(b.slice(0,a.index),d),k(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)):
k(b,d)},process:function(a,c){var b=s(a.params,c),d=b.from;"undefined"==typeof d&&(d=[]);"object"!=typeof d&&(d=[d]);var e=E(d);c[b.item+"__total"]=e;"name"in b&&(c.smarty.foreach[b.name]={},c.smarty.foreach[b.name].total=e);var g="",f=0,k;for(k in d)if(d.hasOwnProperty(k)){if(c.smarty["break"])break;c[b.item+"__key"]=isNaN(k)?k:parseInt(k);"key"in b&&(c[b.key]=c[b.item+"__key"]);c[b.item]=d[k];c[b.item+"__index"]=parseInt(f);c[b.item+"__iteration"]=parseInt(f+1);c[b.item+"__first"]=0===f;c[b.item+
"__last"]=f==e-1;"name"in b&&(c.smarty.foreach[b.name].index=parseInt(f),c.smarty.foreach[b.name].iteration=parseInt(f+1),c.smarty.foreach[b.name].first=0===f?1:"",c.smarty.foreach[b.name].last=f==e-1?1:"");++f;g+=m(a.subTree,c);c.smarty["continue"]=!1}c.smarty["break"]=!1;c[b.item+"__show"]=0<f;b.name&&(c.smarty.foreach[b.name].show=0<f?1:"");return 0<f?g:m(a.subTreeElse,c)}},"function":{type:"block",parse:function(a,c,b){c=[];v[y(a.name?a.name:a[0])]={type:"function",subTree:c,defautParams:a,process:function(a,
b){var c=s(this.defautParams,b);delete c.name;return m(this.subTree,B({},b,c,a))}};k(b,c)}},php:{type:"block",parse:function(a,c,b){}},"extends":{type:"function",parse:function(a,c){c.splice(0,c.length);V(y(a.file?a.file:a[0]),c)}},block:{type:"block",parse:function(a,c,b){c.push({type:"build-in",name:"block",params:a});a.append=0<=C(a,"append");a.prepend=0<=C(a,"prepend");a.hide=0<=C(a,"hide");a.hasChild=a.hasParent=!1;P=function(b){b.match(/^\s*[$]smarty.block.child\s*$/)&&(a.hasChild=!0);b.match(/^\s*[$]smarty.block.parent\s*$/)&&
(a.hasParent=!0)};c=k(b,[]);P=function(a){};b=y(a.name?a.name:a[0]);b in x||(x[b]=[]);x[b].push({tree:c,params:a})},process:function(a,c){c.smarty.block.parent=c.smarty.block.child="";var b=y(a.params.name?a.params.name:a.params[0]);this.processBlocks(x[b],x[b].length-1,c);return c.smarty.block.child},processBlocks:function(a,c,b){if(!c&&a[c].params.hide)b.smarty.block.child="";else for(var d=!0,e=!1;0<=c;--c){if(a[c].params.hasParent){var g=b.smarty.block.child;b.smarty.block.child="";this.processBlocks(a,
c-1,b);b.smarty.block.parent=b.smarty.block.child;b.smarty.block.child=g}var g=b.smarty.block.child,f=m(a[c].tree,b);b.smarty.block.child=g;a[c].params.hasChild?b.smarty.block.child=f:d?b.smarty.block.child=f+b.smarty.block.child:e&&(b.smarty.block.child+=f);d=a[c].params.append;e=a[c].params.prepend}}},strip:{type:"block",parse:function(a,c,b){k(b.replace(/[ \t]*[\r\n]+[ \t]*/g,""),c)}},literal:{type:"block",parse:function(a,c,b){q(b,c)}},ldelim:{type:"function",parse:function(a,c){q(f.prototype.left_delimiter,
c)}},rdelim:{type:"function",parse:function(a,c){q(f.prototype.right_delimiter,c)}},"while":{type:"block",parse:function(a,c,b){c.push({type:"build-in",name:"while",params:a,subTree:k(b,[])})},process:function(a,c){for(var b="";s(a.params,c)[0]&&!c.smarty["break"];)b+=m(a.subTree,c),c.smarty["continue"]=!1;c.smarty["break"]=!1;return b}}},v={},M={},Q={},x=null,I=[],G=[{re:/^\$([\w@]+)/,parse:function(a,c){p(N(c,a,RegExp.$1),a)}},{re:/^(true|false)/i,parse:function(a,c){q(a.token.match(/true/i)?"1":
"",a.tree)}},{re:/^'([^'\\]*(?:\\.[^'\\]*)*)'/,parse:function(a,c){q(J(RegExp.$1),a.tree);p(c,a)}},{re:/^"([^"\\]*(?:\\.[^"\\]*)*)"/,parse:function(a,c){var b=J(RegExp.$1),d=b.match(G[0].re);if(d){var e={token:d[0],tree:[]};N(b,e,d[1]);if(e.token.length==b.length){a.tree.push(e.tree[0]);return}}q.parseEmbeddedVars=!0;a.tree.push({type:"plugin",name:"__quoted",params:{__parsed:k(b,[])}});q.parseEmbeddedVars=!1;p(c,a)}},{re:/^(\w+)\s*[(]([)]?)/,parse:function(a,c){var b=RegExp.$1,d=t(RegExp.$2?"":c,
/^\s*,\s*/);S(b,d,a.tree);a.value+=d.toString();p(c.slice(d.toString().length),a)}},{re:/^\s*\(\s*/,parse:function(a,c){var b=[];a.tree.push(b);b.parent=a.tree;a.tree=b}},{re:/^\s*\)\s*/,parse:function(a,c){a.tree.parent&&(a.tree=a.tree.parent)}},{re:/^\s*(\+\+|--)\s*/,parse:function(a,c){a.tree.length&&"var"==a.tree[a.tree.length-1].type?n(RegExp.$1,"post-unary",1,a.tree):n(RegExp.$1,"pre-unary",1,a.tree)}},{re:/^\s*(===|!==|==|!=)\s*/,parse:function(a,c){n(RegExp.$1,"binary",6,a.tree)}},{re:/^\s+(eq|ne|neq)\s+/i,
parse:function(a,c){var b=RegExp.$1.replace(/ne(q)?/,"!=").replace(/eq/,"==");n(b,"binary",6,a.tree)}},{re:/^\s*!\s*/,parse:function(a,c){n("!","pre-unary",2,a.tree)}},{re:/^\s+not\s+/i,parse:function(a,c){n("!","pre-unary",2,a.tree)}},{re:/^\s*(=|\+=|-=|\*=|\/=|%=)\s*/,parse:function(a,c){n(RegExp.$1,"binary",10,a.tree)}},{re:/^\s*(\*|\/|%)\s*/,parse:function(a,c){n(RegExp.$1,"binary",3,a.tree)}},{re:/^\s+mod\s+/i,parse:function(a,c){n("%","binary",3,a.tree)}},{re:/^\s*(\+|-)\s*/,parse:function(a,
c){a.tree.length&&"operator"!=a.tree[a.tree.length-1].name?n(RegExp.$1,"binary",4,a.tree):n(RegExp.$1,"pre-unary",4,a.tree)}},{re:/^\s*(<=|>=|<>|<|>)\s*/,parse:function(a,c){n(RegExp.$1.replace(/<>/,"!="),"binary",5,a.tree)}},{re:/^\s+(lt|lte|le|gt|gte|ge)\s+/i,parse:function(a,c){var b=RegExp.$1.replace(/lt/,"<").replace(/l(t)?e/,"<=").replace(/gt/,">").replace(/g(t)?e/,">=");n(b,"binary",5,a.tree)}},{re:/^\s+(is\s+(not\s+)?div\s+by)\s+/i,parse:function(a,c){n(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,c){n(RegExp.$1?"odd"==RegExp.$2?"even":"even_not":"odd"==RegExp.$2?"even_not":"even","binary",7,a.tree);RegExp.$3||q("1",a.tree)}},{re:/^\s*(&&)\s*/,parse:function(a,c){n(RegExp.$1,"binary",8,a.tree)}},{re:/^\s*(\|\|)\s*/,parse:function(a,c){n(RegExp.$1,"binary",9,a.tree)}},{re:/^\s+and\s+/i,parse:function(a,c){n("&&","binary",11,a.tree)}},{re:/^\s+xor\s+/i,parse:function(a,c){n("xor","binary",12,a.tree)}},{re:/^\s+or\s+/i,
parse:function(a,c){n("||","binary",13,a.tree)}},{re:/^#(\w+)#/,parse:function(a,c){var b={token:"$smarty",tree:[]};N(".config."+RegExp.$1,b,"smarty");a.tree.push(b.tree[0]);p(c,a)}},{re:/^\s*\[\s*/,parse:function(a,c){var b=t(c,/^\s*,\s*/,/^('[^'\\]*(?:\\.[^'\\]*)*'|"[^"\\]*(?:\\.[^"\\]*)*"|\w+)\s*=>\s*/);a.tree.push({type:"plugin",name:"__array",params:b});a.value+=b.toString();if(b=c.slice(b.toString().length).match(/\s*\]/))a.value+=b[0]}},{re:/^[\d.]+/,parse:function(a,c){q(a.token,a.tree);p(c,
a)}},{re:/^\w+/,parse:function(a,c){q(a.token,a.tree);p(c,a)}}],f=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:f.prototype.left_delimiter,rdelim:f.prototype.right_delimiter,version:"3.2"}};x=this.tree.blocks;k(H(f.prototype.filters_global.pre,
W((new String(a?a:"")).replace(/\r\n/g,"\n"))),this.tree)};f.prototype.fetch=function(a){x=this.tree.blocks;escape_html=this.escape_html;default_modifiers=f.prototype.default_modifiers_global.concat(this.default_modifiers);this.data=B("object"==typeof a?a:{},this.smarty);varFilters=f.prototype.filters_global.variable.concat(this.filters.variable);a=m(this.tree,this.data);f.prototype.debugging&&v.debug.process([],this.data);return H(f.prototype.filters_global.post.concat(this.filters.post),a)};f.prototype.escape_html=
!1;f.prototype.registerPlugin=function(a,c,b){"modifier"==a?M["__"+c]=b:v[c]={type:a,process:b}};f.prototype.registerFilter=function(a,c){(this.tree?this.filters:f.prototype.filters_global)["output"==a?"post":a].push(c)};f.prototype.filters_global={pre:[],variable:[],post:[]};f.prototype.configLoad=function(a,c,b){b=b?b:this.data;a=a.replace(/\r\n/g,"\n").replace(/^\s+|\s+$/g,"");for(var d=/^\s*(?:\[([^\]]+)\]|(?:(\w+)[ \t]*=[ \t]*("""|'[^'\\\n]*(?:\\.[^'\\\n]*)*'|"[^"\\\n]*(?:\\.[^"\\\n]*)*"|[^\n]*)))/m,
e="",g=a.match(d);g;g=a.match(d)){a=a.slice(g.index+g[0].length);if(g[1])e=g[1];else if((!e||e==c)&&"."!=e.substr(0,1))if('"""'==g[3]){var f=a.match(/"""/);f&&(b.smarty.config[g[2]]=a.slice(0,f.index),a=a.slice(f.index+f[0].length))}else b.smarty.config[g[2]]=y(g[3]);if(g=a.match(/\n+/))a=a.slice(g.index+g[0].length);else break}};f.prototype.clearConfig=function(a){a?delete this.data.smarty.config[a]:this.data.smarty.config={}};f.prototype.addDefaultModifier=function(a){a instanceof Array||(a=[a]);
for(var c=0;c<a.length;++c){var b={value:"",tree:[0]};p("|"+a[c],b);(this.tree?this.default_modifiers:this.default_modifiers_global).push(b.tree[0])}};f.prototype.default_modifiers_global=[];f.prototype.getTemplate=function(a){throw Error("No template for "+a);};f.prototype.getFile=function(a){throw Error("No file for "+a);};f.prototype.getJavascript=function(a){throw Error("No Javascript for "+a);};f.prototype.getConfig=function(a){throw Error("No config for "+a);};f.prototype.auto_literal=!0;f.prototype.left_delimiter=
"{";f.prototype.right_delimiter="}";f.prototype.debugging=!1;f.prototype.registerPlugin("function","__array",function(a,c){var b=[],d;for(d in a)a.hasOwnProperty(d)&&a[d]&&"function"!=typeof a[d]&&(b[d]=a[d]);return b});f.prototype.registerPlugin("function","__func",function(a,c){for(var b=[],d={},e=0;e<a.length;++e)b.push(a.name+"__p"+e),d[a.name+"__p"+e]=a[e];return R(("__owner"in c&&a.name in c.__owner?"__owner."+a.name:a.name)+"("+b.join(",")+")",B({},c,d))});f.prototype.registerPlugin("function",
"__quoted",function(a,c){return a.join("")});f.prototype.registerPlugin("function","break",function(a,c){c.smarty["break"]=!0;return""});f.prototype.registerPlugin("function","continue",function(a,c){c.smarty["continue"]=!0;return""});f.prototype.registerPlugin("function","call",function(a,c){var b=a.__get("name",null,0);delete a.name;var d=a.__get("assign",!1);delete a.assign;b=v[b].process(a,c);return d?(z(d,b,c),""):b});f.prototype.registerPlugin("function","append",function(a,c){var b=a.__get("var",
null,0);b in c&&c[b]instanceof Array||(c[b]=[]);var d=a.__get("index",!1),e=a.__get("value",null,1);!1===d?c[b].push(e):c[b][d]=e;return""});f.prototype.registerPlugin("function","assign",function(a,c){z(a.__get("var",null,0),a.__get("value",null,1),c);return""});f.prototype.registerPlugin("block","capture",function(a,c,b,d){c&&(c=c.replace(/^\n/,""),b.smarty.capture[a.__get("name","default",0)]=c,"assign"in a&&z(a.assign,c,b),(a=a.__get("append",!1))&&(a in b?b[a]instanceof Array&&b[a].push(c):b[a]=
[c]));return""});f.prototype.registerPlugin("function","eval",function(a,c){var b=[];k(a.__get("var","",0),b);b=m(b,c);return"assign"in a?(z(a.assign,b,c),""):b});f.prototype.registerPlugin("function","include",function(a,c){var b=a.__get("file",null,0),d=B({},c,a);d.smarty.template=b;b=m(V(b,[],0<=C(a,"nocache")),d);return"assign"in a?(z(a.assign,b,c),""):b});f.prototype.registerPlugin("block","nocache",function(a,c,b,d){return c});f.prototype.registerPlugin("block","javascript",function(a,c,b,d){b.$this=
b;R(c,b);delete b.$this;return""});f.prototype.registerPlugin("function","config_load",function(a,c){f.prototype.configLoad(f.prototype.getConfig(a.__get("file",null,0)),a.__get("section","",1),c);return""});f.prototype.registerPlugin("modifier","defaultValue",function(a,c){return a&&"null"!=a&&"undefined"!=a?a:c?c:""});var r={window:"object"==typeof window?window:{document:{}}};(function(a,c){"function"===typeof define&&define.amd?define([],c):"object"===typeof module&&module.exports?module.exports=
c():a.jSmart=c()})(this,function(){return f});f.prototype.registerPlugin("function","counter",function(a,c){var b=a.__get("name","default");if(b in c.smarty.counter){var d=c.smarty.counter[b];"start"in a?d.value=parseInt(a.start):(d.value=parseInt(d.value),d.skip=parseInt(d.skip),d.value="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 c.smarty.counter[b]={value:parseInt(a.__get("start",
1)),skip:parseInt(a.__get("skip",1)),direction:a.__get("direction","up"),assign:a.__get("assign",!1)};return c.smarty.counter[b].assign?(c[c.smarty.counter[b].assign]=c.smarty.counter[b].value,""):a.__get("print",!0)?c.smarty.counter[b].value:""});f.prototype.registerPlugin("function","cycle",function(a,c){var b=a.__get("name","default"),d=a.__get("reset",!1);b in c.smarty.cycle||(c.smarty.cycle[b]={arr:[""],delimiter:a.__get("delimiter",","),index:0},d=!0);a.__get("delimiter",!1)&&(c.smarty.cycle[b].delimiter=
a.delimiter);var e=a.__get("values",!1);if(e){var g=[];if(e instanceof Object)for(nm in e)g.push(e[nm]);else g=e.split(c.smarty.cycle[b].delimiter);if(g.length!=c.smarty.cycle[b].arr.length||g[0]!=c.smarty.cycle[b].arr[0])c.smarty.cycle[b].arr=g,c.smarty.cycle[b].index=0,d=!0}a.__get("advance","true")&&(c.smarty.cycle[b].index+=1);if(c.smarty.cycle[b].index>=c.smarty.cycle[b].arr.length||d)c.smarty.cycle[b].index=0;return a.__get("assign",!1)?(z(a.assign,c.smarty.cycle[b].arr[c.smarty.cycle[b].index],
c),""):a.__get("print",!0)?c.smarty.cycle[b].arr[c.smarty.cycle[b].index]:""});r.get_html_translation_table=function(a,c){var b={},d={},e,g={},f={},k={},l={};g[0]="HTML_SPECIALCHARS";g[1]="HTML_ENTITIES";f[0]="ENT_NOQUOTES";f[2]="ENT_COMPAT";f[3]="ENT_QUOTES";k=isNaN(a)?a?a.toUpperCase():"HTML_SPECIALCHARS":g[a];l=isNaN(c)?c?c.toUpperCase():"ENT_COMPAT":f[c];if("HTML_SPECIALCHARS"!==k&&"HTML_ENTITIES"!==k)throw Error("Table: "+k+" not supported");b["38"]="&";"HTML_ENTITIES"===k&&(b["160"]=" ",
b["161"]="¡",b["162"]="¢",b["163"]="£",b["164"]="¤",b["165"]="¥",b["166"]="¦",b["167"]="§",b["168"]="¨",b["169"]="©",b["170"]="ª",b["171"]="«",b["172"]="¬",b["173"]="­",b["174"]="®",b["175"]="¯",b["176"]="°",b["177"]="±",b["178"]="²",b["179"]="³",b["180"]="´",b["181"]="µ",b["182"]="¶",b["183"]="·",b["184"]="¸",b["185"]="¹",b["186"]="º",b["187"]="»",b["188"]=
"¼",b["189"]="½",b["190"]="¾",b["191"]="¿",b["192"]="À",b["193"]="Á",b["194"]="Â",b["195"]="Ã",b["196"]="Ä",b["197"]="Å",b["198"]="Æ",b["199"]="Ç",b["200"]="È",b["201"]="É",b["202"]="Ê",b["203"]="Ë",b["204"]="Ì",b["205"]="Í",b["206"]="Î",b["207"]="Ï",b["208"]="Ð",b["209"]="Ñ",b["210"]="Ò",b["211"]="Ó",b["212"]="Ô",b["213"]="Õ",b["214"]=
"Ö",b["215"]="×",b["216"]="Ø",b["217"]="Ù",b["218"]="Ú",b["219"]="Û",b["220"]="Ü",b["221"]="Ý",b["222"]="Þ",b["223"]="ß",b["224"]="à",b["225"]="á",b["226"]="â",b["227"]="ã",b["228"]="ä",b["229"]="å",b["230"]="æ",b["231"]="ç",b["232"]="è",b["233"]="é",b["234"]="ê",b["235"]="ë",b["236"]="ì",b["237"]="í",b["238"]="î",b["239"]="ï",b["240"]=
"ð",b["241"]="ñ",b["242"]="ò",b["243"]="ó",b["244"]="ô",b["245"]="õ",b["246"]="ö",b["247"]="÷",b["248"]="ø",b["249"]="ù",b["250"]="ú",b["251"]="û",b["252"]="ü",b["253"]="ý",b["254"]="þ",b["255"]="ÿ");"ENT_NOQUOTES"!==l&&(b["34"]=""");"ENT_QUOTES"===l&&(b["39"]="'");b["60"]="<";b["62"]=">";for(e in b)b.hasOwnProperty(e)&&(d[String.fromCharCode(e)]=b[e]);return d};r.htmlentities=function(a,
c,b,d){var e=this.get_html_translation_table("HTML_ENTITIES",c);a=null==a?"":a+"";if(!e)return!1;c&&"ENT_QUOTES"===c&&(e["'"]="'");d=null==d||!!d;c=RegExp("&(?:#\\d+|#x[\\da-f]+|[a-zA-Z][\\da-z]*);|["+Object.keys(e).join("").replace(/([()[\]{}\-.*+?^$|\/\\])/g,"\\$1")+"]","g");return a.replace(c,function(a){return 1<a.length?d?e["&"]+a.substr(1):a:e[a]})};r.rawurlencode=function(a){a=(a+"").toString();return encodeURIComponent(a).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,
"%29").replace(/\*/g,"%2A")};r.bin2hex=function(a){var c,b,d="",e;a+="";c=0;for(b=a.length;c<b;c++)e=a.charCodeAt(c).toString(16),d+=2>e.length?"0"+e:e;return d};r.ord=function(a){var c=a+"";a=c.charCodeAt(0);if(55296<=a&&56319>=a){if(1===c.length)return a;c=c.charCodeAt(1);return 1024*(a-55296)+(c-56320)+65536}return a};f.prototype.registerPlugin("modifier","escape",function(a,c,b,d){a=new String(a);b=b||"UTF-8";d="undefined"!=typeof d?Boolean(d):!0;switch(c||"html"){case "html":return d&&(a=a.replace(/&/g,
"&")),a.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,""");case "htmlall":return r.htmlentities(a,3,b);case "url":return r.rawurlencode(a);case "urlpathinfo":return r.rawurlencode(a).replace(/%2F/g,"/");case "quotes":return a.replace(/(^|[^\\])'/g,"$1\\'");case "hex":c="";for(b=0;b<a.length;++b)c+="%"+r.bin2hex(a.substr(b,1));return c;case "hexentity":c="";for(b=0;b<a.length;++b)c+="&#x"+r.bin2hex(a.substr(b,1)).toUpperCase()+";";return c;case "decentity":c=
"";for(b=0;b<a.length;++b)c+="&#"+r.ord(a.substr(b,1))+";";return c;case "mail":return a.replace(/@/g," [AT] ").replace(/[.]/g," [DOT] ");case "nonstd":c="";for(b=0;b<a.length;++b)d=r.ord(a.substr(b,1)),c=126<=d?c+("&#"+d+";"):c+a.substr(b,1);return c;case "javascript":return a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/<\//g,"</")}return a});f.prototype.registerPlugin("modifier","lower",function(a){return(new String(a)).toLowerCase()});
f.prototype.registerPlugin("modifier","nl2br",function(a){return(new String(a)).replace(/\n/g,"<br />\n")});f.prototype.registerPlugin("modifier","regex_replace",function(a,c,b){c=c.match(/^ *\/(.*)\/(.*) *$/);return(new String(a)).replace(RegExp(c[1],"g"+(1<c.length?c[2]:"")),b)});f.prototype.registerPlugin("modifier","replace",function(a,c,b){if(!c)return a;a=new String(a);c=new String(c);b=new String(b);for(var d="",e=-1,e=a.indexOf(c);0<=e;e=a.indexOf(c))d+=a.slice(0,e)+b,e+=c.length,a=a.slice(e);
return d+a});f.prototype.registerPlugin("modifier","strip",function(a,c){c=c?c:" ";return(new String(a)).replace(/[\s]+/g,c)});f.prototype.registerPlugin("modifier","strip_tags",function(a,c){c=null==c?!0:c;return(new String(a)).replace(/<[^>]*?>/g,c?" ":"")});f.prototype.registerPlugin("modifier","upper",function(a){return(new String(a)).toUpperCase()})})();