木漏茶室源码下载中心
整站 PHP 源码:可浏览文件、复制路径、下载单文件或打包 ZIP。
发布版本 v6.25.232
升级后自动生成独立源码包,下载中心只发送这份冻结包
已排除 config.php / 用户数据 / 上传文件 / 升级备份
COMMUNITY DEPLOYMENTS
已经跑起来的木漏茶室
从源码下载中心下载、完成安装并回传验证的站外站点。每个站点只计 1 次部署下载量;已记录站点会实时读取名称、版本、Logo 与在线状态,本机、内网和证书异常站点无法完成回传。
实时检测
2
个站点已部署
木
木漏茶室
mlcs.xnn.lol · v6.25.232
访问 ↗
2026.11.21
在线
木
木漏茶室
mlcs.nbnb.mom · v6.25.232
访问 ↗
2026.11.20
在线
已展示全部 2 个站点。
inc/friends.php
8.7 KB · 发布包 v6.25.232
<?php
/**
* 好友关系与好友会话辅助
*/
function friend_is($userId, $friendId)
{
$userId = (int) $userId;
$friendId = (int) $friendId;
if ($userId <= 0 || $friendId <= 0 || $userId === $friendId) {
return false;
}
return (bool) DB::val('SELECT COUNT(*) FROM ' . DB::table('friends') . ' WHERE user_id = ? AND friend_id = ?', [$userId, $friendId], 0);
}
function friend_add($userId, $friendId)
{
$userId = (int) $userId;
$friendId = (int) $friendId;
if ($userId <= 0 || $friendId <= 0 || $userId === $friendId) {
return false;
}
if (!user_by_id($friendId)) {
return false;
}
if (!friend_is($userId, $friendId)) {
DB::insert('friends', ['user_id' => $userId, 'friend_id' => $friendId, 'remark' => '', 'created_at' => now()]);
}
if (!friend_is($friendId, $userId)) {
DB::insert('friends', ['user_id' => $friendId, 'friend_id' => $userId, 'remark' => '', 'created_at' => now()]);
}
return true;
}
function friend_remark_of($userId, $friendId)
{
return (string) DB::val('SELECT remark FROM ' . DB::table('friends') . ' WHERE user_id = ? AND friend_id = ?', [$userId, $friendId], '');
}
function friend_set_remark($userId, $friendId, $remark)
{
DB::run('UPDATE ' . DB::table('friends') . ' SET remark = ? WHERE user_id = ? AND friend_id = ?',
[mb_substr(trim((string) $remark), 0, 32), (int) $userId, (int) $friendId]);
}
function friend_message_preview($type, $content)
{
$type = (string) $type;
$content = trim((string) $content);
if ($type === 'image') { return '[图片]'; }
if ($type === 'voice') { return '[语音] ' . ($content !== '' ? $content . '″' : ''); }
if ($type === 'video') { return '[视频] ' . $content; }
if ($type === 'audio') { return '[歌曲] ' . $content; }
if ($type === 'file') { return '[文件] ' . $content; }
return $content;
}
function friend_request_get($fromId, $toId)
{
return DB::one('SELECT * FROM ' . DB::table('friend_requests') . ' WHERE from_id = ? AND to_id = ?',
[(int) $fromId, (int) $toId]);
}
function friend_request_status($fromId, $toId)
{
$row = friend_request_get($fromId, $toId);
return $row ? (string) $row['status'] : '';
}
function friend_request_send($fromId, $toId)
{
$fromId = (int) $fromId;
$toId = (int) $toId;
if ($fromId <= 0 || $toId <= 0 || $fromId === $toId) {
return ['ok' => false, 'msg' => '不能添加自己为好友'];
}
$to = user_by_id($toId);
if (!$to) {
return ['ok' => false, 'msg' => '用户不存在'];
}
if ((int) ($to['friend_reject_requests'] ?? 0) === 1) {
return ['ok' => false, 'msg' => '对方已关闭好友申请,暂时不能添加'];
}
if (friend_is($fromId, $toId)) {
return ['ok' => false, 'msg' => '你们已经是好友了'];
}
if (friend_request_status($fromId, $toId) === 'declined'
|| friend_request_status($toId, $fromId) === 'declined') {
return ['ok' => false, 'msg' => '好友请求已被拒绝,不能再次添加'];
}
if (friend_request_status($fromId, $toId) === 'pending') {
return ['ok' => false, 'msg' => '好友请求已发送,等待对方同意'];
}
if (friend_request_status($toId, $fromId) === 'pending') {
return ['ok' => false, 'msg' => '对方已向你发送好友请求,请到通知中心处理'];
}
$existing = friend_request_get($fromId, $toId);
if ($existing) {
DB::run('UPDATE ' . DB::table('friend_requests') . ' SET status = ?, created_at = ? WHERE id = ?',
['pending', now(), (int) $existing['id']]);
$rid = (int) $existing['id'];
} else {
$rid = DB::insert('friend_requests', [
'from_id' => $fromId,
'to_id' => $toId,
'status' => 'pending',
'created_at' => now(),
]);
}
$from = user_by_id($fromId);
notify($toId, $fromId, 'friend_request', $rid, display_name($from) . ' 请求加你为好友');
return ['ok' => true, 'msg' => '好友请求已发送,等待对方同意', 'request_id' => $rid];
}
function friend_request_by_id($requestId)
{
return DB::one('SELECT * FROM ' . DB::table('friend_requests') . ' WHERE id = ?', [(int) $requestId]);
}
function friend_request_accept($requestId, $userId)
{
$req = friend_request_by_id($requestId);
if (!$req || (int) $req['to_id'] !== (int) $userId || $req['status'] !== 'pending') {
return false;
}
friend_add((int) $req['from_id'], (int) $req['to_id']);
DB::run('UPDATE ' . DB::table('friend_requests') . ' SET status = ? WHERE id = ?', ['accepted', (int) $requestId]);
DB::run('UPDATE ' . DB::table('notifications') . ' SET is_read = 1, content = ? WHERE user_id = ? AND type = ? AND target_id = ?',
['已同意好友请求', (int) $userId, 'friend_request', (int) $requestId]);
$user = user_by_id($userId);
notify((int) $req['from_id'], (int) $userId, 'friend_result', (int) $userId, display_name($user) . ' 已同意你的好友请求');
return true;
}
function friend_request_decline($requestId, $userId)
{
$req = friend_request_by_id($requestId);
if (!$req || (int) $req['to_id'] !== (int) $userId || $req['status'] !== 'pending') {
return false;
}
DB::run('UPDATE ' . DB::table('friend_requests') . ' SET status = ? WHERE id = ?', ['declined', (int) $requestId]);
DB::run('UPDATE ' . DB::table('notifications') . ' SET is_read = 1, content = ? WHERE user_id = ? AND type = ? AND target_id = ?',
['已拒绝好友请求', (int) $userId, 'friend_request', (int) $requestId]);
$user = user_by_id($userId);
notify((int) $req['from_id'], (int) $userId, 'friend_result', (int) $userId, display_name($user) . ' 拒绝了好友请求');
return true;
}
function friend_list($userId)
{
$userId = (int) $userId;
$rows = DB::all('SELECT f.friend_id, f.remark, f.created_at AS friend_at,
u.id, u.username, u.nickname, u.avatar, u.verified, u.verify_style, u.verify_title,
u.role, u.status, u.gender
FROM ' . DB::table('friends') . ' f
INNER JOIN ' . DB::table('users') . ' u ON u.id = f.friend_id
WHERE f.user_id = ? AND u.status = 1
ORDER BY f.id DESC', [$userId]);
$out = [];
foreach ($rows as $r) {
$fid = (int) $r['friend_id'];
$last = DB::one('SELECT content, created_at, from_id FROM ' . DB::table('messages') . '
WHERE (from_id = ? AND to_id = ?) OR (from_id = ? AND to_id = ?)
ORDER BY id DESC LIMIT 1', [$userId, $fid, $fid, $userId]);
$unread = (int) DB::val('SELECT COUNT(*) FROM ' . DB::table('messages') . ' WHERE from_id = ? AND to_id = ? AND is_read = 0', [$fid, $userId], 0);
$out[] = [
'id' => $fid,
'name' => trim((string) $r['remark']) !== '' ? (string) $r['remark'] : display_name($r),
'remark' => (string) $r['remark'],
'username' => username_visible($r),
'avatar' => avatar_of($r),
'last' => $last ? plain_excerpt((string) $last['content'], 22) : '',
'time' => $last ? time_ago((string) $last['created_at']) : '',
'last_at' => $last ? (string) $last['created_at'] : (string) $r['friend_at'],
'unread' => $unread,
];
}
usort($out, function ($a, $b) {
return strcmp((string) $b['last_at'], (string) $a['last_at']);
});
return $out;
}
/**
* 好友群发接收者:只发给自己的好友,并跳过开启了「拒收好友群发」的用户。
* $selectedIds 为空表示全部好友,否则只从勾选的好友中发送。
*/
function friend_broadcast_recipients($fromId, array $selectedIds = [])
{
$fromId = (int) $fromId;
if ($fromId <= 0) {
return ['ids' => [], 'skipped' => 0];
}
$friendIds = [];
foreach (DB::all('SELECT friend_id FROM ' . DB::table('friends') . ' WHERE user_id = ?', [$fromId]) as $row) {
$friendIds[(int) $row['friend_id']] = true;
}
$selected = [];
foreach ($selectedIds as $id) {
$id = (int) $id;
if ($id > 0) {
$selected[$id] = true;
}
}
$ids = [];
$skipped = 0;
foreach (array_keys($friendIds) as $fid) {
if ($selected && !isset($selected[$fid])) {
continue;
}
$u = user_by_id($fid);
if (!$u || (int) $u['status'] !== 1) {
$skipped++;
continue;
}
if ((int) ($u['friend_reject_broadcast'] ?? 0) === 1) {
$skipped++;
continue;
}
$ids[] = $fid;
}
return ['ids' => $ids, 'skipped' => $skipped];
}