· 10 years ago · Sep 16, 2016, 07:52 PM
1<?php
2# TinyIB
3#
4# https://github.com/tslocum/TinyIB
5
6error_reporting(E_ALL);
7ini_set("display_errors", 1);
8session_start();
9setcookie(session_name(), session_id(), time() + 2592000);
10ob_implicit_flush();
11if (function_exists('ob_get_level')) {
12 while (ob_get_level() > 0) {
13 ob_end_flush();
14 }
15}
16
17if (get_magic_quotes_gpc()) {
18 foreach ($_GET as $key => $val) {
19 $_GET[$key] = stripslashes($val);
20 }
21 foreach ($_POST as $key => $val) {
22 $_POST[$key] = stripslashes($val);
23 }
24}
25if (get_magic_quotes_runtime()) {
26 set_magic_quotes_runtime(0);
27}
28
29function fancyDie($message) {
30 die('<body text="#800000" bgcolor="#FFFFEE" align="center"><br><div> style="display: inline-block; background-color: #F0E0D6;font-size: 1.25em;font-family: Tahoma, Geneva, sans-serif;padding: 7px;border: 1px solid #D9BFB7;border-left: none;border-top: none;">' . $message . '</div><br><br>- <a href="javascript:history.go(-1)">Click here to go back</a> -</body>');
31}
32
33if (!file_exists('settings.php')) {
34 fancyDie('Please rename the file settings.default.php to settings.php');
35}
36require 'settings.php';
37
38if (TINYIB_TRIPSEED == '' || TINYIB_ADMINPASS == '') {
39 fancyDie('TINYIB_TRIPSEED and TINYIB_ADMINPASS must be configured.');
40}
41
42if (TINYIB_CAPTCHA === 'recaptcha' && (TINYIB_RECAPTCHA_SITE == '' || TINYIB_RECAPTCHA_SECRET == '')) {
43 fancyDie('TINYIB_RECAPTCHA_SITE and TINYIB_RECAPTCHA_SECRET must be configured.');
44}
45
46// Check directories are writable by the script
47$writedirs = array("res", "src", "thumb");
48if (TINYIB_DBMODE == 'flatfile') {
49 $writedirs[] = "inc/flatfile";
50}
51foreach ($writedirs as $dir) {
52 if (!is_writable($dir)) {
53 fancyDie("Directory '" . $dir . "' can not be written to. Please modify its permissions.");
54 }
55}
56
57$includes = array("inc/defines.php", "inc/functions.php", "inc/html.php");
58if (in_array(TINYIB_DBMODE, array('flatfile', 'mysql', 'mysqli', 'sqlite', 'pdo'))) {
59 $includes[] = 'inc/database_' . TINYIB_DBMODE . '.php';
60} else {
61 fancyDie("Unknown database mode specified.");
62}
63
64foreach ($includes as $include) {
65 include $include;
66}
67
68$redirect = true;
69// Check if the request is to make a post
70if (isset($_POST['message']) || isset($_POST['file'])) {
71 if (TINYIB_DBMIGRATE) {
72 fancyDie('Posting is currently disabled.<br>Please try again in a few moments.');
73 }
74
75 list($loggedin, $isadmin) = manageCheckLogIn();
76 $rawpost = isRawPost();
77 if (!$loggedin) {
78 checkCAPTCHA();
79 checkBanned();
80 checkMessageSize();
81 checkFlood();
82 }
83
84 $post = newPost(setParent());
85 $post['ip'] = $_SERVER['REMOTE_ADDR'];
86
87 list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']);
88
89 $post['name'] = cleanString(substr($post['name'], 0, 75));
90 $post['email'] = cleanString(str_replace('"', '"', substr($_POST['email'], 0, 75)));
91 $post['subject'] = cleanString(substr($_POST['subject'], 0, 75));
92 if ($rawpost) {
93 $rawposttext = ($isadmin) ? ' <span style="color: red;">## Admin</span>' : ' <span style="color: purple;">## Mod</span>';
94 $post['message'] = $_POST['message']; // Treat message as raw HTML
95 } else {
96 $rawposttext = '';
97 $post['message'] = str_replace("\n", '<br>', makeLinksClickable(colorQuote(postLink(cleanString(rtrim($_POST['message']))))));
98 }
99 $post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : '';
100 $post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext);
101
102 if (isset($_POST['embed']) && trim($_POST['embed']) != '') {
103 list($service, $embed) = getEmbed(trim($_POST['embed']));
104 if (empty($embed) || !isset($embed['html']) || !isset($embed['title']) || !isset($embed['thumbnail_url'])) {
105 fancyDie("Invalid embed URL. Only YouTube, Vimeo, and SoundCloud URLs are supported.");
106 }
107
108 $post['file_hex'] = $service;
109 $temp_file = time() . substr(microtime(), 2, 3);
110 $file_location = "thumb/" . $temp_file;
111 file_put_contents($file_location, file_get_contents($embed['thumbnail_url']));
112
113 $file_info = getimagesize($file_location);
114 $file_mime = $file_info['mime'];
115 $post['image_width'] = $file_info[0];
116 $post['image_height'] = $file_info[1];
117
118 if ($file_mime == "image/jpeg") {
119 $post['thumb'] = $temp_file . '.jpg';
120 } else if ($file_mime == "image/gif") {
121 $post['thumb'] = $temp_file . '.gif';
122 } else if ($file_mime == "image/png") {
123 $post['thumb'] = $temp_file . '.png';
124 } else {
125 fancyDie("Error while processing audio/video.");
126 }
127 $thumb_location = "thumb/" . $post['thumb'];
128
129 list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);
130
131 if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) {
132 fancyDie("Could not create thumbnail.");
133 }
134
135 addVideoOverlay($thumb_location);
136
137 $thumb_info = getimagesize($thumb_location);
138 $post['thumb_width'] = $thumb_info[0];
139 $post['thumb_height'] = $thumb_info[1];
140
141 $post['file_original'] = cleanString($embed['title']);
142 $post['file'] = str_ireplace(array('src="https://', 'src="http://'), 'src="//', $embed['html']);
143 } else if (isset($_FILES['file'])) {
144 if ($_FILES['file']['name'] != "") {
145 validateFileUpload();
146
147 if (!is_file($_FILES['file']['tmp_name']) || !is_readable($_FILES['file']['tmp_name'])) {
148 fancyDie("File transfer failure. Please retry the submission.");
149 }
150
151 if ((TINYIB_MAXKB > 0) && (filesize($_FILES['file']['tmp_name']) > (TINYIB_MAXKB * 1024))) {
152 fancyDie("That file is larger than " . TINYIB_MAXKBDESC . ".");
153 }
154
155 $post['file_original'] = trim(htmlentities(substr($_FILES['file']['name'], 0, 50), ENT_QUOTES));
156 $post['file_hex'] = md5_file($_FILES['file']['tmp_name']);
157 $post['file_size'] = $_FILES['file']['size'];
158 $post['file_size_formatted'] = convertBytes($post['file_size']);
159
160 // Uploaded file type
161 $file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name']));
162 if ($file_type == '.jpeg') {
163 $file_type = '.jpg';
164 }
165 if ($file_type == '.weba') {
166 $file_type = '.webm';
167 }
168
169 // Thumbnail type
170 if ($file_type == '.webm') {
171 $thumb_type = '.jpg';
172 } else if ($file_type == '.swf') {
173 $thumb_type = '.png';
174 } else {
175 $thumb_type = $file_type;
176 }
177
178 $file_name = time() . substr(microtime(), 2, 3);
179 $post['file'] = $file_name . $file_type;
180 $post['thumb'] = $file_name . "s" . $thumb_type;
181
182 $file_location = "src/" . $post['file'];
183 $thumb_location = "thumb/" . $post['thumb'];
184
185 checkDuplicateFile($post['file_hex']);
186
187 if (!move_uploaded_file($_FILES['file']['tmp_name'], $file_location)) {
188 fancyDie("Could not copy uploaded file.");
189 }
190
191 if ($file_type == '.webm') {
192 $file_mime_output = shell_exec('file --mime-type ' . $file_location);
193 $file_mime_split = explode(' ', $file_mime_output);
194 $file_mime = strtolower(trim(array_pop($file_mime_split)));
195 } else {
196 if (!@getimagesize($file_location)) {
197 @unlink($file_location);
198 fancyDie("Failed to read the size of the uploaded file. Please retry the submission.");
199 }
200
201 $file_info = getimagesize($file_location);
202 $file_mime = $file_info['mime'];
203 }
204
205 if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png" || (TINYIB_WEBM && ($file_mime == "video/webm" || $file_mime == "audio/webm")) || (TINYIB_SWF && ($file_mime == "application/x-shockwave-flash")))) {
206 @unlink($file_location);
207 fancyDie(supportedFileTypes());
208 }
209
210 if ($_FILES['file']['size'] != filesize($file_location)) {
211 @unlink($file_location);
212 fancyDie("File transfer failure. Please go back and try again.");
213 }
214
215 if ($file_mime == "audio/webm" || $file_mime == "video/webm") {
216 $post['image_width'] = intval(shell_exec('mediainfo --Inform="Video;%Width%" ' . $file_location));
217 $post['image_height'] = intval(shell_exec('mediainfo --Inform="Video;%Height%" ' . $file_location));
218
219 if ($post['image_width'] <= 0 || $post['image_height'] <= 0) {
220 $post['image_width'] = 0;
221 $post['image_height'] = 0;
222
223 $file_location_old = $file_location;
224 $file_location = substr($file_location, 0, -1) . 'a'; // replace webm with weba
225 rename($file_location_old, $file_location);
226
227 $post['file'] = substr($post['file'], 0, -1) . 'a'; // replace webm with weba
228 }
229
230 if ($file_mime == "video/webm") {
231 list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);
232 shell_exec("ffmpegthumbnailer -s " . max($thumb_maxwidth, $thumb_maxheight) . " -i $file_location -o $thumb_location");
233
234 $thumb_info = getimagesize($thumb_location);
235 $post['thumb_width'] = $thumb_info[0];
236 $post['thumb_height'] = $thumb_info[1];
237
238 if ($post['thumb_width'] <= 0 || $post['thumb_height'] <= 0) {
239 @unlink($file_location);
240 @unlink($thumb_location);
241 fancyDie("Incorrect file extension/invalid media. Contact ##Admin.");
242 }
243
244 addVideoOverlay($thumb_location);
245 }
246
247 $duration = intval(shell_exec('mediainfo --Inform="' . ($file_mime == 'video/webm' ? 'Video' : 'Audio') . ';%Duration%" ' . $file_location));
248 $mins = floor(round($duration / 1000) / 60);
249 $secs = str_pad(floor(round($duration / 1000) % 60), 2, "0", STR_PAD_LEFT);
250
251 $post['file_original'] = "$mins:$secs" . ($post['file_original'] != '' ? (', ' . $post['file_original']) : '');
252 } else {
253 $file_info = getimagesize($file_location);
254
255 $post['image_width'] = $file_info[0];
256 $post['image_height'] = $file_info[1];
257
258 if ($file_mime == "application/x-shockwave-flash") {
259 if (!copy('swf_thumbnail.png', $thumb_location)) {
260 @unlink($file_location);
261 fancyDie("Could not create thumbnail.");
262 }
263
264 addVideoOverlay($thumb_location);
265 } else {
266 list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);
267
268 if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) {
269 @unlink($file_location);
270 fancyDie("Could not create thumbnail.");
271 }
272 }
273 }
274
275 $thumb_info = getimagesize($thumb_location);
276 $post['thumb_width'] = $thumb_info[0];
277 $post['thumb_height'] = $thumb_info[1];
278 }
279 }
280
281 if ($post['file'] == '') { // No file uploaded
282 $allowed = "";
283 if (TINYIB_PIC || TINYIB_SWF || TINYIB_WEBM) {
284 $allowed = "file";
285 }
286 if (TINYIB_EMBED) {
287 if ($allowed != "") {
288 $allowed .= " or ";
289 }
290 $allowed .= "embed URL";
291 }
292 if ($post['parent'] == TINYIB_NEWTHREAD && $allowed != "" && !TINYIB_NOFILEOK) {
293 fancyDie("A $allowed is required to start a thread.");
294 }
295 if (str_replace('<br>', '', $post['message']) == "") {
296 fancyDie("Please enter a message" . ($allowed != "" ? " and/or upload a $allowed" : "") . ".");
297 }
298 } else {
299 echo $post['file_original'] . ' uploaded.<br>';
300 }
301
302 if (!$loggedin && (($post['file'] != '' && TINYIB_REQMOD == 'files') || TINYIB_REQMOD == 'all')) {
303 $post['moderated'] = '0';
304 echo 'Your ' . ($post['parent'] == TINYIB_NEWTHREAD ? 'thread' : 'post') . ' will be shown <b>once it has been approved</b>.<br>';
305 $slow_redirect = true;
306 }
307
308 $post['id'] = insertPost($post);
309
310 if ($post['moderated'] == '1') {
311 if (strtolower($post['email']) == 'noko') {
312 $redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
313 }
314
315 trimThreads();
316
317 echo 'Updating thread...<br>';
318 if ($post['parent'] != TINYIB_NEWTHREAD) {
319 rebuildThread($post['parent']);
320
321 if (strtolower($post['email']) != 'sage') {
322 if (TINYIB_MAXREPLIES == 0 || numRepliesToThreadByID($post['parent']) <= TINYIB_MAXREPLIES) {
323 bumpThreadByID($post['parent']);
324 }
325 }
326 } else {
327 rebuildThread($post['id']);
328 }
329
330 echo 'Updating index...<br>';
331 rebuildIndexes();
332 }
333// Check if the request is to delete a post and/or its associated image
334} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) {
335 if (!isset($_POST['delete'])) {
336 fancyDie('Tick the box next to a post and click "Delete" to delete it.');
337 }
338
339 if (TINYIB_DBMIGRATE) {
340 fancyDie('Post deletion is currently disabled.<br>Please try again in a few moments.');
341 }
342
343 $post = postByID($_POST['delete']);
344 if ($post) {
345 list($loggedin, $isadmin) = manageCheckLogIn();
346
347 if ($loggedin && $_POST['password'] == '') {
348 // Redirect to post moderation page
349 echo '--> --> --><meta http-equiv="refresh" content="0;url=' . basename($_SERVER['PHP_SELF']) . '?manage&moderate=' . $_POST['delete'] . '">';
350 } elseif ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) {
351 deletePostByID($post['id']);
352 if ($post['parent'] == TINYIB_NEWTHREAD) {
353 threadUpdated($post['id']);
354 } else {
355 threadUpdated($post['parent']);
356 }
357 fancyDie('Post deleted.');
358 } else {
359 fancyDie('Invalid password.');
360 }
361 } else {
362 fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
363 }
364
365 $redirect = false;
366// Check if the request is to access the management area
367} elseif (isset($_GET['manage'])) {
368 $text = '';
369 $onload = '';
370 $navbar = ' ';
371 $redirect = false;
372 $loggedin = false;
373 $isadmin = false;
374 $returnlink = basename($_SERVER['PHP_SELF']);
375
376 list($loggedin, $isadmin) = manageCheckLogIn();
377
378 if ($loggedin) {
379 if ($isadmin) {
380 if (isset($_GET['rebuildall'])) {
381 $allthreads = allThreads();
382 foreach ($allthreads as $thread) {
383 rebuildThread($thread['id']);
384 }
385 rebuildIndexes();
386 $text .= manageInfo('Rebuilt board.');
387 } elseif (isset($_GET['bans'])) {
388 clearExpiredBans();
389
390 if (isset($_POST['ip'])) {
391 if ($_POST['ip'] != '') {
392 $banexists = banByIP($_POST['ip']);
393 if ($banexists) {
394 fancyDie('Sorry, there is already a ban on record for that IP address.');
395 }
396
397 $ban = array();
398 $ban['ip'] = $_POST['ip'];
399 $ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0;
400 $ban['reason'] = $_POST['reason'];
401
402 insertBan($ban);
403 $text .= manageInfo('Ban record added for ' . $ban['ip']);
404 }
405 } elseif (isset($_GET['lift'])) {
406 $ban = banByID($_GET['lift']);
407 if ($ban) {
408 deleteBanByID($_GET['lift']);
409 $text .= manageInfo('Ban record lifted for ' . $ban['ip']);
410 }
411 }
412
413 $onload = manageOnLoad('bans');
414 $text .= manageBanForm();
415 $text .= manageBansTable();
416 } else if (isset($_GET['update'])) {
417 if (is_dir('.git')) {
418 $git_output = shell_exec('git pull 2>&1');
419 $text .= '<blockquote class="reply" style="padding: 7px;font-size: 1.25em;">
420 <pre style="margin: 0;padding: 0;">Attempting update...' . "\n\n" . $git_output . '</pre>
421 </blockquote>
422 <p><b>Note:</b> If TinyIB updates and you have made custom modifications, <a href="https://github.com/tslocum/TinyIB/commits/master">review the changes</a> which have been merged into your installation.
423 Ensure that your modifications do not interfere with any new/modified files.
424 See the <a href="https://github.com/tslocum/TinyIB#readme">README</a> for more information.</p>';
425 } else {
426 $text .= '<p><b>TinyIB was not installed via Git.</b></p>
427 <p>If you installed TinyIB without Git, you must <a href="https://github.com/tslocum/TinyIB">update manually</a>. If you did install with Git, ensure the script has read and write access to the <b>.git</b> folder.</p>';
428 }
429 } elseif (isset($_GET['dbmigrate'])) {
430 if (TINYIB_DBMIGRATE) {
431 if (isset($_GET['go'])) {
432 if (TINYIB_DBMODE == 'flatfile') {
433 if (function_exists('mysqli_connect')) {
434 $link = @mysqli_connect(TINYIB_DBHOST, TINYIB_DBUSERNAME, TINYIB_DBPASSWORD);
435 if (!$link) {
436 fancyDie("Could not connect to database: " . ((is_object($link)) ? mysqli_error($link) : (($link_error = mysqli_connect_error()) ? $link_error : '(unknown error)')));
437 }
438 $db_selected = @mysqli_query($link, "USE " . constant('TINYIB_DBNAME'));
439 if (!$db_selected) {
440 fancyDie("Could not select database: " . ((is_object($link)) ? mysqli_error($link) : (($link_error = mysqli_connect_error()) ? $link_error : '(unknown error')));
441 }
442
443 if (mysqli_num_rows(mysqli_query($link, "SHOW TABLES LIKE '" . TINYIB_DBPOSTS . "'")) == 0) {
444 if (mysqli_num_rows(mysqli_query($link, "SHOW TABLES LIKE '" . TINYIB_DBBANS . "'")) == 0) {
445 mysqli_query($link, $posts_sql);
446 mysqli_query($link, $bans_sql);
447
448 $max_id = 0;
449 $threads = allThreads();
450 foreach ($threads as $thread) {
451 $posts = postsInThreadByID($thread['id']);
452 foreach ($posts as $post) {
453 mysqli_query($link, "INSERT INTO `" . TINYIB_DBPOSTS . "` (`id`, `parent`, `timestamp`, `bumped`, `ip`, `name`, `tripcode`, `email`, `nameblock`, `subject`, `message`, `password`, `file`, `file_hex`, `file_original`, `file_size`, `file_size_formatted`, `image_width`, `image_height`, `thumb`, `thumb_width`, `thumb_height`, `stickied`) VALUES (" . $post['id'] . ", " . $post['parent'] . ", " . time() . ", " . time() . ", '" . $_SERVER['REMOTE_ADDR'] . "', '" . mysqli_real_escape_string($link, $post['name']) . "', '" . mysqli_real_escape_string($link, $post['tripcode']) . "', '" . mysqli_real_escape_string($link, $post['email']) . "', '" . mysqli_real_escape_string($link, $post['nameblock']) . "', '" . mysqli_real_escape_string($link, $post['subject']) . "', '" . mysqli_real_escape_string($link, $post['message']) . "', '" . mysqli_real_escape_string($link, $post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . mysqli_real_escape_string($link, $post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ", " . $post['stickied'] . ")");
454 $max_id = max($max_id, $post['id']);
455 }
456 }
457 if ($max_id > 0 && !mysqli_query($link, "ALTER TABLE `" . TINYIB_DBPOSTS . "` AUTO_INCREMENT = " . ($max_id + 1))) {
458 $text .= '<p><b>Warning:</b> Unable to update the AUTO_INCREMENT value for table ' . TINYIB_DBPOSTS . ', please set it to ' . ($max_id + 1) . '.</p>';
459 }
460
461 $max_id = 0;
462 $bans = allBans();
463 foreach ($bans as $ban) {
464 $max_id = max($max_id, $ban['id']);
465 mysqli_query($link, "INSERT INTO `" . TINYIB_DBBANS . "` (`id`, `ip`, `timestamp`, `expire`, `reason`) VALUES ('" . mysqli_real_escape_string($link, $ban['id']) . "', '" . mysqli_real_escape_string($link, $ban['ip']) . "', '" . mysqli_real_escape_string($link, $ban['timestamp']) . "', '" . mysqli_real_escape_string($link, $ban['expire']) . "', '" . mysqli_real_escape_string($link, $ban['reason']) . "')");
466 }
467 if ($max_id > 0 && !mysqli_query($link, "ALTER TABLE `" . TINYIB_DBBANS . "` AUTO_INCREMENT = " . ($max_id + 1))) {
468 $text .= '<p><b>Warning:</b> Unable to update the AUTO_INCREMENT value for table ' . TINYIB_DBBANS . ', please set it to ' . ($max_id + 1) . '.</p>';
469 }
470
471 $text .= '<p><b>Database migration complete</b>. Set TINYIB_DBMODE to mysqli and TINYIB_DBMIGRATE to false, then click <b>Rebuild All</b> above and ensure everything looks the way it should.</p>';
472 } else {
473 fancyDie('Bans table (' . TINYIB_DBBANS . ') already exists! Please DROP this table and try again.');
474 }
475 } else {
476 fancyDie('Posts table (' . TINYIB_DBPOSTS . ') already exists! Please DROP this table and try again.');
477 }
478 } else {
479 fancyDie('Please install the <a href="http://php.net/manual/en/book.mysqli.php">MySQLi extension</a> and try again.');
480 }
481 } else {
482 fancyDie('Set TINYIB_DBMODE to flatfile and enter in your MySQL settings in settings.php before migrating.');
483 }
484 } else {
485 $text .= '<p>This tool currently only supports migration from a flat file database to MySQL. Your original database will not be deleted. If the migration fails, disable the tool and your board will be unaffected. See the <a href="https://github.com/tslocum/TinyIB#migrating" target="_blank">README</a> <small>(<a href="README.md" target="_blank">alternate link</a>)</small> for instructions.</a><br><br><a href="?manage&dbmigrate&go"><b>Start the migration</b></a></p>';
486 }
487 } else {
488 fancyDie('Set TINYIB_DBMIGRATE to true in settings.php to use this feature.');
489 }
490 }
491 }
492
493 if (isset($_GET['delete'])) {
494 $post = postByID($_GET['delete']);
495 if ($post) {
496 deletePostByID($post['id']);
497 rebuildIndexes();
498 if ($post['parent'] != TINYIB_NEWTHREAD) {
499 rebuildThread($post['parent']);
500 }
501 $text .= manageInfo('Post No.' . $post['id'] . ' deleted.');
502 } else {
503 fancyDie("Sorry, there doesn't appear to be a post with that ID.");
504 }
505 } elseif (isset($_GET['approve'])) {
506 if ($_GET['approve'] > 0) {
507 $post = postByID($_GET['approve']);
508 if ($post) {
509 approvePostByID($post['id']);
510 $thread_id = $post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent'];
511
512 if (strtolower($post['email']) != 'sage' && (TINYIB_MAXREPLIES == 0 || numRepliesToThreadByID($thread_id) <= TINYIB_MAXREPLIES)) {
513 bumpThreadByID($thread_id);
514 }
515 threadUpdated($thread_id);
516
517 $text .= manageInfo('Post No.' . $post['id'] . ' approved.');
518 } else {
519 fancyDie("Sorry, there doesn't appear to be a post with that ID.");
520 }
521 }
522 } elseif (isset($_GET['moderate'])) {
523 if ($_GET['moderate'] > 0) {
524 $post = postByID($_GET['moderate']);
525 if ($post) {
526 $text .= manageModeratePost($post);
527 } else {
528 fancyDie("Sorry, there doesn't appear to be a post with that ID.");
529 }
530 } else {
531 $onload = manageOnLoad('moderate');
532 $text .= manageModeratePostForm();
533 }
534 } elseif (isset($_GET['sticky']) && isset($_GET['setsticky'])) {
535 if ($_GET['sticky'] > 0) {
536 $post = postByID($_GET['sticky']);
537 if ($post && $post['parent'] == TINYIB_NEWTHREAD) {
538 stickyThreadByID($post['id'], (intval($_GET['setsticky'])));
539 threadUpdated($post['id']);
540
541 $text .= manageInfo('Thread No.' . $post['id'] . ' ' . (intval($_GET['setsticky']) == 1 ? 'stickied' : 'un-stickied') . '.');
542 } else {
543 fancyDie("Sorry, there doesn't appear to be a thread with that ID.");
544 }
545 } else {
546 fancyDie("Form data was lost. Please go back and try again.");
547 }
548 } elseif (isset($_GET["rawpost"])) {
549 $onload = manageOnLoad("rawpost");
550 $text .= manageRawPostForm();
551 } elseif (isset($_GET["logout"])) {
552 $_SESSION['tinyib'] = '';
553 session_destroy();
554 die('--> --> --><meta http-equiv="refresh" content="0;url=' . $returnlink . '?manage">');
555 }
556 if ($text == '') {
557 $text = manageStatus();
558 }
559 } else {
560 $onload = manageOnLoad('login');
561 $text .= manageLogInForm();
562 }
563
564 echo managePage($text, $onload);
565} elseif (!file_exists('index.html') || countThreads() == 0) {
566 rebuildIndexes();
567}
568
569if ($redirect) {
570 echo '--> --> --><meta http-equiv="refresh" content="' . (isset($slow_redirect) ? '3' : '0') . ';url=' . (is_string($redirect) ? $redirect : 'index.html') . '">';
571}