This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
review.php
210 lines (190 loc) · 6.87 KB
/
review.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
<?php
session_start(['read_and_close' => true]);
require_once('utils.php');
require_once('database.php');
$db = new MyDB();
if (isset($_SESSION['stuid']) && !isset($USER))
$USER = $db->getUserByStuid($_SESSION['stuid']);
if (isset($_GET['uid'])) {
$uid = $_GET['uid'];
if (!preg_match('/^[a-zA-Z0-9]{4}$/', $uid)) {
http_response_code(404);
exit('Wrong uid format. 投稿編號格式錯誤');
}
if (!($post = $db->getPostByUid($uid))) {
http_response_code(404);
exit('Post not found. 文章不存在');
}
if (isset($USER)) {
$canVote = $db->canVote($uid, $USER['stuid']);
if (!$canVote['ok'])
$post['vote'] = 87;
}
$posts = [$post];
} else {
if (isset($_GET['deleted'])) {
if (isset($USER)) {
$votes = $USER['approvals'] + $USER['rejects'];
$count = max($votes/10, 3);
$posts = $db->getDeletedSubmissions($count);
} else
$posts = [];
} else if (isset($USER))
$posts = $db->getSubmissionsForVoter(50, true, $USER['stuid']);
else
$posts = $db->getSubmissions(50);
}
$postsCanVote = array_filter($posts, function($item) {
return !isset($item['vote']);
});
if (isset($_GET['all'])) {
$showAll = ($_GET['all'] == 'true');
} else {
$showAll = (count($postsCanVote) == 0);
}
if (!$showAll)
$posts = $postsCanVote;
if (isset($post)) {
$hashtag = "待審貼文 {$post['uid']}";
$DESC = $post['body'];
$TITLE = "$hashtag $DESC";
if (mb_strlen($TITLE) > 40)
$TITLE = mb_substr($TITLE, 0, 40) . '...';
if (mb_strlen($DESC) > 150)
$DESC = mb_substr($DESC, 0, 150) . '...';
if ($post['has_img'])
$IMG = "https://$DOMAIN/img/{$post['uid']}.jpg";
} else if (isset($_GET['deleted'])) {
$TITLE = '已刪投稿';
$IMG = "https://$DOMAIN/assets/img/og.png";
} else {
$TITLE = '貼文審核';
$IMG = "https://$DOMAIN/assets/img/og.png";
}
?>
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<?php include('includes/head.php'); ?>
<script src="/assets/js/review.js"></script>
</head>
<?php if (isset($uid)) { ?>
<body data-uid="<?= $uid ?>">
<?php } else { ?>
<body>
<?php }
include('includes/nav.php');
?>
<header class="ts fluid vertically padded heading slate">
<div class="ts narrow container">
<h1 class="ts header"><?= isset($_GET['deleted']) ? '已刪投稿' : '貼文審核' ?></h1>
<div class="description"><?= SITENAME ?></div>
</div>
</header>
<div class="ts container" name="main">
<?php
if (count($posts) == 0) {
if (isset($USER)) {
?>
<h2 class="ts header">太棒了!您已審完所有投稿</h2>
<p>歡迎使用 Telegram Bot 接收投稿通知,並在程式內快速審查</p>
<?php } else if (isset($_GET['deleted'])) { ?>
<div class="ts negative message">
<div class="header">你不是交大生</div>
<p>這邊僅限交大使用者瀏覽,外校生僅可在知道投稿編號的情況下看到刪除記錄,例如 <a href="/review/2C8j">#投稿2C8j</a>。</p>
</div>
<?php } else { ?>
<h2 class="ts header">太棒了!目前沒有待審投稿</h2>
<p>歡迎使用 Telegram Bot 接收投稿通知,並在程式內快速審查</p>
<?php } }
foreach ($posts as $post) {
$uid = $post['uid'];
$ip_masked = ip_mask($post['ip_addr']);
$author_name = toHTML($post['author_name']);
if (strpos($author_name, '境外') !== false)
$ip_masked = $post['ip_addr'];
$author_photo = $post['author_photo'] ?? '';
if (empty($author_photo))
$author_photo = genPic($ip_masked);
$body = toHTML($post['body']);
$ts = strtotime($post['created_at']);
$time = humanTime($post['created_at']);
$canVote = !(isset($post['id']) || isset($post['vote']) || isset($post['deleted_at']));
if (isset($post['deleted_at'])) {
?>
<div class="ts negative message">
<div class="header">此文已刪除</div>
<p>刪除原因:<?= toHTML($post['delete_note']) ?? '(無)' ?></p>
</div>
<?php }
if (isset($post['id'])) {
?>
<div class="ts positive message">
<div class="header">文章已發出</div>
<p>您可以在 <a href="/post/<?= $post['id'] ?>">#告白交大<?= $post['id'] ?></a> 找到這篇文章</p>
</div>
<?php } ?>
<div class="ts card" id="post-<?= $uid ?>" style="margin-bottom: 42px;">
<?php if ($post['has_img']) { ?>
<div class="image">
<?php if (isset($_GET['uid'])) { ?>
<img class="post-image" src="/img/<?= $uid ?>.jpg" />
<?php } else { ?>
<img class="post-image" src="/img/<?= $uid ?>.jpg" onclick="showImg(this);" style="max-height: 40vh; width: auto; cursor: zoom-in;" />
<?php } ?>
</div>
<?php } ?>
<div class="content">
<?php if (isset($_GET['uid'])) { ?>
<div class="header">#投稿<?= $uid ?></div>
<?php } else { ?>
<div class="header"><a href="/review/<?= $uid ?>">#投稿<?= $uid ?></a></div>
<?php } ?>
<p><?= $body ?></p>
</div>
<div class="extra content">
<div class="right floated author">
<img class="ts circular avatar image" src="<?= $author_photo ?>" onerror="this.src='/assets/img/avatar.jpg';"> <?= $author_name ?>
<?php if ((isset($USER) || $post['status'] == 10) && empty($post['author_id'])) { ?>
<br><span class="right floated">(<?= $ip_masked ?>)</span>
<?php } ?>
</div>
<p style="margin-top: 0; line-height: 1.7em">
<span>審核狀況:<button class="ts vote positive button">通過</button> <span id="approvals"><?= $post['approvals'] ?></span> 票 / <button class="ts vote negative button">駁回</button> <span id="rejects"><?= $post['rejects'] ?></span> 票</span>
<br><span>投稿時間:<time data-ts="<?= $ts ?>"><?= $time ?></time></span>
</p>
</div>
<div class="ts fluid bottom attached large buttons" style="<?= $canVote ? '' : 'display: none;' ?>">
<button class="ts positive button" onclick="approve('<?= $uid ?>');">通過貼文</button>
<button class="ts negative button" onclick="reject('<?= $uid ?>');">駁回投稿</button>
</div>
</div>
<?php }
if (isset($_GET['uid'])) {
$VOTES = $db->getVotesByUid($post['uid']);
include('includes/table-vote.php');
if (isset($USER) && 1 <= $post['status'] && $post['status'] <= 3 || $post['status'] == 10) {
?>
<button id="refresh" class="ts primary button" onclick="updateVotes('<?= $uid ?>');">重新整理</button>
<?php } } else if (!isset($_GET['deleted']) && isset($USER)) { ?>
<div class="ts toggle checkbox">
<input id="showAll" <?= $showAll ? 'checked' : '' ?> type="checkbox" onchange="location.href='?all='+this.checked;">
<label for="showAll">顯示所有投稿</label>
</div>
<?php } ?>
<div class="ts modals dimmer" id="img-container-wrapper" style="margin-top: 40px;">
<dialog id="modal" class="ts basic fullscreen closable modal" open>
<i class="close icon"></i>
<div class="ts icon header"></div>
<div class="content">
<img id="img-container-inner" style="width: 100%;">
</div>
<div class="actions">
<button class="ts inverted basic cancel button">關閉</button>
</div>
</dialog>
</div>
</div>
<?php include('includes/footer.php'); ?>
</body>
</html>