public function newThreadEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $title = trim($pl->getParameterValue("title")); $description = trim($pl->getParameterValue("description")); $source = trim($pl->getParameterValue("source")); $categoryId = $pl->getParameterValue("category_id"); $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); } // validate $errors = array(); if ($title == '') { $errors['title'] = _("Thread title can not be empty."); } if (strlen8($title) > 128) { $errors['title'] = _("Thread title should not be longer than 128 characters."); } if (strlen8($description) > 1000) { $errors['description'] = _("Thread description should not be longer than 1000 characters."); } if (strlen($source) > 200000) { $errors['source'] = _("It seems the source is too long."); } elseif ($source == '') { $errors['source'] = _("Post body can not be empty."); } if (count($errors) > 0) { $runData->ajaxResponseAdd("formErrors", $errors); throw new ProcessException("Form errors", "form_errors"); } // compile content $wt = new WikiTransformation(); $wt->setMode('post'); $body = $wt->processSource($source); // new thread $db = Database::connection(); $db->begin(); $c = new Criteria(); $c->add("category_id", $categoryId); $c->setForUpdate(true); $category = DB_ForumCategoryPeer::instance()->selectOne($c); if ($category == null || $category->getSiteId() !== $site->getSiteId()) { throw new ProcessException(_("Problem while selecting forum category."), "no_category"); } WDPermissionManager::instance()->hasForumPermission('new_thread', $runData->getUser(), $category); $thread = new DB_ForumThread(); $thread->setSiteId($site->getSiteId()); $thread->setCategoryId($categoryId); $thread->setTitle($title); $thread->setDescription($description); $thread->setDateStarted(new ODate()); $thread->setNumberPosts(1); // now set user_id, user_string if ($userId) { $thread->setUserId($userId); } else { $thread->setUserId(0); $thread->setUserString($userString); } $thread->save(); $postRevision = new DB_ForumPostRevision(); $postRevision->obtainPK(); $post = new DB_ForumPost(); $post->obtainPK(); $postRevision->setPostId($post->getPostId()); $postRevision->setText($source); $postRevision->setTitle($title); $postRevision->setDate(new ODate()); $post->setSiteId($site->getSiteId()); $post->setRevisionId($postRevision->getRevisionId()); $post->setText($body); $post->setTitle($title); $post->setDatePosted(new ODate()); $post->setThreadId($thread->getThreadId()); // now set user_id, user_string if ($userId) { $postRevision->setUserId($userId); $post->setUserId($userId); } else { $postRevision->setUserId(0); $post->setUserId(0); $postRevision->setUserString($userString); $post->setUserString($userString); } $postRevision->save(); $post->save(); $thread->setLastPostId($post->getPostId()); $thread->save(); // update number of posts in the category $category->setNumberPosts($category->getNumberPosts() + 1); $category->setNumberThreads($category->getNumberThreads() + 1); $category->setLastPostId($post->getPostId()); $category->save(); $o = new Outdater(); $o->forumEvent("post_save", $post); // index thread Indexer::instance()->indexThread($thread); $runData->ajaxResponseAdd("threadId", $thread->getThreadId()); $runData->ajaxResponseAdd("threadUnixifiedTitle", $thread->getUnixifiedTitle()); EventLogger::instance()->logNewThread($thread); $db->commit(); if (GlobalProperties::$UI_SLEEP) { sleep(1); } }