SQL cleanup
This commit is contained in:
parent
6bbe407e18
commit
328484bee7
@ -243,7 +243,7 @@ function rebuildThemes($action, $board = false) {
|
|||||||
// List themes
|
// List themes
|
||||||
$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());
|
||||||
|
|
||||||
while ($theme = $query->fetch()) {
|
while ($theme = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
rebuildTheme($theme['theme'], $action, $board);
|
rebuildTheme($theme['theme'], $action, $board);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,7 +281,7 @@ function themeSettings($theme) {
|
|||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$settings = array();
|
$settings = array();
|
||||||
while ($s = $query->fetch()) {
|
while ($s = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$settings[$s['name']] = $s['value'];
|
$settings[$s['name']] = $s['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ function getBoardInfo($uri) {
|
|||||||
$query->bindValue(':uri', $uri);
|
$query->bindValue(':uri', $uri);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($board = $query->fetch()) {
|
if ($board = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
if ($config['cache']['enabled'])
|
if ($config['cache']['enabled'])
|
||||||
cache::set('board_' . $uri, $board);
|
cache::set('board_' . $uri, $board);
|
||||||
return $board;
|
return $board;
|
||||||
@ -543,7 +543,7 @@ function checkFlood($post) {
|
|||||||
$query->bindValue(':floodsametime', time()-$config['flood_time_same'], PDO::PARAM_INT);
|
$query->bindValue(':floodsametime', time()-$config['flood_time_same'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$flood = (bool)$query->fetch();
|
$flood = (bool) $query->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if (event('check-flood', $post))
|
if (event('check-flood', $post))
|
||||||
return true;
|
return true;
|
||||||
@ -647,7 +647,7 @@ function checkBan($board = 0) {
|
|||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ban = $query->fetch()) {
|
if ($ban = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
if ($ban['expires'] && $ban['expires'] < time()) {
|
if ($ban['expires'] && $ban['expires'] < time()) {
|
||||||
// Ban expired
|
// Ban expired
|
||||||
$query = prepare("DELETE FROM `bans` WHERE `id` = :id");
|
$query = prepare("DELETE FROM `bans` WHERE `id` = :id");
|
||||||
@ -685,12 +685,12 @@ function threadLocked($id) {
|
|||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error());
|
$query->execute() or error(db_error());
|
||||||
|
|
||||||
if (!$post = $query->fetch()) {
|
if (($locked = $query->fetchColumn()) === false) {
|
||||||
// Non-existant, so it can't be locked...
|
// Non-existant, so it can't be locked...
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool)$post['locked'];
|
return (bool)$locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
function threadSageLocked($id) {
|
function threadSageLocked($id) {
|
||||||
@ -703,12 +703,12 @@ function threadSageLocked($id) {
|
|||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error());
|
$query->execute() or error(db_error());
|
||||||
|
|
||||||
if (!$post = $query->fetch()) {
|
if (($sagelocked = $query->fetchColumn()) === false) {
|
||||||
// Non-existant, so it can't be locked...
|
// Non-existant, so it can't be locked...
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) $post['sage'];
|
return (bool)$sagelocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
function threadExists($id) {
|
function threadExists($id) {
|
||||||
@ -842,7 +842,7 @@ function deleteFile($id, $remove_entirely_if_already=true) {
|
|||||||
$query = prepare(sprintf("SELECT `thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri']));
|
$query = prepare(sprintf("SELECT `thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id LIMIT 1", $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if (!$post = $query->fetch())
|
if (!$post = $query->fetch(PDO::FETCH_ASSOC))
|
||||||
error($config['error']['invalidpost']);
|
error($config['error']['invalidpost']);
|
||||||
|
|
||||||
if ($post['file'] == 'deleted' && !$post['thread'])
|
if ($post['file'] == 'deleted' && !$post['thread'])
|
||||||
@ -880,7 +880,7 @@ function rebuildPost($id) {
|
|||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ((!$post = $query->fetch()) || !$post['body_nomarkup'])
|
if ((!$post = $query->fetch(PDO::FETCH_ASSOC)) || !$post['body_nomarkup'])
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
markup($body = &$post['body_nomarkup']);
|
markup($body = &$post['body_nomarkup']);
|
||||||
@ -913,7 +913,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
|||||||
$ids = array();
|
$ids = array();
|
||||||
|
|
||||||
// Delete posts and maybe replies
|
// Delete posts and maybe replies
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
if (!$post['thread']) {
|
if (!$post['thread']) {
|
||||||
// Delete thread HTML page
|
// Delete thread HTML page
|
||||||
file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id']));
|
file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id']));
|
||||||
@ -946,7 +946,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
|||||||
$query = prepare("SELECT `board`, `post` FROM `cites` WHERE `target_board` = :board AND (`target` = " . implode(' OR `target` = ', $ids) . ")");
|
$query = prepare("SELECT `board`, `post` FROM `cites` WHERE `target_board` = :board AND (`target` = " . implode(' OR `target` = ', $ids) . ")");
|
||||||
$query->bindValue(':board', $board['uri']);
|
$query->bindValue(':board', $board['uri']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
while ($cite = $query->fetch()) {
|
while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
if ($board['uri'] != $cite['board']) {
|
if ($board['uri'] != $cite['board']) {
|
||||||
if (!isset($tmp_board))
|
if (!isset($tmp_board))
|
||||||
$tmp_board = $board['uri'];
|
$tmp_board = $board['uri'];
|
||||||
@ -979,7 +979,7 @@ function clean() {
|
|||||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||||
|
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
deletePost($post['id']);
|
deletePost($post['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1000,7 +1000,7 @@ function index($page, $mod=false) {
|
|||||||
|
|
||||||
if ($query->rowCount() < 1 && $page > 1)
|
if ($query->rowCount() < 1 && $page > 1)
|
||||||
return false;
|
return false;
|
||||||
while ($th = $query->fetch()) {
|
while ($th = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$thread = new Thread(
|
$thread = new Thread(
|
||||||
$th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'],
|
$th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'],
|
||||||
$th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'],
|
$th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'],
|
||||||
@ -1115,7 +1115,7 @@ function getPages($mod=false) {
|
|||||||
$count = $board['thread_count'];
|
$count = $board['thread_count'];
|
||||||
} else {
|
} else {
|
||||||
// Count threads
|
// Count threads
|
||||||
$query = query(sprintf("SELECT COUNT(`id`) FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
|
$query = query(sprintf("SELECT COUNT(*) FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
|
||||||
$count = $query->fetchColumn();
|
$count = $query->fetchColumn();
|
||||||
}
|
}
|
||||||
$count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']);
|
$count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']);
|
||||||
@ -1155,7 +1155,7 @@ function checkRobot($body) {
|
|||||||
$query->bindValue(':hash', $body);
|
$query->bindValue(':hash', $body);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($query->fetch()) {
|
if ($query->fetchColumn()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1163,20 +1163,19 @@ function checkRobot($body) {
|
|||||||
$query = prepare("INSERT INTO `robot` VALUES (:hash)");
|
$query = prepare("INSERT INTO `robot` VALUES (:hash)");
|
||||||
$query->bindValue(':hash', $body);
|
$query->bindValue(':hash', $body);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns an associative array with 'replies' and 'images' keys
|
// Returns an associative array with 'replies' and 'images' keys
|
||||||
function numPosts($id) {
|
function numPosts($id) {
|
||||||
global $board;
|
global $board;
|
||||||
$query = prepare(sprintf("SELECT COUNT(*) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(*) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
|
$query = prepare(sprintf("SELECT COUNT(*) FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(*) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
|
||||||
$query->bindValue(':thread', $id, PDO::PARAM_INT);
|
$query->bindValue(':thread', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$num_posts = $query->fetch();
|
$num_posts = $query->fetchColumn();
|
||||||
$num_posts = $num_posts['num'];
|
$num_images = $query->fetchColumn();
|
||||||
$num_images = $query->fetch();
|
|
||||||
$num_images = $num_images['num'];
|
|
||||||
|
|
||||||
return array('replies' => $num_posts, 'images' => $num_images);
|
return array('replies' => $num_posts, 'images' => $num_images);
|
||||||
}
|
}
|
||||||
@ -1188,14 +1187,14 @@ function muteTime() {
|
|||||||
return $time;
|
return $time;
|
||||||
|
|
||||||
// Find number of mutes in the past X hours
|
// Find number of mutes in the past X hours
|
||||||
$query = prepare("SELECT COUNT(*) as `count` FROM `mutes` WHERE `time` >= :time AND `ip` = :ip");
|
$query = prepare("SELECT COUNT(*) FROM `mutes` WHERE `time` >= :time AND `ip` = :ip");
|
||||||
$query->bindValue(':time', time()-($config['robot_mute_hour']*3600), PDO::PARAM_INT);
|
$query->bindValue(':time', time()-($config['robot_mute_hour']*3600), PDO::PARAM_INT);
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$result = $query->fetch();
|
if (!$result = $query->fetchColumn())
|
||||||
if ($result['count'] == 0) return 0;
|
return 0;
|
||||||
return pow($config['robot_mute_multiplier'], $result['count']);
|
return pow($config['robot_mute_multiplier'], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mute() {
|
function mute() {
|
||||||
@ -1225,7 +1224,7 @@ function checkMute() {
|
|||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if (!$mute = $query->fetch()) {
|
if (!$mute = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
// What!? He's muted but he's not muted...
|
// What!? He's muted but he's not muted...
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1514,7 +1513,7 @@ function markup(&$body, $track_cites = false) {
|
|||||||
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
|
$match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($post = $query->fetch()) {
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
|
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
|
||||||
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' .
|
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' .
|
||||||
'>>' . $cite .
|
'>>' . $cite .
|
||||||
@ -1557,7 +1556,7 @@ function markup(&$body, $track_cites = false) {
|
|||||||
$query->bindValue(':id', $cite);
|
$query->bindValue(':id', $cite);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($post = $query->fetch()) {
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
|
$replacement = '<a onclick="highlightReply(\''.$cite.'\');" href="' .
|
||||||
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' .
|
$config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread']?$post['thread']:$post['id']) . '.html#' . $cite . '">' .
|
||||||
'>>>/' . $_board . '/' . $cite .
|
'>>>/' . $_board . '/' . $cite .
|
||||||
@ -1666,7 +1665,7 @@ function buildThread($id, $return = false, $mod = false) {
|
|||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
if (!isset($thread)) {
|
if (!isset($thread)) {
|
||||||
$thread = new Thread(
|
$thread = new Thread(
|
||||||
$post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'],
|
$post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'],
|
||||||
@ -1801,7 +1800,7 @@ function getPostByHash($hash) {
|
|||||||
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
|
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($post = $query->fetch()) {
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1815,7 +1814,7 @@ function getPostByHashInThread($hash, $thread) {
|
|||||||
$query->bindValue(':thread', $thread, PDO::PARAM_INT);
|
$query->bindValue(':thread', $thread, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($post = $query->fetch()) {
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ function create_pm_header() {
|
|||||||
$query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
|
$query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($pm = $query->fetch())
|
if ($pm = $query->fetch(PDO::FETCH_ASSOC))
|
||||||
$header = array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
|
$header = array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
|
||||||
else
|
else
|
||||||
$header = true;
|
$header = true;
|
||||||
|
@ -96,14 +96,14 @@ function mod_dashboard() {
|
|||||||
$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->bindValue(':id', $mod['id']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
$args['unread_pms'] = $query->fetchColumn(0);
|
$args['unread_pms'] = $query->fetchColumn();
|
||||||
|
|
||||||
if ($config['cache']['enabled'])
|
if ($config['cache']['enabled'])
|
||||||
cache::set('pm_unreadcount_' . $mod['id'], $args['unread_pms']);
|
cache::set('pm_unreadcount_' . $mod['id'], $args['unread_pms']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = query('SELECT COUNT(*) FROM `reports`') or error(db_error($query));
|
$query = query('SELECT COUNT(*) FROM `reports`') or error(db_error($query));
|
||||||
$args['reports'] = $query->fetchColumn(0);
|
$args['reports'] = $query->fetchColumn();
|
||||||
|
|
||||||
if ($mod['type'] >= ADMIN && $config['check_updates']) {
|
if ($mod['type'] >= ADMIN && $config['check_updates']) {
|
||||||
if (!$config['version'])
|
if (!$config['version'])
|
||||||
@ -536,7 +536,7 @@ function mod_noticeboard($page_no = 1) {
|
|||||||
|
|
||||||
$query = prepare("SELECT COUNT(*) FROM `noticeboard`");
|
$query = prepare("SELECT COUNT(*) FROM `noticeboard`");
|
||||||
$query->execute() or error(db_error($query));
|
$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));
|
mod_page(_('Noticeboard'), 'mod/noticeboard.html', array('noticeboard' => $noticeboard, 'count' => $count));
|
||||||
}
|
}
|
||||||
@ -597,7 +597,7 @@ function mod_news($page_no = 1) {
|
|||||||
|
|
||||||
$query = prepare("SELECT COUNT(*) FROM `news`");
|
$query = prepare("SELECT COUNT(*) FROM `news`");
|
||||||
$query->execute() or error(db_error($query));
|
$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));
|
mod_page(_('News'), 'mod/news.html', array('news' => $news, 'count' => $count));
|
||||||
}
|
}
|
||||||
@ -637,7 +637,7 @@ function mod_log($page_no = 1) {
|
|||||||
|
|
||||||
$query = prepare("SELECT COUNT(*) FROM `modlogs`");
|
$query = prepare("SELECT COUNT(*) FROM `modlogs`");
|
||||||
$query->execute() or error(db_error($query));
|
$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));
|
mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count));
|
||||||
}
|
}
|
||||||
@ -664,7 +664,7 @@ function mod_user_log($username, $page_no = 1) {
|
|||||||
$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->bindValue(':username', $username);
|
||||||
$query->execute() or error(db_error($query));
|
$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));
|
mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count, 'username' => $username));
|
||||||
}
|
}
|
||||||
@ -906,7 +906,7 @@ function mod_bans($page_no = 1) {
|
|||||||
|
|
||||||
$query = prepare("SELECT COUNT(*) FROM `bans`");
|
$query = prepare("SELECT COUNT(*) FROM `bans`");
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
$count = $query->fetchColumn(0);
|
$count = $query->fetchColumn();
|
||||||
|
|
||||||
foreach ($bans as &$ban) {
|
foreach ($bans as &$ban) {
|
||||||
if (filter_var($ban['ip'], FILTER_VALIDATE_IP) !== false)
|
if (filter_var($ban['ip'], FILTER_VALIDATE_IP) !== false)
|
||||||
@ -1058,7 +1058,7 @@ function mod_move($originBoard, $postID) {
|
|||||||
|
|
||||||
$replies = array();
|
$replies = array();
|
||||||
|
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$post['mod'] = true;
|
$post['mod'] = true;
|
||||||
$post['thread'] = $newID;
|
$post['thread'] = $newID;
|
||||||
|
|
||||||
@ -1365,7 +1365,7 @@ function mod_deletebyip($boardName, $post, $global = false) {
|
|||||||
$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->bindValue(':id', $post);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if (!$ip = $query->fetchColumn(0))
|
if (!$ip = $query->fetchColumn())
|
||||||
error($config['error']['invalidpost']);
|
error($config['error']['invalidpost']);
|
||||||
|
|
||||||
$boards = $global ? listBoards() : array(array('uri' => $boardName));
|
$boards = $global ? listBoards() : array(array('uri' => $boardName));
|
||||||
@ -1387,7 +1387,7 @@ function mod_deletebyip($boardName, $post, $global = false) {
|
|||||||
|
|
||||||
$threads_to_rebuild = array();
|
$threads_to_rebuild = array();
|
||||||
$threads_deleted = array();
|
$threads_deleted = array();
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
openBoard($post['board']);
|
openBoard($post['board']);
|
||||||
|
|
||||||
deletePost($post['id'], false, false);
|
deletePost($post['id'], false, false);
|
||||||
@ -1684,7 +1684,7 @@ function mod_inbox() {
|
|||||||
$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->bindValue(':mod', $mod['id']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
$unread = $query->fetchColumn(0);
|
$unread = $query->fetchColumn();
|
||||||
|
|
||||||
foreach ($messages as &$message) {
|
foreach ($messages as &$message) {
|
||||||
$message['snippet'] = pm_snippet($message['message']);
|
$message['snippet'] = pm_snippet($message['message']);
|
||||||
@ -1706,12 +1706,12 @@ function mod_new_pm($username) {
|
|||||||
$query = prepare("SELECT `id` FROM `mods` WHERE `username` = :username");
|
$query = prepare("SELECT `id` FROM `mods` WHERE `username` = :username");
|
||||||
$query->bindValue(':username', $username);
|
$query->bindValue(':username', $username);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if (!$id = $query->fetchColumn(0)) {
|
if (!$id = $query->fetchColumn()) {
|
||||||
// Old style ?/PM: by user ID
|
// 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->bindValue(':username', $username);
|
||||||
$query->execute() or error(db_error($query));
|
$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']);
|
header('Location: ?/new_PM/' . $username, true, $config['redirect_http']);
|
||||||
else
|
else
|
||||||
error($config['error']['404']);
|
error($config['error']['404']);
|
||||||
@ -1832,7 +1832,7 @@ function mod_reports() {
|
|||||||
$report_posts[$board] = array();
|
$report_posts[$board] = array();
|
||||||
|
|
||||||
$query = query(sprintf('SELECT * FROM `posts_%s` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error());
|
$query = query(sprintf('SELECT * FROM `posts_%s` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error());
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$report_posts[$board][$post['id']] = $post;
|
$report_posts[$board][$post['id']] = $post;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2169,10 +2169,10 @@ function mod_debug_antispam() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query = query('SELECT COUNT(*) FROM `antispam`' . ($where ? " WHERE $where" : '')) or error(db_error());
|
$query = query('SELECT COUNT(*) FROM `antispam`' . ($where ? " WHERE $where" : '')) or error(db_error());
|
||||||
$args['total'] = number_format($query->fetchColumn(0));
|
$args['total'] = number_format($query->fetchColumn());
|
||||||
|
|
||||||
$query = query('SELECT COUNT(*) FROM `antispam` WHERE `expires` IS NOT NULL' . ($where ? " AND $where" : '')) or error(db_error());
|
$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));
|
$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);
|
$args['top'] = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
10
post.php
10
post.php
@ -52,7 +52,7 @@ if (isset($_POST['delete'])) {
|
|||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($post = $query->fetch()) {
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
if ($password != '' && $post['password'] != $password)
|
if ($password != '' && $post['password'] != $password)
|
||||||
error($config['error']['invalidpassword']);
|
error($config['error']['invalidpassword']);
|
||||||
|
|
||||||
@ -115,12 +115,12 @@ if (isset($_POST['delete'])) {
|
|||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$post = $query->fetch();
|
$thread = $query->fetchColumn();
|
||||||
|
|
||||||
if ($post) {
|
if ($thread) {
|
||||||
if ($config['syslog'])
|
if ($config['syslog'])
|
||||||
_syslog(LOG_INFO, 'Reported post: ' .
|
_syslog(LOG_INFO, 'Reported post: ' .
|
||||||
'/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '') .
|
'/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $thread ? $thread : $id) . ($thread ? '#' . $id : '') .
|
||||||
' for "' . $reason . '"'
|
' for "' . $reason . '"'
|
||||||
);
|
);
|
||||||
$query = prepare("INSERT INTO `reports` VALUES (NULL, :time, :ip, :board, :post, :reason)");
|
$query = prepare("INSERT INTO `reports` VALUES (NULL, :time, :ip, :board, :post, :reason)");
|
||||||
@ -231,7 +231,7 @@ if (isset($_POST['delete'])) {
|
|||||||
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
|
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error());
|
$query->execute() or error(db_error());
|
||||||
|
|
||||||
if (!$thread = $query->fetch()) {
|
if (!$thread = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
// Non-existant
|
// Non-existant
|
||||||
error($config['error']['nonexistant']);
|
error($config['error']['nonexistant']);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
$query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM `posts_%s` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
|
$query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM `posts_%s` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
|
||||||
|
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id']));
|
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id']));
|
||||||
$post['board_name'] = $board['name'];
|
$post['board_name'] = $board['name'];
|
||||||
$post['file'] = $config['uri_thumb'] . $post['thumb'];
|
$post['file'] = $config['uri_thumb'] . $post['thumb'];
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
$query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_images'], $query);
|
$query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_images'], $query);
|
||||||
$query = query($query) or error(db_error());
|
$query = query($query) or error(db_error());
|
||||||
|
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
openBoard($post['board']);
|
openBoard($post['board']);
|
||||||
|
|
||||||
// board settings won't be available in the template file, so generate links now
|
// board settings won't be available in the template file, so generate links now
|
||||||
@ -67,7 +67,7 @@
|
|||||||
$query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_posts'], $query);
|
$query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_posts'], $query);
|
||||||
$query = query($query) or error(db_error());
|
$query = query($query) or error(db_error());
|
||||||
|
|
||||||
while ($post = $query->fetch()) {
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
openBoard($post['board']);
|
openBoard($post['board']);
|
||||||
|
|
||||||
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id'];
|
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id'];
|
||||||
@ -78,7 +78,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Total posts
|
// Total posts
|
||||||
$query = 'SELECT SUM(`top`) AS `count` FROM (';
|
$query = 'SELECT SUM(`top`) FROM (';
|
||||||
foreach ($boards as &$_board) {
|
foreach ($boards as &$_board) {
|
||||||
if (in_array($_board['uri'], $this->excluded))
|
if (in_array($_board['uri'], $this->excluded))
|
||||||
continue;
|
continue;
|
||||||
@ -86,11 +86,10 @@
|
|||||||
}
|
}
|
||||||
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
|
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
|
||||||
$query = query($query) or error(db_error());
|
$query = query($query) or error(db_error());
|
||||||
$res = $query->fetch();
|
$stats['total_posts'] = number_format($query->fetchColumn());
|
||||||
$stats['total_posts'] = number_format($res['count']);
|
|
||||||
|
|
||||||
// Unique IPs
|
// Unique IPs
|
||||||
$query = 'SELECT COUNT(DISTINCT(`ip`)) AS `count` FROM (';
|
$query = 'SELECT COUNT(DISTINCT(`ip`)) FROM (';
|
||||||
foreach ($boards as &$_board) {
|
foreach ($boards as &$_board) {
|
||||||
if (in_array($_board['uri'], $this->excluded))
|
if (in_array($_board['uri'], $this->excluded))
|
||||||
continue;
|
continue;
|
||||||
@ -98,11 +97,10 @@
|
|||||||
}
|
}
|
||||||
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
|
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
|
||||||
$query = query($query) or error(db_error());
|
$query = query($query) or error(db_error());
|
||||||
$res = $query->fetch();
|
$stats['unique_posters'] = number_format($query->fetchColumn());
|
||||||
$stats['unique_posters'] = number_format($res['count']);
|
|
||||||
|
|
||||||
// Active content
|
// Active content
|
||||||
$query = 'SELECT SUM(`filesize`) AS `count` FROM (';
|
$query = 'SELECT SUM(`filesize`) FROM (';
|
||||||
foreach ($boards as &$_board) {
|
foreach ($boards as &$_board) {
|
||||||
if (in_array($_board['uri'], $this->excluded))
|
if (in_array($_board['uri'], $this->excluded))
|
||||||
continue;
|
continue;
|
||||||
@ -110,8 +108,7 @@
|
|||||||
}
|
}
|
||||||
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
|
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
|
||||||
$query = query($query) or error(db_error());
|
$query = query($query) or error(db_error());
|
||||||
$res = $query->fetch();
|
$stats['active_content'] = $query->fetchColumn();
|
||||||
$stats['active_content'] = $res['count'];
|
|
||||||
|
|
||||||
return Element('themes/recent/recent.html', Array(
|
return Element('themes/recent/recent.html', Array(
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
|
@ -61,9 +61,8 @@
|
|||||||
// debug just the graphing (not updating) with the --debug switch
|
// debug just the graphing (not updating) with the --debug switch
|
||||||
if (!isset($argv[1]) || $argv[1] != '--debug') {
|
if (!isset($argv[1]) || $argv[1] != '--debug') {
|
||||||
// Update graph
|
// Update graph
|
||||||
$query = query(sprintf("SELECT MAX(`id`) AS `count` FROM `posts_%s`", $board));
|
$query = query(sprintf("SELECT MAX(`id`) FROM `posts_%s`", $board));
|
||||||
$count = $query->fetch();
|
$count = $query->fetchColumn();
|
||||||
$count = $count['count'];
|
|
||||||
|
|
||||||
if (!rrd_update($file, Array(
|
if (!rrd_update($file, Array(
|
||||||
'-t',
|
'-t',
|
||||||
|
Loading…
Reference in New Issue
Block a user