diff options
| author | Macil Tech <maciltech@gmail.com> | 2013-06-18 12:21:41 -0500 |
|---|---|---|
| committer | Macil Tech <maciltech@gmail.com> | 2013-06-18 12:21:41 -0500 |
| commit | 3eda5b054361f7312b40a14728b76841c01628d2 (patch) | |
| tree | d3769bb2948da90eda5c01c449b81249757bc06e /inc/functions.php | |
| parent | fd33e9eba1e72fd4ee5f064944e9592be66c12c1 (diff) | |
Adds image_hard_limit and reply_hard_limit options.
Also reworks the numPosts() function and uses it elsewhere too.
Diffstat (limited to 'inc/functions.php')
| -rw-r--r-- | inc/functions.php | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/inc/functions.php b/inc/functions.php index 16b16901..b8dab90b 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -986,12 +986,8 @@ function index($page, $mod=false) { $replies = array_reverse($posts->fetchAll(PDO::FETCH_ASSOC)); if (count($replies) == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) { - $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->fetchAll(PDO::FETCH_COLUMN); - - $omitted = array('post_count' => $count[0], 'image_count' => $count[1]); + $count = numPosts($th['id']); + $omitted = array('post_count' => $count['replies'], 'image_count' => $count['images']); } else { $omitted = false; } @@ -1134,14 +1130,19 @@ function checkRobot($body) { return false; } +// Returns an associative array with 'replies' and 'images' keys function numPosts($id) { global $board; - $query = prepare(sprintf("SELECT COUNT(*) as `count` FROM `posts_%s` WHERE `thread` = :thread", $board['uri'])); + $query = prepare(sprintf("SELECT COUNT(*) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(*) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri'])); $query->bindValue(':thread', $id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); - $result = $query->fetch(); - return $result['count']; + $num_posts = $query->fetch(); + $num_posts = $num_posts['num']; + $num_images = $query->fetch(); + $num_images = $num_images['num']; + + return array('replies' => $num_posts, 'images' => $num_images); } function muteTime() { |
