uchome2.0 日志评论模块分析(php代码及js代码分析)

首先是评论表单
文件:template\default\space_blog_view.htm
代码:
<form id="quickcommentform_{$id}" name="quickcommentform_{$id}" action="cp.php?ac=comment" method="post" class="quickpost">
   <table cellpadding="0" cellspacing="0">
    <tr>
     <td>
      <a href="###" id="comment_face" title="插入表情" onclick="showFace(this.id, 'comment_message');return false;"><img src="image/facelist.gif" align="absmiddle" /></a>
      <!--{if $_SGLOBAL['magic']['doodle']}-->
      <a id="a_magic_doodle" href="magic.php?mid=doodle&showid=comment_doodle&target=comment_message" this.id, 1)"><img src="image/magic/doodle.small.gif" class="magicicon" />涂鸦板</a>
      <!--{/if}-->
      <br />
      <textarea id="comment_message" onkeydown="ctrlEnter(event, 'commentsubmit_btn');" name="message" rows="5" style="width:500px;"></textarea>
     </td>
    </tr>
    <tr>
     <td>
      <input type="hidden" name="refer" value="space.php?uid=$blog[uid]&do=$do&id=$id" />
      <input type="hidden" name="id" value="$id">
      <input type="hidden" name="idtype" value="blogid">
      <input type="hidden" name="commentsubmit" value="true" />
      <input type="button" id="commentsubmit_btn" name="commentsubmit_btn" class="submit" value="评论" 'comment_add')" />
      <div id="__quickcommentform_{$id}"></div>
     </td>
    </tr>
   </table>
  <input type="hidden" name="formhash" value="<!--{eval echo formhash();}-->" /></form>
然后点击评论按钮调用 'comment_add')"
文件:source\script_ajax.js
代码:
function ajaxpost(formid, func, timeout) {
 showloading();
 
 if(ajaxpostHandle != 0) {
  return false;
 }
 var ajaxframeid = 'ajaxframe';
 var ajaxframe = $(ajaxframeid);
 if(ajaxframe == null) {
  if (is_ie && !is_opera) {
   ajaxframe = document.createElement("<iframe name='" + ajaxframeid + "' id='" + ajaxframeid + "'></iframe>");
  } else {
   ajaxframe = document.createElement("iframe");
   ajaxframe.name = ajaxframeid;
   ajaxframe.id = ajaxframeid;
  }
  ajaxframe.style.display = 'none';
  $('append_parent').appendChild(ajaxframe);
 }
 $(formid).target = ajaxframeid;
 $(formid).action = $(formid).action + '&inajax=1';
 
 ajaxpostHandle = [formid, func, timeout];
 
 if(ajaxframe.attachEvent) {
  ajaxframe.detachEvent (' ajaxpost_load);
  ajaxframe.attachEvent(' ajaxpost_load);
 } else {
  document.removeEventListener('load', ajaxpost_load, true);
  ajaxframe.addEventListener('load', ajaxpost_load, false);
 }
 
 $(formid).submit();
 return false;
}
然后通过ajaxpostHandle = [formid, func, timeout];调用
文件:source\script_manage.js
代码:
function comment_add(id, result) {
 if(result) {
  var obj = $('comment_ul');
  var newli = document.createElement("div");
  var x = new Ajax();
  x.get('do.php?ac=ajax&op=comment', function(s){
   newli.innerHTML = s;
  });
  if($('comment_prepend')){
   obj = obj.firstChild;
   while (obj && obj.nodeType != 1){
    obj = obj.nextSibling;
   }
   obj.parentNode.insertBefore(newli, obj);
  } else {
   obj.appendChild(newli);
  }
  if($('comment_message')) {
   $('comment_message').value= '';
  }
  if($('comment_replynum')) {
   var a = parseInt($('comment_replynum').innerHTML);
   var b = a + 1;
   $('comment_replynum').innerHTML = b + '';
  }
  //提示获得积分
  showreward();
 }
}
然后通过ajax方法
  x.get('do.php?ac=ajax&op=comment', function(s){
   newli.innerHTML = s;
  });
提交到'do.php?ac=ajax&op=comment'此路径下
文件:source\do_ajax.php
代码:
if($op == 'comment') {
 $cid = empty($_GET['cid'])?0:intval($_GET['cid']);
 
 if($cid) {
  $cidsql = "cid='$cid' AND";
  $ajax_edit = 1;
 } else {
  $cidsql = '';
  $ajax_edit = 0;
 }

 //评论
 $list = array();
 $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname($ttb)." WHERE $cidsql authorid='$_SGLOBAL[supe_uid]' ORDER BY dateline DESC LIMIT 0,1");
 while ($value = $_SGLOBAL['db']->fetch_array($query)) {
  realname_set($value['authorid'], $value['author']);
  $list[] = $value;
 }
 
 realname_get();
 
}
返回提交的评论

本文出自 “代军-互联网专家” 博客,谢绝转载!

你可能感兴趣的:(PHP,代码,日志,评论,2.0,uchome)