public function build($runData) { $pl = $runData->getParameterList(); $title = $pl->getParameterValue("title"); $description = trim($pl->getParameterValue("description")); $source = trim($pl->getParameterValue("source")); if ($source == null || $source == '') { throw new ProcessException(_("Post is empty."), "post_empty"); } $wt = new WikiTransformation(); $wt->setMode('post'); $body = $wt->processSource($source); $post = new DB_ForumPost(); $post->setText($body); $post->setTitle($title); $post->setDatePosted(new ODate()); // now set user_id, user_string $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); } if ($userId) { $post->setUserId($userId); } else { $post->setUserId(0); $post->setUserString($userString); } $runData->contextAdd("post", $post); }
public function savePostEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $title = trim($pl->getParameterValue("title")); $source = trim($pl->getParameterValue("source")); $threadId = $pl->getParameterValue("threadId"); $parentPostId = $pl->getParameterValue("parentId"); $user = $runData->getUser(); $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); } $errors = array(); if (strlen8($title) > 128) { $errors['title'] = _("Post title should not be longer than 128 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"); } $c = new Criteria(); $c->add("thread_id", $threadId); $c->add("site_id", $site->getSiteId()); $c->setForUpdate(true); $thread = DB_ForumThreadPeer::instance()->selectOne($c); if ($thread == null || $thread->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("Thread not found."), "no_thread"); } if ($thread->getBlocked()) { // check if moderator or admin $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("user_id", $user->getUserId()); $rel = DB_ModeratorPeer::instance()->selectOne($c); if (!$rel || strpos($rel->getPermissions(), 'f') == false) { $rel = DB_AdminPeer::instance()->selectOne($c); if (!$rel) { throw new WDPermissionException(_("Sorry, this thread is blocked. Nobody can add new posts nor edit existing ones.")); } } } // compile content $wt = new WikiTransformation(); $wt->setMode('post'); $body = $wt->processSource($source); $db = Database::connection(); $db->begin(); $c = new Criteria(); $c->add("category_id", $thread->getCategoryId()); $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_post', $runData->getUser(), $category); $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($threadId); if ($parentPostId) { $post->setParentId($parentPostId); } // 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->setNumberPosts($thread->getNumberPosts() + 1); $thread->save(); // update number of posts in the category $category->setNumberPosts($category->getNumberPosts() + 1); $category->setLastPostId($post->getPostId()); $category->save(); $o = new Outdater(); $o->forumEvent("post_save", $post); // index thread Indexer::instance()->indexThread($thread); EventLogger::instance()->logNewPost($post); $db->commit(); $runData->ajaxResponseAdd("postId", $post->getPostId()); if (GlobalProperties::$UI_SLEEP) { sleep(1); } }