Adds function to count posts and images of a thread
This commit is contained in:
parent
11d59a9181
commit
6448c3fe83
|
@ -97,6 +97,17 @@
|
||||||
return $query->fetchAll(PDO::FETCH_ASSOC);
|
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
|
* Intersperse random threads between those in bump order
|
||||||
*/
|
*/
|
||||||
|
@ -138,27 +149,15 @@
|
||||||
$config['threads_preview'];
|
$config['threads_preview'];
|
||||||
$replies = $this->fetchReplies($post['board'], $post['id'], $preview_count);
|
$replies = $this->fetchReplies($post['board'], $post['id'], $preview_count);
|
||||||
|
|
||||||
// Chomp the last few replies
|
|
||||||
$disp_replies = $replies;
|
$disp_replies = $replies;
|
||||||
$disp_img_count = 0;
|
|
||||||
foreach ($disp_replies as $reply) {
|
foreach ($disp_replies as $reply) {
|
||||||
if ($reply['files'] !== '')
|
|
||||||
++$disp_img_count;
|
|
||||||
|
|
||||||
// Append the reply to the thread as it's being built
|
// Append the reply to the thread as it's being built
|
||||||
$thread->add(new Post($reply, $mod ? '?/' : $config['root'], $mod));
|
$thread->add(new Post($reply, $mod ? '?/' : $config['root'], $mod));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count the number of omitted image replies
|
$threadCount = $this->fetchThreadCount($post['board'], $post['id']);
|
||||||
$omitted_img_count = count(array_filter($replies, function($p) {
|
$thread->omitted = $threadCount['post_count'];
|
||||||
return $p['files'] !== '';
|
$thread->omitted_images = $threadCount['file_count'];
|
||||||
}));
|
|
||||||
|
|
||||||
// Set the corresponding omitted numbers on the thread
|
|
||||||
if (!empty($replies)) {
|
|
||||||
$thread->omitted = count($replies);
|
|
||||||
$thread->omitted_images = $omitted_img_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Board name and link
|
// Board name and link
|
||||||
$html = '<h2><a href="' . $config['root'] . $post['board'] . '/">/' .
|
$html = '<h2><a href="' . $config['root'] . $post['board'] . '/">/' .
|
||||||
|
|
Loading…
Reference in New Issue