From 55f082a4217cdc584dea6a59157d7cd725c7e329 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 17 Feb 2011 17:07:36 +1100 Subject: Show omitted image replies count --- inc/functions.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 35a8d31a..0e6b54ad 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -440,22 +440,28 @@ $posts->bindValue(2, ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT); $posts->execute() or error(db_error($posts)); + $num_images = 0; + while($po = $posts->fetch()) { + if($po['file']) + $num_images++; + + $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : $config['root'], $mod)); + } + if($posts->rowCount() == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) { - $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = ?", $board['uri'])); - $count->bindValue(1, $th['id']); + $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri'])); + $count->bindValue(':thread', $th['id'], PDO::PARAM_INT); $count->execute() or error(db_error($count)); - $count = $count->fetch(); - $omitted = $count['num'] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']); - $thread->omitted = $omitted; - unset($count); - unset($omitted); + $c = $count->fetch(); + $thread->omitted = $c['num'] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']); + + $c = $count->fetch(); + $thread->omitted_images = $c['num'] - $num_images; + + $thread->omitted -= $thread->omitted_images; } - while($po = $posts->fetch()) { - $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : $config['root'], $mod)); - } - $thread->posts = array_reverse($thread->posts); $body .= $thread->build(true); } -- cgit v1.3