-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtop10.php
220 lines (196 loc) · 8.15 KB
/
top10.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<!-- <link rel="icon" href="../../favicon.ico"> -->
<title>Forum</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/main.css" rel="stylesheet">
<!-- jQuery -->
<script src="js/jquery-2.1.4.min.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.twbsPagination.min.js"></script>
</head>
<body>
<?php
/**
* Created by PhpStorm.
* User: Henry
* Date: 2015/6/15
* Time: 20:46
*/
require("connect.php");
require('checkvalid.php');
$username = $_SESSION['username'];
$u_id = $_SESSION['u_id'];
$role = $_SESSION['role'];
$status = $_SESSION['status'];
?>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="nav-wrapper">
<div class="container-fluid">
<ul class="nav navbar-nav ">
<li class="divider-vertical"></li>
<li><a href="index.php"><b>论坛首页</b></a></li>
</ul>
<form class="navbar-form navbar-left" role="search" method="post" action="posts.php">
<div class="form-group">
<input type="text" name="keyword" class="form-control" placeholder="帖子主题">
</div>
<button type="submit" class="btn btn-default" name="search">搜索</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>
<div class="navbar-header">
<img alt="avatar" src="<?php echo $_SESSION['avatar']; ?>" class="img-nav img-rounded">
</div>
</li>
<li class="dropdown">
<a href="#" id="username-nav" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?php echo $username?>
<!-- <span class="caret"></span> -->
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="editinfo.php">编辑信息</a></li>
<li><a href="message.php">短消息</a></li>
<?php if($_SESSION['role'] == 0){ ?>
<li><a href="usermanagement.php">用户管理</a></li>
<li><a href="boardmanagement.php">版块管理</a></li>
<?php } ?>
<li class="divider"></li>
<li><a href="logout.php">注销</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="divider-vertical"></li>
<li><a>浏览 <span class="sr-only">(current)</span></a></li>
<li class="divider-vertical"></li>
<li class="active"><a href="top10.php">热门帖子</a></li>
<li class="divider-vertical"></li>
<li><a>公告</a></li>
<li class="divider-vertical"></li>
<li class="divider-vertical-invisable"></li>
<li class="divider-vertical-invisable"></li>
<li class="divider-vertical-invisable"></li>
<li class="divider-vertical-invisable"></li>
<li class="divider-vertical-invisable"></li>
</ul>
</div>
</div>
</nav>
<div class="panel panel-default panel-size">
<div class="panel-heading">
<ul class="breadcrumb breadcrumb-post">
<li class="active">十大热帖</li>
</ul>
</div>
<div class="panel-body" style="padding-bottom: 0px">
<ul class="list-group">
<table class="table table-striped table-hover table-content">
<thead>
<tr>
<th align="center">主题</th>
<th>版块名</th>
<th>作者</th>
<th>发帖时间</th>
<th>关注</th>
<th>点击/回复</th>
</tr>
</thead>
<tbody>
<?php
$sql = "select p_id, hits, reply_count, post_time from posts_topic where is_announcement = 0 and week(now()) - week(post_time) <= 1";
$query = mysql_query($sql)
or die("Error!");
$post_rank = array();
date_default_timezone_set('Asia/Shanghai');
$local_time = time();
while($row = mysql_fetch_array($query, MYSQL_BOTH)) {
//fetch all the posts within two weeks
$sql2 = "select count(DISTINCT replier_id) from posts_reply where p_id = " . $row['p_id'];
$query2 = mysql_query($sql2)
or die("Error!");
$follower_count = mysql_fetch_array($query2)[0];
$hits = $row['hits'];
$replies = $row['reply_count'];
$post_time = $row['post_time'];
// echo strtotime($post_time) . "<br />";
// echo $local_time . "<br />";
$last_time = ($local_time - strtotime($post_time))/86400;
if($replies == 0){
$replies = 1;
}
if($hits == 0){
$hits = 1;
}
if($follower_count == 0){
$follower_count = 1;
}
$post_rank[$row['p_id']] = $follower_count*(0.7*$replies)*(0.3*$hits)/$last_time;
// echo $last_time;
// echo strtotime($post_time);
// echo $last_time;
}
arsort($post_rank);
$ranked_p_id = array_keys($post_rank);
// print_r($post_rank);
$k = 0;
while($k < 10) {
//fetch all the posts in the board
$sql = "select p_id, board_id, author, post_time, reply_count, title, hits from posts_topic where p_id = " . $ranked_p_id[$k];
$query = mysql_query($sql)
or die("好冷清啊,没有十大T.T");
$row = mysql_fetch_array($query);
$sql = "select b_name from forum_board where b_id = " . $row['board_id'];
$query = mysql_query($sql)
or die("Error!");
$b_name = mysql_fetch_array($query)[0];
$sql2 = "select count(DISTINCT replier_id) from posts_reply where p_id = " . $row['p_id'];
$query2 = mysql_query($sql2)
or die("Error!");
$follower_count = mysql_fetch_array($query2)[0];
?>
<tr class = "table-hover">
<td width="30%">
<a href = "detail.php?id=<?php echo $row['p_id'] ?>"><?php echo $row['title']?></a>
</td>
<td width="10%">
<a href = "posts.php?b_id=<?php echo $row['board_id'] ?>"><?php echo $b_name?></a>
</td>
<td width="10%">
<span class="badge"><?php echo $row['author']?></span>
</td>
<td width="20%">
<span class="badge"><?php echo $row['post_time']?></span>
</td>
<td width="20">
<span class="badge"><?php echo $follower_count ?></span>
</td>
<td width="10">
<span class="badge"><?php echo $row['reply_count']?> reply/<?php echo $row['hits']?>hit(s)</span>
</td>
</tr>
<?php
$k++;
}
mysql_close();
?>
</tbody>
</table>
</ul>
</div>
</div>
<div class="text-center">
<ul class="pagination">
</ul>
</div>
</body>
</html>