// 入库过滤 非管理员全部过滤
$post['message'] = isset($post['gid']) && 1 == $post['gid'] ? $post['message'] : xn_html_safe($post['message']);
break;
case '1':
$post['message'] = xn_txt_to_html($post['message']);
break;
default:
$post['message'] = htmlspecialchars($post['message'], ENT_QUOTES); // html标签全部转换
break;
}
// 对引用进行处理
!empty($post['quotepid']) && $post['quotepid'] > 0 && $post['message'] = comment_quote($post['quotepid']) . $post['message'];
}
unset($post['gid']);
}
/*公用的附件模板,采用函数,效率比 include 高
* @param $filelist 附件列表
* @param bool $include_delete 删除
* @param bool $access TRUE编辑时附件路径
* @param bool $path TRUE后台编辑时附件路径
* @return string
*/
function data_file_list_html($filelist, $include_delete = FALSE, $access = FALSE, $path = FALSE)
{
global $conf;
if (empty($filelist)) return '';
if (FALSE != $path) {
if ($conf['url_rewrite_on'] > 1) {
$path = $conf['path'];
} else {
$path = '../';
}
} else {
$path = '';
}
$s = '
' . "\r\n";
return $s;
}
//--------------------------cache--------------------------
// 从缓存中读取,避免重复从数据库取数据
function data_read_cache($tid)
{
global $conf;
$key = 'website_data_' . $tid;
static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,要跨进程,可以再加一层缓存: memcached/xcache/apc/
if (isset($cache[$key])) return $cache[$key];
if ('mysql' == $conf['cache']['type']) {
$r = data_read($tid);
} else {
$r = cache_get($key);
if (NULL === $r) {
$r = data_read($tid);
$r and cache_set($key, $r, 1800); // 30分钟
}
}
$cache[$key] = $r ? $r : NULL;
return $cache[$key];
}
?>H-软件玩家 - 软件改变生活!
H
总共两个表
- 聊天记录表
- 最近联系人表
私聊
实现思路:
- 进入聊天界面发送消息且成功后,将此好友添加到最近联系人,且注明是用户
- 点击发送后,将本聊天记录存入本人和好友的聊天记录数据库中,默认isme=true,表明此消息是本人发送.
数据库设计:
聊天记录表
- 设置两个用户id, 分别指向本人和好友的id,将两人聊天记录设为数组,每发一条存一条
- 双方取消息的时候,看消息是不是发给自己的,如果是,设isme = false,表明这是好友发来的消息且设置消息状态为未读
最近联系人表
- 当发送方发送消息后,将好友的信息显示到最近联系人,内容包括好友的头像,用户名,最新一条消息,发送时间,以及未读的消息数
- 接收方接收到消息后,自动将发送方的消息存入到最近联系人列表中,且置顶
群聊
和私聊大致思路差不多
- 进入群发送消息后,将此群加入最近联系人中,且置顶,
- 所有该群的成员也将该群置顶,且显示最新的消息
- 将发送的消息存入到这个群的数据库中
数据库设计
- 用户的最近联系人表同上
- 群表:包括群名,群id,群成员,聊天记录
- 聊天记录形式为:发送的用户的昵称、头像,发送的内容,发送的时间
本文标签:
h
发表评论