From 6fd6b92fe828824dee408614805b35fe29177cd2 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Fri, 1 Mar 2013 07:12:17 +0800 Subject: Fix openBoard and boardTitle functions using same caching keys. Added getBoardInfo function that's used by both of the above functions, and can get a board's info without loading it. --- inc/functions.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 16b16901..872c6c23 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -328,11 +328,19 @@ function setupBoard($array) { } function openBoard($uri) { + $board = getBoardInfo($uri); + if ($board) { + setupBoard($board); + return true; + } + return false; +} + +function getBoardInfo($uri) { global $config; if ($config['cache']['enabled'] && ($board = cache::get('board_' . $uri))) { - setupBoard($board); - return true; + return $board; } $query = prepare("SELECT * FROM `boards` WHERE `uri` = :uri LIMIT 1"); @@ -342,27 +350,16 @@ function openBoard($uri) { if ($board = $query->fetch()) { if ($config['cache']['enabled']) cache::set('board_' . $uri, $board); - setupBoard($board); - return true; + return $board; } return false; } function boardTitle($uri) { - global $config; - if ($config['cache']['enabled'] && ($board = cache::get('board_' . $uri))) { + $board = getBoardInfo($uri); + if ($board) return $board['title']; - } - - $query = prepare("SELECT `title` FROM `boards` WHERE `uri` = :uri LIMIT 1"); - $query->bindValue(':uri', $uri); - $query->execute() or error(db_error($query)); - - if ($title = $query->fetch()) { - return $title['title']; - } - return false; } -- cgit v1.3 From b078222ede702b8ecf4b28f5ebd6db5c34b65143 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Sat, 8 Jun 2013 05:55:13 -0500 Subject: Fix "Undefined index: sticky" and "locked" errors on new thread creation. --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 872c6c23..b83d6c86 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -722,13 +722,13 @@ function post(array $post) { $query->bindValue(':password', $post['password']); $query->bindValue(':ip', isset($post['ip']) ? $post['ip'] : $_SERVER['REMOTE_ADDR']); - if ($post['op'] && $post['mod'] && $post['sticky']) { + if ($post['op'] && $post['mod'] && isset($post['sticky']) && $post['sticky']) { $query->bindValue(':sticky', 1, PDO::PARAM_INT); } else { $query->bindValue(':sticky', 0, PDO::PARAM_INT); } - if ($post['op'] && $post['mod'] && $post['locked']) { + if ($post['op'] && $post['mod'] && isset($post['locked']) && $post['locked']) { $query->bindValue(':locked', 1, PDO::PARAM_INT); } else { $query->bindValue(':locked', 0, PDO::PARAM_INT); -- cgit v1.3 From 765e64ee38919c48f840403c4910a37fbce037e9 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Wed, 13 Feb 2013 01:25:56 +0800 Subject: m and n dash fix --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index b83d6c86..a9afb450 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1362,8 +1362,8 @@ function unicodify($body) { // En and em- dashes are rendered exactly the same in // most monospace fonts (they look the same in code // editors). - $body = str_replace('--', '–', $body); // en dash $body = str_replace('---', '—', $body); // em dash + $body = str_replace('--', '–', $body); // en dash return $body; } -- cgit v1.3 From 3eda5b054361f7312b40a14728b76841c01628d2 Mon Sep 17 00:00:00 2001 From: Macil Tech Date: Tue, 18 Jun 2013 12:21:41 -0500 Subject: Adds image_hard_limit and reply_hard_limit options. Also reworks the numPosts() function and uses it elsewhere too. --- inc/config.php | 7 +++++++ inc/functions.php | 19 ++++++++++--------- post.php | 20 ++++++++++++++------ 3 files changed, 31 insertions(+), 15 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index cedf3e06..93a2fde2 100644 --- a/inc/config.php +++ b/inc/config.php @@ -311,6 +311,11 @@ // Reply limit (stops bumping thread when this is reached) $config['reply_limit'] = 250; + // Image hard limit (stops allowing new image replies when this is reached if not zero) + $config['image_hard_limit'] = 0; + // Reply hard limit (stops allowing new replies when this is reached if not zero) + $config['reply_hard_limit'] = 0; + // Strip repeating characters when making hashes $config['robot_enable'] = false; $config['robot_strip_repeating'] = true; @@ -659,6 +664,8 @@ $config['error']['noboard'] = _('Invalid board!'); $config['error']['nonexistant'] = _('Thread specified does not exist.'); $config['error']['locked'] = _('Thread locked. You may not reply at this time.'); + $config['error']['reply_hard_limit'] = _('Thread has reached its maximum reply limit.'); + $config['error']['image_hard_limit'] = _('Thread has reached its maximum image limit.'); $config['error']['nopost'] = _('You didn\'t make a post.'); $config['error']['flood'] = _('Flood detected; Post discarded.'); $config['error']['spam'] = _('Your request looks automated; Post discarded.'); 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() { diff --git a/post.php b/post.php index c5e68578..f236e929 100644 --- a/post.php +++ b/post.php @@ -302,13 +302,21 @@ if (isset($_POST['delete'])) { } } - // Check if thread is locked - // but allow mods to post - if (!$post['op'] && !hasPermission($config['mod']['postinlocked'], $board['uri'])) { - if ($thread['locked']) + if (!$post['op']) { + // Check if thread is locked + // but allow mods to post + if ($thread['locked'] && !hasPermission($config['mod']['postinlocked'], $board['uri'])) error($config['error']['locked']); + + $numposts = numPosts($post['thread']); + + if ($config['reply_hard_limit'] != 0 && $config['reply_hard_limit'] <= $numposts['replies']) + error($config['error']['reply_hard_limit']); + + if ($post['has_file'] && $config['image_hard_limit'] != 0 && $config['image_hard_limit'] <= $numposts['images']) + error($config['error']['image_hard_limit']); } - + if ($post['has_file']) { $size = $_FILES['file']['size']; if ($size > $config['max_filesize']) @@ -636,7 +644,7 @@ if (isset($_POST['delete'])) { buildThread($post['op'] ? $id : $post['thread']); - if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || numPosts($post['thread']) < $config['reply_limit'])) { + if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) { bumpThread($post['thread']); } -- cgit v1.3