Yii隱藏URL中index.php的方法
688
2024-01-30
自己寫(xiě)的一個(gè)評(píng)論系統(tǒng)源碼分享給大家,包括有表情,還有評(píng)論機(jī)制。用戶名是隨機(jī)的
針對(duì)某一篇文章進(jìn)行評(píng)論
function subcomment() { $data['uid'] = getUserid(); $data['mtype'] = I("post.mtype", 0, 'int'); if ($data['uid'] == '') { echo json_encode(array("code" => -1)); } else { $content = addslashes(str_replace("n", "<br />", $_POST['content'])); $data['tid'] = I("post.id", 0, 'int'); //文章id if (strlen(preg_replace('/[ [^)]+? ]/x', '', $content)) < 10) { echo json_encode(array("code" => "short than 10", "error" => "評(píng)論的內(nèi)容不能少于10個(gè)字符。")); exit; } if (C("DB_PWD") != '') { if (time() - session("comment_time") < 60 && session("comment_time") > 0) {//2分鐘以后發(fā)布 echo json_encode(array("code" => "fast", "error" => "您提交評(píng)論的速度太快了,請(qǐng)稍后再發(fā)表評(píng)論。")); exit; } } $data['pid'] = I("post.pid", 0, 'int'); $data['pid_sub'] = I("post.pid_sub", 0, 'int'); $lyid = $data['pid_sub'] > 0 ? $data['pid_sub'] : $data['pid']; if ($lyid > 0) { $lyinfo = M("comment")->field("uid")->where("id='" . $lyid . "'")->find(); $data['touid'] = $lyinfo['uid']; } else { $data['touid'] = 2; } $data['addtime'] = time(); $emots = getTableFile("emot"); foreach ($emots as $v) { $content = str_replace("[" . $v['name'] . "]", "<img alt='" . $v['name'] . "' src='http://www.gimoo.net/t/1807/5b4c59697c962.html" . __APP__ . "/Public/emot/" . ($v['id'] - 1) . ".gif'>", $content); } $data['content'] = addslashes($content); $info = M("comment")->field("id")->where("content='" . $data['content'] . "'")->find(); if ($info['id']) { echo json_encode(array("code" => "comment_repeat", "error" => "檢測(cè)到重復(fù)評(píng)論,您似乎提交過(guò)這條評(píng)論了")); exit; } $lastid = M("comment")->add($data); $points_comment = 20; if ($lastid > 0) { $day_start = strtotime(date("Y-m-d")); $day_end = $day_start + 3600 * 24; $comment_num_day = M("comment")->where("uid = " . $data['uid'] . " AND addtime between " . $day_start . " AND " . $day_end . "")->count(); if ($comment_num_day <= 5) { //少于5條每天,則添加積分 // addPoints("comment", $points_comment, $data['uid'], "評(píng)論獲得" . $points_comment . "積分", 5, 1); } // addMessage('comment', $data['tid'], $data['pid'], $data['mtype'], $data['touid'], $content); } session("comment_time", time()); echo json_encode(array("code" => 200, "comment" => $content, "points" => $points_comment)); } }
根據(jù)分頁(yè)參數(shù)獲取對(duì)應(yīng)評(píng)論列表
function comments() { $id = I("get.id", 0, 'int'); $mtype = I("get.mtype", 1, 'int'); $page = I("get.page", 1, "int"); $totalnum = I("get.totalnum", 1, "int"); $start = 10 * ($page - 1); $sql = "tid = " . $id . " AND pid = 0"; $comments = M("comment")->field("id,uid,content,addtime")->where($sql)->order("id DESC")->limit($start . ",10")->select(); // echo M("comment")->getlastsql(); foreach ($comments as $k => $v) { $comments[$k]['sub'] = M("comment")->field("id,uid,content,pid_sub")->where("tid = " . $id . " AND pid = " . $v['id'] . "")->order("id ASC")->select(); } $this->assign("id", $id); $this->assign("mtype", $mtype); $this->assign("comments", $comments); $this->assign("comments_num", $totalnum - ($page - 1) * 10); $this->display(); }
切換評(píng)論分頁(yè)
if ($("#detail-page").length > 0) { var id = $("#detail-page").attr("data-id"); var mtype = $("#detail-page").attr("data-mtype"); var totalnum = $("#detail-page").attr("data-totalnum"); $("#detail-page").children("a").click(function() { var page = parseInt($(this).attr("data-page")); $("#detail-page").children("a").removeClass("current"); $("#detail-page").children("a").eq(page - 1).addClass("current"); $("#comment_list").html("<div style='padding:20px 0;text-align:center;'><img src='http://www.gimoo.net/t/1807/5b4c59697c962.html" + site_url + "Public/images/loading.gif'></div>"); $.get(getUrl("Box/comments"), { page: page, id: id, totalnum: totalnum, mtype: mtype }, function(data) { $("#comment_list").html(data) }) }) }
評(píng)論表和表情表已放在壓縮包里
CREATE TABLE IF NOT EXISTS `sucai_comment` ( `id` int(11) NOT NULL AUTO_INCREMENT, `uid` int(11) NOT NULL, `touid` int(11) DEFAULT '0', `pid_sub` int(11) DEFAULT '0', `tid` int(11) NOT NULL, `pid` int(11) DEFAULT '0', `mtype` tinyint(1) NOT NULL, `content` text NOT NULL, `addtime` int(10) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5560 ;
功能實(shí)現(xiàn)和demo原址:www.erdangjiade.com/js/816.html
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請(qǐng)用戶自負(fù)。本站信息來(lái)自網(wǎng)絡(luò)收集整理,版權(quán)爭(zhēng)議與本站無(wú)關(guān)。您必須在下載后的24個(gè)小時(shí)之內(nèi),從您的電腦或手機(jī)中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請(qǐng)支持正版,購(gòu)買(mǎi)注冊(cè),得到更好的正版服務(wù)。我們非常重視版權(quán)問(wèn)題,如有侵權(quán)請(qǐng)郵件[admin@lxwl520.com]與我們聯(lián)系進(jìn)行刪除處理。敬請(qǐng)諒解!