diff --git a/inc/database_flatfile.php b/inc/database_flatfile.php index 1d494bd..886e97f 100644 --- a/inc/database_flatfile.php +++ b/inc/database_flatfile.php @@ -150,11 +150,6 @@ function postsInThreadByID($id) { return convertPostsToSQLStyle($rows); } -function latestRepliesInThreadByID($id) { - $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON), 3, new OrderBy(POST_ID, DESCENDING, INTEGER_COMPARISON)); - return convertPostsToSQLStyle($rows); -} - function postsByHex($hex) { $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_FILE_HEX, '=', $hex, STRING_COMPARISON), 1); return convertPostsToSQLStyle($rows); diff --git a/inc/database_mysql.php b/inc/database_mysql.php index 92d35dc..ea13084 100644 --- a/inc/database_mysql.php +++ b/inc/database_mysql.php @@ -108,17 +108,6 @@ function postsInThreadByID($id) { return $posts; } -function latestRepliesInThreadByID($id) { - $posts = array(); - $replies = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = " . $id . " ORDER BY `id` DESC LIMIT 3"); - if ($replies) { - while ($post = mysql_fetch_assoc($replies)) { - $posts[] = $post; - } - } - return $posts; -} - function postsByHex($hex) { $posts = array(); $result = mysql_query("SELECT `id`, `parent` FROM `" . TINYIB_DBPOSTS . "` WHERE `file_hex` = '" . mysql_real_escape_string($hex) . "' LIMIT 1"); diff --git a/inc/database_sqlite.php b/inc/database_sqlite.php index eaf5167..470121f 100644 --- a/inc/database_sqlite.php +++ b/inc/database_sqlite.php @@ -93,15 +93,6 @@ function postsInThreadByID($id) { return $posts; } -function latestRepliesInThreadByID($id) { - $posts = array(); - $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = " . $id . " ORDER BY id DESC LIMIT 3"), SQLITE_ASSOC); - foreach ($result as $post) { - $posts[] = $post; - } - return $posts; -} - function postsByHex($hex) { $posts = array(); $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT id, parent FROM " . TINYIB_DBPOSTS . " WHERE file_hex = '" . sqlite_escape_string($hex) . "' LIMIT 1"), SQLITE_ASSOC); diff --git a/inc/html.php b/inc/html.php index 37a5d2f..02f37eb 100644 --- a/inc/html.php +++ b/inc/html.php @@ -274,23 +274,22 @@ EOF; function rebuildIndexes() { $page = 0; $i = 0; $htmlposts = ''; - $pages = ceil(countThreads() / 10) - 1; $threads = allThreads(); + $pages = ceil(count($threads) / 10) - 1; foreach ($threads as $thread) { - $replies = latestRepliesInThreadByID($thread['id']); + $replies = postsInThreadByID($thread['id']); $htmlreplies = array(); - foreach ($replies as $reply) { - $htmlreplies[] = buildPost($reply, TINYIB_INDEXPAGE); + for ($j = min(count($replies) - 1, TINYIB_PREVIEWREPLIES); $j > 0; $j--) { + $htmlreplies[$j] = buildPost($replies[$j], TINYIB_INDEXPAGE); } - $thread['omitted'] = (count($htmlreplies) == 3) ? (count(postsInThreadByID($thread['id'])) - 4) : 0; + $thread['omitted'] = max(count($replies) - TINYIB_PREVIEWREPLIES - 1, 0); + + $htmlposts .= buildPost($thread, TINYIB_INDEXPAGE) . implode('', $htmlreplies) . "
\n
"; - $htmlposts .= buildPost($thread, TINYIB_INDEXPAGE) . implode('', array_reverse($htmlreplies)) . "
\n
"; - - $i += 1; - if ($i == 10) { + if (++$i == 10) { $file = ($page == 0) ? 'index.html' : $page . '.html'; writePage($file, buildPage($htmlposts, 0, $pages, $page)); diff --git a/settings.default.php b/settings.default.php index 8a4fcd1..80d9431 100644 --- a/settings.default.php +++ b/settings.default.php @@ -1,4 +1,4 @@ -