includes/clientside/static/comments.js
changeset 212 30b857a6b811
parent 108 1c7f59df9474
child 214 a6ed8b6cdbe1
equal deleted inserted replaced
211:753dabeca1ee 212:30b857a6b811
    46           break;
    46           break;
    47         case 'annihilate':
    47         case 'annihilate':
    48           annihiliateComment(response.id);
    48           annihiliateComment(response.id);
    49           break;
    49           break;
    50         case 'materialize':
    50         case 'materialize':
    51           alert('Your comment has been posted. If it does not appear right away, it is probably awaiting approval.');
    51           alert($lang.get('comment_msg_comment_posted'));
    52           hideCommentForm();
    52           hideCommentForm();
    53           materializeComment(response);
    53           materializeComment(response);
    54           break;
    54           break;
    55         case 'error':
    55         case 'error':
    56           new messagebox(MB_OK|MB_ICONSTOP, ( response.title ? response.title : 'Error fetching comment data' ), response.error);
    56           new messagebox(MB_OK|MB_ICONSTOP, ( response.title ? response.title : 'Error fetching comment data' ), response.error);
    68   
    68   
    69   var html = '';
    69   var html = '';
    70   
    70   
    71   // Header
    71   // Header
    72   
    72   
    73     html += '<h3>Article Comments</h3>';
    73     html += '<h3>' + $lang.get('comment_heading') + '</h3>';
    74     
    74     
    75     var ns = ( strToPageID(title)[1]=='Article' ) ? 'article' : ( strToPageID(title)[1].toLowerCase() ) + ' page';
    75     var ns = ENANO_PAGE_TYPE;
    76   
    76   
    77     // Counters
    77     // Counters
    78     if ( data.auth_mod_comments )
    78     if ( data.auth_mod_comments )
    79     {
    79     {
    80       var cnt = ( data.auth_mod_comments ) ? data.count_total : data.count_appr;
    80       var cnt = ( data.auth_mod_comments ) ? data.count_total : data.count_appr;
    81       if ( cnt == 0 ) cnt = 'no';
    81       
    82       var s  = ( cnt == 1 ) ? '' : 's';
    82       var subst = {
    83       var is = ( cnt == 1 ) ? 'is' : 'are';
    83         num_comments: cnt,
    84       html += "<p id=\"comment_status\">There "+is+" " + cnt + " comment"+s+" on this "+ns+".";
    84         page_type: ns
       
    85       }
       
    86       var count_msg = ( cnt == 0 ) ? $lang.get('comment_msg_count_zero', subst) : ( ( cnt == 1 ) ? $lang.get('comment_msg_count_one', subst) : $lang.get('comment_msg_count_plural', subst) );
       
    87       
       
    88       html += "<p id=\"comment_status\"><span>" + count_msg + '</span>';
    85       if ( data.count_unappr > 0 )
    89       if ( data.count_unappr > 0 )
    86       {
    90       {
    87         html += ' <span style="color: #D84308">' + data.count_unappr + ' of those are unapproved.</span>';
    91         html += ' <span style="color: #D84308" id="comment_status_unapp">' + $lang.get('comment_msg_count_unapp_mod', { num_unapp: data.count_unappr }) + '</span>';
    88       }
    92       }
    89       html += '</p>';
    93       html += '</p>';
    90     }
    94     }
    91     else
    95     else
    92     {
    96     {
    93       var cnt = data.count_appr;
    97       var cnt = data.count_appr;
    94       if ( cnt == 0 ) cnt = 'no';
    98       
    95       var s  = ( cnt == 1 ) ? '' : 's';
    99       var subst = {
    96       var is = ( cnt == 1 ) ? 'is' : 'are';
   100         num_comments: cnt,
    97       html += "<p id=\"comment_status\">There "+is+" " + cnt + " comment"+s+" on this "+ns+".";
   101         page_type: ns
       
   102       }
       
   103       var count_msg = ( cnt == 0 ) ? $lang.get('comment_msg_count_zero', subst) : ( ( cnt == 1 ) ? $lang.get('comment_msg_count_one', subst) : $lang.get('comment_msg_count_plural', subst) );
       
   104       
       
   105       html += "<p id=\"comment_status\">" + count_msg;
    98       if ( data.count_unappr > 0 )
   106       if ( data.count_unappr > 0 )
    99       {
   107       {
   100         var s  = ( data.count_unappr == 1 ) ? '' : 's';
   108         var unappr_msg  = ( data.count_unappr == 1 ) ? $lang.get('comment_msg_count_unapp_one') : $lang.get('comment_msg_count_unapp_plural', { num_unapp: data.count_unappr });
   101         var is = ( data.count_unappr == 1 ) ? 'is' : 'are';
   109         html += ' ' + unappr_msg;
   102         html += ' However, there '+is+' '+data.count_unappr+' additional comment'+s+' awaiting approval.';
       
   103       }
   110       }
   104       html += '</p>';
   111       html += '</p>';
   105     }
   112     }
   106     
   113     
   107   // Comment display
   114   // Comment display
   116   if ( data.auth_post_comments )
   123   if ( data.auth_post_comments )
   117   {
   124   {
   118     
   125     
   119     // Posting form
   126     // Posting form
   120   
   127   
   121     html += '<h3>Got something to say?</h3>';
   128     html += '<h3>' + $lang.get('comment_postform_title') + '</h3>';
   122     html += '<p>If you have comments or suggestions on this article, you can shout it out here.';
   129     html += '<p>' + $lang.get('comment_postform_blurb');
   123     if ( data.approval_needed )
   130     if ( data.approval_needed )
   124       html+=' Before your post will be visible to the public, a moderator will have to approve it.';
   131       html+=' ' + $lang.get('comment_postform_blurb_unapp');
   125     html += ' <a id="leave_comment_button" href="#" onclick="displayCommentForm(); return false;">Leave a comment...</a></p>';
   132     html += ' <a id="leave_comment_button" href="#" onclick="displayCommentForm(); return false;">' + $lang.get('comment_postform_blurb_link') + '</a></p>';
   126     html += '<div id="comment_form" style="display: none;">';
   133     html += '<div id="comment_form" style="display: none;">';
   127     html += '  <table border="0">';
   134     html += '  <table border="0">';
   128     html += '    <tr><td>Your name/screen name:</td><td>';
   135     html += '    <tr><td>' + $lang.get('comment_postform_field_name') + '</td><td>';
   129     if ( data.user_id > 1 ) html += data.username + '<input id="commentform_name" type="hidden" value="'+data.username+'" size="40" />';
   136     if ( data.user_id > 1 ) html += data.username + '<input id="commentform_name" type="hidden" value="'+data.username+'" size="40" />';
   130     else html += '<input id="commentform_name" type="text" size="40" />';
   137     else html += '<input id="commentform_name" type="text" size="40" />';
   131     html += '    </td></tr>';
   138     html += '    </td></tr>';
   132     html += '    <tr><td>Comment subject:</td><td><input id="commentform_subject" type="text" size="40" /></td></tr>';
   139     html += '    <tr><td>' + $lang.get('comment_postform_field_subject') + '</td><td><input id="commentform_subject" type="text" size="40" /></td></tr>';
   133     html += '    <tr><td>Comment:</td><td><textarea id="commentform_message" rows="15" cols="50"></textarea></td></tr>';
   140     html += '    <tr><td>' + $lang.get('comment_postform_field_comment') + '</td><td><textarea id="commentform_message" rows="15" cols="50"></textarea></td></tr>';
   134     if ( !data.logged_in && data.guest_posting == '1' )
   141     if ( !data.logged_in && data.guest_posting == '1' )
   135     {
   142     {
   136       html += '  <tr><td>Visual confirmation:<br /><small>Please enter the confirmation code seen in the image on the right into the box. If you cannot read the code, please click on the image to generate a new one. This helps to prevent automated bot posting.</small></td><td>';
   143       html += '  <tr><td>' + $lang.get('comment_postform_field_captcha_title') + '<br /><small>' + $lang.get('comment_postform_field_captcha_blurb') + '</small></td><td>';
   137       html += '  <img alt="CAPTCHA image" src="'+makeUrlNS('Special', 'Captcha/' + data.captcha)+'" onclick="this.src=\''+makeUrlNS('Special', 'Captcha/' + data.captcha)+'/\'+Math.floor(Math.random()*10000000);" style="cursor: pointer;" /><br />';
   144       html += '  <img alt="CAPTCHA image" src="'+makeUrlNS('Special', 'Captcha/' + data.captcha)+'" onclick="this.src=\''+makeUrlNS('Special', 'Captcha/' + data.captcha)+'/\'+Math.floor(Math.random()*10000000);" style="cursor: pointer;" /><br />';
   138       html += '  Confirmation code: <input type="text" size="8" id="commentform_captcha" />';
   145       html += '  ' + $lang.get('comment_postform_field_captcha_label') + ' <input type="text" size="8" id="commentform_captcha" />';
   139       html += '  <!-- This input is used to track the ID of the CAPTCHA image --> <input type="hidden" id="commentform_captcha_id" value="'+data.captcha+'" />';
   146       html += '  <!-- This input is used to track the ID of the CAPTCHA image --> <input type="hidden" id="commentform_captcha_id" value="'+data.captcha+'" />';
   140       html += '  </td></tr>';
   147       html += '  </td></tr>';
   141     }
   148     }
   142     html += '    <tr><td colspan="2" style="text-align: center;"><input type="button" onclick="submitComment();" value="Submit comment" /></td></tr>';
   149     html += '    <tr><td colspan="2" style="text-align: center;"><input type="button" onclick="submitComment();" value="' + $lang.get('comment_postform_btn_submit') + '" /></td></tr>';
   143     html += '  </table>';
   150     html += '  </table>';
   144     html += '</div>';
   151     html += '</div>';
   145     
   152     
   146   }
   153   }
   147     
   154     
   169   tplvars.SUBJECT = this_comment.subject;
   176   tplvars.SUBJECT = this_comment.subject;
   170   tplvars.DATA = this_comment.comment_data;
   177   tplvars.DATA = this_comment.comment_data;
   171   tplvars.SIGNATURE = this_comment.signature;
   178   tplvars.SIGNATURE = this_comment.signature;
   172   
   179   
   173   if ( this_comment.approved != '1' )
   180   if ( this_comment.approved != '1' )
   174     tplvars.SUBJECT += ' <span style="color: #D84308">(Unapproved)</span>';
   181     tplvars.SUBJECT += ' <span style="color: #D84308">' + $lang.get('comment_msg_note_unapp') + '</span>';
   175   
   182   
   176   // Name
   183   // Name
   177   tplvars.NAME = this_comment.name;
   184   tplvars.NAME = this_comment.name;
   178   if ( this_comment.user_id > 1 )
   185   if ( this_comment.user_id > 1 )
   179     tplvars.NAME = '<a href="' + makeUrlNS('User', this_comment.name) + '">' + this_comment.name + '</a>';
   186     tplvars.NAME = '<a href="' + makeUrlNS('User', this_comment.name) + '">' + this_comment.name + '</a>';
   180   
   187   
   181   // User level
   188   // User level
   182   tplvars.USER_LEVEL = 'Guest';
   189   tplvars.USER_LEVEL = $lang.get('user_type_guest');
   183   if ( this_comment.user_level >= data.user_level.member ) tplvars.USER_LEVEL = 'Member';
   190   if ( this_comment.user_level >= data.user_level.member ) tplvars.USER_LEVEL = $lang.get('user_type_member');
   184   if ( this_comment.user_level >= data.user_level.mod )    tplvars.USER_LEVEL = 'Moderator';
   191   if ( this_comment.user_level >= data.user_level.mod ) tplvars.USER_LEVEL = $lang.get('user_type_mod');
   185   if ( this_comment.user_level >= data.user_level.admin )  tplvars.USER_LEVEL = 'Administrator';
   192   if ( this_comment.user_level >= data.user_level.admin ) tplvars.USER_LEVEL = $lang.get('user_type_admin');
   186                               
   193   
   187   // Send PM link
   194   // Send PM link
   188   tplvars.SEND_PM_LINK=(this_comment.user_id>1 && data.logged_in)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( this_comment.name.replace(/ /g, '_') )) +'">Send private message</a><br />':'';
   195   tplvars.SEND_PM_LINK=(this_comment.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( this_comment.name.replace(/ /g, '_') )) +'">' + $lang.get('comment_btn_send_privmsg') + '</a><br />':'';
   189   
   196   
   190   // Add buddy link
   197   // Add buddy link
   191   tplvars.ADD_BUDDY_LINK=(this_comment.user_id>1 && data.logged_in && this_comment.is_buddy != 1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( this_comment.name.replace(/ /g, '_') )) +'">Add to buddy list</a><br />':'';
   198   tplvars.ADD_BUDDY_LINK=(this_comment.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( this_comment.name.replace(/ /g, '_') )) +'">' + $lang.get('comment_btn_add_buddy') + '</a><br />':'';
   192   
   199   
   193   // Edit link
   200   // Edit link
   194   tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">edit</a>';
   201   tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">' + $lang.get('comment_btn_edit') + '</a>';
   195   
   202   
   196   // Delete link
   203   // Delete link
   197   tplvars.DELETE_LINK='<a href="#delete_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">delete</a>';
   204   tplvars.DELETE_LINK='<a href="#delete_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">' + $lang.get('comment_btn_delete') + '</a>';
   198   
   205   
   199   // Moderation: (Un)approve link
   206   // Moderation: (Un)approve link
   200   var appr = ( this_comment.approved == 1 ) ? 'Unapprove' : 'Approve';
   207   var appr = ( this_comment.approved == 1 ) ? $lang.get('comment_btn_mod_unapprove') : $lang.get('comment_btn_mod_approve');
   201   tplvars.MOD_APPROVE_LINK='<a href="#approve_'+i+'" id="comment_approve_'+i+'" onclick="approveComment(\''+i+'\'); return false;">'+appr+'</a>';
   208   tplvars.MOD_APPROVE_LINK='<a href="#approve_'+i+'" id="comment_approve_'+i+'" onclick="approveComment(\''+i+'\'); return false;">'+appr+'</a>';
   202   
   209   
   203   // Moderation: Delete post link
   210   // Moderation: Delete post link
   204   tplvars.MOD_DELETE_LINK='<a href="#mod_del_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">Delete</a>';
   211   tplvars.MOD_DELETE_LINK='<a href="#mod_del_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">' + $lang.get('comment_btn_mod_delete') + '</a>';
   205   
   212   
   206   var tplbool = new Object();
   213   var tplbool = new Object();
   207   
   214   
   208   tplbool.signature = ( this_comment.signature == '' ) ? false : true;
   215   tplbool.signature = ( this_comment.signature == '' ) ? false : true;
   209   tplbool.can_edit = ( data.auth_edit_comments && ( ( this_comment.user_id == data.user_id && data.logged_in ) || data.auth_mod_comments ) );
   216   tplbool.can_edit = ( data.auth_edit_comments && ( ( this_comment.user_id == data.user_id && data.logged_in ) || data.auth_mod_comments ) );
   253   ta.value = src;
   260   ta.value = src;
   254   ta.id = 'comment_edit_'+id;
   261   ta.id = 'comment_edit_'+id;
   255   cmt.appendChild(ta);
   262   cmt.appendChild(ta);
   256   
   263   
   257   link.style.fontWeight = 'bold';
   264   link.style.fontWeight = 'bold';
   258   link.innerHTML = 'save';
   265   link.innerHTML = $lang.get('comment_btn_save');
   259   link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); saveComment(id, this); return false; };
   266   link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); saveComment(id, this); return false; };
   260 }
   267 }
   261 
   268 
   262 function saveComment(id, link)
   269 function saveComment(id, link)
   263 {
   270 {
   271     'local_id' : id,
   278     'local_id' : id,
   272     'data' : data,
   279     'data' : data,
   273     'subj' : subj
   280     'subj' : subj
   274   };
   281   };
   275   link.style.fontWeight = 'normal';
   282   link.style.fontWeight = 'normal';
   276   link.innerHTML = 'edit';
   283   link.innerHTML = $lang.get('comment_btn_edit');
   277   link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); editComment(id, this); return false; };
   284   link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); editComment(id, this); return false; };
   278   ajaxComments(req);
   285   ajaxComments(req);
   279 }
   286 }
   280 
   287 
   281 function deleteComment(id)
   288 function deleteComment(id)
   282 {
   289 {
   283   if ( !shift )
   290   if ( !shift )
   284   {
   291   {
   285     var c = confirm('Do you really want to delete this comment?');
   292     var c = confirm($lang.get('comment_msg_delete_confirm'));
   286     if(!c)
   293     if(!c)
   287       return false;
   294       return false;
   288   }
   295   }
   289   var div = document.getElementById('comment_holder_'+id);
   296   var div = document.getElementById('comment_holder_'+id);
   290   var real_id = div.getElementsByTagName('input')[0]['value'];
   297   var real_id = div.getElementsByTagName('input')[0]['value'];
   338   {
   345   {
   339     document.getElementById('subject_' + data.id).innerHTML = data.subj;
   346     document.getElementById('subject_' + data.id).innerHTML = data.subj;
   340   }
   347   }
   341   if ( data.approved && data.approved != '1' )
   348   if ( data.approved && data.approved != '1' )
   342   {
   349   {
   343     document.getElementById('subject_' + data.id).innerHTML += ' <span style="color: #D84308">(Unapproved)</span>';
   350     document.getElementById('subject_' + data.id).innerHTML += ' <span style="color: #D84308">' + $lang.get('comment_msg_note_unapp') + '</span>';
   344   }
   351   }
   345   if ( data.approved && ( typeof(data.approve_updated) == 'string' && data.approve_updated == 'yes' ) )
   352   if ( data.approved && ( typeof(data.approve_updated) == 'string' && data.approve_updated == 'yes' ) )
   346   {
   353   {
   347     var appr = ( data.approved == '1' ) ? 'Unapprove' : 'Approve';
   354     var appr = ( data.approved == '1' ) ? $lang.get('comment_btn_mod_unapprove') : $lang.get('comment_btn_mod_approve');
   348     document.getElementById('comment_approve_'+data.id).innerHTML = appr;
   355     document.getElementById('comment_approve_'+data.id).innerHTML = appr;
   349     
   356     
   350     // Update approval status
   357     if ( data.approved == '1' )
   351     var p = document.getElementById('comment_status');
   358       comment_decrement_unapproval();
   352     var count = p.firstChild.nodeValue.split(' ')[2];
       
   353     
       
   354     if ( p.firstChild.nextSibling )
       
   355     {
       
   356       var span = p.firstChild.nextSibling;
       
   357       var is = ( data.approved == '1' ) ? -1 : 1;
       
   358       var n_unapp = parseInt(span.firstChild.nodeValue.split(' ')[0]) + is;
       
   359       n_unapp = n_unapp + '';
       
   360     }
       
   361     else
   359     else
   362     {
   360       comment_increment_unapproval();
   363       var span = document.createElement('span');
       
   364       p.innerHTML += ' ';
       
   365       span.innerHTML = ' ';
       
   366       span.style.color = '#D84308';
       
   367       var n_unapp = '1';
       
   368       p.appendChild(span);
       
   369     }
       
   370     span.innerHTML = n_unapp + ' of those are unapproved.';
       
   371     if ( n_unapp == '0' )
       
   372       p.removeChild(span);
       
   373   }
   361   }
   374   if ( data.text )
   362   if ( data.text )
   375   {
   363   {
   376     document.getElementById('comment_' + data.id).innerHTML = data.text;
   364     document.getElementById('comment_' + data.id).innerHTML = data.text;
   377   }
   365   }
   394 }
   382 }
   395 
   383 
   396 // Does the actual DOM object removal
   384 // Does the actual DOM object removal
   397 function annihiliateComment(id) // Did I spell that right?
   385 function annihiliateComment(id) // Did I spell that right?
   398 {
   386 {
   399   // Approved?
   387   var approved = true;
   400   var p = document.getElementById('comment_status');
       
   401   
       
   402   if(document.getElementById('comment_approve_'+id))
   388   if(document.getElementById('comment_approve_'+id))
   403   {
   389   {
   404     var appr = document.getElementById('comment_approve_'+id).firstChild.nodeValue;
   390     var appr = document.getElementById('comment_approve_'+id).firstChild.nodeValue;
   405     if ( p.firstChild.nextSibling && appr == 'Approve' )
   391     if ( appr == $lang.get('comment_btn_mod_approve') )
   406     {
   392     {
   407       var span = p.firstChild.nextSibling;
   393       approved = false;
   408       var t = span.firstChild.nodeValue;
       
   409       var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1;
       
   410       if ( n_unapp == 0 )
       
   411         p.removeChild(span);
       
   412       else
       
   413         span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' '));
       
   414     }
   394     }
   415   }
   395   }
   416   
   396   
   417   var div = document.getElementById('comment_holder_'+id);
   397   var div = document.getElementById('comment_holder_'+id);
   418   div.parentNode.removeChild(div);
   398   div.parentNode.removeChild(div);
   419   var t = p.firstChild.nodeValue.split(' ');
   399   
   420   t[2] = ( parseInt(t[2]) - 1 ) + '';
   400   // update approval status
   421   delete(t.toJSONString);
   401   if ( document.getElementById('comment_count_unapp_inner') && !approved )
   422   if ( t[2] == '1' )
   402   {
   423   {
   403     comment_decrement_unapproval();
   424     t[1] = 'is';
   404   }
   425     t[3] = 'comment';
       
   426   }
       
   427   else
       
   428   {
       
   429     t[1] = 'are';
       
   430     t[3] = 'comments';
       
   431   }
       
   432   t = implode(' ', t);
       
   433   p.firstChild.nodeValue = t;
       
   434 }
   405 }
   435 
   406 
   436 function materializeComment(data)
   407 function materializeComment(data)
   437 {
   408 {
   438   // Intelligently get an ID
   409   // Intelligently get an ID
   463   tplvars.NAME = data.name;
   434   tplvars.NAME = data.name;
   464   if ( data.user_id > 1 )
   435   if ( data.user_id > 1 )
   465     tplvars.NAME = '<a href="' + makeUrlNS('User', data.name) + '">' + data.name + '</a>';
   436     tplvars.NAME = '<a href="' + makeUrlNS('User', data.name) + '">' + data.name + '</a>';
   466   
   437   
   467   if ( data.approved != '1' )
   438   if ( data.approved != '1' )
   468     tplvars.SUBJECT += ' <span style="color: #D84308">(Unapproved)</span>';
   439     tplvars.SUBJECT += ' <span style="color: #D84308">' + $lang.get('comment_msg_note_unapp') + '</span>';
   469   
   440   
   470   // User level
   441   // User level
   471   tplvars.USER_LEVEL = 'Guest';
   442   tplvars.USER_LEVEL = $lang.get('user_type_guest');
   472   if ( data.user_level >= data.user_level_list.member ) tplvars.USER_LEVEL = 'Member';
   443   if ( data.user_level >= data.user_level_list.member ) tplvars.USER_LEVEL = $lang.get('user_type_member');
   473   if ( data.user_level >= data.user_level_list.mod ) tplvars.USER_LEVEL = 'Moderator';
   444   if ( data.user_level >= data.user_level_list.mod ) tplvars.USER_LEVEL = $lang.get('user_type_mod');
   474   if ( data.user_level >= data.user_level_list.admin ) tplvars.USER_LEVEL = 'Administrator';
   445   if ( data.user_level >= data.user_level_list.admin ) tplvars.USER_LEVEL = $lang.get('user_type_admin');
   475   
   446   
   476   // Send PM link
   447   // Send PM link
   477   tplvars.SEND_PM_LINK=(data.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( data.name.replace(/ /g, '_') )) +'">Send private message</a><br />':'';
   448   tplvars.SEND_PM_LINK=(data.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( data.name.replace(/ /g, '_') )) +'">' + $lang.get('comment_btn_send_privmsg') + '</a><br />':'';
   478   
   449   
   479   // Add buddy link
   450   // Add buddy link
   480   tplvars.ADD_BUDDY_LINK=(data.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( data.name.replace(/ /g, '_') )) +'">Add to buddy list</a><br />':'';
   451   tplvars.ADD_BUDDY_LINK=(data.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( data.name.replace(/ /g, '_') )) +'">' + $lang.get('comment_btn_add_buddy') + '</a><br />':'';
   481   
   452   
   482   // Edit link
   453   // Edit link
   483   tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">edit</a>';
   454   tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">' + $lang.get('comment_btn_edit') + '</a>';
   484   
   455   
   485   // Delete link
   456   // Delete link
   486   tplvars.DELETE_LINK='<a href="#delete_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">delete</a>';
   457   tplvars.DELETE_LINK='<a href="#delete_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">' + $lang.get('comment_btn_delete') + '</a>';
   487   
   458   
   488   // Moderation: (Un)approve link
   459   // Moderation: (Un)approve link
   489   var appr = ( data.approved == 1 ) ? 'Unapprove' : 'Approve';
   460   var appr = ( data.approved == 1 ) ? $lang.get('comment_btn_mod_unapprove') : $lang.get('comment_btn_mod_approve');
   490   tplvars.MOD_APPROVE_LINK='<a href="#approve_'+i+'" id="comment_approve_'+i+'" onclick="approveComment(\''+i+'\'); return false;">'+appr+'</a>';
   461   tplvars.MOD_APPROVE_LINK='<a href="#approve_'+i+'" id="comment_approve_'+i+'" onclick="approveComment(\''+i+'\'); return false;">'+appr+'</a>';
   491   
   462   
   492   // Moderation: Delete post link
   463   // Moderation: Delete post link
   493   tplvars.MOD_DELETE_LINK='<a href="#mod_del_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">Delete</a>';
   464   tplvars.MOD_DELETE_LINK='<a href="#mod_del_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">' + $lang.get('comment_btn_mod_delete') + '</a>';
   494   
   465   
   495   var tplbool = new Object();
   466   var tplbool = new Object();
   496   
   467   
   497   tplbool.signature = ( data.signature == '' ) ? false : true;
   468   tplbool.signature = ( data.signature == '' ) ? false : true;
   498   tplbool.can_edit = ( data.auth_edit_comments && ( ( data.user_id == data.user_id && data.logged_in ) || data.auth_mod_comments ) );
   469   tplbool.can_edit = ( data.auth_edit_comments && ( ( data.user_id == data.user_id && data.logged_in ) || data.auth_mod_comments ) );
   517     aec.insertBefore(div, aec.firstChild.nextSibling.nextSibling);
   488     aec.insertBefore(div, aec.firstChild.nextSibling.nextSibling);
   518   }
   489   }
   519   
   490   
   520   document.getElementById('comment_source_'+i).value = data.comment_source;
   491   document.getElementById('comment_source_'+i).value = data.comment_source;
   521   
   492   
   522   var p = document.getElementById('comment_status');
   493   var cnt = document.getElementById('comment_count_inner').innerHTML;
   523   var t = p.firstChild.nodeValue.split(' ');
   494   cnt = parseInt(cnt);
   524   var n = ( isNaN(parseInt(t[2])) ) ? 0 : parseInt(t[2]);
   495   if ( isNaN(cnt) )
   525   t[2] = ( n + 1 ) + '';
   496     cnt = 0;
   526   delete(t.toJSONString);
   497   
   527   if ( t[2] == '1' )
   498   var subst = {
   528   {
   499     num_comments: cnt,
   529     t[1] = 'is';
   500     page_type: ENANO_PAGE_TYPE
   530     t[3] = 'comment';
   501   }
       
   502   
       
   503   var count_msg = ( cnt == 0 ) ? $lang.get('comment_msg_count_zero', subst) : ( ( cnt == 1 ) ? $lang.get('comment_msg_count_one', subst) : $lang.get('comment_msg_count_plural', subst) );
       
   504   
       
   505   document.getElementById('comment_status').firstChild.innerHTML = count_msg;
       
   506   
       
   507   if(document.getElementById('comment_approve_'+i))
       
   508   {
       
   509     var is_unappr = document.getElementById('comment_approve_'+i).firstChild.nodeValue;
       
   510     is_unappr = ( is_unappr == $lang.get('comment_btn_mod_approve') );
       
   511     if ( is_unappr )
       
   512     {
       
   513       comment_increment_unapproval();
       
   514     }
       
   515   }
       
   516   
       
   517 }
       
   518 
       
   519 function comment_decrement_unapproval()
       
   520 {
       
   521   if ( document.getElementById('comment_count_unapp_inner') )
       
   522   {
       
   523     var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML);
       
   524     if ( !isNaN(num_unapp) )
       
   525     {
       
   526       num_unapp = num_unapp - 1;
       
   527       if ( num_unapp == 0 )
       
   528       {
       
   529         var p = document.getElementById('comment_status');
       
   530         p.removeChild(p.childNodes[2]);
       
   531         p.removeChild(p.childNodes[1]);
       
   532       }
       
   533       else
       
   534       {
       
   535         var count_msg = $lang.get('comment_msg_count_unapp_mod', { num_unapp: num_unapp });
       
   536         document.getElementById('comment_count_unapp_inner').parentNode.innerHTML = count_msg;
       
   537       }
       
   538     }
       
   539   }
       
   540 }
       
   541 
       
   542 function comment_increment_unapproval()
       
   543 {
       
   544   if ( document.getElementById('comment_count_unapp_inner') )
       
   545   {
       
   546     var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML);
       
   547     if ( isNaN(num_unapp) )
       
   548       num_unapp = 0;
       
   549     num_unapp = num_unapp + 1;
       
   550     var count_msg = $lang.get('comment_msg_count_unapp_mod', { num_unapp: num_unapp });
       
   551     document.getElementById('comment_count_unapp_inner').parentNode.innerHTML = count_msg;
   531   }
   552   }
   532   else
   553   else
   533   {
   554   {
   534     t[1] = 'are';
   555     var count_msg = $lang.get('comment_msg_count_unapp_mod', { num_unapp: 1 });
   535     t[3] = 'comments';
   556     var status = document.getElementById('comment_status');
   536   }
   557     if ( !status.childNodes[1] )
   537   t = implode(' ', t);
   558       status.appendChild(document.createTextNode(' '));
   538   p.firstChild.nodeValue = t;
   559     var span = document.createElement('span');
   539   
   560     span.id = 'comment_status_unapp';
   540   if(document.getElementById('comment_approve_'+i))
   561     span.style.color = '#D84308';
   541   {
   562     span.innerHTML = count_msg;
   542     var appr = document.getElementById('comment_approve_'+i).firstChild.nodeValue;
   563     status.appendChild(span);
   543     if ( p.firstChild.nextSibling && appr == 'Approve' )
   564   }
   544     {
       
   545       var span = p.firstChild.nextSibling;
       
   546       var t = span.firstChild.nodeValue;
       
   547       var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1;
       
   548       if ( n_unapp == 0 )
       
   549         p.removeChild(span);
       
   550       else
       
   551         span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' '));
       
   552     }
       
   553     else if ( appr == 'Approve' && !p.firstChild.nextSibling )
       
   554     {
       
   555       var span = document.createElement('span');
       
   556       p.innerHTML += ' ';
       
   557       span.innerHTML = '1 of those are unapproved.';
       
   558       span.style.color = '#D84308';
       
   559       var n_unapp = '1';
       
   560       p.appendChild(span);
       
   561     }
       
   562   }
       
   563   
       
   564 }
   565 }
   565 
   566 
   566 function htmlspecialchars(text)
   567 function htmlspecialchars(text)
   567 {
   568 {
   568   text = text.replace(/</g, '&lt;');
   569   text = text.replace(/</g, '&lt;');