|
|
@ -97,6 +97,17 @@ |
|
|
|
return $query->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retrieve count of images and posts in a thread |
|
|
|
*/ |
|
|
|
private function fetchThreadCount($board, $thread_id) { |
|
|
|
$query = prepare("SELECT COUNT(NULLIF(TRIM(files), '')) as file_count, COUNT(id) as post_count FROM ``posts_$board`` WHERE `thread` = :id"); |
|
|
|
$query->bindValue(':id', $thread_id, PDO::PARAM_INT); |
|
|
|
$query->execute() or error(db_error($query)); |
|
|
|
|
|
|
|
return $query->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Intersperse random threads between those in bump order |
|
|
|
*/ |
|
|
@ -138,27 +149,15 @@ |
|
|
|
$config['threads_preview']; |
|
|
|
$replies = $this->fetchReplies($post['board'], $post['id'], $preview_count); |
|
|
|
|
|
|
|
// Chomp the last few replies |
|
|
|
$disp_replies = $replies; |
|
|
|
$disp_img_count = 0; |
|
|
|
foreach ($disp_replies as $reply) { |
|
|
|
if ($reply['files'] !== '') |
|
|
|
++$disp_img_count; |
|
|
|
|
|
|
|
// Append the reply to the thread as it's being built |
|
|
|
$thread->add(new Post($reply, $mod ? '?/' : $config['root'], $mod)); |
|
|
|
} |
|
|
|
|
|
|
|
// Count the number of omitted image replies |
|
|
|
$omitted_img_count = count(array_filter($replies, function($p) { |
|
|
|
return $p['files'] !== ''; |
|
|
|
})); |
|
|
|
|
|
|
|
// Set the corresponding omitted numbers on the thread |
|
|
|
if (!empty($replies)) { |
|
|
|
$thread->omitted = count($replies); |
|
|
|
$thread->omitted_images = $omitted_img_count; |
|
|
|
} |
|
|
|
$threadCount = $this->fetchThreadCount($post['board'], $post['id']); |
|
|
|
$thread->omitted = $threadCount['post_count']; |
|
|
|
$thread->omitted_images = $threadCount['file_count']; |
|
|
|
|
|
|
|
// Board name and link |
|
|
|
$html = '<h2><a href="' . $config['root'] . $post['board'] . '/">/' . |
|
|
|