diff --git a/inc/database/flatfile.php b/inc/database/flatfile.php index 09bdd4a..46a76c5 100644 --- a/inc/database/flatfile.php +++ b/inc/database/flatfile.php @@ -345,8 +345,17 @@ function convertPostsToSQLStyle($posts, $single = false) { return $newposts; } -function allThreads() { - $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON), -1, array(new OrderBy(POST_STICKIED, DESCENDING, INTEGER_COMPARISON), new OrderBy(POST_BUMPED, DESCENDING, INTEGER_COMPARISON))); +function allThreads($moderated_only = true) { + $compClause = new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON); + if ($moderated_only) { + $compClause2 = new AndWhereClause(); + $compClause2->add($compClause); + $compClause2->add(new SimpleWhereClause(POST_MODERATED, '>', 0, INTEGER_COMPARISON)); + } else { + $compClause2 = $compClause; + } + + $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, $compClause2, -1, array(new OrderBy(POST_STICKIED, DESCENDING, INTEGER_COMPARISON), new OrderBy(POST_BUMPED, DESCENDING, INTEGER_COMPARISON))); return convertPostsToSQLStyle($rows); } diff --git a/inc/database/mysql.php b/inc/database/mysql.php index d7a8480..96c80be 100644 --- a/inc/database/mysql.php +++ b/inc/database/mysql.php @@ -193,9 +193,9 @@ function countThreads() { return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 AND `moderated` = 1"), 0, 0); } -function allThreads() { +function allThreads($moderated_only = true) { $threads = array(); - $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 AND `moderated` = 1 ORDER BY `stickied` DESC, `bumped` DESC"); + $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY `stickied` DESC, `bumped` DESC"); if ($result) { while ($thread = mysql_fetch_assoc($result)) { $threads[] = $thread; diff --git a/inc/database/mysqli.php b/inc/database/mysqli.php index e75afc4..421e13c 100644 --- a/inc/database/mysqli.php +++ b/inc/database/mysqli.php @@ -224,10 +224,10 @@ function countThreads() { return mysqli_result(mysqli_query($link, "SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 AND `moderated` = 1"), 0, 0); } -function allThreads() { +function allThreads($moderated_only = true) { global $link; $threads = array(); - $result = mysqli_query($link, "SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 AND `moderated` = 1 ORDER BY `stickied` DESC, `bumped` DESC"); + $result = mysqli_query($link, "SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY `stickied` DESC, `bumped` DESC"); if ($result) { while ($thread = mysqli_fetch_assoc($result)) { $threads[] = $thread; diff --git a/inc/database/pdo.php b/inc/database/pdo.php index 6997ad6..7ca282c 100644 --- a/inc/database/pdo.php +++ b/inc/database/pdo.php @@ -181,9 +181,9 @@ function countThreads() { return (int)$result->fetchColumn(); } -function allThreads() { +function allThreads($moderated_only = true) { $threads = array(); - $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated > 0 ORDER BY stickied DESC, bumped DESC"); + $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY stickied DESC, bumped DESC"); while ($row = $results->fetch()) { $threads[] = $row; } diff --git a/inc/database/pdo_link.php b/inc/database/pdo_link.php index f768a87..dd61bff 100644 --- a/inc/database/pdo_link.php +++ b/inc/database/pdo_link.php @@ -99,13 +99,13 @@ if (TINYIB_DBDRIVER === 'pgsql') { $query = "SELECT column_name FROM information_schema.columns WHERE table_name='" . TINYIB_DBPOSTS . "' and column_name='moderated'"; $moderated_exists = $dbh->query($query)->fetchColumn() != 0; } else { - $dbh->query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'"); + $dbh->query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'moderated'"); $moderated_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0; } - if (!$moderated_exists) { - $dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN moderated TINYINT(1) NOT NULL DEFAULT '0'"); + $dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN moderated TINYINT(1) NOT NULL DEFAULT '1'"); } + if (TINYIB_DBDRIVER === 'pgsql') { $query = "SELECT column_name FROM information_schema.columns WHERE table_name='" . TINYIB_DBPOSTS . "' and column_name='stickied'"; $stickied_exists = $dbh->query($query)->fetchColumn() != 0; @@ -113,7 +113,6 @@ if (TINYIB_DBDRIVER === 'pgsql') { $dbh->query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'"); $stickied_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0; } - if (!$stickied_exists) { $dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN stickied TINYINT(1) NOT NULL DEFAULT '0'"); } @@ -125,7 +124,6 @@ if (TINYIB_DBDRIVER === 'pgsql') { $dbh->query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'locked'"); $locked_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0; } - if (!$locked_exists) { $dbh->exec("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN locked TINYINT(1) NOT NULL DEFAULT '0'"); } diff --git a/inc/database/sqlite.php b/inc/database/sqlite.php index f0972a0..698121c 100644 --- a/inc/database/sqlite.php +++ b/inc/database/sqlite.php @@ -147,7 +147,7 @@ function threadExistsByID($id) { } function insertPost($post) { - sqlite_query($GLOBALS["db"], "INSERT INTO " . TINYIB_DBPOSTS . " (parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . hashData(remoteAddress()) . "', '" . sqlite_escape_string($post['name']) . "', '" . sqlite_escape_string($post['tripcode']) . "', '" . sqlite_escape_string($post['email']) . "', '" . sqlite_escape_string($post['nameblock']) . "', '" . sqlite_escape_string($post['subject']) . "', '" . sqlite_escape_string($post['message']) . "', '" . sqlite_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . sqlite_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ")"); + sqlite_query($GLOBALS["db"], "INSERT INTO " . TINYIB_DBPOSTS . " (parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height, moderated) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . hashData(remoteAddress()) . "', '" . sqlite_escape_string($post['name']) . "', '" . sqlite_escape_string($post['tripcode']) . "', '" . sqlite_escape_string($post['email']) . "', '" . sqlite_escape_string($post['nameblock']) . "', '" . sqlite_escape_string($post['subject']) . "', '" . sqlite_escape_string($post['message']) . "', '" . sqlite_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . sqlite_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ", " . $post['moderated'] . ")"); return sqlite_last_insert_rowid($GLOBALS["db"]); } @@ -171,9 +171,9 @@ function countThreads() { return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = 0")); } -function allThreads() { +function allThreads($moderated_only = true) { $threads = array(); - $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 ORDER BY stickied DESC, bumped DESC"), SQLITE_ASSOC); + $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY stickied DESC, bumped DESC"), SQLITE_ASSOC); foreach ($result as $thread) { $threads[] = $thread; } diff --git a/inc/database/sqlite3.php b/inc/database/sqlite3.php index c06371c..86e8e3d 100644 --- a/inc/database/sqlite3.php +++ b/inc/database/sqlite3.php @@ -171,7 +171,7 @@ function threadExistsByID($id) { function insertPost($post) { global $db; - $db->exec("INSERT INTO " . TINYIB_DBPOSTS . " (parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . hashData(remoteAddress()) . "', '" . $db->escapeString($post['name']) . "', '" . $db->escapeString($post['tripcode']) . "', '" . $db->escapeString($post['email']) . "', '" . $db->escapeString($post['nameblock']) . "', '" . $db->escapeString($post['subject']) . "', '" . $db->escapeString($post['message']) . "', '" . $db->escapeString($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . $db->escapeString($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ")"); + $db->exec("INSERT INTO " . TINYIB_DBPOSTS . " (parent, timestamp, bumped, ip, name, tripcode, email, nameblock, subject, message, password, file, file_hex, file_original, file_size, file_size_formatted, image_width, image_height, thumb, thumb_width, thumb_height, moderated) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . hashData(remoteAddress()) . "', '" . $db->escapeString($post['name']) . "', '" . $db->escapeString($post['tripcode']) . "', '" . $db->escapeString($post['email']) . "', '" . $db->escapeString($post['nameblock']) . "', '" . $db->escapeString($post['subject']) . "', '" . $db->escapeString($post['message']) . "', '" . $db->escapeString($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . $db->escapeString($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ", " . $post['moderated'] . ")"); return $db->lastInsertRowID(); } @@ -200,10 +200,10 @@ function countThreads() { return $db->querySingle("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = 0"); } -function allThreads() { +function allThreads($moderated_only = true) { global $db; $threads = array(); - $result = $db->query("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 ORDER BY stickied DESC, bumped DESC"); + $result = $db->query("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY stickied DESC, bumped DESC"); while ($thread = $result->fetchArray()) { $threads[] = $thread; } diff --git a/inc/database/sqlite3_link.php b/inc/database/sqlite3_link.php index 319722f..7fac5c7 100644 --- a/inc/database/sqlite3_link.php +++ b/inc/database/sqlite3_link.php @@ -81,7 +81,7 @@ if (!$result->fetchArray()) { thumb TEXT NOT NULL, thumb_width INTEGER NOT NULL DEFAULT '0', thumb_height INTEGER NOT NULL DEFAULT '0', - moderated INTEGER NOT NULL DEFAULT '0', + moderated INTEGER NOT NULL DEFAULT '1', stickied INTEGER NOT NULL DEFAULT '0', locked INTEGER NOT NULL DEFAULT '0' )"); @@ -97,7 +97,7 @@ if (!$result->fetchArray()) { } // Add moderated column if it isn't present -@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '0'"); +@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '1'"); // Add stickied column if it isn't present @$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN stickied INTEGER NOT NULL DEFAULT '0'"); diff --git a/inc/database/sqlite_link.php b/inc/database/sqlite_link.php index 382e725..51f5d70 100644 --- a/inc/database/sqlite_link.php +++ b/inc/database/sqlite_link.php @@ -78,7 +78,7 @@ if (sqlite_num_rows($result) == 0) { thumb TEXT NOT NULL, thumb_width INTEGER NOT NULL DEFAULT '0', thumb_height INTEGER NOT NULL DEFAULT '0', - moderated INTEGER NOT NULL DEFAULT '0', + moderated INTEGER NOT NULL DEFAULT '1', stickied INTEGER NOT NULL DEFAULT '0', locked INTEGER NOT NULL DEFAULT '0' )"); @@ -93,7 +93,7 @@ if (sqlite_num_rows($result) == 0) { } // Add moderated column if it isn't present -sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '0'"); +sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '1'"); // Add stickied column if it isn't present sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN stickied INTEGER NOT NULL DEFAULT '0'");