这个说说功能是我最早参考http://www.qianbao666.com来制作的,现在该网站已经没有这功能了。后来被我应用到订餐网站了http://www.17ord.com/Say/index.html,需要订餐源码的联系我,2000元整站功能,带多店铺订餐、留言、抽奖、和后台管理。
0、请不要问“在不在”之类的问题,有问题直接问!1、学生或暂时没有工作的童鞋,整站资源免费下载!2、¥9.9充值终身VIP会员,加我微信,826096331 拉你进VIP群学习!3、程序员加油,技术改变世界。在线 充值
首先遍历最顶级说说和下级说说。
SESSION_START();
include_once("connect.php");
include_once("function.php");
require_once('page.class.php'); //分页类
$showrow = 10; //一页显示的行数
$curpage = empty($_GET['page']) ? 1 : $_GET['page']; //当前的页,还应该处理非数字的情况
$url = "?page={page}"; //分页地址,如果有检索条件 ="?page={page}&q=".$_GET['q']
//省略了链接mysql的代码,测试时自行添加
$sql = "SELECT * FROM say WHERE pid = 0 ORDER BY id DESC";
$total = mysql_num_rows(mysql_query($sql)); //记录总条数
if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow))
$curpage = ceil($total_rows / $showrow); //当前页数大于最后页数,取最后一页
//获取数据
$sql .= " LIMIT " . ($curpage - 1) * $showrow . ",$showrow;";
$query = mysql_query($sql);
$i = 0;
$lists = array();
while ($row = mysql_fetch_array($query)) {
$lists[] = $row;
$query2 = mysql_query("SELECT * FROM say WHERE pid = " . $row['id'] . " ORDER BY id DESC");
while ($row2 = mysql_fetch_array($query2)) {
$lists[$i]['sub'][] = $row2;
}
$i++;
}
引入说说文件say.css,分页page.css,jquery库,表情插入光标textarea.js和表情插件jquery.qqFace.js
<link href="css/say.css" type="text/css" rel="Stylesheet" />
<link href="css/page.css" type="text/css" rel="Stylesheet" />
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="js/textarea.js"></script>
<script type="text/javascript" src="js/jquery.qqFace.js"></script>
发布说说
function saysub(pid) {
var con = $('#saybox_0').val();
var len = con.length;
if (len == 0) {
alert("发布内容不能为空!");
return false;
}
if (len > 140) {
alert("发布内容不能超过140字!");
return false;
}
$.post("ajax.php", {
con: con,
pid: pid
},
function(data) {
if (data == -1) {
checkUserLogin();
return false;
}
location.href = 'http://www.erdangjiade.com/jquery/demo/2/248/';//成功后跳转到说说首页
})
}
留言和回复基本上和说说类似。
替换表情函数
function replace_em(str) {
str = str.replace(/\</g, '<');
str = str.replace(/\>/g, '>');
str = str.replace(/\n/g, '<br/>');
str = str.replace(/\[em_([0-9]*)\]/g, '<img src="face/$1.gif" border="0" />');
return str;
}
文本框字符数判断
function checknum(v, word) {
var len = 140 - v.length;
$('#sayword_' + word).text(len);
if (len < 0) {
$('#sayword_' + word).css({
"color": "red"
});
}
}
表情插件调用
function emotion(div, id) {
$('#' + div).qqFace({
id: 'facebox',
//表情盒子的ID
assign: 'saybox_' + id + '',
//给那个控件赋值
path: 'face/' //表情存放的路径
});
}
遍历子级回复
function get_str($id = 0, $level = 0) {
global $str;
$sql = "select* FROM say where pid= $id";
$result = mysql_query($sql); //查询pid的子类的分类
if ($result && mysql_affected_rows()) {//如果有子类
$level++;
while ($row = mysql_fetch_array($result)) { //循环记录集
$str .= "<dd id='dd_" . $row['id'] . "' style='padding-left:" . ($level * 42) . "px'>
<div class='userPic30'>
<img src='http://www.erdangjiade.com/other/avatar/dir/" . $row['uid'] . ".jpg'>
</div>
<div class='userTalkFont2'>
<p>
<span class='org'>" . $row['uname'] . "</span>
" . ubbReplace($row['content']) . "
</p>
<h4>
" . tranTime($row['addtime']) . "
<a class='org' onclick=reply('" . $row['id'] . "')>回复</a>
</h4>
</div>
</dd>";
get_str($row['id'], $level); //调用get_str(),将记录集中的id参数传入函数中,继续查询下级
}
}
return $str;
}
PHP替换表情
function ubbReplace($str) {
$str = str_replace("<", '<;', $str);
$str = str_replace(">", '>;', $str);
$str = str_replace("\n", '>;br/>;', $str);
$str = preg_replace("[\[em_([0-9]*)\]]", "<img src=\"face/$1.gif\" />", $str);
return $str;
}
PHP“刚刚”、“几分钟前”、“昨天”、“前天”等时间函数
function tranTime($time) {
$rtime = date("m-d H:i", $time);
$htime = date("H:i", $time);
$time = time() - $time;
if ($time < 60) {
$str = '刚刚';
} elseif ($time < 60 * 60) {
$min = floor($time / 60);
$str = $min . '分钟前';
} elseif ($time < 60 * 60 * 24) {
$h = floor($time / (60 * 60));
$str = $h . '小时前 ' . $htime;
} elseif ($time < 60 * 60 * 24 * 3) {
$d = floor($time / (60 * 60 * 24));
if ($d == 1)
$str = '昨天 ' . $rtime;
else
$str = '前天 ' . $rtime;
}
else {
$str = $rtime;
}
return $str;
}
这篇说说功能较多,有bug请留言,我们会及时处理。
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群