function index($table, $post_id, $params) { $comment_model = D("Common/Comments"); $comments = $comment_model->where(array("post_table" => $table, "post_id" => $post_id, "status" => 1))->order("createtime ASC")->select(); $new_comments = array(); $parent_comments = array(); if (!empty($comments)) { foreach ($comments as $m) { if ($m['parentid'] == 0) { $new_comments[$m['id']] = $m; } else { $path = explode("-", $m['path']); $new_comments[$path[1]]['children'][] = $m; } $parent_comments[$m['id']] = $m; } } $data['post_table'] = sp_authencode($table); $data['post_id'] = $post_id; $this->assign($data); $this->assign("comments", $new_comments); $this->assign("params", $params); $this->assign("parent_comments", $parent_comments); $tpl = isset($params['tpl']) && !empty($params['tpl']) ? $params['tpl'] : "comment"; return $this->fetch(":{$tpl}"); }
function index($table, $post_id, $params) { $comment_model = D("Comments"); $comments = $comment_model->where(array("post_table" => $table, "post_id" => $post_id, "status" => 1))->order("createtime DESC")->select(); $data['post_table'] = sp_authencode($table); $data['post_id'] = $post_id; $this->assign($data); $this->assign("comments", $comments); $tpl = isset($params['tpl']) && !empty($params['tpl']) ? $params['tpl'] : "comment"; return $this->fetch(":{$tpl}"); }
/** * 用于生成收藏内容用的key * @param string $table 收藏内容所在表 * @param int $object_id 收藏内容的id */ function sp_get_favorite_key($table, $object_id) { $auth_code = C("AUTHCODE"); $string = "{$auth_code} {$table} {$object_id}"; return sp_authencode($string); }
<form class="form-horizontal comment-form" action="<?php echo u('comment/comment/post'); ?> " method="post"> <div class="control-group"> <div class="comment-postbox-wraper"> <textarea class="form-control comment-postbox" placeholder="Write your comment here" style="min-height:90px;" name="content"></textarea> </div> </div> <div class="control-group"> <button type="submit" class="btn pull-right btn-primary J_ajax_submit_btn"><i class="fa fa-comment-o"></i> 发表评论</button> </div> <input type="hidden" name="post_table" value="<?php echo sp_authencode('posts'); ?> "/> <input type="hidden" name="post_id" value="<?php echo $post_id; ?> "/> <input type="hidden" name="to_uid" value="0"/> <input type="hidden" name="parentid" value="0"/> </form> <script class="comment-tpl" type="text/html"> <div class="comment" data-username="******"user_nicename"]; ?> " data-uid="<?php