diff options
author | uckelman <uckelman@nomic.net> | 2010-04-11 15:35:25 +0000 |
---|---|---|
committer | uckelman <uckelman@nomic.net> | 2010-04-11 15:35:25 +0000 |
commit | bae4e7aa3345ca56dd86ca5fb84abbde8ae5383b (patch) | |
tree | 9e5e3f2af57911b11df2bc2a5c76cae4476764d3 /src | |
parent | 66be33480a0b891106ab3e8a75420843f36f6665 (diff) |
Added topicExists().
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6655 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src')
-rw-r--r-- | src/PhpBB3.php | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/PhpBB3.php b/src/PhpBB3.php index b12841f..5a60712 100644 --- a/src/PhpBB3.php +++ b/src/PhpBB3.php @@ -81,6 +81,39 @@ class PhpBB3 { } } + public function topicExists($topicId) { + global $db; + + if (!is_int($topicId)) { + trigger_error('topic id is not an integer', E_USER_ERROR); + } + + if ($topicId < 0) { + trigger_error('topic id is negative', E_USER_ERROR); + } + + $sql = 'SELECT 1 FROM ' . TOPICS_TABLE . ' ' . + 'WHERE topic_id = ' . $topicId . ' LIMIT 1'; + + $result = $db->sql_query($sql); + + $rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + switch (count($rows)) { + case 0: + return false; + + case 1: + return true; + + default: + # Should be impossible due to LIMIT 1. + trigger_error("Too many rows returned: $sql", E_USER_ERROR); + break; + } + } + public function postMessage($postType, $forumId, $topicId, $msg) { if ($postType != 'post' && $postType != 'reply') { trigger_error('bad post type: ' . $postType, E_USER_ERROR); @@ -94,10 +127,12 @@ class PhpBB3 { trigger_error('forum does not exist: ' . $forumId, E_USER_ERROR); } - if ($topicId !== null) { - if (!is_int($topicId) || $topicId < 0) { - trigger_error('bad topic id: ' . $topicId, E_USER_ERROR); - } + if (!is_int($topicId)) { + trigger_error('bad topic id: ' . $topicId, E_USER_ERROR); + } + + if ($postType == 'reply' && !$this->topicExists($topicId)) { + trigger_error('topic does not exist: ' . $topicId, E_USER_ERROR); } if ($msg === null) { |