public function build($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $limit = $pl->getParameterValue("limit", "MODULE"); if ($limit == null || !is_numeric($limit) || $limit < 1 || $limit > 300) { $limit = 5; } $categoryId = $pl->getParameterValue("categoryId", "MODULE", "AMODULE"); if ($categoryId !== null) { $category = DB_ForumCategoryPeer::instance()->selectByPrimaryKey($categoryId); if ($category == null || $category->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("The category can not be found.")); } } // get recent forum posts $c = new Criteria(); $c->add("forum_post.site_id", $site->getSiteId()); if ($category) { $c->add("forum_post.category_id", $category->getCategoryId()); } $c->addJoin("thread_id", "forum_thread.thread_id"); $c->addOrderDescending("post_id"); $c->setLimit($limit); $posts = DB_ForumPostPeer::instance()->select($c); $runData->contextAdd("posts", $posts); }
public function calculate($user) { $c = new Criteria(); $c->add('user_id', $user->getUserId()); $count = DB_ForumPostPeer::instance()->selectCount($c); return $count; }
public function build($runData) { $pl = $runData->getParameterList(); $postId = $pl->getParameterValue("postId", "AMODULE"); $user = $runData->getUser(); $site = $runData->getTemp("site"); if ($postId == null || !is_numeric($postId)) { throw new ProcessException(_("No post specified."), "no_post"); } $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId); if ($post == null || $post->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("No post specified."), "no_post"); } $category = $post->getForumThread()->getCategory(); try { WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category); } catch (Exception $e) { throw new WDPermissionException(_("Sorry, you are not allowed to delete posts. Only site administrators and moderators are the ones who can.")); } // OK for now... //check if there any child posts $c = new Criteria(); $c->add("parent_id", $postId); $chpc = DB_ForumPostPeer::instance()->selectCount($c); if ($chpc > 0) { $runData->contextAdd("hasChildren", true); } $runData->contextAdd("post", $post); $runData->ajaxResponseAdd("postId", $postId); }
public function getLastPost() { if ($this->getLastPostId() == null) { return; } $c = new Criteria(); $c->add("post_id", $this->getLastPostId()); $c->addJoin("user_id", "ozone_user.user_id"); $post = DB_ForumPostPeer::instance()->selectOne($c); return $post; }
public function build($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $userId = $pl->getParameterValue("userId"); if ($runData->getUser() && $userId == $runData->getUser()->getUserId()) { $own = true; } $categoryId = $pl->getParameterValue("categoryId"); $limit = $pl->getParameterValue("limit"); if ($limit == null || !is_numeric($limit)) { $limit = 20; } $pageNumber = $pl->getParameterValue("page"); $op = $pl->getParameterValue("options"); if ($pageNumber === null) { $pageNumber = 1; } $perPage = $limit; $offset = ($pageNumber - 1) * $perPage; $count = $perPage * 2 + 1; $c = new Criteria(); if ($categoryId !== null && is_numeric($categoryId)) { $c->add("forum_thread.category_id", $categoryId); } $c->add("forum_post.user_id", $userId); if (!$own) { $c->add("site.private", false); } $c->addJoin("thread_id", "forum_thread.thread_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->addJoin("forum_post.site_id", "site.site_id"); $c->add("site.deleted", false); $c->addOrderDescending("post_id"); $c->setLimit($count, $offset); $posts = DB_ForumPostPeer::instance()->select($c); $counted = count($posts); $pagerData = array(); $pagerData['currentPage'] = $pageNumber; if ($counted > $perPage * 2) { $knownPages = $pageNumber + 2; $pagerData['knownPages'] = $knownPages; } elseif ($counted > $perPage) { $knownPages = $pageNumber + 1; $pagerData['totalPages'] = $knownPages; } else { $totalPages = $pageNumber; $pagerData['totalPages'] = $totalPages; } $posts = array_slice($posts, 0, $perPage); $runData->contextAdd("pagerData", $pagerData); $runData->contextAdd("posts", $posts); }
public function build($runData) { $user = $runData->getUser(); $pl = $runData->getParameterList(); $pageNumber = $pl->getParameterValue("page"); if ($pageNumber === null) { $pageNumber = 1; } $limit = $pl->getParameterValue("limit"); if ($limit == null || !is_numeric($limit)) { $limit = 20; } $perPage = $limit; $offset = ($pageNumber - 1) * $perPage; $count = $perPage * 2 + 1; // join the tables: watched_forum_thread, forum_thread, forum_post, site, user???. OK??? $c = new Criteria(); $c->addJoin("thread_id", "forum_thread.thread_id"); $c->addJoin("thread_id", "watched_forum_thread.thread_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->add("watched_forum_thread.user_id", $user->getUserId()); $c->addOrderDescending("post_id"); $c->setLimit($count, $offset); $posts = DB_ForumPostPeer::instance()->select($c); $counted = count($posts); $pagerData = array(); $pagerData['currentPage'] = $pageNumber; if ($counted > $perPage * 2) { $knownPages = $pageNumber + 2; $pagerData['knownPages'] = $knownPages; } elseif ($counted > $perPage) { $knownPages = $pageNumber + 1; $pagerData['totalPages'] = $knownPages; } else { $totalPages = $pageNumber; $pagerData['totalPages'] = $totalPages; } $posts = array_slice($posts, 0, $perPage); $runData->contextAdd("pagerData", $pagerData); $runData->contextAdd("posts", $posts); }
public function build($runData) { $pl = $runData->getParameterList(); $postId = $pl->getParameterValue("postId", "AMODULE"); $user = $runData->getUser(); $site = $runData->getTemp("site"); if ($postId == null || !is_numeric($postId)) { throw new ProcessException(_("No post specified."), "no_post"); } $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId); if ($post == null || $post->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("No post specified."), "no_post"); } $category = $post->getForumThread()->getCategory(); WDPermissionManager::instance()->hasForumPermission('edit_post', $runData->getUser(), $category, null, $post); // check if thread blocked $thread = $post->getForumThread(); 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.")); } } } // OK for now... // keep the session - i.e. put an object into session storage not to delete it!!! $runData->sessionAdd("keep", true); $runData->contextAdd("post", $post); $runData->ajaxResponseAdd("postId", $postId); $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); $runData->contextAdd("anonymousString", $userString); } }
public function build($runData) { $pl = $runData->getParameterList(); $postId = $pl->getParameterValue("postId"); $site = $runData->getTemp("site"); if ($postId == null || !is_numeric($postId)) { throw new ProcessException(_("No post specified."), "no_post"); } $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId); if ($post == null || $post->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("No post specified."), "no_post"); } // get all revisions $c = new Criteria(); $c->add("post_id", $postId); $c->addOrderDescending("revision_id"); $revs = DB_ForumPostRevisionPeer::instance()->select($c); $runData->contextAdd("revisions", $revs); $runData->contextAdd("post", $post); $runData->ajaxResponseAdd("postId", $postId); }
public function getFirstPost() { $c = new Criteria(); $c->add("thread_id", $this->getThreadId()); $c->addOrderAscending("post_id"); $post = DB_ForumPostPeer::instance()->selectOne($c); return $post; }
public function build($runData) { $site = $runData->getTemp("site"); $page = $runData->getTemp("page"); $pl = $runData->getParameterList(); if ($page == null) { $pageId = $pl->getParameterValue("pageId"); if ($pageId !== null && is_numeric($pageId)) { $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId); } else { $pageName = $runData->getTemp("pageUnixName"); $site = $runData->getTemp("site"); $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $pageName); } if ($page == null || $page->getSiteId() !== $site->getSiteId()) { throw new ProcessException(_("Can not find related page."), "no_page"); } } // check for a discussion thread. if not exists - create it! $c = new Criteria(); $c->add("page_id", $page->getPageId()); $c->add("site_id", $site->getSiteId()); $thread = DB_ForumThreadPeer::instance()->selectOne($c); if ($thread == null) { // create thread!!! $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("per_page_discussion", true); $category = DB_ForumCategoryPeer::instance()->selectOne($c); if ($category == null) { // create this category! $category = new DB_ForumCategory(); $category->setName(_("Per page discussions")); $category->setDescription(_("This category groups discussions related to particular pages within this site.")); $category->setPerPageDiscussion(true); $category->setSiteId($site->getSiteId()); // choose group. create one? $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("name", "Hidden"); $group = DB_ForumGroupPeer::instance()->selectOne($c); if ($group == null) { $group = new DB_ForumGroup(); $group->setName(_("Hidden")); $group->setDescription(_("Hidden group used for storing some discussion threads.")); $group->setSiteId($site->getSiteId()); $group->setVisible(false); $group->save(); } $category->setGroupId($group->getGroupId()); $category->save(); } // now create thread... $thread = new DB_ForumThread(); $thread->setCategoryId($category->getCategoryId()); $thread->setSiteId($site->getSiteId()); $thread->setPageId($page->getPageId()); $thread->setUserId(-1); $thread->setDateStarted(new ODate()); $thread->setNumberPosts(0); $thread->save(); $page->setThreadId($thread->getThreadId()); $page->save(); $category->setNumberThreads($category->getNumberThreads() + 1); $category->save(); } else { $category = $thread->getForumCategory(); } $this->threadId = $thread->getThreadId(); $c = new Criteria(); $c->add("thread_id", $thread->getThreadId()); $c->add("site_id", $site->getSiteId()); $c->addJoin("user_id", "ozone_user.user_id"); $c->addOrderAscending("post_id"); $posts = DB_ForumPostPeer::instance()->select($c); // make a mapping first. $map = array(); $levels = array(); foreach ($posts as $post) { $parentId = $post->getParentId(); $postId = $post->getPostId(); if ($parentId === null) { // if no parrent - simply add at the end of $map $map[] = $postId; $levels[$postId] = 0; } else { // find a parent $cpos = array_search($parentId, $map); $clevel = $levels[$parentId]; // find a place for the post, i.e. the place where level_next == level or the end of array $cpos++; while (isset($map[$cpos]) && $levels[$map[$cpos]] > $clevel) { $cpos++; } // insert at this position!!! array_splice($map, $cpos, 0, $postId); $levels[$postId] = $clevel + 1; } } // create container control list $cc = array(); foreach ($map as $pos => $m) { // open if previous post has LOWER level $clevel = $levels[$m]; if (isset($map[$pos + 1])) { $nlevel = $levels[$map[$pos + 1]]; if ($nlevel > $clevel) { $cc[$pos] = 'k'; } if ($nlevel < $clevel) { $cc[$pos] = str_repeat('c', $clevel - $nlevel); } } else { $cc[$pos] = str_repeat('c', $clevel); } } $runData->contextAdd("postmap", $map); $runData->contextAdd("levels", $levels); $runData->contextAdd("containerControl", $cc); $runData->contextAdd("thread", $thread); $runData->contextAdd("category", $category); $runData->contextAdd("posts", $posts); $runData->ajaxResponseAdd("threadId", $thread->getThreadId()); }
public function build($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $categoryId = $pl->getParameterValue("c"); $category = DB_ForumCategoryPeer::instance()->selectByPrimaryKey($categoryId); if ($category == null) { throw new ProcessException("No such category.", "no_category"); } $channel = array(); $channel['title'] = $category->getName() . " (" . _('new posts') . ")"; $channel['link'] = "http://" . $site->getDomain() . "/forum/c-" . $categoryId . "/" . $category->getUnixifiedName(); $channel['description'] = _("Posts in the forum category") . " \"" . $category->getName() . "\""; if ($category->getDescription()) { $channel['description'] .= " - " . $category->getDescription(); } $items = array(); $c = new Criteria(); $c->add("category_id", $categoryId); $c->add("forum_post.site_id", $site->getSiteId()); $c->addJoin("thread_id", "forum_thread.thread_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->addOrderDescending("post_id"); $c->setLimit(20); $posts = DB_ForumPostPeer::instance()->select($c); foreach ($posts as $post) { $item = array(); $thread = $post->getForumThread(); $item['title'] = $thread->getTitle() . ': ' . $post->getTitle(); $item['link'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '#post-' . $post->getPostId(); $item['guid'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '#post-' . $post->getPostId(); $item['date'] = date('r', $post->getDatePosted()->getTimestamp()); // TODO: replace relative links with absolute links! $content = $post->getText(); $content = preg_replace(';(<.*?)(src|href)="/([^"]+)"([^>]*>);si', '\\1\\2="http://' . $site->getDomain() . '/\\3"\\4', $content); $content = preg_replace(';<script\\s+[^>]+>.*?</script>;is', '', $content); $content = preg_replace(';(<[^>]*\\s+)on[a-z]+="[^"]+"([^>]*>);si', '\\1 \\2', $content); $item['content'] = $content; if ($post->getUserId() > 0) { $item['authorUserId'] = $post->getUserId(); $user = $post->getUser(); $item['author'] = $user->getNickName(); } else { $item['author'] = $post->getUserString(); } $items[] = $item; } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function indexThread($thread) { // look for an existing fts_entry $ie = DB_FtsEntryPeer::instance()->selectByThreadId($thread->getThreadId()); if (!$ie) { $ie = new DB_FtsEntry(); $ie->setThreadId($thread->getThreadId()); $ie->setSiteId($thread->getSiteId()); } $ie->setTitle(htmlspecialchars($thread->getTitle())); $ie->setUnixName($thread->getUnixifiedTitle()); // to create thread text select all posts and extract body $c = new Criteria(); $c->add("thread_id", $thread->getThreadId()); $c->addOrderAscending("post_id"); $posts = DB_ForumPostPeer::instance()->select($c); $text = ''; foreach ($posts as $post) { $text .= $post->getTitle() . "\n"; $text .= strip_tags($post->getText()) . "\n\n"; } $ie->setText(htmlspecialchars($thread->getDescription()) . "\n\n" . $text); $title = db_escape_string(htmlspecialchars($thread->getTitle())); $description = db_escape_string(htmlspecialchars($thread->getDescription())); $db = Database::connection(); $v = pg_version($db->getLink()); if (!preg_match(';^8\\.3;', $v['server'])) { $db->query("SELECT set_curcfg('default')"); } $ie->setVector("setweight( to_tsvector('{$title}'), 'C') || setweight( to_tsvector('{$description}'), 'C') || to_tsvector('" . db_escape_string($text) . "')", true); $ie->save(); }
public function build($runData) { $pl = $runData->getParameterList(); $postId = $pl->getParameterValue("postId"); $threadId = $pl->getParameterValue("threadId"); $user = $runData->getUser(); $site = $runData->getTemp("site"); $title = ''; $db = Database::connection(); $db->begin(); $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($threadId); if ($thread == null || $thread->getSiteId() !== $site->getSiteId()) { throw new ProcessException(_("No thread found... Is it deleted?"), "no_thread"); } // check if thread blocked if ($thread->getBlocked()) { // check if moderator or admin if ($runData->getUser()) { $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.")); } } } // now check if user is allowed $category = $thread->getCategory(); WDPermissionManager::instance()->hasForumPermission('new_post', $runData->getUser(), $category); if ($postId !== null && is_numeric($postId)) { $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId); if ($post == null || $post->getThreadId() !== $thread->getThreadId()) { throw new ProcessException(_("Original post does not exist! Please reload the page to make it up-to-date."), "no_post"); } // try to determine true parent id based on the nesting level. // TODO! $maxNest = $thread->getForumCategory()->getEffectiveMaxNestLevel(); // now check the nest level of the post... woooo... $parentId6 = $post->getParentId(); $nestLevel6 = 0; $parents = array(); while ($parentId6 != null) { $parent6 = DB_ForumPostPeer::instance()->selectByPrimaryKey($parentId6); $parents[] = $parent6; $parentId6 = $parent6->getParentId(); $nestLevel6++; } if ($nestLevel6 >= $maxNest) { // change parent id to the maxNest-1 in the chain $parent = $parents[$nestLevel6 - ($maxNest - 1) - 1]; if ($parent) { $parentId = $parent->getPostId(); $parentChanged = true; } } else { $parentId = $post->getPostId(); } $title = preg_replace('/^Re:\\s?/', '', $post->getTitle()); $title = 'Re: ' . $title; } else { // only if NOT a page discussion if ($thread->getPageId() == null) { $title = 'Re: ' . $thread->getTitle(); } } $runData->contextAdd("thread", $thread); if ($parentId) { $runData->ajaxResponseAdd("parentId", $parentId); $runData->contextAdd("parentId", $parentId); if ($parentChanged) { $runData->ajaxResponseAdd("parentChanged", true); } } $runData->contextAdd("title", $title); // keep the session - i.e. put an object into session storage not to delete it!!! $runData->sessionAdd("keep", true); $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); $runData->contextAdd("anonymousString", $userString); } $db->commit(); }
public function build($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $categoryId = $pl->getParameterValue("c"); $channel = array(); $channel['title'] = $site->getName() . " - " . _("new forum posts"); $channel['link'] = "http://" . $site->getDomain() . "/forum/start"; $channel['description'] = _("Posts in forums of the site") . " \"" . $site->getName() . "\""; if ($site->getSubtitle()) { $channel['description'] .= " - " . $site->getSubtitle(); } $items = array(); $c = new Criteria(); $c->add("forum_post.site_id", $site->getSiteId()); $c->add("forum_group.visible", true); $c->addJoin("thread_id", "forum_thread.thread_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->addJoin("forum_thread.category_id", "forum_category.category_id"); $c->addJoin("forum_category.group_id", "forum_group.group_id"); $c->addOrderDescending("post_id"); $c->setLimit(20); $posts = DB_ForumPostPeer::instance()->select($c); foreach ($posts as $post) { $item = array(); $thread = $post->getForumThread(); $item['title'] = $post->getTitle(); $item['link'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '#post-' . $post->getPostId(); $item['guid'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '#post-' . $post->getPostId(); $item['date'] = date('r', $post->getDatePosted()->getTimestamp()); // TODO: replace relative links with absolute links! $content = $post->getText(); $content = preg_replace(';(<.*?)(src|href)="/([^"]+)"([^>]*>);si', '\\1\\2="http://' . $site->getDomain() . '/\\3"\\4', $content); $content = preg_replace(';<script\\s+[^>]+>.*?</script>;is', '', $content); $content = preg_replace(';(<[^>]*\\s+)on[a-z]+="[^"]+"([^>]*>);si', '\\1 \\2', $content); // add extra info. $content .= '<br/>'; $fcategory = $thread->getForumCategory(); $content .= _('Forum category') . ': <a href="http://' . $site->getDomain() . '/forum/c-' . $thread->getCategoryId() . '">' . htmlspecialchars($fcategory->getForumGroup()->getName() . ' / ' . $fcategory->getName()) . '</a><br/>'; $content .= _('Forum thread') . ': <a href="http://' . $site->getDomain() . '/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '">' . htmlspecialchars($thread->getTitle()) . '</a>'; $item['content'] = $content; if ($post->getUserId() > 0) { $item['authorUserId'] = $post->getUserId(); $user = $post->getUser(); $item['author'] = $user->getNickName(); } else { $item['author'] = $post->getUserString(); } $items[] = $item; } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function build($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $threadId = $pl->getParameterValue("t"); if ($threadId == null || !is_numeric($threadId)) { throw new ProcessException(_("Invalid thread."), "invalid_thread"); } $c = new Criteria(); $c->add("thread_id", $threadId); $c->add("site_id", $site->getSiteId()); $thread = DB_ForumThreadPeer::instance()->selectOne($c); if ($thread == null) { throw new ProcessException(_("No thread."), "no_thread"); } $this->threadTitle = $thread->getTitle(); $this->threadId = $thread->getThreadId(); $category = $thread->getForumCategory(); $this->categoryName = $category->getName(); // check if connected to a page $this->tpage = $thread->getPage(); // get posts $c = new Criteria(); $c->add("thread_id", $threadId); $c->add("site_id", $site->getSiteId()); $c->addJoin("user_id", "ozone_user.user_id"); $c->addOrderAscending("post_id"); $posts = DB_ForumPostPeer::instance()->select($c); // make a mapping first. $map = array(); $levels = array(); foreach ($posts as $post) { $parentId = $post->getParentId(); $postId = $post->getPostId(); if ($parentId === null) { // if no parrent - simply add at the end of $map $map[] = $postId; $levels[$postId] = 0; } else { // find a parent $cpos = array_search($parentId, $map); $clevel = $levels[$parentId]; // find a place for the post, i.e. the place where level_next == level or the end of array $cpos++; while (isset($map[$cpos]) && $levels[$map[$cpos]] > $clevel) { $cpos++; } // insert at this position!!! array_splice($map, $cpos, 0, $postId); $levels[$postId] = $clevel + 1; } } // create container control list $cc = array(); foreach ($map as $pos => $m) { // open if previous post has LOWER level $clevel = $levels[$m]; if (isset($map[$pos + 1])) { $nlevel = $levels[$map[$pos + 1]]; if ($nlevel > $clevel) { $cc[$pos] = 'k'; } if ($nlevel < $clevel) { $cc[$pos] = str_repeat('c', $clevel - $nlevel); } } else { $cc[$pos] = str_repeat('c', $clevel); } } $runData->contextAdd("postmap", $map); $runData->contextAdd("levels", $levels); $runData->contextAdd("containerControl", $cc); $runData->contextAdd("thread", $thread); $runData->contextAdd("category", $category); $runData->contextAdd("posts", $posts); $page = $GLOBALS['page']; }
public function build($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $pageId = $pl->getParameterValue("p"); $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId); $threadId = $page->getThreadId(); $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($threadId); if ($thread == null) { throw new ProcessException("No such thread.", "no_thread"); } $this->threadId = $thread->getThreadId(); $channel = array(); $channel['title'] = _('Comments for page') . ' "' . $page->getTitleOrUnixName() . '"'; $channel['link'] = "http://" . $site->getDomain() . "/" . $page->getUnixName() . "/comments/show"; $items = array(); $c = new Criteria(); $c->add("thread_id", $threadId); $c->add("forum_post.site_id", $site->getSiteId()); $c->addJoin("user_id", "ozone_user.user_id"); $c->addOrderDescending("post_id"); $c->setLimit(20); $posts = DB_ForumPostPeer::instance()->select($c); foreach ($posts as $post) { $item = array(); if ($post->getTitle() != '') { $item['title'] = $post->getTitle(); } else { $item['title'] = "(no title)"; } $item['link'] = $channel['link'] . '#post-' . $post->getPostId(); $item['guid'] = $item['link']; $item['date'] = date('r', $post->getDatePosted()->getTimestamp()); // TODO: replace relative links with absolute links! $content = $post->getText(); $content = preg_replace(';(<.*?)(src|href)="/([^"]+)"([^>]*>);si', '\\1\\2="http://' . $site->getDomain() . '/\\3"\\4', $content); $content = preg_replace(';<script\\s+[^>]+>.*?</script>;is', '', $content); $content = preg_replace(';(<[^>]*\\s+)on[a-z]+="[^"]+"([^>]*>);si', '\\1 \\2', $content); $item['content'] = $content; if ($post->getUserId() > 0) { $item['authorUserId'] = $post->getUserId(); $user = $post->getUser(); $item['author'] = $user->getNickName(); } else { $item['author'] = $post->getUserString(); } $items[] = $item; } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function build($runData) { $user = $runData->getTemp("user"); $userId = $user->getUserId(); // set language for the user $lang = $user->getLanguage(); $runData->setLanguage($lang); $GLOBALS['lang'] = $lang; // and for gettext too: switch ($lang) { case 'pl': $glang = "pl_PL"; break; case 'en': $glang = "en_US"; break; } putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); // now just get watched page changes for the user... $c = new Criteria(); $c->addJoin("thread_id", "forum_thread.thread_id"); $c->addJoin("thread_id", "watched_forum_thread.thread_id"); $c->addJoin("user_id", "ozone_user.user_id"); $c->add("watched_forum_thread.user_id", $user->getUserId()); $c->addOrderDescending("post_id"); $c->setLimit(30); $posts = DB_ForumPostPeer::instance()->select($c); $channel['title'] = _('Wikidot.com watched forum discussions for user') . ' "' . $user->getNickName() . '"'; $channel['link'] = "http://" . GlobalProperties::$URL_HOST . "/account:you/start/watched-forum"; $items = array(); foreach ($posts as $post) { $thread = $post->getForumThread(); $site = $post->getSite(); $item = array(); $item['title'] = $post->getTitle() . ' (' . _('on site') . ' "' . htmlspecialchars($site->getName()) . '")'; $item['link'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '#post-' . $post->getPostId(); $item['guid'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '#post-' . $post->getPostId(); $item['date'] = date('r', $post->getDatePosted()->getTimestamp()); $content = $post->getText(); $content = preg_replace(';(<.*?)(src|href)="/([^"]+)"([^>]*>);si', '\\1\\2="http://' . $site->getDomain() . '/\\3"\\4', $content); $content = preg_replace(';<script\\s+[^>]+>.*?</script>;is', '', $content); $content = preg_replace(';(<[^>]*\\s+)on[a-z]+="[^"]+"([^>]*>);si', '\\1 \\2', $content); // add extra info. $content .= '<br/><hr/>'; $content .= _('Site') . ': <a href="http://' . $site->getDomain() . '">' . htmlspecialchars($site->getName()) . '</a><br/>'; $content .= _('Forum category') . ': <a href="http://' . $site->getDomain() . '/forum/c-' . $thread->getCategoryId() . '">' . htmlspecialchars($thread->getForumCategory()->getName()) . '</a><br/>'; $content .= _('Forum thread') . ': <a href="http://' . $site->getDomain() . '/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '">' . htmlspecialchars($thread->getTitle()) . '</a><br/>'; $content .= _('Author of the post') . ': ' . WDRenderUtils::renderUser($post->getUserOrString()) . '<br/>'; $item['content'] = $content; if ($post->getUserId() > 0) { $item['authorUserId'] = $post->getUserId(); $user = $post->getUser(); $item['author'] = $user->getNickName(); } else { $item['author'] = $post->getUserString(); } $items[] = $item; } $runData->contextAdd("channel", $channel); $runData->contextAdd("items", $items); }
public function deletePostEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $postId = $pl->getParameterValue("postId"); if ($postId == null || !is_numeric($postId)) { throw new ProcessException(_("No such post."), "no_post"); } $db = Database::connection(); $db->begin(); $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId); if ($post == null || $post->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("No such post."), "no_post"); } $thread = $post->getForumThread(); $category = $thread->getForumCategory(); try { WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category); } catch (Exception $e) { throw new WDPermissionException(_("Sorry, you are not allowed to delete posts. Only site administrators and moderators are the ones who can.")); } $c = new Criteria(); $c->add("parent_id", $postId); $toDelete = array(); $chposts = DB_ForumPostPeer::instance()->select($c); while ($chposts && count($chposts) > 0) { $toDelete = array_merge($toDelete, $chposts); $c = new Criteria(); foreach ($chposts as $f) { $c->addOr("parent_id", $f->getPostId()); } $chposts = DB_ForumPostPeer::instance()->select($c); } DB_ForumPostPeer::instance()->deleteByPrimaryKey($post->getPostId()); foreach ($toDelete as $f) { DB_ForumPostPeer::instance()->deleteByPrimaryKey($f->getPostId()); } // now recalculate a few things... $thread->calculateNumberPosts(); $thread->findLastPost(); $thread->save(); $category->calculateNumberPosts(); $category->findLastPost(); $category->save(); // outdate $o = new Outdater(); $o->forumEvent("thread_save", $thread); // index thread Indexer::instance()->indexThread($thread); EventLogger::instance()->logPostDelete($thread, $post->getTitle()); $db->commit(); if (GlobalProperties::$UI_SLEEP) { sleep(1); } }