summaryrefslogtreecommitdiff
path: root/inc/mod/pages.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/mod/pages.php')
-rw-r--r--inc/mod/pages.php422
1 files changed, 284 insertions, 138 deletions
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index d5ec6018..b3f09a66 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -82,7 +82,7 @@ function mod_dashboard() {
if (hasPermission($config['mod']['noticeboard'])) {
if (!$config['cache']['enabled'] || !$args['noticeboard'] = cache::get('noticeboard_preview')) {
- $query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :limit");
+ $query = prepare("SELECT ``noticeboard``.*, `username` FROM ``noticeboard`` LEFT JOIN ``mods`` ON ``mods``.`id` = `mod` ORDER BY `id` DESC LIMIT :limit");
$query->bindValue(':limit', $config['mod']['noticeboard_dashboard'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$args['noticeboard'] = $query->fetchAll(PDO::FETCH_ASSOC);
@@ -93,17 +93,17 @@ function mod_dashboard() {
}
if (!$config['cache']['enabled'] || ($args['unread_pms'] = cache::get('pm_unreadcount_' . $mod['id'])) == false) {
- $query = prepare('SELECT COUNT(*) FROM `pms` WHERE `to` = :id AND `unread` = 1');
+ $query = prepare('SELECT COUNT(*) FROM ``pms`` WHERE `to` = :id AND `unread` = 1');
$query->bindValue(':id', $mod['id']);
$query->execute() or error(db_error($query));
- $args['unread_pms'] = $query->fetchColumn(0);
+ $args['unread_pms'] = $query->fetchColumn();
if ($config['cache']['enabled'])
cache::set('pm_unreadcount_' . $mod['id'], $args['unread_pms']);
}
- $query = query('SELECT COUNT(*) FROM `reports`') or error(db_error($query));
- $args['reports'] = $query->fetchColumn(0);
+ $query = query('SELECT COUNT(*) FROM ``reports``') or error(db_error($query));
+ $args['reports'] = $query->fetchColumn();
if ($mod['type'] >= ADMIN && $config['check_updates']) {
if (!$config['version'])
@@ -174,6 +174,11 @@ function mod_search_redirect() {
$query = str_replace('_', '%5F', $query);
$query = str_replace('+', '_', $query);
+ if ($query === '') {
+ header('Location: ?/', true, $config['redirect_http']);
+ return;
+ }
+
header('Location: ?/search/' . $_POST['type'] . '/' . $query, true, $config['redirect_http']);
} else {
header('Location: ?/', true, $config['redirect_http']);
@@ -203,6 +208,8 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
// Use asterisk as wildcard instead
$query = str_replace('*', '%', $query);
+ $query = str_replace('`', '!`', $query);
+
// Array of phrases to match
$match = array();
@@ -225,7 +232,7 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
// Which `field` to search?
if ($type == 'posts')
- $sql_field = 'body';
+ $sql_field = array('body_nomarkup', 'filename', 'subject', 'filehash', 'ip', 'name', 'trip');
if ($type == 'IP_notes')
$sql_field = 'body';
if ($type == 'bans')
@@ -239,32 +246,59 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
if (!empty($sql_like))
$sql_like .= ' AND ';
$phrase = preg_replace('/^\'(.+)\'$/', '\'%$1%\'', $phrase);
- $sql_like .= '`' . $sql_field . '` LIKE ' . $phrase . ' ESCAPE \'!\'';
+ if (is_array($sql_field)) {
+ foreach ($sql_field as $field) {
+ $sql_like .= '`' . $field . '` LIKE ' . $phrase . ' ESCAPE \'!\' OR';
+ }
+ $sql_like = preg_replace('/ OR$/', '', $sql_like);
+ } else {
+ $sql_like .= '`' . $sql_field . '` LIKE ' . $phrase . ' ESCAPE \'!\'';
+ }
}
// Compile SQL query
if ($type == 'posts') {
- error('Searching posts is under development. Sorry.');
+ $query = '';
+
+ $boards = listBoards();
+ if (empty($boards))
+ error(_('There are no boards to search!'));
+
+ foreach ($boards as $board) {
+ openBoard($board['uri']);
+ if (!hasPermission($config['mod']['search_posts'], $board['uri']))
+ continue;
+
+ if (!empty($query))
+ $query .= ' UNION ALL ';
+ $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE %s", $board['uri'], $board['uri'], $sql_like);
+ }
+
+ // You weren't allowed to search any boards
+ if (empty($query))
+ error($config['error']['noaccess']);
+
+ $query .= ' ORDER BY `sticky` DESC, `id` DESC';
}
if ($type == 'IP_notes') {
- $query = 'SELECT * FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE ' . $sql_like . ' ORDER BY `time` DESC';
+ $query = 'SELECT * FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE ' . $sql_like . ' ORDER BY `time` DESC';
$sql_table = 'ip_notes';
if (!hasPermission($config['mod']['view_notes']) || !hasPermission($config['mod']['show_ip']))
error($config['error']['noaccess']);
}
if ($type == 'bans') {
- $query = 'SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE ' . $sql_like . ' ORDER BY (`expires` IS NOT NULL AND `expires` < UNIX_TIMESTAMP()), `set` DESC';
+ $query = 'SELECT ``bans``.*, `username` FROM ``bans`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE ' . $sql_like . ' ORDER BY (`expires` IS NOT NULL AND `expires` < UNIX_TIMESTAMP()), `set` DESC';
$sql_table = 'bans';
if (!hasPermission($config['mod']['view_banlist']))
error($config['error']['noaccess']);
}
if ($type == 'log') {
- $query = 'SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE ' . $sql_like . ' ORDER BY `time` DESC';
+ $query = 'SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE ' . $sql_like . ' ORDER BY `time` DESC';
$sql_table = 'modlogs';
if (!hasPermission($config['mod']['modlog']))
error($config['error']['noaccess']);
@@ -273,10 +307,15 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
// Execute SQL query (with pages)
$q = query($query . ' LIMIT ' . (($page_no - 1) * $config['mod']['search_page']) . ', ' . $config['mod']['search_page']) or error(db_error());
$results = $q->fetchAll(PDO::FETCH_ASSOC);
-
+
// Get total result count
- $q = query('SELECT COUNT(*) FROM `' . $sql_table . '` WHERE ' . $sql_like) or error(db_error());
- $result_count = $q->fetchColumn();
+ if ($type == 'posts') {
+ $q = query("SELECT COUNT(*) FROM ($query) AS `tmp_table`") or error(db_error());
+ $result_count = $q->fetchColumn();
+ } else {
+ $q = query('SELECT COUNT(*) FROM `' . $sql_table . '` WHERE ' . $sql_like) or error(db_error());
+ $result_count = $q->fetchColumn();
+ }
if ($type == 'bans') {
foreach ($results as &$ban) {
@@ -285,6 +324,12 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
}
}
+ if ($type == 'posts') {
+ foreach ($results as &$post) {
+ $post['snippet'] = pm_snippet($post['body']);
+ }
+ }
+
// $results now contains the search results
mod_page(_('Search results'), 'mod/search_results.html', array(
@@ -310,7 +355,7 @@ function mod_edit_board($boardName) {
if (!hasPermission($config['mod']['manageboards'], $board['uri']))
error($config['error']['deleteboard']);
- $query = prepare('DELETE FROM `boards` WHERE `uri` = :uri');
+ $query = prepare('DELETE FROM ``boards`` WHERE `uri` = :uri');
$query->bindValue(':uri', $board['uri']);
$query->execute() or error(db_error($query));
@@ -320,19 +365,19 @@ function mod_edit_board($boardName) {
rrmdir($board['uri'] . '/');
// Delete posting table
- $query = query(sprintf('DROP TABLE IF EXISTS `posts_%s`', $board['uri'])) or error(db_error());
+ $query = query(sprintf('DROP TABLE IF EXISTS ``posts_%s``', $board['uri'])) or error(db_error());
// Clear reports
- $query = prepare('DELETE FROM `reports` WHERE `board` = :id');
+ $query = prepare('DELETE FROM ``reports`` WHERE `board` = :id');
$query->bindValue(':id', $board['uri'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
// Delete from table
- $query = prepare('DELETE FROM `boards` WHERE `uri` = :uri');
+ $query = prepare('DELETE FROM ``boards`` WHERE `uri` = :uri');
$query->bindValue(':uri', $board['uri'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
- $query = prepare("SELECT `board`, `post` FROM `cites` WHERE `target_board` = :board");
+ $query = prepare("SELECT `board`, `post` FROM ``cites`` WHERE `target_board` = :board");
$query->bindValue(':board', $board['uri']);
$query->execute() or error(db_error($query));
while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
@@ -344,28 +389,28 @@ function mod_edit_board($boardName) {
}
}
- $query = prepare('DELETE FROM `cites` WHERE `board` = :board OR `target_board` = :board');
+ $query = prepare('DELETE FROM ``cites`` WHERE `board` = :board OR `target_board` = :board');
$query->bindValue(':board', $board['uri']);
$query->execute() or error(db_error($query));
- $query = prepare('DELETE FROM `antispam` WHERE `board` = :board');
+ $query = prepare('DELETE FROM ``antispam`` WHERE `board` = :board');
$query->bindValue(':board', $board['uri']);
$query->execute() or error(db_error($query));
// Remove board from users/permissions table
- $query = query('SELECT `id`,`boards` FROM `mods`') or error(db_error());
+ $query = query('SELECT `id`,`boards` FROM ``mods``') or error(db_error());
while ($user = $query->fetch(PDO::FETCH_ASSOC)) {
$user_boards = explode(',', $user['boards']);
if (in_array($board['uri'], $user_boards)) {
unset($user_boards[array_search($board['uri'], $user_boards)]);
- $_query = prepare('UPDATE `mods` SET `boards` = :boards WHERE `id` = :id');
+ $_query = prepare('UPDATE ``mods`` SET `boards` = :boards WHERE `id` = :id');
$_query->bindValue(':boards', implode(',', $user_boards));
$_query->bindValue(':id', $user['id']);
$_query->execute() or error(db_error($_query));
}
}
} else {
- $query = prepare('UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri');
+ $query = prepare('UPDATE ``boards`` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri');
$query->bindValue(':uri', $board['uri']);
$query->bindValue(':title', $_POST['title']);
$query->bindValue(':subtitle', $_POST['subtitle']);
@@ -400,14 +445,31 @@ function mod_new_board() {
if ($_POST['title'] == '')
error(sprintf($config['error']['required'], 'title'));
- #if (!preg_match('/^\w+$/', $_POST['uri']))
- # error(sprintf($config['error']['invalidfield'], 'URI'));
+ if (!preg_match('/^' . $config['board_regex'] . '$/u', $_POST['uri']))
+ error(sprintf($config['error']['invalidfield'], 'URI'));
+
+ $bytes = 0;
+ $chars = preg_split('//u', $_POST['uri'], -1, PREG_SPLIT_NO_EMPTY);
+ foreach ($chars as $char) {
+ $o = 0;
+ $ord = ordutf8($char, $o);
+ if ($ord > 0x0080)
+ $bytes += 5; // @01ff
+ else
+ $bytes ++;
+ }
+ $bytes + strlen('posts_.frm');
+
+ if ($bytes > 255) {
+ error('Your filesystem cannot handle a board URI of that length (' . $bytes . '/255 bytes)');
+ exit;
+ }
if (openBoard($_POST['uri'])) {
error(sprintf($config['error']['boardexists'], $board['url']));
}
- $query = prepare('INSERT INTO `boards` VALUES (:uri, :title, :subtitle)');
+ $query = prepare('INSERT INTO ``boards`` VALUES (:uri, :title, :subtitle)');
$query->bindValue(':uri', $_POST['uri']);
$query->bindValue(':title', $_POST['title']);
$query->bindValue(':subtitle', $_POST['subtitle']);
@@ -418,7 +480,12 @@ function mod_new_board() {
if (!openBoard($_POST['uri']))
error(_("Couldn't open board after creation."));
- query(Element('posts.sql', array('board' => $board['uri']))) or error(db_error());
+ $query = Element('posts.sql', array('board' => $board['uri']));
+
+ if (mysql_version() < 50503)
+ $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query);
+
+ query($query) or error(db_error());
if ($config['cache']['enabled'])
cache::delete('all_boards');
@@ -447,9 +514,10 @@ function mod_noticeboard($page_no = 1) {
if (!hasPermission($config['mod']['noticeboard_post']))
error($config['error']['noaccess']);
+ $_POST['body'] = escape_markup_modifiers($_POST['body']);
markup($_POST['body']);
- $query = prepare('INSERT INTO `noticeboard` VALUES (NULL, :mod, :time, :subject, :body)');
+ $query = prepare('INSERT INTO ``noticeboard`` VALUES (NULL, :mod, :time, :subject, :body)');
$query->bindValue(':mod', $mod['id']);
$query->bindvalue(':time', time());
$query->bindValue(':subject', $_POST['subject']);
@@ -464,7 +532,7 @@ function mod_noticeboard($page_no = 1) {
header('Location: ?/noticeboard#' . $pdo->lastInsertId(), true, $config['redirect_http']);
}
- $query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :offset, :limit");
+ $query = prepare("SELECT ``noticeboard``.*, `username` FROM ``noticeboard`` LEFT JOIN ``mods`` ON ``mods``.`id` = `mod` ORDER BY `id` DESC LIMIT :offset, :limit");
$query->bindValue(':limit', $config['mod']['noticeboard_page'], PDO::PARAM_INT);
$query->bindValue(':offset', ($page_no - 1) * $config['mod']['noticeboard_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
@@ -473,9 +541,9 @@ function mod_noticeboard($page_no = 1) {
if (empty($noticeboard) && $page_no > 1)
error($config['error']['404']);
- $query = prepare("SELECT COUNT(*) FROM `noticeboard`");
+ $query = prepare("SELECT COUNT(*) FROM ``noticeboard``");
$query->execute() or error(db_error($query));
- $count = $query->fetchColumn(0);
+ $count = $query->fetchColumn();
mod_page(_('Noticeboard'), 'mod/noticeboard.html', array('noticeboard' => $noticeboard, 'count' => $count));
}
@@ -486,7 +554,7 @@ function mod_noticeboard_delete($id) {
if (!hasPermission($config['mod']['noticeboard_delete']))
error($config['error']['noaccess']);
- $query = prepare('DELETE FROM `noticeboard` WHERE `id` = :id');
+ $query = prepare('DELETE FROM ``noticeboard`` WHERE `id` = :id');
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
@@ -508,9 +576,10 @@ function mod_news($page_no = 1) {
if (!hasPermission($config['mod']['news']))
error($config['error']['noaccess']);
+ $_POST['body'] = escape_markup_modifiers($_POST['body']);
markup($_POST['body']);
- $query = prepare('INSERT INTO `news` VALUES (NULL, :name, :time, :subject, :body)');
+ $query = prepare('INSERT INTO ``news`` VALUES (NULL, :name, :time, :subject, :body)');
$query->bindValue(':name', isset($_POST['name']) && hasPermission($config['mod']['news_custom']) ? $_POST['name'] : $mod['username']);
$query->bindvalue(':time', time());
$query->bindValue(':subject', $_POST['subject']);
@@ -524,7 +593,7 @@ function mod_news($page_no = 1) {
header('Location: ?/news#' . $pdo->lastInsertId(), true, $config['redirect_http']);
}
- $query = prepare("SELECT * FROM `news` ORDER BY `id` DESC LIMIT :offset, :limit");
+ $query = prepare("SELECT * FROM ``news`` ORDER BY `id` DESC LIMIT :offset, :limit");
$query->bindValue(':limit', $config['mod']['news_page'], PDO::PARAM_INT);
$query->bindValue(':offset', ($page_no - 1) * $config['mod']['news_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
@@ -533,9 +602,9 @@ function mod_news($page_no = 1) {
if (empty($news) && $page_no > 1)
error($config['error']['404']);
- $query = prepare("SELECT COUNT(*) FROM `news`");
+ $query = prepare("SELECT COUNT(*) FROM ``news``");
$query->execute() or error(db_error($query));
- $count = $query->fetchColumn(0);
+ $count = $query->fetchColumn();
mod_page(_('News'), 'mod/news.html', array('news' => $news, 'count' => $count));
}
@@ -546,7 +615,7 @@ function mod_news_delete($id) {
if (!hasPermission($config['mod']['news_delete']))
error($config['error']['noaccess']);
- $query = prepare('DELETE FROM `news` WHERE `id` = :id');
+ $query = prepare('DELETE FROM ``news`` WHERE `id` = :id');
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
@@ -564,7 +633,7 @@ function mod_log($page_no = 1) {
if (!hasPermission($config['mod']['modlog']))
error($config['error']['noaccess']);
- $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY `time` DESC LIMIT :offset, :limit");
+ $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` ORDER BY `time` DESC LIMIT :offset, :limit");
$query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT);
$query->bindValue(':offset', ($page_no - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
@@ -573,9 +642,9 @@ function mod_log($page_no = 1) {
if (empty($logs) && $page_no > 1)
error($config['error']['404']);
- $query = prepare("SELECT COUNT(*) FROM `modlogs`");
+ $query = prepare("SELECT COUNT(*) FROM ``modlogs``");
$query->execute() or error(db_error($query));
- $count = $query->fetchColumn(0);
+ $count = $query->fetchColumn();
mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count));
}
@@ -589,7 +658,7 @@ function mod_user_log($username, $page_no = 1) {
if (!hasPermission($config['mod']['modlog']))
error($config['error']['noaccess']);
- $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `username` = :username ORDER BY `time` DESC LIMIT :offset, :limit");
+ $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `username` = :username ORDER BY `time` DESC LIMIT :offset, :limit");
$query->bindValue(':username', $username);
$query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT);
$query->bindValue(':offset', ($page_no - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT);
@@ -599,10 +668,10 @@ function mod_user_log($username, $page_no = 1) {
if (empty($logs) && $page_no > 1)
error($config['error']['404']);
- $query = prepare("SELECT COUNT(*) FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `username` = :username");
+ $query = prepare("SELECT COUNT(*) FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `username` = :username");
$query->bindValue(':username', $username);
$query->execute() or error(db_error($query));
- $count = $query->fetchColumn(0);
+ $count = $query->fetchColumn();
mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count, 'username' => $username));
}
@@ -645,7 +714,7 @@ function mod_ip_remove_note($ip, $id) {
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
error("Invalid IP address.");
- $query = prepare('DELETE FROM `ip_notes` WHERE `ip` = :ip AND `id` = :id');
+ $query = prepare('DELETE FROM ``ip_notes`` WHERE `ip` = :ip AND `id` = :id');
$query->bindValue(':ip', $ip);
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
@@ -677,8 +746,9 @@ function mod_page_ip($ip) {
if (!hasPermission($config['mod']['create_notes']))
error($config['error']['noaccess']);
+ $_POST['note'] = escape_markup_modifiers($_POST['note']);
markup($_POST['note']);
- $query = prepare('INSERT INTO `ip_notes` VALUES (NULL, :ip, :mod, :time, :body)');
+ $query = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)');
$query->bindValue(':ip', $ip);
$query->bindValue(':mod', $mod['id']);
$query->bindValue(':time', time());
@@ -701,8 +771,9 @@ function mod_page_ip($ip) {
$boards = listBoards();
foreach ($boards as $board) {
openBoard($board['uri']);
-
- $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `id` DESC LIMIT :limit', $board['uri']));
+ if (!hasPermission($config['mod']['show_ip'], $board['uri']))
+ continue;
+ $query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `ip` = :ip ORDER BY `sticky` DESC, `id` DESC LIMIT :limit', $board['uri']));
$query->bindValue(':ip', $ip);
$query->bindValue(':limit', $config['mod']['ip_recentposts'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
@@ -734,21 +805,21 @@ function mod_page_ip($ip) {
$args['token'] = make_secure_link_token('ban');
if (hasPermission($config['mod']['view_ban'])) {
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
+ $query = prepare("SELECT ``bans``.*, `username` FROM ``bans`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `set` DESC");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
}
if (hasPermission($config['mod']['view_notes'])) {
- $query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
+ $query = prepare("SELECT ``ip_notes``.*, `username` FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `time` DESC");
$query->bindValue(':ip', $ip);
$query->execute() or error(db_error($query));
$args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
}
if (hasPermission($config['mod']['modlog_ip'])) {
- $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 20");
+ $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50");
$query->bindValue(':search', '%' . $ip . '%');
$query->execute() or error(db_error($query));
$args['logs'] = $query->fetchAll(PDO::FETCH_ASSOC);
@@ -801,7 +872,7 @@ function mod_bans($page_no = 1) {
if (isset($config['mod']['unban_limit'])){
if (count($unban) <= $config['mod']['unban_limit'] || $config['mod']['unban_limit'] == -1){
if (!empty($unban)) {
- query('DELETE FROM `bans` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error());
+ query('DELETE FROM ``bans`` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error());
foreach ($unban as $id) {
modLog("Removed ban #{$id}");
@@ -814,7 +885,7 @@ function mod_bans($page_no = 1) {
} else {
if (!empty($unban)) {
- query('DELETE FROM `bans` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error());
+ query('DELETE FROM ``bans`` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error());
foreach ($unban as $id) {
modLog("Removed ban #{$id}");
@@ -826,10 +897,10 @@ function mod_bans($page_no = 1) {
}
if ($config['mod']['view_banexpired']) {
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY (`expires` IS NOT NULL AND `expires` < :time), `set` DESC LIMIT :offset, :limit");
+ $query = prepare("SELECT ``bans``.*, `username` FROM ``bans`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` ORDER BY (`expires` IS NOT NULL AND `expires` < :time), `set` DESC LIMIT :offset, :limit");
} else {
// Filter out expired bans
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC LIMIT :offset, :limit");
+ $query = prepare("SELECT ``bans``.*, `username` FROM ``bans`` INNER JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC LIMIT :offset, :limit");
}
$query->bindValue(':time', time(), PDO::PARAM_INT);
$query->bindValue(':limit', $config['mod']['banlist_page'], PDO::PARAM_INT);
@@ -840,9 +911,9 @@ function mod_bans($page_no = 1) {
if (empty($bans) && $page_no > 1)
error($config['error']['404']);
- $query = prepare("SELECT COUNT(*) FROM `bans`");
+ $query = prepare("SELECT COUNT(*) FROM ``bans``");
$query->execute() or error(db_error($query));
- $count = $query->fetchColumn(0);
+ $count = $query->fetchColumn();
foreach ($bans as &$ban) {
if (filter_var($ban['ip'], FILTER_VALIDATE_IP) !== false)
@@ -862,7 +933,7 @@ function mod_lock($board, $unlock, $post) {
if (!hasPermission($config['mod']['lock'], $board))
error($config['error']['noaccess']);
- $query = prepare(sprintf('UPDATE `posts_%s` SET `locked` = :locked WHERE `id` = :id AND `thread` IS NULL', $board));
+ $query = prepare(sprintf('UPDATE ``posts_%s`` SET `locked` = :locked WHERE `id` = :id AND `thread` IS NULL', $board));
$query->bindValue(':id', $post);
$query->bindValue(':locked', $unlock ? 0 : 1);
$query->execute() or error(db_error($query));
@@ -873,7 +944,7 @@ function mod_lock($board, $unlock, $post) {
}
if ($config['mod']['dismiss_reports_on_lock']) {
- $query = prepare('DELETE FROM `reports` WHERE `board` = :board AND `post` = :id');
+ $query = prepare('DELETE FROM ``reports`` WHERE `board` = :board AND `post` = :id');
$query->bindValue(':board', $board);
$query->bindValue(':id', $post);
$query->execute() or error(db_error($query));
@@ -896,7 +967,7 @@ function mod_sticky($board, $unsticky, $post) {
if (!hasPermission($config['mod']['sticky'], $board))
error($config['error']['noaccess']);
- $query = prepare(sprintf('UPDATE `posts_%s` SET `sticky` = :sticky WHERE `id` = :id AND `thread` IS NULL', $board));
+ $query = prepare(sprintf('UPDATE ``posts_%s`` SET `sticky` = :sticky WHERE `id` = :id AND `thread` IS NULL', $board));
$query->bindValue(':id', $post);
$query->bindValue(':sticky', $unsticky ? 0 : 1);
$query->execute() or error(db_error($query));
@@ -918,7 +989,7 @@ function mod_bumplock($board, $unbumplock, $post) {
if (!hasPermission($config['mod']['bumplock'], $board))
error($config['error']['noaccess']);
- $query = prepare(sprintf('UPDATE `posts_%s` SET `sage` = :bumplock WHERE `id` = :id AND `thread` IS NULL', $board));
+ $query = prepare(sprintf('UPDATE ``posts_%s`` SET `sage` = :bumplock WHERE `id` = :id AND `thread` IS NULL', $board));
$query->bindValue(':id', $post);
$query->bindValue(':bumplock', $unbumplock ? 0 : 1);
$query->execute() or error(db_error($query));
@@ -940,7 +1011,7 @@ function mod_move($originBoard, $postID) {
if (!hasPermission($config['mod']['move'], $originBoard))
error($config['error']['noaccess']);
- $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id AND `thread` IS NULL', $originBoard));
+ $query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL', $originBoard));
$query->bindValue(':id', $postID);
$query->execute() or error(db_error($query));
if (!$post = $query->fetch(PDO::FETCH_ASSOC))
@@ -988,13 +1059,13 @@ function mod_move($originBoard, $postID) {
// go back to the original board to fetch replies
openBoard($originBoard);
- $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id`', $originBoard));
+ $query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id`', $originBoard));
$query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$replies = array();
- while ($post = $query->fetch()) {
+ while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$post['mod'] = true;
$post['thread'] = $newID;
@@ -1017,7 +1088,7 @@ function mod_move($originBoard, $postID) {
openBoard($targetBoard);
foreach ($replies as &$post) {
- $query = prepare('SELECT `target` FROM `cites` WHERE `target_board` = :board AND `board` = :board AND `post` = :post');
+ $query = prepare('SELECT `target` FROM ``cites`` WHERE `target_board` = :board AND `board` = :board AND `post` = :post');
$query->bindValue(':board', $originBoard);
$query->bindValue(':post', $post['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($qurey));
@@ -1049,7 +1120,7 @@ function mod_move($originBoard, $postID) {
}
foreach ($post['tracked_cites'] as $cite) {
- $query = prepare('INSERT INTO `cites` VALUES (:board, :post, :target_board, :target)');
+ $query = prepare('INSERT INTO ``cites`` VALUES (:board, :post, :target_board, :target)');
$query->bindValue(':board', $board['uri']);
$query->bindValue(':post', $newPostID, PDO::PARAM_INT);
$query->bindValue(':target_board',$cite[0]);
@@ -1074,7 +1145,7 @@ function mod_move($originBoard, $postID) {
if ($shadow) {
// lock old thread
- $query = prepare(sprintf('UPDATE `posts_%s` SET `locked` = 1 WHERE `id` = :id', $originBoard));
+ $query = prepare(sprintf('UPDATE ``posts_%s`` SET `locked` = 1 WHERE `id` = :id', $originBoard));
$query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
@@ -1133,7 +1204,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
$security_token = make_secure_link_token($board . '/ban/' . $post);
- $query = prepare(sprintf('SELECT `ip`, `thread` FROM `posts_%s` WHERE `id` = :id', $board));
+ $query = prepare(sprintf('SELECT `ip`, `thread` FROM ``posts_%s`` WHERE `id` = :id', $board));
$query->bindValue(':id', $post);
$query->execute() or error(db_error($query));
if (!$_post = $query->fetch(PDO::FETCH_ASSOC))
@@ -1152,10 +1223,15 @@ function mod_ban_post($board, $delete, $post, $token = false) {
if (isset($_POST['public_message'], $_POST['message'])) {
// public ban message
- $query = prepare(sprintf('UPDATE `posts_%s` SET `body` = CONCAT(`body`, :body) WHERE `id` = :id', $board));
+ $length_english = parse_time($_POST['length']) ? 'for ' . until(parse_time($_POST['length'])) : 'permanently';
+ $_POST['message'] = preg_replace('/[\r\n]/', '', $_POST['message']);
+ $_POST['message'] = str_replace('%length%', $length_english, $_POST['message']);
+ $_POST['message'] = str_replace('%LENGTH%', strtoupper($length_english), $_POST['message']);
+ $query = prepare(sprintf('UPDATE ``posts_%s`` SET `body_nomarkup` = CONCAT(`body_nomarkup`, :body_nomarkup) WHERE `id` = :id', $board));
$query->bindValue(':id', $post);
- $query->bindValue(':body', sprintf($config['mod']['ban_message'], utf8tohtml($_POST['message'])));
+ $query->bindValue(':body_nomarkup', sprintf("\n<tinyboard ban message>%s</tinyboard>", utf8tohtml($_POST['message'])));
$query->execute() or error(db_error($query));
+ rebuildPost($post);
modLog("Attached a public ban message to post #{$post}: " . utf8tohtml($_POST['message']));
buildThread($thread ? $thread : $post);
@@ -1198,7 +1274,7 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
$security_token = make_secure_link_token($board . '/edit' . ($edit_raw_html ? '_raw' : '') . '/' . $postID);
- $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id', $board));
+ $query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id', $board));
$query->bindValue(':id', $postID);
$query->execute() or error(db_error($query));
@@ -1207,14 +1283,18 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
if (isset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['body'])) {
if ($edit_raw_html)
- $query = prepare(sprintf('UPDATE `posts_%s` SET `name` = :name, `email` = :email, `subject` = :subject, `body` = :body WHERE `id` = :id', $board));
+ $query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name, `email` = :email, `subject` = :subject, `body` = :body, `body_nomarkup` = :body_nomarkup WHERE `id` = :id', $board));
else
- $query = prepare(sprintf('UPDATE `posts_%s` SET `name` = :name, `email` = :email, `subject` = :subject, `body_nomarkup` = :body WHERE `id` = :id', $board));
+ $query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name, `email` = :email, `subject` = :subject, `body_nomarkup` = :body WHERE `id` = :id', $board));
$query->bindValue(':id', $postID);
$query->bindValue('name', $_POST['name']);
$query->bindValue(':email', $_POST['email']);
$query->bindValue(':subject', $_POST['subject']);
$query->bindValue(':body', $_POST['body']);
+ if ($edit_raw_html) {
+ $body_nomarkup = '<tinyboard raw html>' . $_POST['body'] . '</tinyboard>';
+ $query->bindValue(':body_nomarkup', $body_nomarkup);
+ }
$query->execute() or error(db_error($query));
if ($edit_raw_html) {
@@ -1229,10 +1309,12 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']);
} else {
if ($config['minify_html']) {
- $post['body_nomarkup'] = str_replace("\n", '&#010;', $post['body_nomarkup']);
- $post['body'] = str_replace("\n", '&#010;', $post['body']);
+ $post['body_nomarkup'] = str_replace("\n", '&#010;', utf8tohtml($post['body_nomarkup']));
+ $post['body'] = str_replace("\n", '&#010;', utf8tohtml($post['body']));
+ $post['body_nomarkup'] = str_replace("\r", '', $post['body_nomarkup']);
+ $post['body'] = str_replace("\r", '', $post['body']);
}
-
+
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post));
}
}
@@ -1292,17 +1374,17 @@ function mod_deletebyip($boardName, $post, $global = false) {
error($config['error']['noaccess']);
// Find IP address
- $query = prepare(sprintf('SELECT `ip` FROM `posts_%s` WHERE `id` = :id', $boardName));
+ $query = prepare(sprintf('SELECT `ip` FROM ``posts_%s`` WHERE `id` = :id', $boardName));
$query->bindValue(':id', $post);
$query->execute() or error(db_error($query));
- if (!$ip = $query->fetchColumn(0))
+ if (!$ip = $query->fetchColumn())
error($config['error']['invalidpost']);
$boards = $global ? listBoards() : array(array('uri' => $boardName));
$query = '';
foreach ($boards as $_board) {
- $query .= sprintf("SELECT `thread`, `id`, '%s' AS `board` FROM `posts_%s` WHERE `ip` = :ip UNION ALL ", $_board['uri'], $_board['uri']);
+ $query .= sprintf("SELECT `thread`, `id`, '%s' AS `board` FROM ``posts_%s`` WHERE `ip` = :ip UNION ALL ", $_board['uri'], $_board['uri']);
}
$query = preg_replace('/UNION ALL $/', '', $query);
@@ -1317,7 +1399,7 @@ function mod_deletebyip($boardName, $post, $global = false) {
$threads_to_rebuild = array();
$threads_deleted = array();
- while ($post = $query->fetch()) {
+ while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
openBoard($post['board']);
deletePost($post['id'], false, false);
@@ -1354,7 +1436,7 @@ function mod_user($uid) {
if (!hasPermission($config['mod']['editusers']) && !(hasPermission($config['mod']['change_password']) && $uid == $mod['id']))
error($config['error']['noaccess']);
- $query = prepare('SELECT * FROM `mods` WHERE `id` = :id');
+ $query = prepare('SELECT * FROM ``mods`` WHERE `id` = :id');
$query->bindValue(':id', $uid);
$query->execute() or error(db_error($query));
if (!$user = $query->fetch(PDO::FETCH_ASSOC))
@@ -1371,7 +1453,7 @@ function mod_user($uid) {
$boards = array();
foreach ($_POST as $name => $value) {
- if (preg_match('/^board_(\w+)$/', $name, $matches) && in_array($matches[1], $_boards))
+ if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards))
$boards[] = $matches[1];
}
}
@@ -1380,7 +1462,7 @@ function mod_user($uid) {
if (!hasPermission($config['mod']['deleteusers']))
error($config['error']['noaccess']);
- $query = prepare('DELETE FROM `mods` WHERE `id` = :id');
+ $query = prepare('DELETE FROM ``mods`` WHERE `id` = :id');
$query->bindValue(':id', $uid);
$query->execute() or error(db_error($query));
@@ -1394,7 +1476,7 @@ function mod_user($uid) {
if ($_POST['username'] == '')
error(sprintf($config['error']['required'], 'username'));
- $query = prepare('UPDATE `mods` SET `username` = :username, `boards` = :boards WHERE `id` = :id');
+ $query = prepare('UPDATE ``mods`` SET `username` = :username, `boards` = :boards WHERE `id` = :id');
$query->bindValue(':id', $uid);
$query->bindValue(':username', $_POST['username']);
$query->bindValue(':boards', implode(',', $boards));
@@ -1406,9 +1488,13 @@ function mod_user($uid) {
}
if ($_POST['password'] != '') {
- $query = prepare('UPDATE `mods` SET `password` = SHA1(:password) WHERE `id` = :id');
+ $salt = generate_salt();
+ $password = hash('sha256', $salt . sha1($_POST['password']));
+
+ $query = prepare('UPDATE ``mods`` SET `password` = :password, `salt` = :salt WHERE `id` = :id');
$query->bindValue(':id', $uid);
- $query->bindValue(':password', $_POST['password']);
+ $query->bindValue(':password', $password);
+ $query->bindValue(':salt', $salt);
$query->execute() or error(db_error($query));
modLog('Changed password for ' . utf8tohtml($_POST['username']) . ' <small>(#' . $user['id'] . ')</small>');
@@ -1429,9 +1515,13 @@ function mod_user($uid) {
if (hasPermission($config['mod']['change_password']) && $uid == $mod['id'] && isset($_POST['password'])) {
if ($_POST['password'] != '') {
- $query = prepare('UPDATE `mods` SET `password` = SHA1(:password) WHERE `id` = :id');
+ $salt = generate_salt();
+ $password = hash('sha256', $salt . sha1($_POST['password']));
+
+ $query = prepare('UPDATE ``mods`` SET `password` = :password, `salt` = :salt WHERE `id` = :id');
$query->bindValue(':id', $uid);
- $query->bindValue(':password', $_POST['password']);
+ $query->bindValue(':password', $password);
+ $query->bindValue(':salt', $salt);
$query->execute() or error(db_error($query));
modLog('Changed own password');
@@ -1449,7 +1539,7 @@ function mod_user($uid) {
}
if (hasPermission($config['mod']['modlog'])) {
- $query = prepare('SELECT * FROM `modlogs` WHERE `mod` = :id ORDER BY `time` DESC LIMIT 5');
+ $query = prepare('SELECT * FROM ``modlogs`` WHERE `mod` = :id ORDER BY `time` DESC LIMIT 5');
$query->bindValue(':id', $uid);
$query->execute() or error(db_error($query));
$log = $query->fetchAll(PDO::FETCH_ASSOC);
@@ -1484,7 +1574,7 @@ function mod_user_new() {
$boards = array();
foreach ($_POST as $name => $value) {
- if (preg_match('/^board_(\w+)$/', $name, $matches) && in_array($matches[1], $_boards))
+ if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards))
$boards[] = $matches[1];
}
}
@@ -1493,9 +1583,13 @@ function mod_user_new() {
if ($_POST['type'] !== JANITOR && $_POST['type'] !== MOD && $_POST['type'] !== ADMIN)
error(sprintf($config['error']['invalidfield'], 'type'));
- $query = prepare('INSERT INTO `mods` VALUES (NULL, :username, SHA1(:password), :type, :boards)');
+ $salt = generate_salt();
+ $password = hash('sha256', $salt . sha1($_POST['password']));
+
+ $query = prepare('INSERT INTO ``mods`` VALUES (NULL, :username, :password, :salt, :type, :boards)');
$query->bindValue(':username', $_POST['username']);
- $query->bindValue(':password', $_POST['password']);
+ $query->bindValue(':password', $password);
+ $query->bindValue(':salt', $salt);
$query->bindValue(':type', $_POST['type']);
$query->bindValue(':boards', implode(',', $boards));
$query->execute() or error(db_error($query));
@@ -1518,7 +1612,7 @@ function mod_users() {
if (!hasPermission($config['mod']['manageusers']))
error($config['error']['noaccess']);
- $query = query("SELECT *, (SELECT `time` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `last`, (SELECT `text` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `action` FROM `mods` ORDER BY `type` DESC,`id`") or error(db_error());
+ $query = query("SELECT *, (SELECT `time` FROM ``modlogs`` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `last`, (SELECT `text` FROM ``modlogs`` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `action` FROM ``mods`` ORDER BY `type` DESC,`id`") or error(db_error());
$users = $query->fetchAll(PDO::FETCH_ASSOC);
mod_page(sprintf('%s (%d)', _('Manage users'), count($users)), 'mod/users.html', array('users' => $users));
@@ -1530,7 +1624,7 @@ function mod_user_promote($uid, $action) {
if (!hasPermission($config['mod']['promoteusers']))
error($config['error']['noaccess']);
- $query = prepare("UPDATE `mods` SET `type` = `type` " . ($action == 'promote' ? "+1 WHERE `type` < " . (int)ADMIN : "-1 WHERE `type` > " . (int)JANITOR) . " AND `id` = :id");
+ $query = prepare("UPDATE ``mods`` SET `type` = `type` " . ($action == 'promote' ? "+1 WHERE `type` < " . (int)ADMIN : "-1 WHERE `type` > " . (int)JANITOR) . " AND `id` = :id");
$query->bindValue(':id', $uid);
$query->execute() or error(db_error($query));
@@ -1545,7 +1639,7 @@ function mod_pm($id, $reply = false) {
if ($reply && !hasPermission($config['mod']['create_pm']))
error($config['error']['noaccess']);
- $query = prepare("SELECT `mods`.`username`, `mods_to`.`username` AS `to_username`, `pms`.* FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` LEFT JOIN `mods` AS `mods_to` ON `mods_to`.`id` = `to` WHERE `pms`.`id` = :id");
+ $query = prepare("SELECT ``mods``.`username`, `mods_to`.`username` AS `to_username`, ``pms``.* FROM ``pms`` LEFT JOIN ``mods`` ON ``mods``.`id` = `sender` LEFT JOIN ``mods`` AS `mods_to` ON `mods_to`.`id` = `to` WHERE ``pms``.`id` = :id");
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
@@ -1553,7 +1647,7 @@ function mod_pm($id, $reply = false) {
error($config['error']['404']);
if (isset($_POST['delete'])) {
- $query = prepare("DELETE FROM `pms` WHERE `id` = :id");
+ $query = prepare("DELETE FROM ``pms`` WHERE `id` = :id");
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
@@ -1567,7 +1661,7 @@ function mod_pm($id, $reply = false) {
}
if ($pm['unread'] && $pm['to'] == $mod['id']) {
- $query = prepare("UPDATE `pms` SET `unread` = 0 WHERE `id` = :id");
+ $query = prepare("UPDATE ``pms`` SET `unread` = 0 WHERE `id` = :id");
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
@@ -1594,15 +1688,15 @@ function mod_pm($id, $reply = false) {
function mod_inbox() {
global $config, $mod;
- $query = prepare('SELECT `unread`,`pms`.`id`, `time`, `sender`, `to`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC');
+ $query = prepare('SELECT `unread`,``pms``.`id`, `time`, `sender`, `to`, `message`, `username` FROM ``pms`` LEFT JOIN ``mods`` ON ``mods``.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC');
$query->bindValue(':mod', $mod['id']);
$query->execute() or error(db_error($query));
$messages = $query->fetchAll(PDO::FETCH_ASSOC);
- $query = prepare('SELECT COUNT(*) FROM `pms` WHERE `to` = :mod AND `unread` = 1');
+ $query = prepare('SELECT COUNT(*) FROM ``pms`` WHERE `to` = :mod AND `unread` = 1');
$query->bindValue(':mod', $mod['id']);
$query->execute() or error(db_error($query));
- $unread = $query->fetchColumn(0);
+ $unread = $query->fetchColumn();
foreach ($messages as &$message) {
$message['snippet'] = pm_snippet($message['message']);
@@ -1621,24 +1715,25 @@ function mod_new_pm($username) {
if (!hasPermission($config['mod']['create_pm']))
error($config['error']['noaccess']);
- $query = prepare("SELECT `id` FROM `mods` WHERE `username` = :username");
+ $query = prepare("SELECT `id` FROM ``mods`` WHERE `username` = :username");
$query->bindValue(':username', $username);
$query->execute() or error(db_error($query));
- if (!$id = $query->fetchColumn(0)) {
+ if (!$id = $query->fetchColumn()) {
// Old style ?/PM: by user ID
- $query = prepare("SELECT `username` FROM `mods` WHERE `id` = :username");
+ $query = prepare("SELECT `username` FROM ``mods`` WHERE `id` = :username");
$query->bindValue(':username', $username);
$query->execute() or error(db_error($query));
- if ($username = $query->fetchColumn(0))
+ if ($username = $query->fetchColumn())
header('Location: ?/new_PM/' . $username, true, $config['redirect_http']);
else
error($config['error']['404']);
}
if (isset($_POST['message'])) {
+ $_POST['message'] = escape_markup_modifiers($_POST['message']);
markup($_POST['message']);
- $query = prepare("INSERT INTO `pms` VALUES (NULL, :me, :id, :message, :time, 1)");
+ $query = prepare("INSERT INTO ``pms`` VALUES (NULL, :me, :id, :message, :time, 1)");
$query->bindValue(':me', $mod['id']);
$query->bindValue(':id', $id);
$query->bindValue(':message', $_POST['message']);
@@ -1711,7 +1806,7 @@ function mod_rebuild() {
}
if (isset($_POST['rebuild_thread'])) {
- $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
+ $query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$log[] = '<strong>' . sprintf($config['board_abbreviation'], $board['uri']) . '</strong>: Rebuilding thread #' . $post['id'];
buildThread($post['id']);
@@ -1732,7 +1827,7 @@ function mod_reports() {
if (!hasPermission($config['mod']['reports']))
error($config['error']['noaccess']);
- $query = prepare("SELECT * FROM `reports` ORDER BY `time` DESC LIMIT :limit");
+ $query = prepare("SELECT * FROM ``reports`` ORDER BY `time` DESC LIMIT :limit");
$query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$reports = $query->fetchAll(PDO::FETCH_ASSOC);
@@ -1748,8 +1843,8 @@ function mod_reports() {
foreach ($report_queries as $board => $posts) {
$report_posts[$board] = array();
- $query = query(sprintf('SELECT * FROM `posts_%s` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error());
- while ($post = $query->fetch()) {
+ $query = query(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error());
+ while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$report_posts[$board][$post['id']] = $post;
}
}
@@ -1759,7 +1854,7 @@ function mod_reports() {
foreach ($reports as $report) {
if (!isset($report_posts[$report['board']][$report['post']])) {
// // Invalid report (post has since been deleted)
- $query = prepare("DELETE FROM `reports` WHERE `post` = :id AND `board` = :board");
+ $query = prepare("DELETE FROM ``reports`` WHERE `post` = :id AND `board` = :board");
$query->bindValue(':id', $report['post'], PDO::PARAM_INT);
$query->bindValue(':board', $report['board']);
$query->execute() or error(db_error($query));
@@ -1815,7 +1910,7 @@ function mod_reports() {
function mod_report_dismiss($id, $all = false) {
global $config;
- $query = prepare("SELECT `post`, `board`, `ip` FROM `reports` WHERE `id` = :id");
+ $query = prepare("SELECT `post`, `board`, `ip` FROM ``reports`` WHERE `id` = :id");
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
if ($report = $query->fetch(PDO::FETCH_ASSOC)) {
@@ -1832,10 +1927,10 @@ function mod_report_dismiss($id, $all = false) {
error($config['error']['noaccess']);
if ($all) {
- $query = prepare("DELETE FROM `reports` WHERE `ip` = :ip");
+ $query = prepare("DELETE FROM ``reports`` WHERE `ip` = :ip");
$query->bindValue(':ip', $ip);
} else {
- $query = prepare("DELETE FROM `reports` WHERE `id` = :id");
+ $query = prepare("DELETE FROM ``reports`` WHERE `id` = :id");
$query->bindValue(':id', $id);
}
$query->execute() or error(db_error($query));
@@ -1850,12 +1945,43 @@ function mod_report_dismiss($id, $all = false) {
}
-function mod_config() {
- global $config, $mod;
+function mod_config($board_config = false) {
+ global $config, $mod, $board;
+
+ if ($board_config && !openBoard($board_config))
+ error($config['error']['noboard']);
- if (!hasPermission($config['mod']['edit_config']))
+ if (!hasPermission($config['mod']['edit_config'], $board_config))
error($config['error']['noaccess']);
+ $config_file = $board_config ? $board['dir'] . 'config.php' : 'inc/instance-config.php';
+
+ if ($config['mod']['config_editor_php']) {
+ $readonly = !(is_file($config_file) ? is_writable($config_file) : is_writable(dirname($config_file)));
+
+ if (!$readonly && isset($_POST['code'])) {
+ $code = $_POST['code'];
+ file_put_contents($config_file, $code);
+ header('Location: ?/config' . ($board_config ? '/' . $board_config : ''), true, $config['redirect_http']);
+ return;
+ }
+
+ $instance_config = @file_get_contents($config_file);
+ if ($instance_config === false) {
+ $instance_config = "<?php\n\n// This file does not exist yet. You are creating it.";
+ }
+ $instance_config = str_replace("\n", '&#010;', utf8tohtml($instance_config));
+
+ mod_page(_('Config editor'), 'mod/config-editor-php.html', array(
+ 'php' => $instance_config,
+ 'readonly' => $readonly,
+ 'boards' => listBoards(),
+ 'board' => $board_config,
+ 'file' => $config_file
+ ));
+ return;
+ }
+
require_once 'inc/mod/config-editor.php';
$conf = config_vars();
@@ -1866,7 +1992,7 @@ function mod_config() {
foreach ($var['name'] as $n)
$c = &$c[$n];
} else {
- $c = $config[$var['name']];
+ $c = @$config[$var['name']];
}
$var['value'] = $c;
@@ -1901,14 +2027,28 @@ function mod_config() {
$config_append .= '[' . var_export($var['name'], true) . ']';
}
- $config_append .= ' = ' . var_export($value, true) . ";\n";
+
+ $config_append .= ' = ';
+ if (@$var['permissions'] && in_array($value, array(JANITOR, MOD, ADMIN, DISABLED))) {
+ $perm_array = array(
+ JANITOR => 'JANITOR',
+ MOD => 'MOD',
+ ADMIN => 'ADMIN',
+ DISABLED => 'DISABLED'
+ );
+ $config_append .= $perm_array[$value];
+ } else {
+ $config_append .= var_export($value, true);
+ }
+ $config_append .= ";\n";
}
}
if (!empty($config_append)) {
$config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
-
- if (!@file_put_contents('inc/instance-config.php', $config_append, FILE_APPEND)) {
+ if (!is_file($config_file))
+ $config_append = "<?php\n\n$config_append";
+ if (!@file_put_contents($config_file, $config_append, FILE_APPEND)) {
$config_append = htmlentities($config_append);
if ($config['minify_html'])
@@ -1917,8 +2057,8 @@ function mod_config() {
$page['title'] = 'Cannot write to file!';
$page['config'] = $config;
$page['body'] = '
- <p style="text-align:center">Tinyboard could not write to <strong>inc/instance-config.php</strong> with the ammended configuration, probably due to a permissions error.</p>
- <p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>inc/instance-config.php</strong>:</p>
+ <p style="text-align:center">Tinyboard could not write to <strong>' . $config_file . '</strong> with the ammended configuration, probably due to a permissions error.</p>
+ <p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>' . $config_file . '</strong>:</p>
<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" readonly>' . $config_append . '</textarea>
';
echo Element('page.html', $page);
@@ -1926,12 +2066,18 @@ function mod_config() {
}
}
- header('Location: ?/', true, $config['redirect_http']);
+ header('Location: ?/config', true, $config['redirect_http']);
exit;
}
- mod_page(_('Config editor'), 'mod/config-editor.html', array('conf' => $conf));
+ mod_page(_('Config editor') . ($board_config ? ': ' . sprintf($config['board_abbreviation'], $board_config) : ''),
+ 'mod/config-editor.html', array(
+ 'boards' => listBoards(),
+ 'board' => $board_config,
+ 'conf' => $conf,
+ 'file' => $config_file
+ ));
}
function mod_themes_list() {
@@ -1945,7 +2091,7 @@ function mod_themes_list() {
if (!$dir = opendir($config['dir']['themes']))
error(_('Cannot open themes directory; check permissions.'));
- $query = query('SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL') or error(db_error());
+ $query = query('SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL') or error(db_error());
$themes_in_use = $query->fetchAll(PDO::FETCH_COLUMN);
// Scan directory for themes
@@ -1981,19 +2127,19 @@ function mod_theme_configure($theme_name) {
}
// Clear previous settings
- $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme");
+ $query = prepare("DELETE FROM ``theme_settings`` WHERE `theme` = :theme");
$query->bindValue(':theme', $theme_name);
$query->execute() or error(db_error($query));
foreach ($theme['config'] as &$conf) {
- $query = prepare("INSERT INTO `theme_settings` VALUES(:theme, :name, :value)");
+ $query = prepare("INSERT INTO ``theme_settings`` VALUES(:theme, :name, :value)");
$query->bindValue(':theme', $theme_name);
$query->bindValue(':name', $conf['name']);
$query->bindValue(':value', $_POST[$conf['name']]);
$query->execute() or error(db_error($query));
}
- $query = prepare("INSERT INTO `theme_settings` VALUES(:theme, NULL, NULL)");
+ $query = prepare("INSERT INTO ``theme_settings`` VALUES(:theme, NULL, NULL)");
$query->bindValue(':theme', $theme_name);
$query->execute() or error(db_error($query));
@@ -2011,7 +2157,7 @@ function mod_theme_configure($theme_name) {
if (!$result) {
// Install failed
- $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme");
+ $query = prepare("DELETE FROM ``theme_settings`` WHERE `theme` = :theme");
$query->bindValue(':theme', $theme_name);
$query->execute() or error(db_error($query));
}
@@ -2043,7 +2189,7 @@ function mod_theme_uninstall($theme_name) {
if (!hasPermission($config['mod']['themes']))
error($config['error']['noaccess']);
- $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme");
+ $query = prepare("DELETE FROM ``theme_settings`` WHERE `theme` = :theme");
$query->bindValue(':theme', $theme_name);
$query->execute() or error(db_error($query));
@@ -2074,7 +2220,7 @@ function mod_debug_antispam() {
$where .= ' AND `thread` = ' . $pdo->quote($_POST['thread']);
if (isset($_POST['purge'])) {
- $query = prepare('UPDATE `antispam` SET `expires` = UNIX_TIMESTAMP() + :expires WHERE' . $where);
+ $query = prepare(', DATE ``antispam`` SET `expires` = UNIX_TIMESTAMP() + :expires WHERE' . $where);
$query->bindValue(':expires', $config['spam']['hidden_inputs_expire']);
$query->execute() or error(db_error());
}
@@ -2085,16 +2231,16 @@ function mod_debug_antispam() {
$where = '';
}
- $query = query('SELECT COUNT(*) FROM `antispam`' . ($where ? " WHERE $where" : '')) or error(db_error());
- $args['total'] = number_format($query->fetchColumn(0));
+ $query = query('SELECT COUNT(*) FROM ``antispam``' . ($where ? " WHERE $where" : '')) or error(db_error());
+ $args['total'] = number_format($query->fetchColumn());
- $query = query('SELECT COUNT(*) FROM `antispam` WHERE `expires` IS NOT NULL' . ($where ? " AND $where" : '')) or error(db_error());
- $args['expiring'] = number_format($query->fetchColumn(0));
+ $query = query('SELECT COUNT(*) FROM ``antispam`` WHERE `expires` IS NOT NULL' . ($where ? " AND $where" : '')) or error(db_error());
+ $args['expiring'] = number_format($query->fetchColumn());
- $query = query('SELECT * FROM `antispam` ' . ($where ? "WHERE $where" : '') . ' ORDER BY `passed` DESC LIMIT 40') or error(db_error());
+ $query = query('SELECT * FROM ``antispam`` ' . ($where ? "WHERE $where" : '') . ' ORDER BY `passed` DESC LIMIT 40') or error(db_error());
$args['top'] = $query->fetchAll(PDO::FETCH_ASSOC);
- $query = query('SELECT * FROM `antispam` ' . ($where ? "WHERE $where" : '') . ' ORDER BY `created` DESC LIMIT 20') or error(db_error());
+ $query = query('SELECT * FROM ``antispam`` ' . ($where ? "WHERE $where" : '') . ' ORDER BY `created` DESC LIMIT 20') or error(db_error());
$args['recent'] = $query->fetchAll(PDO::FETCH_ASSOC);
mod_page(_('Debug: Anti-spam'), 'mod/debug/antispam.html', $args);
@@ -2110,7 +2256,7 @@ function mod_debug_recent_posts() {
// Manually build an SQL query
$query = 'SELECT * FROM (';
foreach ($boards as $board) {
- $query .= sprintf('SELECT *, %s AS `board` FROM `posts_%s` UNION ALL ', $pdo->quote($board['uri']), $board['uri']);
+ $query .= sprintf('SELECT *, %s AS `board` FROM ``posts_%s`` UNION ALL ', $pdo->quote($board['uri']), $board['uri']);
}
// Remove the last "UNION ALL" seperator and complete the query
$query = preg_replace('/UNION ALL $/', ') AS `all_posts` ORDER BY `time` DESC LIMIT ' . $limit, $query);