/* jSmart Javascript template engine http://code.google.com/p/jsmart/ Copyright 2011, Max Miroshnikov jSmart is licensed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html */ (function(){function F(a,b){for(var c=1;cc&&(c=0)}return null} function L(a,b,c){var d="",e=null,f=null,g=0;do{e&&(g+=e[0].length);e=w(a,c);if(!e)throw Error("Unclosed {"+b+"}");d+=c.slice(0,e.index);g+=e.index;c=c.slice(e.index+e[0].length);(f=w(b,d))&&(d=d.slice(f.index+f[0].length))}while(f);e.index=g;return e}function G(a,b,c,d){for(var e=0,f=w(c,d);f;f=w(c,d)){var g=w(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;f=L(b,a,d);d=d.slice(f.index+f[0].length);e+=f.index+f[0].length}return null}function M(a, b){if("string"==typeof a)with({__code:a})with(D)with(b)try{return eval(__code)}catch(c){throw Error(c.message+" in \n"+a);}return a}function v(a,b,c){a.match(/\[\]$/)?c[a.replace(/\[\]$/,"")].push(b):c[a]=b}function n(a,b){for(var c=w("",a);c;c=w("",a)){c.index&&q(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],d=2\s*|\[\s*)/,f=a.match(e);f;f=a.match(e)){b.token+=f[0];a=a.slice(f[0].length);var g={value:"",tree:[]};if(f[0].match(/\[/)){if(g=E(a))b.token+=g.value,c.push(g.tree),a=a.slice(g.value.length);if(f=a.match(/\s*\]/))b.token+=f[0],a=a.slice(f[0].length)}else{f=l.stop;l.stop=!0;if(O(a,g)){b.token+= g.value;var h=g.tree[0];"plugin"==h.type&&"__func"==h.name&&(h.hasOwner=!0);c.push(h);a=a.slice(g.value.length)}else g=!1;l.stop=f}g||c.push({type:"text",data:""})}b.tree.push({type:"var",parts:c});b.value+=b.token.substr(d.length);P(b.token);return a}function P(a){}function l(a,b){if(!l.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+/,"");l.stop=!0;for(var c=[],e=a.match(/^\s*:\s*/);e;e=a.match(/^\s*:\s*/))b.value+= a.slice(0,e[0].length),a=a.slice(e[0].length),e={value:"",tree:[]},O(a,e)?(b.value+=e.value,c.push(e.tree[0]),a=a.slice(e.value.length)):q("",c);l.stop=!1;c.unshift(b.tree.pop());b.tree.push(T(d,{__parsed:c},[])[0]);l(a,b)}}}function O(a,b){if(!a)return!1;if(a.substr(0,jSmart.prototype.left_delimiter.length)==jSmart.prototype.left_delimiter){var c=w("",a);if(c)return b.token=c[0],b.value+=c[0],n(c[0],b.tree),l(a.slice(b.value.length),b),!0}for(c=0;cc;++c)if(2== c||10==c)for(b=a.length;0C(c,"nofilter")){for(c=0;c":return d>c;case ">=":return d>=c;case "===":return d===c;case "!==":return d!==c}}else{if("!"==a.op)return!d;(c="var"==a.params.__parsed[0].type)&& (d=y(a.params.__parsed[0],b));var e=d;if("pre-unary"==a.optype){switch(a.op){case "-":e=-d;break;case "++":e=++d;break;case "--":e=--d}c&&y(a.params.__parsed[0],b,d)}else{switch(a.op){case "++":d++;break;case "--":d--}y(a.params.__parsed[0],b,d)}return e}}},section:{type:"block",parse:function(a,b,c){var d=[],e=[];b.push({type:"build-in",name:"section",params:a,subTree:d,subTreeElse:e});(a=G("section [^}]+","/section","sectionelse",c))?(n(c.slice(0,a.index),d),n(c.slice(a.index+a[0].length).replace(/^[\r\n]/, ""),e)):n(c,d)},process:function(a,b){var c=r(a.params,b),d={};b.smarty.section[c.__get("name",null,0)]=d;var e=c.__get("show",!0);d.show=e;if(!e)return m(a.subTreeElse,b);var e=parseInt(c.__get("start",0)),f=c.loop instanceof Object?S(c.loop):isNaN(c.loop)?0:parseInt(c.loop),g=parseInt(c.__get("step",1)),c=parseInt(c.__get("max"));isNaN(c)&&(c=Number.MAX_VALUE);0>e?(e+=f,0>e&&(e=0)):e>=f&&(e=f?f-1:0);for(var h=0,k=e;0<=k&&kk+g||k+g>=f,d.index=k,d.index_prev=k-g,d.index_next=k+g,d.iteration=d.rownum=h+1,x+=m(a.subTree,b),b.smarty["continue"]=!1;b.smarty["break"]=!1;return h?x:m(a.subTreeElse,b)}},setfilter:{type:"block",parseParams:function(a){return[E("__t()|"+a).tree]},parse:function(a,b,c){b.push({type:"build-in",name:"setfilter",params:a,subTree:n(c,[])})},process:function(a,b){J=a.params;var c=m(a.subTree,b);J=[];return 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 Error("Invalid {for} parameters: "+a);return t("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});(a=G("for\\s[^}]+","/for","forelse",c))?(n(c.slice(0,a.index),d),n(c.slice(a.index+a[0].length),e)):n(c,d)},process:function(a,b){var c=r(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,k="",d=Math.min(Math.ceil(((0\s*[$](\w+))?\s*$/i);b&&(a="from="+b[1]+" item="+(b[4]||b[2]),b[4]&&(a+=" key="+b[2]));return t(a)},parse:function(a,b,c){var d=[],e=[]; b.push({type:"build-in",name:"foreach",params:a,subTree:d,subTreeElse:e});(a=G("foreach\\s[^}]+","/foreach","foreachelse",c))?(n(c.slice(0,a.index),d),n(c.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)):n(c,d)},process:function(a,b){var c=r(a.params,b),d=c.from;d instanceof Object||(d=[d]);var e=S(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,h;for(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+=m(a.subTree,b);b.smarty["continue"]=!1}b.smarty["break"]=!1;b[c.item+"__show"]=0=|<>|<|>)\s*/,parse:function(a,b){p(RegExp.$1.replace(/<>/,"!="),"binary",5,a.tree)}},{re:/^\s+(lt|lte|le|gt|gte|ge)\s+/i,parse:function(a, b){var c=RegExp.$1.replace(/lt/,"<").replace(/l(t)?e/,"<=").replace(/gt/,">").replace(/g(t)?e/,">=");p(c,"binary",5,a.tree)}},{re:/^\s+(is\s+(not\s+)?div\s+by)\s+/i,parse:function(a,b){p(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,b){p(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,b){p(RegExp.$1,"binary",8,a.tree)}}, {re:/^\s*(\|\|)\s*/,parse:function(a,b){p(RegExp.$1,"binary",9,a.tree)}},{re:/^\s+and\s+/i,parse:function(a,b){p("&&","binary",11,a.tree)}},{re:/^\s+xor\s+/i,parse:function(a,b){p("xor","binary",12,a.tree)}},{re:/^\s+or\s+/i,parse:function(a,b){p("||","binary",13,a.tree)}},{re:/^#(\w+)#/,parse:function(a,b){var c={token:"$smarty",tree:[]};N(".config."+RegExp.$1,c,"smarty");a.tree.push(c.tree[0]);l(b,a)}},{re:/^\s*\[\s*/,parse:function(a,b){var c=t(b,/^\s*,\s*/,/^('[^'\\]*(?:\\.[^'\\]*)*'|"[^"\\]*(?:\\.[^"\\]*)*"|\w+)\s*=>\s*/); a.tree.push({type:"plugin",name:"__array",params:c});a.value+=c.toString();if(c=b.slice(c.toString().length).match(/\s*\]/))a.value+=c[0]}},{re:/^[\d.]+/,parse:function(a,b){q(a.token,a.tree);l(b,a)}},{re:/^\w+/,parse:function(a,b){q(a.token,a.tree);l(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.9"}};z=this.tree.blocks;n(I(jSmart.prototype.filters_global.pre,X((new String(a?a:"")).replace(/\r\n/g,"\n"))),this.tree)};jSmart.prototype.fetch=function(a){z=this.tree.blocks;R=this.scripts;escape_html=this.escape_html;default_modifiers=jSmart.prototype.default_modifiers_global.concat(this.default_modifiers);this.data=F("object"==typeof a?a:{},this.smarty); varFilters=jSmart.prototype.filters_global.variable.concat(this.filters.variable);a=m(this.tree,this.data);jSmart.prototype.debugging&&u.debug.process([],this.data);return I(jSmart.prototype.filters_global.post.concat(this.filters.post),a)};jSmart.prototype.escape_html=!1;jSmart.prototype.registerPlugin=function(a,b,c){"modifier"==a?D[b]=c:u[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;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="",f=a.match(d);f;f=a.match(d)){a=a.slice(f.index+f[0].length);if(f[1])e=f[1];else if((!e||e==b)&&"."!=e.substr(0,1))if('"""'==f[3]){var g=a.match(/"""/);g&&(c.smarty.config[f[2]]=a.slice(0,g.index),a= a.slice(g.index+g[0].length))}else c.smarty.config[f[2]]=A(f[3]);if(f=a.match(/\n+/))a=a.slice(f.index+f[0].length);else break}};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=b.smarty.cycle[c].arr.length||d)b.smarty.cycle[c].index=0;return a.__get("assign", !1)?(v(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")+"
",d;for(d in a)a.hasOwnProperty(d)&&(c+=b+"  "+d+" : "+jSmart.prototype.print_r(a[d],b+"   ")+"
");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,e;for(e in b)c+=""+e+""+jSmart.prototype.print_r(b[e],"")+"";dbgWnd.document.write(" \t\t jSmart Debug Console

jSmart Debug Console

assigned template variables

"+ c+"
");return""});jSmart.prototype.registerPlugin("function","eval",function(a,b){var c=[];n(a.__get("var","",0),c);c=m(c,b);return"assign"in a?(v(a.assign,c,b),""):c});jSmart.prototype.registerPlugin("function","fetch",function(a,b){var c=jSmart.prototype.getFile(a.__get("file",null,0));return"assign"in a?(v(a.assign,c,b),""):c});jSmart.prototype.registerPlugin("function","html_checkboxes",function(a,b){var c=a.__get("type","checkbox"), d=a.__get("name",c);"checkbox"==c&&(d+="[]");var e=a.__get("values",a.options),f=a.__get("options",[]),g="options"in a,h;if(!g)for(h in a.output)f.push(a.output[h]);var k=a.__get("selected",!1),x=a.__get("separator",""),m=Boolean(a.__get("labels",!0)),n=[],p=0,l="";for(h in e)e.hasOwnProperty(h)&&(l=m?"