forked from Moearly/YouBBS-EOEN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newmessage.php
193 lines (154 loc) · 6.88 KB
/
newmessage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
define('IN_SAESPOT', 1);
define('CURRENT_DIR', pathinfo(__FILE__, PATHINFO_DIRNAME));
include(CURRENT_DIR . '/config.php');
include(CURRENT_DIR . '/common.php');
if (!$cur_user) exit('error: 401 login please');
if ($cur_user['flag']==0){
exit('error: 403 Access Denied');
}else if($cur_user['flag']==1){
exit('error: 401 Access Denied');
}
$cid = intval($_GET['cid']);
$page = isset($_GET['page']) ? intval($_GET['page']) : '1';
$act = isset($_GET['act']) ? $_GET['act'] : '';
$tid = isset($_GET['tid']) ? intval($_GET['tid']) : '0';
// 处理操作
if($act && $tid > 0){
// 获取需要操作的消息数据
// $user_msg = $DBS->fetch_one_array("SELECT * FROM yunbbs_messages WHERE ID='".$tid."'");
// if($act == 'setread'){
// // 设置为已读,消息存在,并且消息是发给自己的
// if($user_msg && $user_msg['ToUID'] == $cur_uid){
// $DBS->unbuffered_query("UPDATE yunbbs_messages SET IsRead=1 WHERE ID='$tid'");
// echo 1;
// }else{
// echo 0;
// }
// exit();
// }else
if($act == 'del'){
// 删除,只有发送消息的人才可以删除
$DBS->unbuffered_query("Delete from yunbbs_messages WHERE FromUID = $cur_uid and ID='$tid'");
}
}
if($cid){
$query = "SELECT id,name,flag,avatar,url,articles,replies,regtime,about FROM yunbbs_users WHERE id='$cid'";
}else{
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
include(CURRENT_DIR . '/404.html');
exit;
}
$c_obj = $DBS->fetch_one_array($query);
if($c_obj){
if($c_obj['flag'] == 0){
if(!$cur_user || ($cur_user && $cur_user['flag']<99)){
//header("content-Type: text/html; charset=UTF-8");
//exit('该用户已被禁用');
}
}
$openid_user = $DBS->fetch_one_array("SELECT name FROM yunbbs_qqweibo WHERE uid='".$cid."'");
$weibo_user = $DBS->fetch_one_array("SELECT `openid` FROM `yunbbs_weibo` WHERE `uid`='".$cid."'");
$c_obj['regtime'] = showtime($c_obj['regtime']);
}else{
exit('404');
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(empty($_SERVER['HTTP_REFERER']) || $_POST['formhash'] != formhash() || preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) !== preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])) {
exit('403: unknown referer.');
}
$p_title = addslashes(trim($_POST['title']));
$p_content = addslashes(trim($_POST['content']));
// spam_words
if($options['spam_words'] && $cur_user['flag']<99){
$check_con = ' '.$p_title.$p_content;
$spam_words_arr = explode(",", $options['spam_words']);
foreach($spam_words_arr as $spam){
if(strpos($check_con, $spam)){
// has spam word
$DBS->unbuffered_query("UPDATE yunbbs_users SET flag='0' WHERE id='$cur_uid'");
exit('403: dont post any spam.');
}
}
}
if($p_content && mb_strlen($p_content,'utf-8') > 0){
//mb_strlen($p_title,'utf-8')<=$options['article_title_max_len'] &&
if(mb_strlen($p_content,'utf-8')<=$options['article_content_max_len']){
$p_title = '';//htmlspecialchars($p_title);
$p_content = htmlspecialchars($p_content);
$factor = 10000000;
$referid=0;
if($cid > $cur_uid){
$referid=$cur_uid*$factor+$cid;
}else{
$referid=$cid*$factor+$cur_uid;
}
$DBS->query("INSERT INTO yunbbs_messages (ID,FromUID,ToUID,FromUName,ToUName,title,content,addtime,ReferID) VALUES (null,$cur_uid,$cid,'$cur_uname','".$c_obj['name']."', '$p_title', '$p_content', $timestamp,$referid)");
$new_mid = $DBS->insert_id();
$DBS->unbuffered_query("UPDATE yunbbs_users SET lastposttime=$timestamp WHERE id='$cur_uid'");
// 更新u_code
$cur_user['lastposttime'] = $timestamp;
//
$new_ucode = md5($cur_uid.$cur_user['password'].$cur_user['regtime'].$cur_user['lastposttime'].$cur_user['lastreplytime']);
setcookie("cur_uid", $cur_uid, $timestamp+ 86400 * 365, '/');
setcookie("cur_uname", $cur_uname, $timestamp+86400 * 365, '/');
setcookie("cur_ucode", $new_ucode, $timestamp+86400 * 365, '/');
// mentions 没有提醒用户的id
// $mentions = find_mentions(' '.$p_title.' '.$p_content, $cur_uname);
// if($mentions && count($mentions)<=10){
// foreach($mentions as $m_name){
// $DBS->unbuffered_query("UPDATE yunbbs_users SET notic = concat('$new_aid,', notic) WHERE name='$m_name'");
// }
// }
$p_title = $p_content = '';
header('location: /newmessage/'.$cid);
exit;
}else{
$tip = '内容'.mb_strlen($p_content,'utf-8').' 太长了';
}
}else{
$tip = '内容 不能留空';
}
}else{
$p_title = '';
$p_content = '';
$tip = '';
}
// 获取我发送的和发送给的私信的数量
$table_msgCount = $DBS->fetch_one_array("SELECT count(1) as count FROM `yunbbs_messages`
WHERE (FromUID=$cur_uid and ToUID=$cid) OR (FromUID = $cid and ToUID=$cur_uid)");
$total_msg = $table_msgCount['count'];
// 处理正确的页数
// 第一页是1
$total_page = ceil($total_msg/$options['list_shownum']);
if($page<=0 || $total_page == 0){
$page = 1;
}elseif($page>$total_page){
$page = $total_page;
}
$query_sql = "SELECT m.*,u1.avatar FROM `yunbbs_messages` m
inner join yunbbs_users u1 on m.FromUID=u1.id
WHERE (FromUID=$cur_uid and ToUID=$cid) OR (FromUID = $cid and ToUID=$cur_uid)
order by id desc limit ".($page-1)*$options['list_shownum'].",".$options['list_shownum'];
$query = $DBS->query($query_sql);
$messagedb=array();
while ($message = $DBS->fetch_array($query)) {
// 格式化内容
if($message['IsRead'] == '0' && $message['ToUID'] == $cur_uid){
$message['Title'] = "<span class=\"label label-success\">未读</span>";
}else{
$message['Title']='';
}
$message['AddTime'] = showtime($message['AddTime']);
$messagedb[] = $message;
}
unset($message);
$DBS->free_result($query);
// 设置此人发给我的消息为已读
$DBS->unbuffered_query("UPDATE yunbbs_messages SET IsRead=1 WHERE FromUID=$cid and ToUID=$cur_uid");
// 页面变量
$title = '发私信';
$pagefile = CURRENT_DIR . '/templates/default/'.$tpl.'newmessage.php';
include(CURRENT_DIR . '/templates/default/'.$tpl.'layout.php');
?>