-
Notifications
You must be signed in to change notification settings - Fork 3
/
show.php
280 lines (251 loc) · 9.96 KB
/
show.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
require_once('config.php');
require_once('lib.php');
session_cache_limiter('private');
session_start();
header("Cache-control: max-age=60");
if (!isset($_GET['url']) && (!isset($_GET['thread']) || !isset($_GET['page']))) {
header('HTTP/1.1 404 Not Found');
die();
}
$thread = intval($_GET['thread']);
$pg = intval($_GET['page']);
if (isset($_GET['url'])) {
$parsed = parse_url($_GET['url']);
$thread = intval(basename($parsed['path']));
parse_str($parsed['query'], $out);
$pg = intval($out['page']);
if ($pg == 0) $pg = 1;
}
$arr = $link->query("select * from discuss_log where thread=$thread and page=$pg")->fetch_assoc();
$url = "https://www.luogu.com.cn/discuss/$thread?page=$pg";
$arr['click'] = addClick($thread);
$tq = $link->query("select reply_count, title from discuss_count where thread=$thread");
date_default_timezone_set("Asia/Shanghai");
$tim = strtotime($arr['time']);
$timstr = date('Y-m-d H:i:s', strtotime("+0 hours", $tim)); // time adjust
if (!$tq->num_rows) {
$arr['title'] = '还未保存过QwQ, 请点击下方更新以保存';
$timstr = '将来某时';
} else {
$rs = $tq->fetch_assoc();
$arr['title'] = $rs['title'];
$arr['reply_count'] = $rs['reply_count'];
}
if ($arr['content'] == 'None') {
$arr['title'] = '这个帖子在被保存之前就被删除了QwQ';
$arr['content'] = '';
}
$pgs = 1;
if ($arr['reply_count'] == -1) {
$pgs = $link->query("select count(*) from discuss_log where thread = $thread")->fetch_row()[0];
$arr['reply_count'] = 'N/A';
} else {
$pgs = intval(($arr['reply_count'] - 1) / 10) + 1;
}
$link->close();
$arr['content'] = decompress($arr['content']);
if (isset($_GET['_contentOnly'])) {
$rs = array(
'content' => $arr['content'],
'title' => $arr['title'],
);
die(json_encode($rs));
}
function pageLink($p) {
global $thread;
echo "/show.php?url=https://www.luogu.com.cn/discuss/$thread?page=$p";
}
?>
<!DOCTYPE html>
<head>
<title><?php echo $arr['title']; ?></title>
<?php require_once 'header.php'; ?>
<script>
hljs.initHighlightingOnLoad();
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
delimiters: [{
left: '$$',
right: '$$',
display: true
}, {
left: '$',
right: '$',
display: false
}],
throwOnError: false
});
});
</script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-light navbar-light fixed-top vluogu-navbar">
<div class="container">
<a class="navbar-brand" href="/">洛谷帖子</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/">首页</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/list.php">列表</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/rank.php">排行</a>
</li>
</ul>
</div>
</nav>
<div class="container" style="margin-top:80px">
<div class="row">
<div class="col-sm-8">
<h2><?php echo $arr['title']; ?></h2>
<hr />
<div class="lfe-body">
<?php echo $arr['content']; ?>
<?php if ($arr['content'] == '') { ?>
<div align="center">
<script src="https://down.52pojie.cn/.fancyindex/js/phaser.min.js"></script>
<script src="https://down.52pojie.cn/.fancyindex/js/catch-the-cat.js"></script>
<div id="catch-the-cat"></div>
<script>
window.game = new CatchTheCatGame({
w: 12,
h: 11,
r: 20,
backgroundColor: 16777215,
parent: "catch-the-cat",
statusBarAlign: "center",
credit: "luogulo.gq",
});
</script>
<style type="text/css">
.style9 {
font-size: 24px;
font-family: "楷体_GB2312";
}
</style>
</div>
<?php } ?>
<ul class="pagination justify-content-center">
<?php if ($pg > 1) { ?>
<li class="page-item"><a class="page-link" href="<?php pageLink(1); ?>">«</a></li>
<?php } ?>
<?php
for ($x = 1; $pg - $x > 1; $x *= 2) ;
for ($x /= 2; $x >= 1; $x /= 2) {
?>
<li class="page-item"><a class="page-link" href="<?php pageLink($pg - $x); ?>"><?php echo $pg - $x; ?></a></li>
<?php } ?>
<li class="page-item active"><a class="page-link" href="#"><?php echo $pg; ?></a></li>
<?php for ($x = 1; $pg + $x < $pgs; $x *= 2) { ?>
<li class="page-item"><a class="page-link" href="<?php pageLink($pg + $x); ?>"><?php echo $pg + $x; ?></a></li>
<?php } ?>
<?php if ($pg < $pgs) { ?>
<li class="page-item"><a class="page-link" href="<?php pageLink($pgs); ?>">»</a></li>
<?php } ?>
</ul>
</div>
</div>
<div class="col-sm-4">
<section style="background-color: #ffffff;padding: 10px 10px;box-shadow: 0 3px 5px rgb(50 50 93 / 10%), 0 2px 3px rgb(0 0 0 / 8%);">
<table class="table table-borderless">
<tbody>
<tr>
<th>访问</th>
<td><?php echo $arr['click']; ?></td>
</tr>
<tr>
<th>页数</th>
<td><?php echo $pgs; ?></td>
</tr>
<tr>
<th>回复</th>
<td><?php echo $arr['reply_count']; ?></td>
</tr>
<tr>
<th>更新</th>
<td><?php echo $timstr; ?></td>
</tr>
</tbody>
</table>
<a href="<?php echo $url; ?>" class="btn btn-primary" target="_blank">原帖</a>
<button type="button" onclick="update('<?php echo $url; ?>')" id="update"
class="btn btn-success">点此更新</button>
<?php if (isset($_SESSION['admin'])) { ?>
<button type="button" class="btn btn-danger" onclick="del(<?php echo $thread; ?>)">
删除
</button>
<?php } ?>
<!-- 按钮:用于打开模态框 -->
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal"
id="openUserGuide">
用户指南
</button>
<!-- 模态框 -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- 模态框头部 -->
<div class="modal-header">
<h4 class="modal-title">用户指南</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- 模态框主体 -->
<div class="modal-body" id="userguide">
</div>
<!-- 模态框底部 -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
<script>
let isUpdating = 0;
function update(url) {
if (isUpdating)
return;
isUpdating = 1
let h = $('#update').text("正在更新").attr('href');
$('#update').addClass('disabled');
$('#update').removeAttr('href');
$.get(`/save.php?url=${url}`).then((u) => {
if (u == 'success')
Toast.fire({
icon: "success",
title: "更新成功",
}).then(() => location.reload());
else Toast.fire({
icon: "error",
title: u,
})
$('#update').text("点此更新").attr('href', h);
isUpdating = 0
$('#update').removeClass('disabled');
});
}
</script>
<script>
$("#openUserGuide").on('click', (e) => {
$.get('/userguide.html').then((u) => $("#userguide").html(u));
})
</script>
<?php if (isset($_SESSION['admin'])) { ?>
<script>
function del(thread) {
$.get(`/delete.php?thread=${thread}`).then((u) => {
Toast.fire({
icon: "success",
title: u,
}).then(() => history.back());
})
}
</script>
<?php } ?>
<?php require_once('footer.php'); ?>
</body>