-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.php
84 lines (69 loc) · 2.04 KB
/
home.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
<?php
include('header.php');
include('lib.php');
if (($user = isLogin())==false) {
header('location:index.php');
exit;
}
$r = connredis();
/*
// 取出自己发的和关注的人发的微博
$r->ltrim('recivepost'.$user['userid'],0,49);
*/
//获取关注的人
$star = $r->smembers('following:'.$user['userid']);
//把自己加入其中
$star[] = $user['userid'];
$lastpull = $r->get('lastpull:userid:'.$user['userid']);
if(!$lastpull) {
$lastpull = 0;
}
$latest = array();
//拉取数据
foreach ($star as $s) {
$latest = array_merge($latest,$r->zrangebyscore('starpost:userid:'.$s,$lastpull+1,1<<32-1));
}
sort($latest,SORT_NUMERIC);
//更新lastpull
$r->set('lastpull:userid:'.$user['userid'],end($latest));
//循环把latest放到自己主页应该收取的微博链表里
foreach ($latest as $l) {
$r->lpush('recivepost:'.$user['userid'],$l);
}
$r->ltrim('recivepost:'.$user['userid'],0,999);
//之多收取100微博
$newpost = $r->sort('recivepost:'.$user['userid'],array('sort'=>'desc'));
// 计算几个粉丝,几个关注(集合个数)
$myfans = $r->sCard('follower:'.$user['userid']);
$mystars = $r->sCard('folloer:'.$user['userid']);
?>
<div id="navbar">
<a href="index.php">主页</a>
| <a href="timeline.php">热点</a>
| <a href="logout.php">退出</a>
</div>
</div>
<div id="postform">
<form method="POST" action="post.php">
<?php echo $user['username']; ?>, 有啥感想?
<br>
<table>
<tr><td><textarea cols="70" rows="3" name="status"></textarea></td></tr>
<tr><td align="right"><input type="submit" name="doit" value="提交"></td></tr>
</table>
</form>
<div id="homeinfobox">
<?php echo $myfans; ?> 粉丝<br>
<?php echo $mystars; ?>关注<br>
</div>
</div>
<?php
foreach ($newpost as $postid) {
$p = $r->hmget('post:postid:'.$postid,array('userid','time','content'));
?>
<div class="post">
<a class="username" href="profile.php?u=<?php echo $p['userid']; ?>"><?php echo $p['userid']; ?></a><?php echo $p['content']; ?><br>
<i><?php echo formattimes($p['time']); ?>前 通过 web发布</i>
</div>
<?php } ?>
<?php include('footer.php');?>