forked from Moearly/YouBBS-EOEN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow.php
119 lines (97 loc) · 3.98 KB
/
follow.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
<?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){
header("content-Type: text/html; charset=UTF-8");
exit('error: 403 该帐户已被禁用');
}else if($cur_user['flag']==1){
header("content-Type: text/html; charset=UTF-8");
exit('error: 401 该帐户还在审核中');
}
$act = isset($_GET['act']) ? $_GET['act'] : '';
$tid = isset($_GET['id']) ? intval($_GET['id']) : '0';
$page = isset($_GET['page']) ? intval($_GET['page']) : '1';
// 处理操作
if($act && $tid > 0){
if($act == 'add'){
// 添加关注
$DBS->query("INSERT ignore INTO `yunbbs_follow`(`ID`, `UserID`, `ObjID`, `Type`, `FollowTime`) VALUES (null,$cur_uid,$tid,0, $timestamp)");
$DBS->unbuffered_query("UPDATE yunbbs_users SET fuer=fuer+1 WHERE id='$cur_uid'");
$new_mid = $DBS->insert_id();
echo 1;
}else if($act == 'del'){
// 取消关注
$DBS->unbuffered_query("Delete from yunbbs_follow WHERE ObjID='$tid' and UserID='$cur_uid' and Type=0");
$DBS->unbuffered_query("UPDATE yunbbs_users SET fuer=fuer-1 WHERE id='$cur_uid'");
echo 1;
}else if($act == 'isfo'){
// 是否关注过此用户
$table_followCount = $DBS->fetch_one_array("select count(1) as count from yunbbs_follow WHERE ObjID='$tid' and UserID='$cur_uid' and Type=0");
echo $table_followCount['count'];
}
exit();
}
// 获取我的关注的用户发布的帖子数量
$query_sql = "SELECT count(1) as count
FROM `yunbbs_follow` f
inner join `yunbbs_users` u ON f.ObjID=u.id
inner join `yunbbs_articles` a ON a.uid=u.id
LEFT JOIN `yunbbs_categories` c ON c.id=a.cid
LEFT JOIN `yunbbs_users` ru ON a.ruid=ru.id
WHERE f.UserID=$cur_uid and Type=0";
$table_followCount = $DBS->fetch_one_array($query_sql);
$total_follow = $table_followCount['count'];
// 处理正确的页数
// 第一页是1
$total_page = ceil($total_follow/$options['list_shownum']);
if($page<=0 || $total_page == 0){
$page = 1;
}elseif($page>$total_page){
$page = $total_page;
}
$query_sql = "SELECT a.id,a.cid,a.uid,a.ruid,a.title,a.addtime,a.content,a.views,a.edittime,a.comments,a.isred,c.name as cname,u.avatar as uavatar,u.name as author,ru.name as rauthor
FROM `yunbbs_follow` f
inner join `yunbbs_users` u ON f.ObjID=u.id
inner join `yunbbs_articles` a ON a.uid=u.id
LEFT JOIN `yunbbs_categories` c ON c.id=a.cid
LEFT JOIN `yunbbs_users` ru ON a.ruid=ru.id
WHERE f.UserID=$cur_uid and Type=0
ORDER BY `edittime` DESC LIMIT ".($page-1)*$options['list_shownum'].",".$options['list_shownum'];
$query = $DBS->query($query_sql);
$articledb=array();
while ($article = $DBS->fetch_array($query)) {
// 格式化内容
if($article['isred'] == '1'){
$article['title'] = $article['title']."<span class=\"label label-success\">推荐</span>";
}
$article['addtime'] = showtime($article['addtime']);
$article['edittime'] = showtime($article['edittime']);
$article['content'] = set_content($article['content'], 1);
$articledb[] = $article;
}
unset($article);
$DBS->free_result($query);
//我关注的人
$quero = "SELECT a.ID,a.UserID,a.Type,a.ObjID,a.FollowTime,u.name,u.avatar
FROM yunbbs_follow a
LEFT JOIN yunbbs_users u ON a.ObjID=u.id
WHERE a.UserID=$cur_uid and Type=0 ORDER BY a.FollowTime DESC";
$leavin = $DBS->query($quero);
$leavindb=array();
while ($leaving = $DBS->fetch_array($leavin)) {
// 格式化内容
$leavindb[] = $leaving;
}
unset($leaving);
$DBS->free_result($leavin);
$follouser = "SELECT fuer FROM yunbbs_users WHERE id='$cur_uid'";
$uu_obj = $DBS->fetch_one_array($follouser);
// 页面变量
$title = '我关注的用户';
$pagefile = CURRENT_DIR . '/templates/default/'.$tpl.'followuser.php';
$newest_nodes = get_newest_nodes();
include(CURRENT_DIR . '/templates/default/'.$tpl.'layout.php');
?>