summaryrefslogtreecommitdiff
path: root/src/PhpBB3.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/PhpBB3.php')
-rw-r--r--src/PhpBB3.php48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/PhpBB3.php b/src/PhpBB3.php
index 7fb0f80..51d4bbe 100644
--- a/src/PhpBB3.php
+++ b/src/PhpBB3.php
@@ -82,29 +82,21 @@ class PhpBB3 {
}
public function postMessage($postType, $forumId, $topicId, $msg) {
- if ($postType === null) {
- trigger_error('post type is null', E_USER_ERROR);
+ if ($postType != 'post' && $postType != 'reply') {
+ trigger_error('bad post type: ' . $postType, E_USER_ERROR);
}
- if (!is_int($forumId)) {
- trigger_error('forum id is not an integer', E_USER_ERROR);
- }
-
- if ($forumId < 0) {
- trigger_error('forum id is negative', E_USER_ERROR);
+ if (!is_int($forumId) || $forumId < 0) {
+ trigger_error('bad forum id: ' . $forumId, E_USER_ERROR);
}
if (!$this->forumExists($forumId)) {
trigger_error('forum does not exist: ' . $forumId, E_USER_ERROR);
}
- if ($topicId != null) {
- 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);
+ if ($topicId !== null) {
+ if (!is_int($topicId) || $topicId < 0) {
+ trigger_error('bad topic id: ' . $topicId, E_USER_ERROR);
}
}
@@ -115,11 +107,27 @@ class PhpBB3 {
$subject = $msg->getSubject();
$message = 'foo'; # FIXME: fill in with acutal message contents
- $userId = $phpbb->getUserId($msg->getFrom());
- $userName = $phpbb->getUserName($userId);
+ $userId = $this->getUserId($msg->getFrom());
+ $userName = $this->getUserName($userId);
+
+ # authenticate ourselves
+ global $phpEx, $phpbb_root_path, $user, $auth;
+ $user->session_create($userId);
+ $auth->acl($user->data);
+
+ $subject = utf8_normalize_nfc($subject);
+ $message = utf8_normalize_nfc($message);
+
+ $uid = $bitfield = $options = '';
+
+ generate_text_for_storage(
+ $subject, $uid, $bitfield, $options, false, false, false
+ );
+
+ generate_text_for_storage(
+ $message, $uid, $bitfield, $options, true, true, true
+ );
- $poll = $uid = $bitfield = '';
- $topicId = -1;
$postId = null;
$data = array(
@@ -148,6 +156,8 @@ class PhpBB3 {
'enable_indexing' => true,
);
+ $poll = '';
+
submit_post($postType, $subject, $userName, POST_NORMAL, $poll, $data);
return $postId;