2011-06-15 19:11:52 +02:00
|
|
|
<?php
|
2012-04-11 18:49:22 +02:00
|
|
|
|
|
|
|
/*
|
2013-01-20 11:23:46 +01:00
|
|
|
* Copyright (c) 2010-2013 Tinyboard Development Group
|
2012-04-11 18:49:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
require 'inc/functions.php';
|
2012-04-12 13:56:01 +02:00
|
|
|
require 'inc/anti-bot.php';
|
2012-04-11 18:49:22 +02:00
|
|
|
|
|
|
|
// Fix for magic quotes
|
|
|
|
if (get_magic_quotes_gpc()) {
|
|
|
|
function strip_array($var) {
|
2012-04-12 13:56:01 +02:00
|
|
|
return is_array($var) ? array_map('strip_array', $var) : stripslashes($var);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
$_GET = strip_array($_GET);
|
|
|
|
$_POST = strip_array($_POST);
|
|
|
|
}
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (isset($_POST['delete'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
// Delete
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!isset($_POST['board'], $_POST['password']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['bot']);
|
|
|
|
|
|
|
|
$password = &$_POST['password'];
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($password == '')
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['invalidpassword']);
|
|
|
|
|
|
|
|
$delete = array();
|
2012-04-12 16:18:19 +02:00
|
|
|
foreach ($_POST as $post => $value) {
|
|
|
|
if (preg_match('/^delete_(\d+)$/', $post, $m)) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$delete[] = (int)$m[1];
|
2011-01-21 03:14:11 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkDNSBL();
|
2011-01-21 03:14:11 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
// Check if board exists
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!openBoard($_POST['board']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['noboard']);
|
|
|
|
|
|
|
|
// Check if banned
|
|
|
|
checkBan($board['uri']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (empty($delete))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['nodelete']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
foreach ($delete as &$id) {
|
2013-08-01 04:14:26 +02:00
|
|
|
$query = prepare(sprintf("SELECT `thread`, `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
2012-04-11 18:49:22 +02:00
|
|
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
|
|
|
$query->execute() or error(db_error($query));
|
2011-07-27 05:40:27 +02:00
|
|
|
|
2013-08-01 02:51:43 +02:00
|
|
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($password != '' && $post['password'] != $password)
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['invalidpassword']);
|
2011-01-21 03:14:11 +01:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['time'] >= time() - $config['delete_time']) {
|
2012-04-11 18:49:22 +02:00
|
|
|
error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time'])));
|
|
|
|
}
|
2011-01-21 03:14:11 +01:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (isset($_POST['file'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
// Delete just the file
|
|
|
|
deleteFile($id);
|
|
|
|
} else {
|
|
|
|
// Delete entire post
|
|
|
|
deletePost($id);
|
2011-01-21 03:14:11 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
|
|
|
|
_syslog(LOG_INFO, 'Deleted post: ' .
|
|
|
|
'/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '')
|
|
|
|
);
|
2011-01-21 03:14:11 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
2011-02-20 07:19:57 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
buildIndex();
|
|
|
|
|
|
|
|
$is_mod = isset($_POST['mod']) && $_POST['mod'];
|
|
|
|
$root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
|
|
|
|
|
|
|
|
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
} elseif (isset($_POST['report'])) {
|
|
|
|
if (!isset($_POST['board'], $_POST['password'], $_POST['reason']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['bot']);
|
|
|
|
|
|
|
|
$report = array();
|
2012-04-12 16:18:19 +02:00
|
|
|
foreach ($_POST as $post => $value) {
|
|
|
|
if (preg_match('/^delete_(\d+)$/', $post, $m)) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$report[] = (int)$m[1];
|
2011-02-20 07:19:57 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkDNSBL();
|
2011-02-20 07:19:57 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
// Check if board exists
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!openBoard($_POST['board']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['noboard']);
|
|
|
|
|
|
|
|
// Check if banned
|
|
|
|
checkBan($board['uri']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (empty($report))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['noreport']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (count($report) > $config['report_limit'])
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['toomanyreports']);
|
|
|
|
|
2013-08-01 00:59:54 +02:00
|
|
|
$reason = escape_markup_modifiers($_POST['reason']);
|
2012-04-11 18:49:22 +02:00
|
|
|
markup($reason);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
foreach ($report as &$id) {
|
2013-08-01 04:14:26 +02:00
|
|
|
$query = prepare(sprintf("SELECT `thread` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
2012-04-11 18:49:22 +02:00
|
|
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
|
|
|
$query->execute() or error(db_error($query));
|
|
|
|
|
2013-08-01 02:51:43 +02:00
|
|
|
$thread = $query->fetchColumn();
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2013-08-11 13:22:25 +02:00
|
|
|
if ($config['syslog'])
|
|
|
|
_syslog(LOG_INFO, 'Reported post: ' .
|
|
|
|
'/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $thread ? $thread : $id) . ($thread ? '#' . $id : '') .
|
|
|
|
' for "' . $reason . '"'
|
|
|
|
);
|
|
|
|
$query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)");
|
|
|
|
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
|
|
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
|
|
|
|
$query->bindValue(':board', $board['uri'], PDO::PARAM_INT);
|
|
|
|
$query->bindValue(':post', $id, PDO::PARAM_INT);
|
|
|
|
$query->bindValue(':reason', $reason, PDO::PARAM_STR);
|
|
|
|
$query->execute() or error(db_error($query));
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$is_mod = isset($_POST['mod']) && $_POST['mod'];
|
|
|
|
$root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
|
|
|
|
|
|
|
|
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
|
2012-04-12 16:18:19 +02:00
|
|
|
} elseif (isset($_POST['post'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2012-08-30 12:07:23 +02:00
|
|
|
if (!isset($_POST['body'], $_POST['board']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['bot']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!isset($_POST['name']))
|
2012-04-11 18:49:22 +02:00
|
|
|
$_POST['name'] = $config['anonymous'];
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!isset($_POST['email']))
|
2012-04-11 18:49:22 +02:00
|
|
|
$_POST['email'] = '';
|
|
|
|
|
2012-08-30 12:07:23 +02:00
|
|
|
if (!isset($_POST['subject']))
|
|
|
|
$_POST['subject'] = '';
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!isset($_POST['password']))
|
2012-04-11 18:49:22 +02:00
|
|
|
$_POST['password'] = '';
|
|
|
|
|
|
|
|
$post = array('board' => $_POST['board']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (isset($_POST['thread'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['op'] = false;
|
|
|
|
$post['thread'] = round($_POST['thread']);
|
2012-04-12 16:18:19 +02:00
|
|
|
} elseif ($config['quick_reply'] && isset($_POST['quick-reply'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['op'] = false;
|
|
|
|
$post['thread'] = round($_POST['quick-reply']);
|
|
|
|
} else
|
|
|
|
$post['op'] = true;
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!(($post['op'] && $_POST['post'] == $config['button_newtopic']) ||
|
2012-04-11 18:49:22 +02:00
|
|
|
(!$post['op'] && $_POST['post'] == $config['button_reply'])))
|
|
|
|
error($config['error']['bot']);
|
|
|
|
|
|
|
|
// Check the referrer
|
2013-07-31 08:08:55 +02:00
|
|
|
if (!isset($_SERVER['HTTP_REFERER']) || !preg_match($config['referer_match'], urldecode($_SERVER['HTTP_REFERER'])))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['referer']);
|
|
|
|
|
|
|
|
checkDNSBL();
|
2011-02-20 07:19:57 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
// Check if board exists
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!openBoard($post['board']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['noboard']);
|
|
|
|
|
|
|
|
// Check if banned
|
|
|
|
checkBan($board['uri']);
|
|
|
|
|
|
|
|
// Check for CAPTCHA right after opening the board so the "return" link is in there
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['recaptcha']) {
|
|
|
|
if (!isset($_POST['recaptcha_challenge_field']) || !isset($_POST['recaptcha_response_field']))
|
2011-02-12 07:25:15 +01:00
|
|
|
error($config['error']['bot']);
|
2012-04-11 18:49:22 +02:00
|
|
|
// Check what reCAPTCHA has to say...
|
|
|
|
$resp = recaptcha_check_answer($config['recaptcha_private'],
|
|
|
|
$_SERVER['REMOTE_ADDR'],
|
|
|
|
$_POST['recaptcha_challenge_field'],
|
|
|
|
$_POST['recaptcha_response_field']);
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!$resp->is_valid) {
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['captcha']);
|
2011-02-16 10:37:57 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['mod'] = isset($_POST['mod']) && $_POST['mod']) {
|
2012-04-12 13:56:01 +02:00
|
|
|
require 'inc/mod.php';
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!$mod) {
|
2012-04-12 13:56:01 +02:00
|
|
|
// Liar. You're not a mod.
|
|
|
|
error($config['error']['notamod']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$post['sticky'] = $post['op'] && isset($_POST['sticky']);
|
|
|
|
$post['locked'] = $post['op'] && isset($_POST['lock']);
|
|
|
|
$post['raw'] = isset($_POST['raw']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['sticky'] && !hasPermission($config['mod']['sticky'], $board['uri']))
|
2012-04-12 13:56:01 +02:00
|
|
|
error($config['error']['noaccess']);
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['locked'] && !hasPermission($config['mod']['lock'], $board['uri']))
|
2012-04-12 13:56:01 +02:00
|
|
|
error($config['error']['noaccess']);
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['raw'] && !hasPermission($config['mod']['rawhtml'], $board['uri']))
|
2012-04-12 13:56:01 +02:00
|
|
|
error($config['error']['noaccess']);
|
|
|
|
}
|
|
|
|
|
2012-05-07 15:51:15 +02:00
|
|
|
if (!$post['mod']) {
|
2013-08-03 23:42:34 +02:00
|
|
|
$post['antispam_hash'] = checkSpam(array($board['uri'], isset($post['thread']) && !($config['quick_reply'] && isset($_POST['quick-reply'])) ? $post['thread'] : ($config['try_smarter'] && isset($_POST['page']) ? 0 - (int)$_POST['page'] : null)));
|
2012-05-07 15:51:15 +02:00
|
|
|
if ($post['antispam_hash'] === true)
|
|
|
|
error($config['error']['spam']);
|
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['robot_enable'] && $config['robot_mute']) {
|
2012-04-11 18:49:22 +02:00
|
|
|
checkMute();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if thread exists
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!$post['op']) {
|
2013-08-01 04:14:26 +02:00
|
|
|
$query = prepare(sprintf("SELECT `sticky`,`locked`,`sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
|
2012-04-11 18:49:22 +02:00
|
|
|
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
|
|
|
|
$query->execute() or error(db_error());
|
|
|
|
|
2013-08-01 02:51:43 +02:00
|
|
|
if (!$thread = $query->fetch(PDO::FETCH_ASSOC)) {
|
2012-04-11 18:49:22 +02:00
|
|
|
// Non-existant
|
|
|
|
error($config['error']['nonexistant']);
|
2011-10-10 17:58:22 +02:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
2011-05-18 09:05:48 +02:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
|
|
|
|
// Check for an embed field
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['enable_embedding'] && isset($_POST['embed']) && !empty($_POST['embed'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
// yep; validate it
|
|
|
|
$value = $_POST['embed'];
|
2012-04-12 16:18:19 +02:00
|
|
|
foreach ($config['embedding'] as &$embed) {
|
2013-07-20 00:36:12 +02:00
|
|
|
if (preg_match($embed[0], $value)) {
|
|
|
|
// Valid link
|
|
|
|
$post['embed'] = $value;
|
|
|
|
// This is bad, lol.
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['no_longer_require_an_image_for_op'] = true;
|
|
|
|
break;
|
2011-05-18 09:05:48 +02:00
|
|
|
}
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!isset($post['embed'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['invalid_embed']);
|
2011-02-22 01:09:43 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!hasPermission($config['mod']['bypass_field_disable'], $board['uri'])) {
|
|
|
|
if ($config['field_disable_name'])
|
2012-04-11 18:49:22 +02:00
|
|
|
$_POST['name'] = $config['anonymous']; // "forced anonymous"
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['field_disable_email'])
|
2012-04-11 18:49:22 +02:00
|
|
|
$_POST['email'] = '';
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['field_disable_password'])
|
2012-04-11 18:49:22 +02:00
|
|
|
$_POST['password'] = '';
|
2012-08-30 12:07:23 +02:00
|
|
|
|
|
|
|
if ($config['field_disable_subject'] || (!$post['op'] && $config['field_disable_reply_subject']))
|
|
|
|
$_POST['subject'] = '';
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 14:51:46 +02:00
|
|
|
if ($config['allow_upload_by_url'] && isset($_POST['file_url']) && !empty($_POST['file_url'])) {
|
|
|
|
$post['file_url'] = $_POST['file_url'];
|
|
|
|
if (!preg_match($config['url_regex'], $post['file_url']))
|
|
|
|
error($config['error']['invalidimg']);
|
|
|
|
|
|
|
|
|
|
|
|
$post['extension'] = strtolower(mb_substr($post['file_url'], mb_strrpos($post['file_url'], '.') + 1));
|
|
|
|
if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files']))
|
|
|
|
error($config['error']['unknownext']);
|
|
|
|
|
|
|
|
$post['file_tmp'] = tempnam($config['tmp'], 'url');
|
2013-08-12 15:35:27 +02:00
|
|
|
function unlink_tmp_file($file) {
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
register_shutdown_function('unlink_tmp_file', $post['file_tmp']);
|
2013-08-12 14:51:46 +02:00
|
|
|
|
|
|
|
$fp = fopen($post['file_tmp'], 'w');
|
|
|
|
|
|
|
|
$curl = curl_init();
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $post['file_url']);
|
|
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, true);
|
|
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
|
|
|
|
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
|
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
|
|
|
|
curl_setopt($curl, CURLOPT_USERAGENT, 'Tinyboard');
|
|
|
|
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
|
|
|
|
curl_setopt($curl, CURLOPT_FILE, $fp);
|
2013-08-12 16:07:23 +02:00
|
|
|
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
2013-08-12 14:51:46 +02:00
|
|
|
|
|
|
|
if (curl_exec($curl) === false)
|
|
|
|
error($config['error']['nomove']);
|
|
|
|
|
|
|
|
curl_close($curl);
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
$_FILES['file'] = array(
|
|
|
|
'name' => basename($post['file_url']),
|
|
|
|
'tmp_name' => $post['file_tmp'],
|
|
|
|
'error' => 0,
|
|
|
|
'size' => filesize($post['file_tmp'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
// Check for a file
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['op'] && !isset($post['no_longer_require_an_image_for_op'])) {
|
|
|
|
if (!isset($_FILES['file']['tmp_name']) || $_FILES['file']['tmp_name'] == '' && $config['force_image_op'])
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['noimage']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous'];
|
|
|
|
$post['subject'] = $_POST['subject'];
|
2012-08-26 18:18:31 +02:00
|
|
|
$post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email']));
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['body'] = $_POST['body'];
|
|
|
|
$post['password'] = $_POST['password'];
|
|
|
|
$post['has_file'] = !isset($post['embed']) && (($post['op'] && !isset($post['no_longer_require_an_image_for_op']) && $config['force_image_op']) || (isset($_FILES['file']) && $_FILES['file']['tmp_name'] != ''));
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['has_file'])
|
2013-07-31 22:34:50 +02:00
|
|
|
$post['filename'] = urldecode(get_magic_quotes_gpc() ? stripslashes($_FILES['file']['name']) : $_FILES['file']['name']);
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!($post['has_file'] || isset($post['embed'])) || (($post['op'] && $config['force_body_op']) || (!$post['op'] && $config['force_body']))) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$stripped_whitespace = preg_replace('/[\s]/u', '', $post['body']);
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($stripped_whitespace == '') {
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['tooshort_body']);
|
2011-01-19 02:37:31 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
2013-06-18 19:21:41 +02:00
|
|
|
if (!$post['op']) {
|
|
|
|
// Check if thread is locked
|
|
|
|
// but allow mods to post
|
|
|
|
if ($thread['locked'] && !hasPermission($config['mod']['postinlocked'], $board['uri']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['locked']);
|
2013-06-18 19:21:41 +02:00
|
|
|
|
|
|
|
$numposts = numPosts($post['thread']);
|
|
|
|
|
|
|
|
if ($config['reply_hard_limit'] != 0 && $config['reply_hard_limit'] <= $numposts['replies'])
|
|
|
|
error($config['error']['reply_hard_limit']);
|
|
|
|
|
|
|
|
if ($post['has_file'] && $config['image_hard_limit'] != 0 && $config['image_hard_limit'] <= $numposts['images'])
|
|
|
|
error($config['error']['image_hard_limit']);
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
2013-06-18 19:21:41 +02:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['has_file']) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$size = $_FILES['file']['size'];
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($size > $config['max_filesize'])
|
2012-04-11 18:49:22 +02:00
|
|
|
error(sprintf3($config['error']['filesize'], array(
|
|
|
|
'sz' => number_format($size),
|
|
|
|
'filesz' => number_format($size),
|
|
|
|
'maxsz' => number_format($config['max_filesize'])
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2012-05-07 10:22:20 +02:00
|
|
|
|
|
|
|
$post['capcode'] = false;
|
|
|
|
|
|
|
|
if ($mod && preg_match('/^((.+) )?## (.+)$/', $post['name'], $matches)) {
|
|
|
|
$name = $matches[2] != '' ? $matches[2] : $config['anonymous'];
|
|
|
|
$cap = $matches[3];
|
|
|
|
|
|
|
|
if (isset($config['mod']['capcode'][$mod['type']])) {
|
|
|
|
if ( $config['mod']['capcode'][$mod['type']] === true ||
|
|
|
|
(is_array($config['mod']['capcode'][$mod['type']]) &&
|
|
|
|
in_array($cap, $config['mod']['capcode'][$mod['type']])
|
|
|
|
)) {
|
|
|
|
|
|
|
|
$post['capcode'] = utf8tohtml($cap);
|
|
|
|
$post['name'] = $name;
|
|
|
|
}
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$trip = generate_tripcode($post['name']);
|
|
|
|
$post['name'] = $trip[0];
|
|
|
|
$post['trip'] = isset($trip[1]) ? $trip[1] : '';
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (strtolower($post['email']) == 'noko') {
|
2012-04-11 18:49:22 +02:00
|
|
|
$noko = true;
|
|
|
|
$post['email'] = '';
|
|
|
|
} else $noko = false;
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['has_file']) {
|
2013-07-31 22:34:50 +02:00
|
|
|
$post['extension'] = strtolower(mb_substr($post['filename'], mb_strrpos($post['filename'], '.') + 1));
|
2012-04-12 16:18:19 +02:00
|
|
|
if (isset($config['filename_func']))
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['file_id'] = $config['filename_func']($post);
|
|
|
|
else
|
|
|
|
$post['file_id'] = time() . substr(microtime(), 2, 3);
|
|
|
|
|
|
|
|
$post['file'] = $board['dir'] . $config['dir']['img'] . $post['file_id'] . '.' . $post['extension'];
|
|
|
|
$post['thumb'] = $board['dir'] . $config['dir']['thumb'] . $post['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension']);
|
|
|
|
}
|
|
|
|
|
2013-07-29 02:33:26 +02:00
|
|
|
if ($config['strip_combining_chars']) {
|
|
|
|
$post['name'] = strip_combining_chars($post['name']);
|
|
|
|
$post['email'] = strip_combining_chars($post['email']);
|
2013-07-29 02:46:00 +02:00
|
|
|
$post['subject'] = strip_combining_chars($post['subject']);
|
2013-07-29 02:33:26 +02:00
|
|
|
$post['body'] = strip_combining_chars($post['body']);
|
|
|
|
}
|
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
// Check string lengths
|
2012-04-12 16:18:19 +02:00
|
|
|
if (mb_strlen($post['name']) > 35)
|
2012-04-11 18:49:22 +02:00
|
|
|
error(sprintf($config['error']['toolong'], 'name'));
|
2012-04-12 16:18:19 +02:00
|
|
|
if (mb_strlen($post['email']) > 40)
|
2012-04-11 18:49:22 +02:00
|
|
|
error(sprintf($config['error']['toolong'], 'email'));
|
2012-04-12 16:18:19 +02:00
|
|
|
if (mb_strlen($post['subject']) > 100)
|
2012-04-11 18:49:22 +02:00
|
|
|
error(sprintf($config['error']['toolong'], 'subject'));
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!$mod && mb_strlen($post['body']) > $config['max_body'])
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['toolong_body']);
|
2012-04-12 16:18:19 +02:00
|
|
|
if (mb_strlen($post['password']) > 20)
|
2012-04-11 18:49:22 +02:00
|
|
|
error(sprintf($config['error']['toolong'], 'password'));
|
2013-07-29 02:33:26 +02:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
wordfilters($post['body']);
|
2013-08-01 00:59:54 +02:00
|
|
|
$post['body'] = escape_markup_modifiers($post['body']);
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2013-08-16 13:25:56 +02:00
|
|
|
if ($mod && isset($post['raw']) && $post['raw']) {
|
|
|
|
$post['body'] .= '<tinyboard raw html>1</tinyboard>';
|
|
|
|
}
|
|
|
|
|
2013-08-16 13:08:01 +02:00
|
|
|
if ($config['country_flags']) {
|
|
|
|
if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
|
|
|
|
error('GeoIP not available: ' . geoip_db_filename(GEOIP_COUNTRY_EDITION));
|
|
|
|
}
|
2013-08-16 13:25:56 +02:00
|
|
|
if ($country_code = @geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])) {
|
2013-08-16 14:12:25 +02:00
|
|
|
$post['body'] .= '<tinyboard flag>' . strtolower($country_code) . '</tinyboard>';
|
2013-08-16 13:08:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-31 18:05:19 +02:00
|
|
|
if (mysql_version() >= 50503) {
|
2013-07-31 04:08:56 +02:00
|
|
|
$post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset
|
2013-07-31 18:05:19 +02:00
|
|
|
} else {
|
|
|
|
// MySQL's `utf8` charset only supports up to 3-byte symbols
|
|
|
|
// Remove anything >= 0x010000
|
|
|
|
|
|
|
|
$chars = preg_split('//u', $post['body'], -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
$post['body_nomarkup'] = '';
|
|
|
|
foreach ($chars as $char) {
|
|
|
|
$o = 0;
|
|
|
|
$ord = ordutf8($char, $o);
|
|
|
|
if ($ord >= 0x010000)
|
|
|
|
continue;
|
|
|
|
$post['body_nomarkup'] .= $char;
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2013-08-01 01:18:55 +02:00
|
|
|
$post['tracked_cites'] = markup($post['body'], true);
|
2012-04-11 18:49:22 +02:00
|
|
|
|
|
|
|
// Check for a flood
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!hasPermission($config['mod']['flood'], $board['uri']) && checkFlood($post)) {
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['flood']);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once 'inc/filters.php';
|
|
|
|
|
|
|
|
do_filters($post);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['has_file']) {
|
|
|
|
if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files']))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['unknownext']);
|
2010-11-05 17:46:20 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
$is_an_image = !in_array($post['extension'], $config['allowed_ext_files']);
|
2011-04-06 11:18:36 +02:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
// Truncate filename if it is too long
|
2013-07-31 22:34:50 +02:00
|
|
|
$post['filename'] = mb_substr($post['filename'], 0, $config['max_filename_len']);
|
2011-02-03 10:28:14 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
$upload = $_FILES['file']['tmp_name'];
|
2010-11-05 17:46:20 +01:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!is_readable($upload))
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['nomove']);
|
2011-01-18 14:41:43 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['filehash'] = $config['file_hash']($upload);
|
|
|
|
$post['filesize'] = filesize($upload);
|
2011-03-26 12:50:03 +01:00
|
|
|
|
2013-08-03 02:52:58 +02:00
|
|
|
if ($is_an_image && $config['ie_mime_type_detection'] !== false) {
|
2012-04-11 18:49:22 +02:00
|
|
|
// Check IE MIME type detection XSS exploit
|
|
|
|
$buffer = file_get_contents($upload, null, null, null, 255);
|
2012-04-12 16:18:19 +02:00
|
|
|
if (preg_match($config['ie_mime_type_detection'], $buffer)) {
|
2012-04-11 18:49:22 +02:00
|
|
|
undoImage($post);
|
|
|
|
error($config['error']['mime_exploit']);
|
|
|
|
}
|
2012-03-18 09:53:56 +01:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
require_once 'inc/image.php';
|
2012-03-10 10:53:41 +01:00
|
|
|
|
2012-07-19 08:16:50 +02:00
|
|
|
// find dimensions of an image using GD
|
|
|
|
if (!$size = @getimagesize($upload)) {
|
|
|
|
error($config['error']['invalidimg']);
|
|
|
|
}
|
|
|
|
if ($size[0] > $config['max_width'] || $size[1] > $config['max_height']) {
|
|
|
|
error($config['error']['maxsize']);
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 21:50:45 +02:00
|
|
|
|
2013-08-04 02:34:59 +02:00
|
|
|
if ($config['convert_auto_orient'] && ($post['extension'] == 'jpg' || $post['extension'] == 'jpeg')) {
|
2013-07-21 21:50:45 +02:00
|
|
|
// The following code corrects the image orientation.
|
|
|
|
// Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered.
|
2013-08-04 06:48:28 +02:00
|
|
|
if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool']) && ($post['extension'] == 'jpg' || $post['extension'] == 'jpeg')))) {
|
2013-08-04 02:34:59 +02:00
|
|
|
if (in_array($config['thumb_method'], array('convert', 'convert+gifsicle', 'gm', 'gm+gifsicle'))) {
|
2013-08-05 05:02:15 +02:00
|
|
|
$exif = @exif_read_data($upload);
|
2013-08-04 02:34:59 +02:00
|
|
|
$gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle'));
|
2013-08-02 03:28:16 +02:00
|
|
|
if (isset($exif['Orientation']) && $exif['Orientation'] != 1) {
|
2013-08-04 04:14:25 +02:00
|
|
|
if ($config['convert_manual_orient']) {
|
|
|
|
$error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' .
|
|
|
|
escapeshellarg($upload) . ' ' .
|
2013-08-04 06:48:28 +02:00
|
|
|
ImageConvert::jpeg_exif_orientation(false, $exif) . ' ' .
|
2013-08-04 06:54:27 +02:00
|
|
|
($config['strip_exif'] ? '+profile "*"' :
|
|
|
|
($config['use_exiftool'] ? '' : '+profile "*"')
|
|
|
|
) . ' ' .
|
2013-08-04 04:14:25 +02:00
|
|
|
escapeshellarg($upload));
|
2013-08-04 06:54:27 +02:00
|
|
|
if ($config['use_exiftool'] && !$config['strip_exif']) {
|
2013-08-04 06:48:28 +02:00
|
|
|
if ($exiftool_error = shell_exec_error(
|
|
|
|
'exiftool -q -orientation=1 -n ' . escapeshellarg($upload)))
|
|
|
|
error('exiftool failed!', null, $exiftool_error);
|
|
|
|
} else {
|
|
|
|
// TODO: Find another way to remove the Orientation tag from the EXIF profile
|
|
|
|
// without needing `exiftool`.
|
|
|
|
}
|
2013-08-04 04:14:25 +02:00
|
|
|
} else {
|
|
|
|
$error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' .
|
|
|
|
escapeshellarg($upload) . ' -auto-orient ' . escapeshellarg($upload));
|
|
|
|
}
|
|
|
|
if ($error)
|
2013-08-04 02:34:59 +02:00
|
|
|
error('Could not auto-orient image!', null, $error);
|
2013-08-04 03:47:24 +02:00
|
|
|
$size = @getimagesize($upload);
|
2013-08-04 06:54:27 +02:00
|
|
|
if ($config['strip_exif'])
|
|
|
|
$post['exif_stripped'] = true;
|
2013-08-02 03:28:16 +02:00
|
|
|
}
|
2013-01-23 17:24:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
// create image object
|
2013-08-04 02:50:37 +02:00
|
|
|
$image = new Image($upload, $post['extension'], $size);
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($image->size->width > $config['max_width'] || $image->size->height > $config['max_height']) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$image->delete();
|
|
|
|
error($config['error']['maxsize']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$post['width'] = $image->size->width;
|
|
|
|
$post['height'] = $image->size->height;
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['thumb'] = 'spoiler';
|
2011-10-01 13:43:23 +02:00
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
$size = @getimagesize($config['spoiler_image']);
|
2011-04-13 12:57:41 +02:00
|
|
|
$post['thumbwidth'] = $size[0];
|
|
|
|
$post['thumbheight'] = $size[1];
|
2012-04-12 16:18:19 +02:00
|
|
|
} elseif ($config['minimum_copy_resize'] &&
|
2012-04-11 18:49:22 +02:00
|
|
|
$image->size->width <= $config['thumb_width'] &&
|
|
|
|
$image->size->height <= $config['thumb_height'] &&
|
|
|
|
$post['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'])) {
|
|
|
|
|
|
|
|
// Copy, because there's nothing to resize
|
|
|
|
copy($upload, $post['thumb']);
|
|
|
|
|
|
|
|
$post['thumbwidth'] = $image->size->width;
|
|
|
|
$post['thumbheight'] = $image->size->height;
|
2011-03-14 12:30:42 +01:00
|
|
|
} else {
|
2012-04-11 18:49:22 +02:00
|
|
|
$thumb = $image->resize(
|
|
|
|
$config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'],
|
|
|
|
$post['op'] ? $config['thumb_op_width'] : $config['thumb_width'],
|
|
|
|
$post['op'] ? $config['thumb_op_height'] : $config['thumb_height']
|
|
|
|
);
|
|
|
|
|
|
|
|
$thumb->to($post['thumb']);
|
|
|
|
|
|
|
|
$post['thumbwidth'] = $thumb->width;
|
|
|
|
$post['thumbheight'] = $thumb->height;
|
|
|
|
|
|
|
|
$thumb->_destroy();
|
2011-03-14 12:30:42 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2013-08-04 06:54:27 +02:00
|
|
|
if ($config['redraw_image'] || (!@$post['exif_stripped'] && $config['strip_exif'] && ($post['extension'] == 'jpg' || $post['extension'] == 'jpeg'))) {
|
2013-08-04 06:48:28 +02:00
|
|
|
if (!$config['redraw_image'] && $config['use_exiftool']) {
|
2013-08-05 05:15:01 +02:00
|
|
|
if($error = shell_exec_error('exiftool -ignoreMinorErrors -q -q -all= ' . escapeshellarg($upload)))
|
2013-08-04 02:34:59 +02:00
|
|
|
error('Could not strip EXIF metadata!', null, $error);
|
|
|
|
} else {
|
|
|
|
$image->to($post['file']);
|
|
|
|
$dont_copy_file = true;
|
|
|
|
}
|
2011-12-13 10:15:46 +01:00
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
$image->destroy();
|
2010-11-05 17:46:20 +01:00
|
|
|
} else {
|
2012-04-11 18:49:22 +02:00
|
|
|
// not an image
|
|
|
|
//copy($config['file_thumb'], $post['thumb']);
|
|
|
|
$post['thumb'] = 'file';
|
|
|
|
|
|
|
|
$size = @getimagesize($config['file_thumb']);
|
|
|
|
$post['thumbwidth'] = $size[0];
|
|
|
|
$post['thumbheight'] = $size[1];
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
2012-04-20 11:04:37 +02:00
|
|
|
|
|
|
|
if (!isset($dont_copy_file) || !$dont_copy_file) {
|
2013-08-12 14:51:46 +02:00
|
|
|
if (isset($post['file_tmp'])) {
|
|
|
|
if (!@rename($upload, $post['file']))
|
|
|
|
error($config['error']['nomove']);
|
2013-08-12 15:06:58 +02:00
|
|
|
chmod($post['file'], 0755);
|
2013-08-12 14:51:46 +02:00
|
|
|
} elseif (!@move_uploaded_file($upload, $post['file']))
|
2012-04-20 11:04:37 +02:00
|
|
|
error($config['error']['nomove']);
|
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-11-14 21:33:27 +01:00
|
|
|
if ($post['has_file']) {
|
|
|
|
if ($config['image_reject_repost']) {
|
|
|
|
if ($p = getPostByHash($post['filehash'])) {
|
|
|
|
undoImage($post);
|
|
|
|
error(sprintf($config['error']['fileexists'],
|
|
|
|
$post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'] .
|
|
|
|
$board['dir'] . $config['dir']['res'] .
|
|
|
|
($p['thread'] ?
|
|
|
|
$p['thread'] . '.html#' . $p['id']
|
|
|
|
:
|
|
|
|
$p['id'] . '.html'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
} else if (!$post['op'] && $config['image_reject_repost_in_thread']) {
|
|
|
|
if ($p = getPostByHashInThread($post['filehash'], $post['thread'])) {
|
|
|
|
undoImage($post);
|
|
|
|
error(sprintf($config['error']['fileexistsinthread'],
|
|
|
|
$post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'] .
|
|
|
|
$board['dir'] . $config['dir']['res'] .
|
|
|
|
($p['thread'] ?
|
|
|
|
$p['thread'] . '.html#' . $p['id']
|
|
|
|
:
|
|
|
|
$p['id'] . '.html'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!hasPermission($config['mod']['postunoriginal'], $board['uri']) && $config['robot_enable'] && checkRobot($post['body_nomarkup'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
undoImage($post);
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['robot_mute']) {
|
2012-04-11 18:49:22 +02:00
|
|
|
error(sprintf($config['error']['muted'], mute()));
|
2010-11-30 10:40:37 +01:00
|
|
|
} else {
|
2012-04-11 18:49:22 +02:00
|
|
|
error($config['error']['unoriginal']);
|
2010-11-05 17:46:20 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
|
|
|
|
// Remove board directories before inserting them into the database.
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['has_file']) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$post['file_path'] = $post['file'];
|
2013-07-31 08:08:55 +02:00
|
|
|
$post['file'] = mb_substr($post['file'], mb_strlen($board['dir'] . $config['dir']['img']));
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($is_an_image && $post['thumb'] != 'spoiler')
|
2013-07-31 08:08:55 +02:00
|
|
|
$post['thumb'] = mb_substr($post['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb']));
|
2012-04-11 18:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$post = (object)$post;
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($error = event('post', $post)) {
|
2012-04-11 18:49:22 +02:00
|
|
|
undoImage((array)$post);
|
|
|
|
error($error);
|
|
|
|
}
|
|
|
|
$post = (array)$post;
|
|
|
|
|
2012-05-27 12:55:56 +02:00
|
|
|
$post['id'] = $id = post($post);
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2012-05-07 15:51:15 +02:00
|
|
|
if (isset($post['antispam_hash'])) {
|
|
|
|
incrementSpamHash($post['antispam_hash']);
|
|
|
|
}
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (isset($post['tracked_cites'])) {
|
|
|
|
foreach ($post['tracked_cites'] as $cite) {
|
2013-08-01 04:14:26 +02:00
|
|
|
$query = prepare('INSERT INTO ``cites`` VALUES (:board, :post, :target_board, :target)');
|
2012-04-11 18:49:22 +02:00
|
|
|
$query->bindValue(':board', $board['uri']);
|
|
|
|
$query->bindValue(':post', $id, PDO::PARAM_INT);
|
|
|
|
$query->bindValue(':target_board',$cite[0]);
|
|
|
|
$query->bindValue(':target', $cite[1], PDO::PARAM_INT);
|
|
|
|
$query->execute() or error(db_error($query));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 19:21:41 +02:00
|
|
|
if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
bumpThread($post['thread']);
|
|
|
|
}
|
|
|
|
|
2013-08-03 23:42:34 +02:00
|
|
|
buildThread($post['op'] ? $id : $post['thread']);
|
|
|
|
|
|
|
|
if ($config['try_smarter'] && $post['op'])
|
|
|
|
$build_pages = range(1, $config['max_pages']);
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($post['op'])
|
2012-04-11 18:49:22 +02:00
|
|
|
clean();
|
|
|
|
|
|
|
|
event('post-after', $post);
|
|
|
|
|
|
|
|
buildIndex();
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if (isset($_SERVER['HTTP_REFERER'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
// Tell Javascript that we posted successfully
|
2012-04-12 16:18:19 +02:00
|
|
|
if (isset($_COOKIE[$config['cookies']['js']]))
|
2012-04-11 18:49:22 +02:00
|
|
|
$js = json_decode($_COOKIE[$config['cookies']['js']]);
|
|
|
|
else
|
|
|
|
$js = (object) array();
|
|
|
|
// Tell it to delete the cached post for referer
|
|
|
|
$js->{$_SERVER['HTTP_REFERER']} = true;
|
|
|
|
// Encode and set cookie
|
|
|
|
setcookie($config['cookies']['js'], json_encode($js), 0, $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
$root = $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['always_noko'] || $noko) {
|
2012-04-11 18:49:22 +02:00
|
|
|
$redirect = $root . $board['dir'] . $config['dir']['res'] .
|
|
|
|
sprintf($config['file_page'], $post['op'] ? $id:$post['thread']) . (!$post['op'] ? '#' . $id : '');
|
|
|
|
} else {
|
|
|
|
$redirect = $root . $board['dir'] . $config['file_index'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-12 16:18:19 +02:00
|
|
|
if ($config['syslog'])
|
2012-04-11 18:49:22 +02:00
|
|
|
_syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] .
|
2012-04-13 19:43:04 +02:00
|
|
|
sprintf($config['file_page'], $post['op'] ? $id : $post['thread']) . (!$post['op'] ? '#' . $id : ''));
|
2012-04-11 18:49:22 +02:00
|
|
|
|
2013-07-18 18:06:26 +02:00
|
|
|
if ($post['op'])
|
|
|
|
rebuildThemes('post-thread', $board['uri']);
|
|
|
|
else
|
|
|
|
rebuildThemes('post', $board['uri']);
|
|
|
|
|
2012-04-11 18:49:22 +02:00
|
|
|
header('Location: ' . $redirect, true, $config['redirect_http']);
|
|
|
|
} else {
|
2012-04-12 16:18:19 +02:00
|
|
|
if (!file_exists($config['has_installed'])) {
|
2012-04-11 18:49:22 +02:00
|
|
|
header('Location: install.php', true, $config['redirect_http']);
|
|
|
|
} else {
|
|
|
|
// They opened post.php in their browser manually.
|
|
|
|
error($config['error']['nopost']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|