diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e842665 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Max Miroshnikov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/smart.core.js b/smart.core.js index bc84aa0..1a48bb7 100644 --- a/smart.core.js +++ b/smart.core.js @@ -336,7 +336,12 @@ var buildInFunctions = } else if (node.op == '!') { - return (arg1 instanceof Array) ? !arg1.length : !arg1; + if (arg1 instanceof Array) { + return !arg1.length; + } else if (typeof arg1 == 'object') { + return !countProperties(arg1); + } + return arg1==='0' ? true : !arg1; } else { @@ -1649,7 +1654,7 @@ function getActualParamValues(params,data) actualParams.__get = function(nm,defVal,id) { - if (nm in actualParams && typeof(actualParams[nm]) != 'undefined') + if (nm in actualParams && typeof(actualParams[nm]) != 'undefined' && typeof(actualParams[nm]) != 'function') { return actualParams[nm]; } @@ -1801,14 +1806,17 @@ function getTemplate(name, tree, nocache) function stripComments(s) { var sRes = ''; - for (var openTag=s.match(/{\*/); openTag; openTag=s.match(/{\*/)) + var open = new RegExp(jSmart.prototype.left_delimiter+'\\*'); + var close = new RegExp('\\*'+jSmart.prototype.right_delimiter); + + for (var openTag=s.match(open); openTag; openTag=s.match(open)) { sRes += s.slice(0,openTag.index); s = s.slice(openTag.index+openTag[0].length); - var closeTag = s.match(/\*}/); + var closeTag = s.match(close); if (!closeTag) { - throw new Error('Unclosed {*'); + throw new Error('Unclosed '+jSmart.left_delimiter+'*'); } s = s.slice(closeTag.index+closeTag[0].length); } diff --git a/smart.core.min.js b/smart.core.min.js index e959e39..6b494c4 100644 --- a/smart.core.min.js +++ b/smart.core.min.js @@ -8,64 +8,64 @@ jSmart is licensed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html */ -(function(){function D(a,c){for(var b=1;bb&&(b=0)}return null} -function K(a,c,b){var d="",e=null,f=null,g=0;do{e&&(g+=e[0].length);e=u(a,b);if(!e)throw Error("Unclosed {"+c+"}");d+=b.slice(0,e.index);g+=e.index;b=b.slice(e.index+e[0].length);(f=u(c,d))&&(d=d.slice(f.index+f[0].length))}while(f);e.index=g;return e}function E(a,c,b,d){for(var e=0,f=u(b,d);f;f=u(b,d)){var g=u(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=K(c,a,d);d=d.slice(f.index+f[0].length);e+=f.index+f[0].length}return null}function Q(a, +function K(a,c,b){var d="",e=null,f=null,g=0;do{e&&(g+=e[0].length);e=u(a,b);if(!e)throw Error("Unclosed {"+c+"}");d+=b.slice(0,e.index);g+=e.index;b=b.slice(e.index+e[0].length);(f=u(c,d))&&(d=d.slice(f.index+f[0].length))}while(f);e.index=g;return e}function F(a,c,b,d){for(var e=0,f=u(b,d);f;f=u(b,d)){var g=u(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=K(c,a,d);d=d.slice(f.index+f[0].length);e+=f.index+f[0].length}return null}function Q(a, c){if("string"==typeof a)with({__code:a})with(L)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 m(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\s*|\[\s*)/,f=a.match(e);f;f=a.match(e)){c.token+=f[0];a=a.slice(f[0].length);var g={value:"",tree:[]};if(f[0].match(/\[/)){if(g=C(a))c.token+=g.value,b.push(g.tree),a=a.slice(g.value.length);if(f=a.match(/\s*\]/))c.token+=f[0],a=a.slice(f[0].length)}else{f=p.stop;p.stop=!0;if(N(a,g)){c.token+= g.value;var h=g.tree[0];"plugin"==h.type&&"__func"==h.name&&(h.hasOwner=!0);b.push(h);a=a.slice(g.value.length)}else g=!1;p.stop=f}g||b.push({type:"text",data:""})}c.tree.push({type:"var",parts:b});c.value+=c.token.substr(d.length);O(c.token);return a}function O(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:[]},N(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(R(d,{__parsed:b},[])[0]);p(a,c)}}}function N(a,c){if(!a)return!1;if(a.substr(0,jSmart.prototype.left_delimiter.length)==jSmart.prototype.left_delimiter){var b=u("",a);if(b)return c.token=b[0],c.value+=b[0],m(b[0],c.tree),p(a.slice(c.value.length),c),!0}for(b=0;bb;++b)if(2== +a.slice(0,e[0].length),a=a.slice(e[0].length),e={value:"",tree:[]},N(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(R(d,{__parsed:b},[])[0]);p(a,c)}}}function N(a,c){if(!a)return!1;if(a.substr(0,jSmart.prototype.left_delimiter.length)==jSmart.prototype.left_delimiter){var b=u("",a);if(b)return c.token=b[0],c.value+=b[0],m(b[0],c.tree),p(a.slice(c.value.length),c),!0}for(b=0;bb;++b)if(2== b||10==b)for(c=a.length;0B(b,"nofilter")){for(b=0;b":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:!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=E("section [^}]+","/section","sectionelse",b))?(m(b.slice(0,a.index),d),m(b.slice(a.index+ -a[0].length).replace(/^[\r\n]/,""),e)):m(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 l(a.subTreeElse,c);var e=parseInt(b.__get("start",0)),f=b.loop instanceof Object?I(b.loop):isNaN(b.loop)?0:parseInt(b.loop),g=parseInt(b.__get("step",1)),b=parseInt(b.__get("max"));isNaN(b)&&(b=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,m+=l(a.subTree,c),c.smarty["continue"]=!1;c.smarty["break"]=!1;return h?m:l(a.subTreeElse,c)}},setfilter:{type:"block",parseParams:function(a){return[C("__t()|"+a).tree]},parse:function(a,c,b){c.push({type:"build-in",name:"setfilter",params:a,subTree:m(b,[])})},process:function(a,c){H=a.params;var b=l(a.subTree,c);H=[];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=E("for\\s[^}]+","/for","forelse",b))?(m(b.slice(0,a.index),d),m(b.slice(a.index+a[0].length),e)):m(b,d)},process:function(a,c){var b=s(a.params, -c),d=parseInt(b.__get("from")),e=parseInt(b.__get("to")),f=parseInt(b.__get("step"));isNaN(f)&&(f=1);var g=parseInt(b.__get("max"));isNaN(g)&&(g=Number.MAX_VALUE);for(var h=0,k="",d=Math.min(Math.ceil(((0\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=E("foreach\\s[^}]+","/foreach","foreachelse",b))?(m(b.slice(0,a.index),d),m(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)):m(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=I(d);c[b.item+"__total"]=e;"name"in b&&(c.smarty.foreach[b.name]={},c.smarty.foreach[b.name].total= -e);var f="",g=0,h;for(h in d)if(d.hasOwnProperty(h)){if(c.smarty["break"])break;c[b.item+"__key"]=isNaN(h)?h:parseInt(h);"key"in b&&(c[b.key]=c[b.item+"__key"]);c[b.item]=d[h];c[b.item+"__index"]=parseInt(g);c[b.item+"__iteration"]=parseInt(g+1);c[b.item+"__first"]=0===g;c[b.item+"__last"]=g==e-1;"name"in b&&(c.smarty.foreach[b.name].index=parseInt(g),c.smarty.foreach[b.name].iteration=parseInt(g+1),c.smarty.foreach[b.name].first=0===g?1:"",c.smarty.foreach[b.name].last=g==e-1?1:"");++g;f+=l(a.subTree, -c);c.smarty["continue"]=!1}c.smarty["break"]=!1;c[b.item+"__show"]=0=|<>|<|>)\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:[]};M(".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)}}];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"}};x=this.tree.blocks;m(G(jSmart.prototype.filters_global.pre,V((new String(a?a:"")).replace(/\r\n/g,"\n"))),this.tree)};jSmart.prototype.fetch=function(a){x=this.tree.blocks;escape_html=this.escape_html; -default_modifiers=jSmart.prototype.default_modifiers_global.concat(this.default_modifiers);this.data=D("object"==typeof a?a:{},this.smarty);varFilters=jSmart.prototype.filters_global.variable.concat(this.filters.variable);a=l(this.tree,this.data);jSmart.prototype.debugging&&v.debug.process([],this.data);return G(jSmart.prototype.filters_global.post.concat(this.filters.post),a)};jSmart.prototype.escape_html=!1;jSmart.prototype.registerPlugin=function(a,c,b){"modifier"==a?L["__"+c]=b:v[c]={type:a,process:b}}; -jSmart.prototype.registerFilter=function(a,c){(this.tree?this.filters:jSmart.prototype.filters_global)["output"==a?"post":a].push(c)};jSmart.prototype.filters_global={pre:[],variable:[],post:[]};jSmart.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="",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==c)&&"."!=e.substr(0,1))if('"""'==f[3]){var g=a.match(/"""/);g&&(b.smarty.config[f[2]]=a.slice(0,g.index),a=a.slice(g.index+g[0].length))}else b.smarty.config[f[2]]=y(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 c=0;c=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,f={},g={},h={},k={};f[0]="HTML_SPECIALCHARS";f[1]="HTML_ENTITIES";g[0]="ENT_NOQUOTES";g[2]="ENT_COMPAT";g[3]="ENT_QUOTES";h=isNaN(a)?a?a.toUpperCase():"HTML_SPECIALCHARS":f[a];k=isNaN(c)?c?c.toUpperCase():"ENT_COMPAT":g[c];if("HTML_SPECIALCHARS"!==h&&"HTML_ENTITIES"!==h)throw Error("Table: "+h+" not supported");b["38"]="&";"HTML_ENTITIES"===h&&(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"!==k&&(b["34"]=""");"ENT_QUOTES"===k&&(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 1e.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};jSmart.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,""");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\n")});jSmart.prototype.registerPlugin("modifier","regex_replace",function(a,c,b){c=c.match(/^ *\/(.*)\/(.*) *$/);return(new String(a)).replace(RegExp(c[1],"g"+(1]*?>/g,c?" ":"")});jSmart.prototype.registerPlugin("modifier","upper",function(a){return(new String(a)).toUpperCase()})})(); +e.__parsed[f]=g.tree):(e.push(g.value),e.__parsed.push(g.tree));a+=d.slice(0,g.value.length);d=d.slice(g.value.length);if(f=d.match(c))a+=d.slice(0,f[0].length),d=d.slice(f[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=l([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="",f=0;fB(b,"nofilter")){for(b=0;b":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))?(m(b.slice(0,a.index),d),m(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)):m(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 l(a.subTreeElse,c);var e=parseInt(b.__get("start",0)),f=b.loop instanceof Object?E(b.loop):isNaN(b.loop)?0:parseInt(b.loop), +g=parseInt(b.__get("step",1)),b=parseInt(b.__get("max"));isNaN(b)&&(b=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,m+=l(a.subTree,c),c.smarty["continue"]=!1;c.smarty["break"]=!1;return h?m:l(a.subTreeElse,c)}},setfilter:{type:"block",parseParams:function(a){return[C("__t()|"+ +a).tree]},parse:function(a,c,b){c.push({type:"build-in",name:"setfilter",params:a,subTree:m(b,[])})},process:function(a,c){I=a.params;var b=l(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))?(m(b.slice(0,a.index),d),m(b.slice(a.index+a[0].length),e)):m(b,d)},process:function(a,c){var b=s(a.params,c),d=parseInt(b.__get("from")),e=parseInt(b.__get("to")),f=parseInt(b.__get("step"));isNaN(f)&&(f=1);var g=parseInt(b.__get("max"));isNaN(g)&&(g=Number.MAX_VALUE);for(var h=0,k="",d=Math.min(Math.ceil(((0\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))?(m(b.slice(0,a.index),d),m(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)): +m(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 f="",g=0,h;for(h in d)if(d.hasOwnProperty(h)){if(c.smarty["break"])break;c[b.item+"__key"]=isNaN(h)?h:parseInt(h);"key"in b&&(c[b.key]=c[b.item+"__key"]);c[b.item]=d[h];c[b.item+"__index"]=parseInt(g);c[b.item+"__iteration"]=parseInt(g+1);c[b.item+"__first"]=0===g;c[b.item+ +"__last"]=g==e-1;"name"in b&&(c.smarty.foreach[b.name].index=parseInt(g),c.smarty.foreach[b.name].iteration=parseInt(g+1),c.smarty.foreach[b.name].first=0===g?1:"",c.smarty.foreach[b.name].last=g==e-1?1:"");++g;f+=l(a.subTree,c);c.smarty["continue"]=!1}c.smarty["break"]=!1;c[b.item+"__show"]=0=|<>|<|>)\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:[]};M(".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)}}];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"}};x=this.tree.blocks; +m(H(jSmart.prototype.filters_global.pre,V((new String(a?a:"")).replace(/\r\n/g,"\n"))),this.tree)};jSmart.prototype.fetch=function(a){x=this.tree.blocks;escape_html=this.escape_html;default_modifiers=jSmart.prototype.default_modifiers_global.concat(this.default_modifiers);this.data=D("object"==typeof a?a:{},this.smarty);varFilters=jSmart.prototype.filters_global.variable.concat(this.filters.variable);a=l(this.tree,this.data);jSmart.prototype.debugging&&v.debug.process([],this.data);return H(jSmart.prototype.filters_global.post.concat(this.filters.post), +a)};jSmart.prototype.escape_html=!1;jSmart.prototype.registerPlugin=function(a,c,b){"modifier"==a?L["__"+c]=b:v[c]={type:a,process:b}};jSmart.prototype.registerFilter=function(a,c){(this.tree?this.filters:jSmart.prototype.filters_global)["output"==a?"post":a].push(c)};jSmart.prototype.filters_global={pre:[],variable:[],post:[]};jSmart.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="",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==c)&&"."!=e.substr(0,1))if('"""'==f[3]){var g=a.match(/"""/);g&&(b.smarty.config[f[2]]=a.slice(0,g.index),a=a.slice(g.index+g[0].length))}else b.smarty.config[f[2]]=y(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 c=0;c=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,f={},g={},h={},k={};f[0]="HTML_SPECIALCHARS";f[1]="HTML_ENTITIES";g[0]="ENT_NOQUOTES";g[2]="ENT_COMPAT";g[3]="ENT_QUOTES";h=isNaN(a)?a?a.toUpperCase():"HTML_SPECIALCHARS":f[a];k=isNaN(c)?c?c.toUpperCase():"ENT_COMPAT":g[c];if("HTML_SPECIALCHARS"!==h&&"HTML_ENTITIES"!==h)throw Error("Table: "+h+" not supported");b["38"]="&";"HTML_ENTITIES"===h&&(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"!==k&&(b["34"]=""");"ENT_QUOTES"===k&&(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 1e.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};jSmart.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,""");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\n")});jSmart.prototype.registerPlugin("modifier","regex_replace",function(a,c,b){c=c.match(/^ *\/(.*)\/(.*) *$/);return(new String(a)).replace(RegExp(c[1],"g"+(1]*?>/g,c?" ":"")});jSmart.prototype.registerPlugin("modifier","upper",function(a){return(new String(a)).toUpperCase()})})(); diff --git a/smart.js b/smart.js index c746588..2d3924e 100644 --- a/smart.js +++ b/smart.js @@ -336,7 +336,12 @@ var buildInFunctions = } else if (node.op == '!') { - return (arg1 instanceof Array) ? !arg1.length : !arg1; + if (arg1 instanceof Array) { + return !arg1.length; + } else if (typeof arg1 == 'object') { + return !countProperties(arg1); + } + return arg1==='0' ? true : !arg1; } else { @@ -1649,7 +1654,7 @@ function getActualParamValues(params,data) actualParams.__get = function(nm,defVal,id) { - if (nm in actualParams && typeof(actualParams[nm]) != 'undefined') + if (nm in actualParams && typeof(actualParams[nm]) != 'undefined' && typeof(actualParams[nm]) != 'function') { return actualParams[nm]; } @@ -1801,14 +1806,17 @@ function getTemplate(name, tree, nocache) function stripComments(s) { var sRes = ''; - for (var openTag=s.match(/{\*/); openTag; openTag=s.match(/{\*/)) + var open = new RegExp(jSmart.prototype.left_delimiter+'\\*'); + var close = new RegExp('\\*'+jSmart.prototype.right_delimiter); + + for (var openTag=s.match(open); openTag; openTag=s.match(open)) { sRes += s.slice(0,openTag.index); s = s.slice(openTag.index+openTag[0].length); - var closeTag = s.match(/\*}/); + var closeTag = s.match(close); if (!closeTag) { - throw new Error('Unclosed {*'); + throw new Error('Unclosed '+jSmart.left_delimiter+'*'); } s = s.slice(closeTag.index+closeTag[0].length); } diff --git a/smart.min.js b/smart.min.js index 75dcd37..c6eb09d 100644 --- a/smart.min.js +++ b/smart.min.js @@ -8,58 +8,58 @@ jSmart is licensed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html */ -(function(){function J(a,c){for(var b=1;bb&&(b=0)}return null} -function Q(a,c,b){var d="",e=null,f=null,g=0;do{e&&(g+=e[0].length);e=B(a,b);if(!e)throw Error("Unclosed {"+c+"}");d+=b.slice(0,e.index);g+=e.index;b=b.slice(e.index+e[0].length);(f=B(c,d))&&(d=d.slice(f.index+f[0].length))}while(f);e.index=g;return e}function K(a,c,b,d){for(var e=0,f=B(b,d);f;f=B(b,d)){var g=B(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=Q(c,a,d);d=d.slice(f.index+f[0].length);e+=f.index+f[0].length}return null}function R(a, +function Q(a,c,b){var d="",e=null,f=null,g=0;do{e&&(g+=e[0].length);e=B(a,b);if(!e)throw Error("Unclosed {"+c+"}");d+=b.slice(0,e.index);g+=e.index;b=b.slice(e.index+e[0].length);(f=B(c,d))&&(d=d.slice(f.index+f[0].length))}while(f);e.index=g;return e}function L(a,c,b,d){for(var e=0,f=B(b,d);f;f=B(b,d)){var g=B(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=Q(c,a,d);d=d.slice(f.index+f[0].length);e+=f.index+f[0].length}return null}function R(a, c){if("string"==typeof a)with({__code:a})with(H)with(c)try{return eval(__code)}catch(b){throw Error(b.message+" in \n"+a);}return a}function x(a,c,b){a.match(/\[\]$/)?b[a.replace(/\[\]$/,"")].push(c):b[a]=c}function r(a,c){for(var b=B("",a);b;b=B("",a)){b.index&&w(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\s*|\[\s*)/,f=a.match(e);f;f=a.match(e)){c.token+=f[0];a=a.slice(f[0].length);var g={value:"",tree:[]};if(f[0].match(/\[/)){if(g=I(a))c.token+=g.value,b.push(g.tree),a=a.slice(g.value.length);if(f=a.match(/\s*\]/))c.token+=f[0],a=a.slice(f[0].length)}else{f=u.stop;u.stop=!0;if(T(a,g)){c.token+= g.value;var l=g.tree[0];"plugin"==l.type&&"__func"==l.name&&(l.hasOwner=!0);b.push(l);a=a.slice(g.value.length)}else g=!1;u.stop=f}g||b.push({type:"text",data:""})}c.tree.push({type:"var",parts:b});c.value+=c.token.substr(d.length);U(c.token);return a}function U(a){}function u(a,c){if(!u.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+/,"");u.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:[]},T(a,e)?(c.value+=e.value,b.push(e.tree[0]),a=a.slice(e.value.length)):w("",b);u.stop=!1;b.unshift(c.tree.pop());c.tree.push(Y(d,{__parsed:b},[])[0]);u(a,c)}}}function T(a,c){if(!a)return!1;if(a.substr(0,jSmart.prototype.left_delimiter.length)==jSmart.prototype.left_delimiter){var b=B("",a);if(b)return c.token=b[0],c.value+=b[0],r(b[0],c.tree),u(a.slice(c.value.length),c),!0}for(b=0;bb;++b)if(2== +a.slice(0,e[0].length),a=a.slice(e[0].length),e={value:"",tree:[]},T(a,e)?(c.value+=e.value,b.push(e.tree[0]),a=a.slice(e.value.length)):w("",b);u.stop=!1;b.unshift(c.tree.pop());c.tree.push(Y(d,{__parsed:b},[])[0]);u(a,c)}}}function T(a,c){if(!a)return!1;if(a.substr(0,jSmart.prototype.left_delimiter.length)==jSmart.prototype.left_delimiter){var b=B("",a);if(b)return c.token=b[0],c.value+=b[0],r(b[0],c.tree),u(a.slice(c.value.length),c),!0}for(b=0;bb;++b)if(2== b||10==b)for(c=a.length;0G(b,"nofilter")){for(b=0;b":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:!d;(b="var"== -a.params.__parsed[0].type)&&(d=C(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&&C(a.params.__parsed[0],c,d)}else{switch(a.op){case "++":d++;break;case "--":d--}C(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=K("section [^}]+","/section","sectionelse",b))?(r(b.slice(0,a.index),d),r(b.slice(a.index+ -a[0].length).replace(/^[\r\n]/,""),e)):r(b,d)},process:function(a,c){var b=y(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 p(a.subTreeElse,c);var e=parseInt(b.__get("start",0)),f=b.loop instanceof Object?O(b.loop):isNaN(b.loop)?0:parseInt(b.loop),g=parseInt(b.__get("step",1)),b=parseInt(b.__get("max"));isNaN(b)&&(b=Number.MAX_VALUE);0>e?(e+=f,0>e&&(e=0)):e>=f&&(e=f?f-1:0);for(var l=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=l+1,h+=p(a.subTree,c),c.smarty["continue"]=!1;c.smarty["break"]=!1;return l?h:p(a.subTreeElse,c)}},setfilter:{type:"block",parseParams:function(a){return[I("__t()|"+a).tree]},parse:function(a,c,b){c.push({type:"build-in",name:"setfilter",params:a,subTree:r(b,[])})},process:function(a,c){N=a.params;var b=p(a.subTree,c);N=[];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 z("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=K("for\\s[^}]+","/for","forelse",b))?(r(b.slice(0,a.index),d),r(b.slice(a.index+a[0].length),e)):r(b,d)},process:function(a,c){var b=y(a.params, -c),d=parseInt(b.__get("from")),e=parseInt(b.__get("to")),f=parseInt(b.__get("step"));isNaN(f)&&(f=1);var g=parseInt(b.__get("max"));isNaN(g)&&(g=Number.MAX_VALUE);for(var l=0,k="",d=Math.min(Math.ceil(((0\s*[$](\w+))?\s*$/i);c&&(a="from="+ -c[1]+" item="+(c[4]||c[2]),c[4]&&(a+=" key="+c[2]));return z(a)},parse:function(a,c,b){var d=[],e=[];c.push({type:"build-in",name:"foreach",params:a,subTree:d,subTreeElse:e});(a=K("foreach\\s[^}]+","/foreach","foreachelse",b))?(r(b.slice(0,a.index),d),r(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)):r(b,d)},process:function(a,c){var b=y(a.params,c),d=b.from;"undefined"==typeof d&&(d=[]);"object"!=typeof d&&(d=[d]);var e=O(d);c[b.item+"__total"]=e;"name"in b&&(c.smarty.foreach[b.name]={},c.smarty.foreach[b.name].total= -e);var f="",g=0,l;for(l in d)if(d.hasOwnProperty(l)){if(c.smarty["break"])break;c[b.item+"__key"]=isNaN(l)?l:parseInt(l);"key"in b&&(c[b.key]=c[b.item+"__key"]);c[b.item]=d[l];c[b.item+"__index"]=parseInt(g);c[b.item+"__iteration"]=parseInt(g+1);c[b.item+"__first"]=0===g;c[b.item+"__last"]=g==e-1;"name"in b&&(c.smarty.foreach[b.name].index=parseInt(g),c.smarty.foreach[b.name].iteration=parseInt(g+1),c.smarty.foreach[b.name].first=0===g?1:"",c.smarty.foreach[b.name].last=g==e-1?1:"");++g;f+=p(a.subTree, -c);c.smarty["continue"]=!1}c.smarty["break"]=!1;c[b.item+"__show"]=0=|<>|<|>)\s*/, -parse:function(a,c){t(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/,">=");t(b,"binary",5,a.tree)}},{re:/^\s+(is\s+(not\s+)?div\s+by)\s+/i,parse:function(a,c){t(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){t(RegExp.$1?"odd"==RegExp.$2?"even":"even_not":"odd"==RegExp.$2?"even_not": -"even","binary",7,a.tree);RegExp.$3||w("1",a.tree)}},{re:/^\s*(&&)\s*/,parse:function(a,c){t(RegExp.$1,"binary",8,a.tree)}},{re:/^\s*(\|\|)\s*/,parse:function(a,c){t(RegExp.$1,"binary",9,a.tree)}},{re:/^\s+and\s+/i,parse:function(a,c){t("&&","binary",11,a.tree)}},{re:/^\s+xor\s+/i,parse:function(a,c){t("xor","binary",12,a.tree)}},{re:/^\s+or\s+/i,parse:function(a,c){t("||","binary",13,a.tree)}},{re:/^#(\w+)#/,parse:function(a,c){var b={token:"$smarty",tree:[]};S(".config."+RegExp.$1,b,"smarty");a.tree.push(b.tree[0]); -u(c,a)}},{re:/^\s*\[\s*/,parse:function(a,c){var b=z(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){w(a.token,a.tree);u(c,a)}},{re:/^\w+/,parse:function(a,c){w(a.token,a.tree);u(c,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"}};D=this.tree.blocks;r(M(jSmart.prototype.filters_global.pre,ba((new String(a?a:"")).replace(/\r\n/g,"\n"))),this.tree)};jSmart.prototype.fetch=function(a){D=this.tree.blocks;W=this.scripts; -escape_html=this.escape_html;default_modifiers=jSmart.prototype.default_modifiers_global.concat(this.default_modifiers);this.data=J("object"==typeof a?a:{},this.smarty);varFilters=jSmart.prototype.filters_global.variable.concat(this.filters.variable);a=p(this.tree,this.data);jSmart.prototype.debugging&&A.debug.process([],this.data);return M(jSmart.prototype.filters_global.post.concat(this.filters.post),a)};jSmart.prototype.escape_html=!1;jSmart.prototype.registerPlugin=function(a,c,b){"modifier"== -a?H["__"+c]=b:A[c]={type:a,process:b}};jSmart.prototype.registerFilter=function(a,c){(this.tree?this.filters:jSmart.prototype.filters_global)["output"==a?"post":a].push(c)};jSmart.prototype.filters_global={pre:[],variable:[],post:[]};jSmart.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="",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==c)&&"."!=e.substr(0,1))if('"""'==f[3]){var g=a.match(/"""/);g&&(b.smarty.config[f[2]]=a.slice(0,g.index),a=a.slice(g.index+g[0].length))}else b.smarty.config[f[2]]=E(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 c=0;c=c.smarty.cycle[b].arr.length||d)c.smarty.cycle[b].index=0;return a.__get("assign",!1)?(x(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]:""});jSmart.prototype.print_r=function(a,c){if(a instanceof Object){var b=(a instanceof Array?"Array["+a.length+"]":"Object")+"
",d;for(d in a)a.hasOwnProperty(d)&&(b+=c+"  "+d+" : "+jSmart.prototype.print_r(a[d],c+"   ")+"
");return b}return a};jSmart.prototype.registerPlugin("function","debug",function(a,c){"undefined"!=typeof dbgWnd&&dbgWnd.close();dbgWnd=window.open("","","width=680,height=600,resizable,scrollbars=yes"); -var b="",d=0,e;for(e in c)b+=""+e+""+jSmart.prototype.print_r(c[e],"")+"";dbgWnd.document.write(" \t jSmart Debug Console

jSmart Debug Console

assigned template variables

"+ +e.__parsed[f]=g.tree):(e.push(g.value),e.__parsed.push(g.tree));a+=d.slice(0,g.value.length);d=d.slice(g.value.length);if(f=d.match(c))a+=d.slice(0,f[0].length),d=d.slice(f[0].length);else break}e.toString=function(){return a};return e}function y(a,c){var b=[],d;for(d in a.__parsed)if(a.__parsed.hasOwnProperty(d)){var e=p([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 C(a,c,b){for(var d=c,e="",f=0;fG(b,"nofilter")){for(b=0;b":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?!K(d):"0"===d?!0:!d;(b="var"==a.params.__parsed[0].type)&&(d=C(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&&C(a.params.__parsed[0],c,d)}else{switch(a.op){case "++":d++;break;case "--":d--}C(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=L("section [^}]+","/section","sectionelse",b))?(r(b.slice(0,a.index),d),r(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)):r(b,d)},process:function(a,c){var b=y(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 p(a.subTreeElse,c);var e=parseInt(b.__get("start",0)),f=b.loop instanceof Object?K(b.loop):isNaN(b.loop)?0:parseInt(b.loop), +g=parseInt(b.__get("step",1)),b=parseInt(b.__get("max"));isNaN(b)&&(b=Number.MAX_VALUE);0>e?(e+=f,0>e&&(e=0)):e>=f&&(e=f?f-1:0);for(var l=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=l+1,h+=p(a.subTree,c),c.smarty["continue"]=!1;c.smarty["break"]=!1;return l?h:p(a.subTreeElse,c)}},setfilter:{type:"block",parseParams:function(a){return[I("__t()|"+ +a).tree]},parse:function(a,c,b){c.push({type:"build-in",name:"setfilter",params:a,subTree:r(b,[])})},process:function(a,c){O=a.params;var b=p(a.subTree,c);O=[];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 z("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=L("for\\s[^}]+","/for","forelse",b))?(r(b.slice(0,a.index),d),r(b.slice(a.index+a[0].length),e)):r(b,d)},process:function(a,c){var b=y(a.params,c),d=parseInt(b.__get("from")),e=parseInt(b.__get("to")),f=parseInt(b.__get("step"));isNaN(f)&&(f=1);var g=parseInt(b.__get("max"));isNaN(g)&&(g=Number.MAX_VALUE);for(var l=0,k="",d=Math.min(Math.ceil(((0\s*[$](\w+))?\s*$/i);c&&(a="from="+c[1]+" item="+(c[4]||c[2]),c[4]&&(a+=" key="+c[2]));return z(a)},parse:function(a,c,b){var d=[],e=[];c.push({type:"build-in",name:"foreach",params:a,subTree:d,subTreeElse:e});(a=L("foreach\\s[^}]+","/foreach","foreachelse",b))?(r(b.slice(0,a.index),d),r(b.slice(a.index+a[0].length).replace(/^[\r\n]/,""),e)): +r(b,d)},process:function(a,c){var b=y(a.params,c),d=b.from;"undefined"==typeof d&&(d=[]);"object"!=typeof d&&(d=[d]);var e=K(d);c[b.item+"__total"]=e;"name"in b&&(c.smarty.foreach[b.name]={},c.smarty.foreach[b.name].total=e);var f="",g=0,l;for(l in d)if(d.hasOwnProperty(l)){if(c.smarty["break"])break;c[b.item+"__key"]=isNaN(l)?l:parseInt(l);"key"in b&&(c[b.key]=c[b.item+"__key"]);c[b.item]=d[l];c[b.item+"__index"]=parseInt(g);c[b.item+"__iteration"]=parseInt(g+1);c[b.item+"__first"]=0===g;c[b.item+ +"__last"]=g==e-1;"name"in b&&(c.smarty.foreach[b.name].index=parseInt(g),c.smarty.foreach[b.name].iteration=parseInt(g+1),c.smarty.foreach[b.name].first=0===g?1:"",c.smarty.foreach[b.name].last=g==e-1?1:"");++g;f+=p(a.subTree,c);c.smarty["continue"]=!1}c.smarty["break"]=!1;c[b.item+"__show"]=0=|<>|<|>)\s*/,parse:function(a,c){t(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/,">=");t(b,"binary",5,a.tree)}},{re:/^\s+(is\s+(not\s+)?div\s+by)\s+/i,parse:function(a,c){t(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){t(RegExp.$1?"odd"==RegExp.$2?"even":"even_not":"odd"==RegExp.$2?"even_not":"even","binary",7,a.tree);RegExp.$3||w("1",a.tree)}},{re:/^\s*(&&)\s*/,parse:function(a,c){t(RegExp.$1,"binary",8,a.tree)}},{re:/^\s*(\|\|)\s*/,parse:function(a,c){t(RegExp.$1,"binary",9,a.tree)}},{re:/^\s+and\s+/i,parse:function(a,c){t("&&","binary",11,a.tree)}},{re:/^\s+xor\s+/i,parse:function(a,c){t("xor","binary",12,a.tree)}},{re:/^\s+or\s+/i, +parse:function(a,c){t("||","binary",13,a.tree)}},{re:/^#(\w+)#/,parse:function(a,c){var b={token:"$smarty",tree:[]};S(".config."+RegExp.$1,b,"smarty");a.tree.push(b.tree[0]);u(c,a)}},{re:/^\s*\[\s*/,parse:function(a,c){var b=z(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){w(a.token,a.tree);u(c, +a)}},{re:/^\w+/,parse:function(a,c){w(a.token,a.tree);u(c,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"}};D=this.tree.blocks; +r(N(jSmart.prototype.filters_global.pre,ba((new String(a?a:"")).replace(/\r\n/g,"\n"))),this.tree)};jSmart.prototype.fetch=function(a){D=this.tree.blocks;W=this.scripts;escape_html=this.escape_html;default_modifiers=jSmart.prototype.default_modifiers_global.concat(this.default_modifiers);this.data=J("object"==typeof a?a:{},this.smarty);varFilters=jSmart.prototype.filters_global.variable.concat(this.filters.variable);a=p(this.tree,this.data);jSmart.prototype.debugging&&A.debug.process([],this.data); +return N(jSmart.prototype.filters_global.post.concat(this.filters.post),a)};jSmart.prototype.escape_html=!1;jSmart.prototype.registerPlugin=function(a,c,b){"modifier"==a?H["__"+c]=b:A[c]={type:a,process:b}};jSmart.prototype.registerFilter=function(a,c){(this.tree?this.filters:jSmart.prototype.filters_global)["output"==a?"post":a].push(c)};jSmart.prototype.filters_global={pre:[],variable:[],post:[]};jSmart.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="",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==c)&&"."!=e.substr(0,1))if('"""'==f[3]){var g=a.match(/"""/);g&&(b.smarty.config[f[2]]=a.slice(0,g.index),a=a.slice(g.index+g[0].length))}else b.smarty.config[f[2]]=E(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 c=0;c=c.smarty.cycle[b].arr.length||d)c.smarty.cycle[b].index=0;return a.__get("assign",!1)?(x(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]:""});jSmart.prototype.print_r=function(a,c){if(a instanceof Object){var b=(a instanceof Array?"Array["+a.length+"]":"Object")+"
",d;for(d in a)a.hasOwnProperty(d)&&(b+=c+"  "+d+" : "+jSmart.prototype.print_r(a[d],c+"   ")+ +"
");return b}return a};jSmart.prototype.registerPlugin("function","debug",function(a,c){"undefined"!=typeof dbgWnd&&dbgWnd.close();dbgWnd=window.open("","","width=680,height=600,resizable,scrollbars=yes");var b="",d=0,e;for(e in c)b+="
";dbgWnd.document.write(" \t jSmart Debug Console

jSmart Debug Console

assigned template variables

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