Skip to content
Snippets Groups Projects
Commit 96e4a04e authored by deuce's avatar deuce
Browse files

Overhaul of template.ssjs

======== THERE IS NEW SYNTAX ========
It is absolutely forbidden to include one tag inside another... NO
execptions anymore.  This one will have the largest impact.  Essentially,
@@JS:if(somevar)then'@@something:else@@'else''@@ will *NOT* work.
Now, if you want to access to current iteration of the repeated array
inside a <<REPEAT objname>> section, it's available inside of JS: bits as
RepeatObj.  This should remove all need for nested tags.

A new convinience functions has been added... Nz(value[, valIfUndef])
returns valIfUndef (defaults to the empty string) if value is undefined
and value if it IS defined.
parent d86084bf
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,13 @@ ...@@ -18,6 +18,13 @@
/* the value of template.name.sname. */ /* the value of template.name.sname. */
/* (^^ and %% are also supported) */ /* (^^ and %% are also supported) */
/* */ /* */
/* Inside of REPEAT sections, the current object from the repeated array is */
/* Available to JS: replacements as RepeatObj */
/* */
/* The convienience function Nz(value[, valifundefined]) is also available. */
/* It returns valifindefined if value is undefined, or value if it is. */
/* valifundefined defaults to the empty string. */
/* */
/*****************************************************************************/ /*****************************************************************************/
/* $Id$ */ /* $Id$ */
...@@ -35,6 +42,15 @@ template.Theme_CSS_File=Themes[CurrTheme].css; ...@@ -35,6 +42,15 @@ template.Theme_CSS_File=Themes[CurrTheme].css;
template.server=server; template.server=server;
template.system=system; template.system=system;
function Nz(value, valifundefined)
{
if(valifundefined==undefined)
valifundefined='';
if(value==undefined)
return(valifundefined);
return(value);
}
function write_template(filename) { function write_template(filename) {
var fname='../web/templates/'+Themes[CurrTheme].dir+'/'+filename; var fname='../web/templates/'+Themes[CurrTheme].dir+'/'+filename;
if(!file_exists(fname)) { if(!file_exists(fname)) {
...@@ -48,63 +64,55 @@ function write_template(filename) { ...@@ -48,63 +64,55 @@ function write_template(filename) {
} }
var file=inc.read(); var file=inc.read();
inc.close(); inc.close();
/* The following 'if' statement fixes performance problem with pages *not* containing REPEAT clauses */ var offset;
if(file.search(/<<REPEAT .*>>/)>0) while((offset=file.search(/<<REPEAT .*?>>/))>-1) {
file=file.replace(/([\x00-\xff]*?)<<REPEAT (.*?)>>([\x00-\xff]*?)<<END REPEAT \2>>/g, parse_regular_bit(file.substr(0,offset),'',template);
function(matched, start, objname, bit, offset, s) { file=file.substr(offset);
var ret=''; var m=file.match(/^<<REPEAT (.*?)>>([\x00-\xff]*?)<<END REPEAT \1>>/);
start=parse_regular_bit(start,"",template); if(m.index>-1) {
start=start.replace(/\<\!-- Magical Synchronet ([\^%@])-code --\>/g,'$1'); for(obj in template[m[1]]) {
write(start); parse_regular_bit(m[2],m[1],template[m[1]][obj]);
for(obj in template[objname]) { }
var thisbit=parse_regular_bit(bit,objname,template[objname][obj]); file=file.substr(m[0].length);
thisbit=parse_regular_bit(thisbit,"",template); }
thisbit=thisbit.replace(/\<\!-- Magical Synchronet ([\^%@])-code --\>/g,'$1'); }
write(thisbit); parse_regular_bit(file, "", template);
} }
return("");
}); function parse_regular_bit(bit, objname, RepeatObj) {
file=parse_regular_bit(file, "", template); var offset;
file=file.replace(/\<\!-- Magical Synchronet ([\^%@])-code --\>/g,'$1'); var i=0;
write(file); while((offset=bit.search(/([%^@])\1(.*?)\1\1/))>-1) {
} write(bit.substr(0,offset));
function parse_regular_bit(bit, objname, obj) { bit=bit.substr(offset);
if(objname=="JS") { var m=bit.match(/^([%^@])\1([\x00-\xff]*?)\1\1/);
return(bit); if(m.index>-1) {
} if(m[2].substr(0,3)=='JS:') {
if(objname=='') { var val=eval(m[2].substr(3));
bit=bit.replace(/([%^@])\1([^^%@\r\n]*?)\:([^:%^@\r\n]*?)\1\1/g, if(val!=undefined)
function (matched, start, objname, prop, offset, s) { write(escape_match(m[1],eval(m[2].substr(3))));
var res=matched; }
if(template[objname]!=undefined) else if(m[2].substr(0,objname.length+1)==objname+':') {
res=escape_match(start, template[objname][prop]); if(RepeatObj[m[2].substr(objname.length+1)]!=undefined)
return(res); write(escape_match(m[1],RepeatObj[m[2].substr(objname.length+1)]));
}); }
bit=bit.replace(/([%^@])\1([^:^%@\r\n]*?)\1\1/g, else if((i=m[2].search(/:/))>0) {
function (matched, start, exp, offset, s) { if(template[m[2].substr(0,i)]!=undefined) {
var res=escape_match(start, template[exp]); if(template[m[2].substr(0,i)][m[2].substr(i+1)]!=undefined)
return(res); write(escape_match(m[1],template[m[2].substr(0,i)][m[2].substr(i+1)]));
}); }
bit=bit.replace(/([%^@])\1JS:([\x00-\xff]*?)\1\1/g,
function (matched, start, exp, offset, s) {
var res=escape_match(start, eval(exp));
return(res);
});
bit=bit.replace(/([%^@])\1(.*?)\1\1/g,'');
} }
else { else {
bit=bit.replace(new RegExp('([%^@])\\1'+regex_escape(objname)+':([^^%@\r\n]*?)\\1\\1',"g"), if(template[m[2]]!=undefined)
function (matched, start, exp, offset, s) { write(escape_match(m[1],template[m[2]]));
var res=matched; }
if(obj[exp]!=undefined) }
res=escape_match(start, obj[exp]); bit=bit.substr(m[0].length);
return(res);
});
} }
return bit; write(bit);
} }
function escape_match(start, exp, end) { function escape_match(start, exp) {
if(exp==undefined) if(exp==undefined)
exp=''; exp='';
exp=exp.toString(); exp=exp.toString();
...@@ -112,9 +120,6 @@ function escape_match(start, exp, end) { ...@@ -112,9 +120,6 @@ function escape_match(start, exp, end) {
exp=html_encode(exp,false,false,false,false); exp=html_encode(exp,false,false,false,false);
if(start=="^") if(start=="^")
exp=encodeURIComponent(exp); exp=encodeURIComponent(exp);
exp=exp.replace(/\@/g,'<!-- Magical Synchronet @-code -->');
exp=exp.replace(/\^/g,'<!-- Magical Synchronet ^-code -->');
exp=exp.replace(/\%/g,'<!-- Magical Synchronet %-code -->');
return(exp); return(exp);
} }
......
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
<!-- start Nodelisting --> <!-- start Nodelisting -->
@@JS:if(!template.node_list.length || http_request.virtual_path=="/nodelist.ssjs")'<!--';@@Who's Online now ...<br /><table class="left_nodelist"><tbody><<REPEAT node_list>><tr><td class="left_nodelist"><a href="mailto:@@node_list:email@@">%%node_list:name%%</a> %%node_list:action%%</td></tr><<END REPEAT node_list>></tbody></table>@@JS:if(!template.node_list.length || http_request.virtual_path=="/nodelist.ssjs")'-->';@@ @@JS:if(!template.node_list.length || http_request.virtual_path=="/nodelist.ssjs")'<!--';@@
Who's Online now ...<br /><table class="left_nodelist"><tbody><<REPEAT node_list>><tr><td class="left_nodelist"><a href="mailto:@@node_list:email@@">%%node_list:name%%</a> %%node_list:action%%</td></tr><<END REPEAT node_list>></tbody></table>
@@JS:if(!template.node_list.length || http_request.virtual_path=="/nodelist.ssjs")'-->';@@
</div> </div>
</td> </td>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<<REPEAT groups>> <<REPEAT groups>>
<tr> <tr>
<td class="grouplist"><a class="grouplist" href="choosesubs.ssjs?msg_grp=^^groups:name^^">%%groups:description%%</a></td> <td class="grouplist"><a class="grouplist" href="choosesubs.ssjs?msg_grp=^^groups:name^^">%%groups:description%%</a></td>
<td class="grouplist" align="right">@@JS:msg_area.grp_list['@@groups:index@@'].sub_list.length@@</td> <td class="grouplist" align="right">@@JS:msg_area.grp_list[RepeatObj.index].sub_list.length@@</td>
</tr> </tr>
<<END REPEAT groups>> <<END REPEAT groups>>
</table> </table>
......
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
<td class="sublistright">%%subs:messages%%</td> <td class="sublistright">%%subs:messages%%</td>
<td class="sublistright" nowrap="nowrap">%%subs:lastmsg%%</td> <td class="sublistright" nowrap="nowrap">%%subs:lastmsg%%</td>
<td class="sublist"> <td class="sublist">
<input name="sub-%%subs:code%%" type="radio" value="1" @@JS:if(%%subs:ischecked%%==1)' checked="checked"';@@ /> <input name="sub-%%subs:code%%" type="radio" value="1" @@JS:if(RepeatObj.ischecked==1)' checked="checked"';@@ />
</td> </td>
<td class="sublist"> <td class="sublist">
<input name="sub-%%subs:code%%" type="radio" value="2" @@JS:if(%%subs:ischecked%%==2)' checked="checked"';@@ /> <input name="sub-%%subs:code%%" type="radio" value="2" @@JS:if(RepeatObj.ischecked==2)' checked="checked"';@@ />
</td> </td>
<td class="sublist"> <td class="sublist">
<input name="sub-%%subs:code%%" type="radio" value="3" @@JS:if(%%subs:ischecked%%==3)' checked="checked"';@@ /> <input name="sub-%%subs:code%%" type="radio" value="3" @@JS:if(RepeatObj.ischecked==3)' checked="checked"';@@ />
</td> </td>
</tr> </tr>
<<END REPEAT subs>> <<END REPEAT subs>>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<<REPEAT groups>> <<REPEAT groups>>
<tr> <tr>
<td class="grouplist"><a class="grouplist" href="subs.ssjs?msg_grp=^^groups:name^^">%%groups:description%%</a></td> <td class="grouplist"><a class="grouplist" href="subs.ssjs?msg_grp=^^groups:name^^">%%groups:description%%</a></td>
<td class="grouplist" align="right">@@JS:msg_area.grp_list['@@groups:index@@'].sub_list.length@@</td> <td class="grouplist" align="right">@@JS:msg_area.grp_list[RepeatObj.index].sub_list.length@@</td>
</tr> </tr>
<<END REPEAT groups>> <<END REPEAT groups>>
</table> </table>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<td width="1%" class="msgheader" nowrap="nowrap" onDblClick="window.open().document.write('%%hfields%%')">Subject:</td> <td width="1%" class="msgheader" nowrap="nowrap" onDblClick="window.open().document.write('%%hfields%%')">Subject:</td>
<td nowrap="nowrap">%%hdr:subject%%</td> <td nowrap="nowrap">%%hdr:subject%%</td>
<td width="1%" class="msgheader" nowrap="nowrap">Date:</td> <td width="1%" class="msgheader" nowrap="nowrap">Date:</td>
<td nowrap="nowrap">%%JS:system.timestr(@@hdr:when_written_time@@)%%</td> <td nowrap="nowrap">%%JS:system.timestr(template.hdr.when_written_time)%%</td>
</tr> </tr>
<tr class="msg"> <tr class="msg">
<td width="1%" class="msgheader" nowrap="nowrap">From:</td> <td width="1%" class="msgheader" nowrap="nowrap">From:</td>
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
<table class="msg2" width="100%"> <table class="msg2" width="100%">
<tr> <tr>
<td width="1%" class="msgnavleft" nowrap="nowrap">@@prevlink@@</td> <td width="1%" class="msgnavleft" nowrap="nowrap">@@prevlink@@</td>
<td width="1%" class="msgnavmid">@@JS:template.can_post?'<a href="reply.ssjs?msg_sub=^^sub:code^^&amp;reply_to=^^hdr:number^^">Reply</a>':'Reply'@@</td> <td width="1%" class="msgnavmid">@@JS:template.can_post?'<a href="reply.ssjs?msg_sub='+template.sub.code+'&amp;reply_to='+template.hdr.number+'">Reply</a>':'Reply'@@</td>
<td width="1%"class="msgnavmid">@@JS:template.can_post?'<a href="post.ssjs?msg_sub=^^sub:code^^&amp;post=new">Post New</a>':'Post New'@@</td> <td width="1%"class="msgnavmid">@@JS:template.can_post?'<a href="post.ssjs?msg_sub='+template.sub.code+'&amp;post=new">Post New</a>':'Post New'@@</td>
@@JS:template.can_delete?'<td width="1%" class="msgnavmid"><a href="management.ssjs?Action=Delete+Selected+Message%28s%29&amp;msg_sub='+template.sub.code+'&amp;number='+template.hdr.number+'">Delete</a>':'Delete'@@</td> @@JS:template.can_delete?'<td width="1%" class="msgnavmid"><a href="management.ssjs?Action=Delete+Selected+Message%28s%29&amp;msg_sub='+template.sub.code+'&amp;number='+template.hdr.number+'">Delete</a>':'Delete'@@</td>
<td width="1%" class="msgnavright" nowrap="nowrap">@@nextlink@@</td> <td width="1%" class="msgnavright" nowrap="nowrap">@@nextlink@@</td>
</tr> </tr>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div align="center"> <div align="center">
@@JS:template.can_post?'<form name="PostMsg" action="post.ssjs?msg_sub=^^sub:code^^&amp;post=new" method="post"><input type="submit" value="'+template.post_button+'" /></form>':''@@ @@JS:template.can_post?'<form name="PostMsg" action="post.ssjs?msg_sub=^^sub:code^^&amp;post=new" method="post"><input type="submit" value="'+template.post_button+'" /></form>':''@@
@@JS:template.show_choice==undefined ? '' : '(@@show_choice@@)<br /><br />'@@ @@JS:template.show_choice==undefined ? '' : '(' + template.show_choice + ')<br /><br />'@@
</div> </div>
<form name="DeleteMsg" action="management.ssjs" method="post"> <form name="DeleteMsg" action="management.ssjs" method="post">
...@@ -27,27 +27,27 @@ ...@@ -27,27 +27,27 @@
<tr class=@@JS:((template.color++)%2==0)?'"msglist1"':'"msglist2"';@@> <tr class=@@JS:((template.color++)%2==0)?'"msglist1"':'"msglist2"';@@>
@@JS:template.can_delete?'<td align=center><input name="number" value="^^messages:number^^" type="checkbox"></td>':''@@ @@JS:template.can_delete?'<td align=center><input name="number" value="^^messages:number^^" type="checkbox"></td>':''@@
<td align="center"> <td align="center">
@@JS:if(@@messages:attachments@@>0) '<img alt="Attachment" src="/graphics/attach_black.gif" />'; else '&nbsp;';@@ @@JS:if(RepeatObj.attachments>0) '<img alt="Attachment" src="/graphics/attach_black.gif" />'; else '&nbsp;';@@
</td> </td>
<td> <td>
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '<b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '<b>';@@
<a class="msglist" href="msg.ssjs?msg_sub=^^sub:code^^&amp;message=^^messages:number^^">%%messages:subject%%</a> <a class="msglist" href="msg.ssjs?msg_sub=^^sub:code^^&amp;message=^^messages:number^^">%%messages:subject%%</a>
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '</b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '</b>';@@
</td> </td>
<td> <td>
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '<b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '<b>';@@
%%messages:from%% %%messages:from%%
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '</b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '</b>';@@
</td> </td>
<td> <td>
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '<b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '<b>';@@
%%messages:to%% %%messages:to%%
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '</b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '</b>';@@
</td> </td>
<td align="right" nowrap="nowrap"> <td align="right" nowrap="nowrap">
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '<b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '<b>';@@
%%JS:system.timestr(@@messages:when_written_time@@)%% %%JS:system.timestr(RepeatObj.when_written_time)%%
@@JS:if(sub=='mail' && !(@@messages:attr@@ & MSG_READ)) '</b>';@@ @@JS:if(sub=='mail' && !(RepeatObj.attr & MSG_READ)) '</b>';@@
</td> </td>
</tr> </tr>
<<END REPEAT messages>> <<END REPEAT messages>>
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<tr> <tr>
<td class="newuser">&nbsp;</td> <td class="newuser">&nbsp;</td>
<td class="newuser"> <td class="newuser">
<input type="submit" value="Join!" />Join! <input type="submit" value="Join!" />
</td> </td>
</tr> </tr>
</table> </table>
......
...@@ -27,9 +27,8 @@ ...@@ -27,9 +27,8 @@
<td class="main_nodelist" width="1%">@@who_online:node@@</td> <td class="main_nodelist" width="1%">@@who_online:node@@</td>
<td class="main_nodelist"><a href="mailto:@@who_online:email@@">@@who_online:name@@</a></td> <td class="main_nodelist"><a href="mailto:@@who_online:email@@">@@who_online:name@@</a></td>
<td class="main_nodelist">@@who_online:action@@</td> <td class="main_nodelist">@@who_online:action@@</td>
@@JS:if(show_location)'<td class="main_nodelist" width="25%">@@who_online:location@@</td>'@@ @@JS:if(show_location)'<td class="main_nodelist" width="25%">'+Nz(RepeatObj.location)+'</td>'@@
@@JS:if(show_age)'<td class="main_nodelist" width="1%">%%who_online:age%%</td>'@@ @@JS:if(show_gender)'<td class="main_nodelist" width="1%">'+Nz(RepeatObj.gender)+'</td>'@@
@@JS:if(show_gender)'<td class="main_nodelist" width="1%">@@who_online:gender@@</td>'@@
<td class="main_nodelist" width="1%">@@who_online:timeon@@</td> <td class="main_nodelist" width="1%">@@who_online:timeon@@</td>
</tr> </tr>
<<END REPEAT who_online>> <<END REPEAT who_online>>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment