-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewpost.php
More file actions
283 lines (250 loc) · 9.94 KB
/
Copy pathnewpost.php
File metadata and controls
283 lines (250 loc) · 9.94 KB
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
281
282
283
<?php
declare(strict_types=1);
/**
* PowerPHPBoard - New Post Form
*
* MIT License - Copyright (c) 2026 PowerScripts
*/
use PowerPHPBoard\CSRF;
use PowerPHPBoard\Database;
use PowerPHPBoard\Security;
use PowerPHPBoard\Session;
use PowerPHPBoard\Validator;
require_once __DIR__ . '/config.inc.php';
Session::start();
$threadid = Security::getInt('threadid');
$postid = Security::getInt('postid');
$current = Security::getInt('current');
$newpost = Security::getInt('newpost');
try {
$db = Database::getInstance($mysql);
} catch (PDOException $e) {
die('Database connection failed');
}
$thread = [];
$board = [];
$boardid = 0;
if ($threadid > 0) {
$thread = $db->fetchOne(
"SELECT * FROM ppb_posts WHERE id = ? AND type = 'Thread'",
[$threadid]
);
if ($thread !== null) {
$boardid = (int) $thread['boardid'];
} else {
$thread = [];
}
}
if ($boardid > 0) {
$board = $db->fetchOne(
"SELECT * FROM ppb_boards WHERE id = ? AND type = 'Board'",
[$boardid]
);
if ($board === null) {
$board = [];
}
}
$boardpassword = Security::getString('boardpassword', 'POST');
$boardpassworddb = '';
if (Session::isLoggedIn() && ($board['status'] ?? '') === 'Private') {
$userId = Session::getUserId();
$visit = $db->fetchOne(
"SELECT password FROM ppb_visits WHERE userid = ? AND vid = ? AND type = 'Board'",
[$userId, $board['id'] ?? 0]
);
if ($visit !== null) {
$boardpassworddb = base64_decode((string) $visit['password']);
}
}
$settings = $db->fetchOne('SELECT * FROM ppb_config WHERE id = ?', [1]) ?? [];
$ppbuser = [];
$loggedin = 'NO';
if (Session::isLoggedIn()) {
$userId = Session::getUserId();
$ppbuser = $db->fetchOne('SELECT * FROM ppb_users WHERE id = ?', [$userId]);
if ($ppbuser !== null) {
$loggedin = 'YES';
} else {
$ppbuser = [];
Session::logout();
}
}
$langFile = match ($settings['language'] ?? 'English') {
'Deutsch-Sie' => 'deutsch-sie.inc.php',
'Deutsch-Du' => 'deutsch-du.inc.php',
default => 'english.inc.php',
};
require_once __DIR__ . '/' . $langFile;
require_once __DIR__ . '/functions.inc.php';
$formError = '';
$postCreated = false;
$newPostId = 0;
if (!empty($board['title']) && !empty($thread['title'])
&& ($board['status'] ?? '') !== 'Closed' && ($thread['status'] ?? '') !== 'Closed'
&& $_SERVER['REQUEST_METHOD'] === 'POST' && $newpost === 1) {
if (!CSRF::validateFromPost()) {
$formError = 'Security token invalid. Please try again.';
} else {
$boardpasswordCoded = base64_encode($boardpassword);
if (($board['status'] ?? '') === 'Private' && $boardpasswordCoded !== $board['password']) {
$formError = $lang_bpwdnotcorrect ?? 'Board password incorrect';
} else {
$text = Security::getString('text', 'POST');
if ($text === '') {
$formError = $lang_insertvaluesforall ?? 'Please fill in all fields';
} elseif (!Validator::withinLength($text, Validator::POST_MAX)) {
$formError = $lang_posttoolong ?? 'Post text is too long.';
} elseif ($loggedin !== 'YES') {
$formError = $lang_loginfirst ?? 'You have to log in first';
} else {
$text = trim($text);
$now = time();
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
$db->query(
"INSERT INTO ppb_posts (boardid, threadid, type, time, author, text, ip) VALUES (?, ?, 'Post', ?, ?, ?, ?)",
[$board['id'], $thread['id'], $now, $ppbuser['id'], $text, $ip]
);
$newPostId = (int) $db->lastInsertId();
$db->query(
'UPDATE ppb_boards SET lastchange = ?, lastauthor = ? WHERE id = ?',
[$now, $ppbuser['id'], $board['id']]
);
$db->query(
'UPDATE ppb_posts SET lastreply = ?, lastauthor = ? WHERE id = ?',
[$now, $ppbuser['id'], $thread['id']]
);
CSRF::regenerate();
$postCreated = true;
}
}
}
}
include __DIR__ . '/header.inc.php';
$quoteText = '';
if ($postid > 0 && !$postCreated) {
$quotePost = $db->fetchOne('SELECT text FROM ppb_posts WHERE id = ?', [$postid]);
if ($quotePost !== null) {
$quoteText = '[quote]' . $quotePost['text'] . "[/quote]\n";
}
}
?>
<?php if (empty($board['title']) || empty($thread['title'])): ?>
<?php
default_error(
$lang_choosethread ?? 'Please select a thread',
'index.php',
$lang_boardlist ?? 'Board list'
);
?>
<?php elseif (($board['status'] ?? '') === 'Closed' || ($thread['status'] ?? '') === 'Closed'): ?>
<?php
default_error(
$lang_threadclosedcannotpost ?? 'Thread is closed, cannot post',
'showboard.php?boardid=' . (int) ($board['id'] ?? 0) . '¤t=' . (int) $current,
($lang_backto ?? 'Back to') . ' "' . ($board['title'] ?? '') . '" ' . ($lang_board ?? 'board')
);
?>
<?php elseif ($postCreated): ?>
<div class="card shadow-sm border-success mb-4">
<header class="card-header bg-success text-white">
<h2 class="h6 mb-0">
<i class="bi bi-check-circle-fill" aria-hidden="true"></i>
<?php echo $lang_statusmessage ?? 'Status'; ?>
</h2>
</header>
<div class="card-body">
<p class="mb-3">
<?php echo $lang_newpostcreated ?? 'Post created successfully'; ?>
</p>
<a href="showthread.php?threadid=<?php echo (int) $thread['id']; ?>¤t=<?php echo (int) $current; ?>#post<?php echo $newPostId; ?>"
class="btn btn-primary">
<i class="bi bi-arrow-left" aria-hidden="true"></i>
<?php echo $lang_backto ?? 'Back to'; ?>
"<?php echo Security::escape((string) $thread['title']); ?>"
<?php echo $lang_thread ?? 'thread'; ?>
</a>
</div>
</div>
<?php else: ?>
<?php if ($formError !== ''): ?>
<div class="alert alert-danger" role="alert">
<i class="bi bi-exclamation-triangle-fill" aria-hidden="true"></i>
<?php echo Security::escape($formError); ?>
</div>
<?php endif; ?>
<form action="newpost.php?threadid=<?php echo (int) $thread['id']; ?>&newpost=1¤t=<?php echo (int) $current; ?>"
method="post" class="needs-validation" novalidate>
<?php echo CSRF::getTokenField(); ?>
<section class="card shadow-sm mb-3">
<header class="card-header bg-secondary-subtle">
<h1 class="h5 mb-0">
<i class="bi bi-reply" aria-hidden="true"></i>
<?php echo $lang_newpost ?? 'New Post'; ?>
<small class="text-body-secondary">· <?php echo Security::escape((string) $thread['title']); ?></small>
</h1>
</header>
<div class="card-body">
<?php if ($loggedin !== 'YES'): ?>
<div class="alert alert-warning small d-flex align-items-center gap-2" role="alert">
<i class="bi bi-info-circle" aria-hidden="true"></i>
<div>
<?php echo $lang_loginfirst ?? 'You have to log in first.'; ?>
<a class="alert-link" href="login.php">
<?php echo $lang_login ?? 'Login'; ?>
</a>
</div>
</div>
<?php endif; ?>
<?php if (($board['status'] ?? '') === 'Private'): ?>
<div class="mb-3">
<label for="boardpassword" class="form-label fw-semibold">
<?php echo $lang_boardpassword ?? 'Board Password'; ?>
</label>
<input id="boardpassword" name="boardpassword" type="password"
class="form-control" maxlength="25"
value="<?php echo Security::escape($boardpassworddb); ?>">
<div class="form-text">Wird benötigt, weil dieser Bereich privat ist.</div>
</div>
<?php endif; ?>
<div class="mb-3">
<label for="text" class="form-label fw-semibold">
<?php echo $lang_text ?? 'Text'; ?>
<span class="text-danger" aria-hidden="true">*</span>
</label>
<textarea id="text" name="text" class="form-control" rows="12" required
maxlength="<?php echo Validator::POST_MAX; ?>"><?php echo Security::escape($quoteText); ?></textarea>
<div class="form-text">
<?php echo $lang_htmlcodeis ?? 'HTML ist'; ?>
<strong><?php echo ppb_onoff_label($settings['htmlcode'] ?? 'OFF'); ?></strong>,
<a href="bbcode.php?catid=<?php echo (int) ($catid ?? 0); ?>&boardid=<?php echo (int) $boardid; ?>"
target="_blank" rel="noopener">
<?php echo $lang_bbcodeis ?? 'BBCode ist'; ?>
<strong><?php echo ppb_onoff_label($settings['bbcode'] ?? 'ON'); ?></strong>
</a>,
<a href="smilies.php?catid=<?php echo (int) ($catid ?? 0); ?>&boardid=<?php echo (int) $boardid; ?>"
target="_blank" rel="noopener">
<?php echo $lang_smiliesare ?? 'Smilies sind'; ?>
<strong><?php echo ppb_onoff_label($settings['smilies'] ?? 'ON'); ?></strong>
</a>.
</div>
<div class="invalid-feedback">Bitte einen Text eingeben.</div>
</div>
</div>
<footer class="card-footer bg-light d-flex flex-wrap gap-2">
<button type="submit" class="btn btn-primary">
<i class="bi bi-send" aria-hidden="true"></i>
<?php echo $lang_send ?? 'Send'; ?>
</button>
<button type="reset" class="btn btn-outline-secondary">
<i class="bi bi-arrow-counterclockwise" aria-hidden="true"></i>
<?php echo $lang_reset ?? 'Reset'; ?>
</button>
<a class="btn btn-link"
href="showthread.php?threadid=<?php echo (int) $thread['id']; ?>¤t=<?php echo (int) $current; ?>">
<?php echo $lang_back ?? 'Back'; ?>
</a>
</footer>
</section>
</form>
<?php endif; ?>
<?php include __DIR__ . '/footer.inc.php'; ?>