Пример #1
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $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");
     }
     $category = $thread->getForumCategory();
     WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
     $runData->contextAdd("thread", $thread);
     $runData->contextAdd("category", $thread->getForumCategory());
     // and select categories to move into too.
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderDescending("visible");
     $c->addOrderAscending("sort_index");
     $groups = DB_ForumGroupPeer::instance()->select($c);
     $res = array();
     foreach ($groups as $g) {
         $c = new Criteria();
         $c->add("group_id", $g->getGroupId());
         $c->addOrderAscending("sort_index");
         $categories = DB_ForumCategoryPeer::instance()->select($c);
         foreach ($categories as $cat) {
             $res[] = array('group' => $g, 'category' => $cat);
         }
     }
     $runData->contextAdd("categories", $res);
     $db->commit();
 }
Пример #2
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $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
         $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."));
             }
         }
     }
     $category = $thread->getCategory();
     WDPermissionManager::instance()->hasForumPermission('edit_thread', $runData->getUser(), $category, $thread);
     $runData->contextAdd("thread", $thread);
     $db->commit();
 }
Пример #3
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("t");
     $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($threadId);
     if ($thread == null) {
         throw new ProcessException(_("No such thread."), "no_thread");
     }
     $page = $thread->getPage();
     $channel = array();
     if ($page) {
         $channel['title'] = _('Comments for page') . ' "' . $page->getTitleOrUnixName() . '"';
     } else {
         $channel['title'] = $thread->getTitle();
     }
     $channel['link'] = "http://" . $site->getDomain() . "/forum/t-" . $threadId . "/" . $thread->getUnixifiedTitle();
     $channel['description'] = _("Posts in the discussion thread") . " \"" . $thread->getTitle() . "\"";
     if ($thread->getDescription()) {
         $channel['description'] .= " - " . $thread->getDescription();
     }
     $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'] = "http://" . $site->getDomain() . "/forum/t-" . $threadId . '#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);
 }
Пример #4
0
 /**
  * Scans for the last post.
  */
 public function findLastPost()
 {
     $c = new Criteria();
     $c->add("category_id", $this->getCategoryId());
     $c->add("last_post_id", null, "!=");
     $c->addOrderDescending("last_post_id");
     $thread = DB_ForumThreadPeer::instance()->selectOne($c);
     if ($thread) {
         $this->setLastPostId($thread->getLastPostId());
     } else {
         $this->setLastPostId(null);
     }
 }
Пример #5
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $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");
     }
     $category = $thread->getForumCategory();
     WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
     $runData->contextAdd("thread", $thread);
     $db->commit();
 }
Пример #6
0
 public function getForumThread()
 {
     if (is_array($this->prefetched)) {
         if (in_array('forum_thread', $this->prefetched)) {
             if (in_array('forum_thread', $this->prefetchedObjects)) {
                 return $this->prefetchedObjects['forum_thread'];
             } else {
                 $obj = new DB_ForumThread($this->sourceRow, $this->prefetched);
                 $obj->setNew(false);
                 $this->prefetchedObjects['forum_thread'] = $obj;
                 return $obj;
             }
         }
     }
     return DB_ForumThreadPeer::instance()->selectByPrimaryKey($this->getThreadId());
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     // get recent forum threads
     $pl = $runData->getParameterList();
     $limit = $pl->getParameterValue("limit", "MODULE");
     if ($limit == null || !is_numeric($limit) || $limit < 1 || $limit > 300) {
         $limit = 5;
     }
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderDescending("thread_id");
     $c->setLimit($limit);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     $runData->contextAdd("threads", $threads);
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     // get recent forum threads
     $pl = $runData->getParameterList();
     $limit = $pl->getParameterValue("limit", "MODULE");
     if ($limit == null || !is_numeric($limit) || $limit < 1 || $limit > 300) {
         $limit = 5;
     }
     $date = new ODate();
     $date->addSeconds(-60 * 60 * 24 * 7);
     // 7 days
     $q = "SELECT forum_thread.thread_id, count(*) AS count FROM forum_thread, forum_post " . "WHERE forum_thread.site_id='" . $site->getSiteId() . "' " . "AND forum_thread.thread_id = forum_post.thread_id " . "AND forum_post.date_posted > '" . $date->getDate() . "' " . "GROUP BY forum_thread.thread_id ORDER BY count DESC LIMIT " . db_escape_string($limit);
     $c = new Criteria();
     $c->setExplicitQuery($q);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     foreach ($threads as &$thread) {
         $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($thread->getThreadId());
     }
     $runData->contextAdd("threads", $threads);
 }
Пример #9
0
 public function build($runData)
 {
     $user = $runData->getUser();
     $runData->contextAdd("user", $user);
     $pl = $runData->getParameterList();
     // get watched threads for this user
     $c = new Criteria();
     /*$c->add("watched_forum_thread.user_id", $user->getUserId());
     		$c->addJoin("thread_id", "forum_thread.thread_id");
     		$c->addOrderAscending("watched_id");
     		*/
     /*
     $c->setExplicitFrom("forum_thread, watched_forum_thread");
     $c->add("watched_forum_thread.user_id", $user->getUserId());
     $c->
     */
     $q = "SELECT forum_thread.* FROM watched_forum_thread, forum_thread " . "WHERE watched_forum_thread.user_id='" . $user->getUserId() . "' " . "AND watched_forum_thread.thread_id=forum_thread.thread_id";
     $c->setExplicitQuery($q);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     $runData->contextAdd("threads", $threads);
     $runData->contextAdd("threadsCount", count($threads));
 }
Пример #10
0
 public function render($runData)
 {
     // get site
     $site = $runData->getTemp("site");
     $runData->contextAdd("site", $site);
     $this->handleNotifications($runData);
     $pl = $runData->getParameterList();
     $wikiPage = $pl->getParameterValue("wiki_page");
     $privateAccessGranted = true;
     // check if the site is private
     if ($site->getPrivate()) {
         $user = $runData->getUser();
         if ($user && !$user->getSuperAdmin() && !$user->getSuperModerator()) {
             // check if member
             $c = new Criteria();
             $c->add("site_id", $site->getSiteId());
             $c->add("user_id", $user->getUserId());
             $mem = DB_MemberPeer::instance()->selectOne($c);
             if (!$mem) {
                 // check if a viewer
                 $c = new Criteria();
                 $c->add("site_id", $site->getSiteId());
                 $c->add("user_id", $user->getUserId());
                 $vi = DB_SiteViewerPeer::instance()->selectOne($c);
                 if (!$vi) {
                     $user = null;
                 }
             }
         }
         if ($user == null) {
             $wikiPage = $site->getSettings()->getPrivateLandingPage();
             $privateAccessGranted = false;
         }
     }
     if ($wikiPage == "") {
         $wikiPage = $site->getDefaultPage();
     }
     $wikiPage = WDStringUtils::toUnixName($wikiPage);
     $runData->setTemp("pageUnixName", $wikiPage);
     $memcache = Ozone::$memcache;
     if ($runData->getAction() == null && $runData->getRequestMethod() == "GET" && $privateAccessGranted) {
         // try to get content from the memorycache server
         $mcKey = 'page..' . $site->getUnixName() . '..' . $wikiPage;
         if (strpos($wikiPage, ":") != false) {
             $tmp0 = explode(':', $wikiPage);
             $categoryName = $tmp0[0];
         } else {
             $categoryName = "_default";
         }
         $aKey = 'category_lc..' . $site->getUnixName() . '..' . $categoryName;
         $changeTime = $memcache->get($aKey);
         $cachedPage = $memcache->get($mcKey);
         if ($cachedPage !== false && $changeTime && $changeTime <= $cachedPage['timestamp']) {
             $runData->setTemp("page", $cachedPage['page']);
             $GLOBALS['page'] = $cachedPage['page'];
             $out = $cachedPage['content'];
             if ($this->vars['notificationsDialog']) {
                 $out = preg_replace(';<div id="account-notifications-dummy" style="display:none"></div>;', '<div id="notifications-dialog" style="display:none">' . $this->vars['notificationsDialog'] . '</div>', $out, 1);
             }
             return $out;
         } else {
             $storeLater = true;
         }
     }
     $runData->contextAdd("wikiPageName", $wikiPage);
     $settings = $site->getSettings();
     // get wiki page from the database
     $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $wikiPage);
     if ($page == null) {
         $runData->contextAdd("pageNotExists", true);
         // get category based on suggested page name
         if (strpos($wikiPage, ":") != false) {
             $tmp0 = explode(':', $wikiPage);
             $categoryName = $tmp0[0];
         } else {
             $categoryName = "_default";
         }
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
         if ($category == null) {
             $category = DB_CategoryPeer::instance()->selectByName('_default', $site->getSiteId());
         }
         $runData->setTemp("category", $category);
     } else {
         // page exists!!! wooo!!!
         $runData->setTemp("page", $page);
         $GLOBALS['page'] = $page;
         $compiled = $page->getCompiled();
         $runData->contextAdd("wikiPage", $page);
         $runData->contextAdd("pageContent", $compiled->getText());
         $category = $page->getCategory();
         $runData->setTemp("category", $category);
         // show options?
         $showPageOptions = true;
         $runData->contextAdd("showPageoptions", $showPageOptions);
         // get the tags
         $c = new Criteria();
         $c->add("page_id", $page->getPageId());
         $c->addOrderAscending("tag");
         $tags = DB_PageTagPeer::instance()->select($c);
         $t2 = array();
         foreach ($tags as $t) {
             $t2[] = $t->getTag();
         }
         $runData->contextAdd("tags", $t2);
         // has discussion?
         if ($page->getThreadId() !== null) {
             $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($page->getThreadId());
             if ($thread == null) {
                 $page->setThreadId(null);
                 $page->save();
             } else {
                 $page->setTemp("numberPosts", $thread->getNumberPosts());
             }
         }
         // look for parent pages (and prepare breadcrumbs)
         if ($page->getParentPageId()) {
             $breadcrumbs = array();
             $ppage = DB_PagePeer::instance()->selectByPrimaryKey($page->getParentPageId());
             array_unshift($breadcrumbs, $ppage);
             $bcount = 0;
             while ($ppage->getParentPageId() && $bcount <= 4) {
                 $ppage = DB_PagePeer::instance()->selectByPrimaryKey($ppage->getParentPageId());
                 array_unshift($breadcrumbs, $ppage);
                 $bcount++;
             }
             $runData->contextAdd("breadcrumbs", $breadcrumbs);
         }
     }
     $runData->contextAdd("category", $category);
     // GET THEME for the category
     $theme = $category->getTheme();
     $runData->contextAdd("theme", $theme);
     // GET LICENSE for the category
     $licenseText = $category->getLicenseText();
     $runData->contextAdd("licenseText", $licenseText);
     // show nav elements?
     if ($privateAccessGranted || !$settings->getHideNavigationUnauthorized()) {
         if ($theme->getUseSideBar()) {
             $sideBar1 = $category->getSidePage();
             if ($sideBar1 !== null) {
                 $sideBar1Compiled = $sideBar1->getCompiled();
                 $ccc = $sideBar1Compiled->getText();
                 $ccc = preg_replace('/id="[^"]*"/', '', $ccc);
                 $runData->contextAdd("sideBar1Content", $ccc);
             }
         }
         if ($theme->getUseTopBar()) {
             $topBar = $category->getTopPage();
             if ($topBar !== null) {
                 $topBarCompiled = $topBar->getCompiled();
                 $ccc = $topBarCompiled->getText();
                 $ccc = preg_replace('/id="[^"]*"/', '', $ccc);
                 $runData->contextAdd("topBarContent", $ccc);
             }
         }
     }
     // OpenID stuff now !!!
     if ($settings->getOpenidEnabled() && $page) {
         // find a page
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         if ($_SERVER['REQUEST_URI'] == "/") {
             $c->add("page_id", null);
         } else {
             $c->add("page_id", $page->getPageId());
         }
         $oentry = DB_OpenidEntryPeer::instance()->selectOne($c);
         if ($oentry) {
             $openId = array();
             $openId['enabled'] = true;
             $openId['identity'] = $oentry->getUrl();
             $openId['server'] = $oentry->getServerUrl();
             $runData->contextAdd("openId", $openId);
         }
     }
     // check wether to include a special JS file for custom domains or a special JS file for private files
     //if (preg_match('/^([a-zA-Z0-9\-]+)\.' . GlobalProperties::$URL_DOMAIN_PREG . '$/',$_SERVER["HTTP_HOST"], $matches) !==1) {
     //	$runData->contextAdd("useCustomDomainScript", true);
     //}
     $smarty = Ozone::getSmarty();
     // put context into context
     $context = $runData->getContext();
     if ($context !== null) {
         foreach ($context as $key => $value) {
             $smarty->assign($key, $value);
         }
     }
     $templateFile = PathManager::screenTemplate("wiki/WikiScreen");
     $screenContent = $smarty->fetch($templateFile);
     $smarty->assign("screen_placeholder", $screenContent);
     $layoutFile = PathManager::layoutTemplate("WikiLayout");
     $out = $smarty->fetch($layoutFile);
     if ($storeLater) {
         $now = time();
         if (!$changeTime) {
             $memcache->set($aKey, $now, 0, 864000);
         }
         $memcache->set($mcKey, array("page" => $page, "content" => $out, "timestamp" => $now), 0, 864000);
     }
     if ($this->vars['notificationsDialog']) {
         $out = preg_replace(';<div id="account-notifications-dummy" style="display:none"></div>;', '<div id="notifications-dialog" style="display:none">' . $this->vars['notificationsDialog'] . '</div>', $out, 1);
     }
     return $out;
 }
Пример #11
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $categoryIds = $pl->getParameterValue("category");
     $limit = $pl->getParameterValue("limit");
     $offset = $pl->getParameterValue("offset");
     if ($limit == null) {
         $limit = 20;
     }
     if ($categoryIds === null) {
         throw new ProcessException(_('No forum category has been specified. Please use attribute category="id" where id is the index number of the category.'), "no_category");
     }
     if (strlen($categoryIds) > 90) {
         throw new ProcessException(_("Category string too long."), "max_categories");
     }
     $cats = preg_split('/[,;] ?/', $categoryIds);
     $ccat = new Criteria();
     $categories = array();
     if (count($cats) > 20) {
         throw new ProcessException(_("Maximum number of categories exceeded."), "max_categories");
     }
     foreach ($cats as $categoryId) {
         if ($categoryId === null || !is_numeric($categoryId)) {
             throw new ProcessException(_('Problem parsing attribute "category".'), "no_category");
         }
         $category = DB_ForumCategoryPeer::instance()->selectByPrimaryKey($categoryId);
         if ($category == null) {
             throw new ProcessException(_('Requested forum category does not exist.'), "no_category");
         }
         if ($category->getSiteId() !== $site->getSiteId()) {
             $fSite = DB_SitePeer::instance()->selectByPrimaryKey($category->getSiteId());
             if ($fSite->getPrivate()) {
                 throw new ProcessException(_('The requested category belongs to a private site.'), "no_category");
             }
         }
         $category->setTemp("group", $category->getForumGroup());
         $categories[$category->getCategoryId()] = $category;
         $ccat->addOr("category_id", $category->getCategoryId());
     }
     $c = new Criteria();
     $c->addCriteriaAnd($ccat);
     $c->addOrderDescending("thread_id");
     $c->setLimit($limit, $offset);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     $format = $pl->getParameterValue("module_body");
     if ($format == null || $format == '') {
         $format = "" . "+ %%linked_title%%\n\n" . _("by") . " %%author%% %%date|%O ago (%e %b %Y, %H:%M %Z)%%\n\n" . "%%content%%\n\n%%comments%% | " . _("category") . ": %%category%%";
     }
     // process the format and create the message template
     $wt = new WikiTransformation();
     $wt->setMode("feed");
     $template = $wt->processSource($format);
     $template = preg_replace('/<p\\s*>\\s*(%%((?:short)|(?:description)|(?:summary)|(?:content)|(?:long)|(?:body)|(?:text))%%)\\s*<\\/\\s*p>/smi', "<div>\\1</div>", $template);
     $items = array();
     foreach ($threads as $thread) {
         $post = $thread->getFirstPost();
         if (!$post) {
             continue;
         }
         $b = $template;
         $b = str_ireplace("%%title%%", htmlspecialchars($thread->getTitle()), $b);
         $b = preg_replace("/%%((linked_title)|(title_linked))%%/i", preg_quote_replacement('<a href="/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '">' . htmlspecialchars($thread->getTitle()) . '</a>'), $b);
         $b = str_ireplace("%%author%%", WDRenderUtils::renderUser($thread->getUserOrString(), array("image" => true)), $b);
         $dateString = '<span class="odate">' . $thread->getDateStarted()->getTimestamp() . '|%e %b %Y, %H:%M %Z|agohover</span>';
         $b = str_ireplace('%%date%%', $dateString, $b);
         $b = preg_replace('/%%date\\|(.*?)%%/i', '<span class="odate">' . preg_quote_replacement($thread->getDateStarted()->getTimestamp()) . '|\\1</span>', $b);
         $b = str_ireplace("%%comments%%", '<a href="/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle() . '">' . _('Comments') . ': ' . ($thread->getNumberPosts() - 1) . '</a>', $b);
         $b = str_ireplace("%%link%%", '/forum/t-' . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle(), $b);
         $category = $categories[$thread->getCategoryId()];
         $b = str_ireplace("%%category%%", '<a href="/forum/c-' . $category->getCategoryId() . '/' . $category->getUnixifiedName() . '">' . htmlspecialchars($category->getTemp("group")->getName() . " / " . $category->getName()) . '</a>', $b);
         $b = preg_replace("/%%((description)|(short)|(summary))%%/i", preg_quote_replacement(htmlspecialchars($thread->getDescription())), $b);
         $b = preg_replace("/%%((body)|(text)|(long)|(content))%%/i", preg_quote_replacement($post->getText()), $b);
         $items[] = $b;
     }
     $runData->contextAdd("items", $items);
     // post a feed???
     $flabel = WDStringUtils::toUnixName($pl->getParameterValue("feed"));
     $page = $runData->getTemp("page");
     if ($flabel && $page) {
         $ftitle = trim($pl->getParameterValue("feedTitle"));
         if ($ftitle == '') {
             $ftitle = $site->getName() . " feed";
         }
         $fdescription = $pl->getParameterValue("feedDescription");
         $fcats = trim($categoryIds);
         $parmhash = crc32($ftitle . " " . $fcats);
         // first check the memcache!!! to avoid db connection.
         // get the feed object
         $c = new Criteria();
         $c->add("page_id", $page->getPageId());
         $c->add("label", $flabel);
         $feed = DB_FrontForumFeedPeer::instance()->selectOne($c);
         if ($feed == null) {
             // create the feed
             $feed = new DB_FrontForumFeed();
             $feed->setLabel($flabel);
             $feed->setTitle($ftitle);
             $feed->setCategories($fcats);
             $feed->setPageId($page->getPageId());
             $feed->setDescription($fdescription);
             $feed->setSiteId($site->getSiteId());
             $feed->save();
         } else {
             // 	check hash
             if ($feed->getParmhash() != $parmhash) {
                 $feed->setTitle($ftitle);
                 $feed->setCategories($fcats);
                 $feed->setDescription($fdescription);
                 $feed->save();
             }
         }
         // and the feed url is:
         $feedUrl = "/feed/front/" . $page->getUnixName() . "/" . $flabel . ".xml";
         $this->vars['feedUrl'] = $feedUrl;
         $this->vars['feedTitle'] = $ftitle;
         $this->vars['feedLabel'] = $flabel;
         // put a link into text
         $runData->contextAdd("feedUri", $feedUrl);
     }
 }
Пример #12
0
 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 threads)";
     $channel['link'] = "http://" . $site->getDomain() . "/forum/c-" . $categoryId . "/" . $category->getUnixifiedName();
     $channel['description'] = _("Threads in the forum category") . " \"" . $category->getName() . "\"";
     if ($category->getDescription()) {
         $channel['description'] .= " - " . $category->getDescription();
     }
     $items = array();
     $c = new Criteria();
     $c->add("category_id", $categoryId);
     $c->addJoin("user_id", "ozone_user.user_id");
     $c->addOrderDescending("thread_id");
     $c->setLimit(20);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     foreach ($threads as $thread) {
         $item = array();
         $item['title'] = $thread->getTitle();
         $item['link'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle();
         $item['guid'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId();
         $item['date'] = date('r', $thread->getDateStarted()->getTimestamp());
         //replace relative links with absolute links!
         $post = $thread->getFirstPost();
         $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);
         if ($thread->getDescription()) {
             $item['description'] = $thread->getDescription();
         }
         $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);
 }
Пример #13
0
 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();
 }
Пример #14
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $categoryId = $pl->getParameterValue("c");
     $channel = array();
     $channel['title'] = $site->getName() . " - " . _("new forum threads");
     $channel['link'] = "http://" . $site->getDomain() . "/forum/start";
     $channel['description'] = _("Threads in forums of the site") . " \"" . $site->getName() . "\"";
     if ($site->getSubtitle()) {
         $channel['description'] .= " - " . $site->getSubtitle();
     }
     $items = array();
     $c = new Criteria();
     $c->add("forum_thread.site_id", $site->getSiteId());
     $c->add("forum_group.visible", true);
     $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("thread_id");
     $c->setLimit(20);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     foreach ($threads as $thread) {
         $item = array();
         $item['title'] = $thread->getTitle();
         $item['link'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle();
         $item['guid'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId();
         $item['date'] = date('r', $thread->getDateStarted()->getTimestamp());
         //replace relative links with absolute links!
         $post = $thread->getFirstPost();
         if (!$post) {
             continue;
         }
         $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);
         if ($thread->getDescription()) {
             $item['description'] = $thread->getDescription();
         }
         $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);
 }
Пример #15
0
 public function moveThreadEvent($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $categoryId = $pl->getParameterValue("categoryId");
     $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");
     }
     if ($thread->getCategoryId() == $categoryId) {
         throw new ProcessException(_("Destination category is the same as current. Not moved."), "same_category");
     }
     $oldCategory = $thread->getForumCategory();
     // get destination category
     $category = DB_ForumCategoryPeer::instance()->selectByPrimaryKey($categoryId);
     if ($category == null || $category->getSiteId() !== $site->getSiteId()) {
         throw new ProcessException(_("No destination category found... Is it deleted?"), "no_thread");
     }
     WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
     $thread->setCategoryId($categoryId);
     $thread->save();
     $oldCategory->calculateNumberThreads();
     $oldCategory->calculateNumberPosts();
     $oldCategory->findLastPost();
     $oldCategory->save();
     $category->calculateNumberThreads();
     $category->calculateNumberPosts();
     $category->findLastPost();
     $category->save();
     $o = new Outdater();
     $o->forumEvent("outdate_forum");
     // index thread
     Indexer::instance()->indexThread($thread);
     EventLogger::instance()->logThreadMoved($thread, $category);
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Пример #16
0
 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'];
 }
Пример #17
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $pageName = $pl->getParameterValue("page");
     $label = $pl->getParameterValue("label");
     // get the feed object
     $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $pageName);
     if (!$page) {
         throw new ProcessException(_("No such page."), "no_page");
     }
     $c = new Criteria();
     $c->add("page_id", $page->getPageId());
     $c->add("label", $label);
     $feed = DB_FrontForumFeedPeer::instance()->selectOne($c);
     $categoryIds = $feed->getCategories();
     $cats = preg_split('/[,;] ?/', $categoryIds);
     $ccat = new Criteria();
     $categories = array();
     if (count($cats) > 20) {
         throw new ProcessException(_("Maximum number of categories exceeded."), "max_categories");
     }
     // get page
     $page = DB_PagePeer::instance()->selectByPrimaryKey($feed->getPageId());
     if (!$page) {
         throw new ProcessException(_("Page can not be found."), "no_page");
     }
     foreach ($cats as $categoryId) {
         if ($categoryId === null || !is_numeric($categoryId)) {
             throw new ProcessException(_('Problem parsing attribute "category".'), "no_category");
         }
         $category = DB_ForumCategoryPeer::instance()->selectByPrimaryKey($categoryId);
         if ($category == null || $category->getSiteId() !== $site->getSiteId()) {
             throw new ProcessException(_("Requested forum category does not exist."), "no_category");
         }
         $categories[$category->getCategoryId()] = $category;
         $ccat->addOr("category_id", $category->getCategoryId());
     }
     $c = new Criteria();
     $c->addCriteriaAnd($ccat);
     $c->addOrderDescending("thread_id");
     $c->setLimit(30);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     $channel['title'] = $feed->getTitle();
     $channel['link'] = "http://" . $site->getDomain() . "/" . $page->getUnixName();
     if ($feed->getDescription()) {
         $channel['description'] = $feed->getDescription();
     }
     $items = array();
     foreach ($threads as $thread) {
         $item = array();
         $item['title'] = $thread->getTitle();
         $item['link'] = "http://" . $site->getDomain() . "/forum/t-" . $thread->getThreadId() . '/' . $thread->getUnixifiedTitle();
         $item['guid'] = $item['link'];
         $item['date'] = date('r', $thread->getDateStarted()->getTimestamp());
         $item['category'] = $thread->getCategory()->getName();
         //replace relative links with absolute links!
         $post = $thread->getFirstPost();
         if (!$post) {
             continue;
         }
         $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);
         if ($thread->getDescription()) {
             $item['description'] = $thread->getDescription();
         }
         $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);
 }
Пример #18
0
 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 = 10;
     }
     $order = $pl->getParameterValue("order");
     $minRating = $pl->getParameterValue("minRating");
     if ($minRating !== null && !is_numeric($minRating)) {
         $minRating = null;
     }
     $maxRating = $pl->getParameterValue("maxRating");
     if ($maxRating !== null && !is_numeric($maxRating)) {
         $maxRating = null;
     }
     $showComments = $pl->getParameterValue("comments", "MODULE");
     $categoryName = $pl->getParameterValue("category", "MODULE", "AMODULE");
     if ($categoryName !== null) {
         $category = DB_CategoryPeer::instance()->selectByName($categoryName, $site->getSiteId());
         if ($category == null) {
             throw new ProcessException(_("The category can not be found."));
         }
     }
     $c = new Criteria();
     if ($category) {
         $c->add("category_id", $category->getCategoryId());
     }
     $c->add("site_id", $site->getSiteId());
     if ($minRating !== null) {
         $c->add("rate", $minRating, '>=');
     }
     if ($maxRating !== null) {
         $c->add("rate", $maxRating, '<=');
     }
     switch ($order) {
         case 'date-created-asc':
             $c->addOrderAscending("date_created");
             break;
         case 'date-created-desc':
             $c->addOrderDescending("date_created");
             break;
         case 'rate-asc':
             $c->addOrderAscending("rate");
             break;
         case 'rating-asc':
             $c->addOrderAscending("rate");
             break;
         default:
             $c->addOrderDescending("rate");
             break;
     }
     $c->addOrderAscending("COALESCE(title, unix_name)");
     if ($limit) {
         $c->setLimit($limit);
     }
     $pages = DB_PagePeer::instance()->select($c);
     if ($showComments) {
         foreach ($pages as &$page) {
             if ($page->getThreadId()) {
                 $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($page->getThreadId());
                 $noc = $thread->getNumberPosts();
             } else {
                 $noc = 0;
             }
             $page->setTemp("numberComments", $noc);
         }
     }
     $runData->contextAdd("pages", $pages);
 }
Пример #19
0
 private function _handleComementsCount($m)
 {
     $page = $this->_tmpPage;
     $threadId = $page->getThreadId();
     if ($threadId) {
         $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($threadId);
     }
     if ($thread) {
         return $thread->getNumberPosts();
     }
     return 0;
 }
Пример #20
0
 public function saveForumLayoutEvent($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $cats0 = $json->decode($pl->getParameterValue("categories"));
     $groups0 = $json->decode($pl->getParameterValue("groups"));
     $db = Database::connection();
     $db->begin();
     // compare against stored groups and categories. add if necessary, delete if necessary etc.
     for ($i = 0; $i < count($groups0); $i++) {
         $group = $groups0[$i];
         $g = null;
         if ($group['group_id'] == null) {
             // new group, add to database!
             $g = new DB_ForumGroup();
             $g->setName(trim($group['name']));
             $g->setDescription(trim($group['description']));
             $g->setVisible($group['visible']);
             $g->setSiteId($site->getSiteId());
             $g->setSortIndex($i);
             $g->save();
         } else {
             $c = new Criteria();
             $c->add("site_id", $site->getSiteId());
             $c->add("group_id", $group['group_id']);
             $g = DB_ForumGroupPeer::instance()->selectOne($c);
             if ($g == null) {
                 throw new ProcessException(_("Error fatching one of the forum groups."));
             }
             // update values
             $changed = false;
             if ($g->getName() !== trim($group['name'])) {
                 $g->setName(trim($group['name']));
                 $changed = true;
             }
             if ($g->getDescription() !== trim($group['description'])) {
                 $g->setDescription(trim($group['description']));
                 $changed = true;
             }
             if ($g->getVisible() !== $group['visible']) {
                 $g->setVisible($group['visible']);
                 $changed = true;
             }
             if ($g->getSortIndex() !== $i) {
                 $g->setSortIndex($i);
                 $changed = true;
             }
             if ($changed) {
                 $g->save();
             }
         }
         // now proceed with categories for this group!!!
         $cates = $cats0[$i];
         for ($j = 0; $j < count($cates); $j++) {
             $cat = $cates[$j];
             if ($cat['category_id'] == null) {
                 // new category!
                 $ca = new DB_ForumCategory();
                 $ca->setName(trim($cat['name']));
                 $ca->setDescription(trim($cat['description']));
                 $ca->setMaxNestLevel($cat['max_nest_level']);
                 $ca->setSiteId($site->getSiteId());
                 $ca->setGroupId($g->getGroupId());
                 $ca->setSortIndex($j);
                 $ca->save();
             } else {
                 $c = new Criteria();
                 $c->add("site_id", $site->getSiteId());
                 $c->add("category_id", $cat['category_id']);
                 $ca = DB_ForumCategoryPeer::instance()->selectOne($c);
                 if ($ca == null) {
                     throw new ProcessException(_("Error fatching one of the forum categories."));
                 }
                 $changed = false;
                 if ($ca->getName() !== trim($cat['name'])) {
                     $ca->setName(trim($cat['name']));
                     $changed = true;
                 }
                 if ($ca->getDescription() !== trim($cat['description'])) {
                     $ca->setDescription(trim($cat['description']));
                     $changed = true;
                 }
                 if ($ca->getMaxNestLevel() !== $cat['max_nest_level']) {
                     $ca->setMaxNestLevel($cat['max_nest_level']);
                     $changed = true;
                 }
                 if ($ca->getSortIndex() !== $j) {
                     $ca->setSortIndex($j);
                     $changed = true;
                 }
                 if ($ca->getGroupId() != $g->getGroupId()) {
                     $ca->setGroupId($g->getGroupId());
                     $changed = true;
                 }
                 if ($changed) {
                     $ca->save();
                 }
             }
         }
     }
     // and deleted categories
     $dcats = $json->decode($pl->getParameterValue("deleted_categories"));
     foreach ($dcats as $dcat) {
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("category_id", $dcat);
         // check if empty
         $cacount = DB_ForumThreadPeer::instance()->selectCount($c);
         if ($cacount > 0) {
             throw new ProcessException(_("One of the categories marked for deletation was not empty."));
         }
         DB_ForumCategoryPeer::instance()->delete($c);
     }
     // now process deleted groups...
     $dgroups = $json->decode($pl->getParameterValue("deleted_groups"));
     for ($i = 0; $i < count($dgroups); $i++) {
         $group = $dgroups[$i];
         // check if has group_id - if not, this should not be in the database...
         if ($group['group_id'] !== null) {
             $c = new Criteria();
             $c->add("site_id", $site->getSiteId());
             $c->add("group_id", $group['group_id']);
             $cacount = DB_ForumCategoryPeer::instance()->selectCount($c);
             if ($cacount > 0) {
                 throw new ProcessException(_("One of the groups marked for deletation was not empty."));
             }
             DB_ForumGroupPeer::instance()->delete($c);
         }
     }
     // and deleted categories
     $dcats = $json->decode($pl->getParameterValue("deleted_categories"));
     foreach ($dcats as $dcat) {
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("category_id", $dcat);
         // check if empty
         $cacount = DB_ForumThreadPeer::instance()->selectCount($c);
         if ($cacount > 0) {
             throw new ProcessException(_("One of the categories marked for deletation was not empty."));
         }
         DB_ForumCategoryPeer::instance()->delete($c);
     }
     $outdater = new Outdater();
     $outdater->forumEvent("outdate_forum");
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Пример #21
0
 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());
 }
Пример #22
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $pl = $runData->getParameterList();
     $categoryId = $pl->getParameterValue("c");
     $pageNumber = $pl->getParameterValue("p");
     if ($pageNumber == null || !is_numeric($pageNumber) || $pageNumber < 1) {
         $pageNumber = 1;
     }
     if ($categoryId === null || !is_numeric($categoryId)) {
         throw new ProcessException(_("No forum category has been specified."), "no_category");
     }
     $sort = $pl->getParameterValue("sort");
     $c = new Criteria();
     $c->add("category_id", $categoryId);
     $c->add("site_id", $site->getSiteId());
     $category = DB_ForumCategoryPeer::instance()->selectOne($c);
     if ($category == null || $category->getSiteId() !== $site->getSiteId()) {
         throw new ProcessException(_("Requested forum category does not exist."), "no_category");
     }
     $this->categoryName = $category->getName();
     $this->categoryId = $category->getCategoryId();
     // select threads...
     $perPage = 20;
     $offset = ($pageNumber - 1) * $perPage;
     $pagerData = array();
     $pagerData['current_page'] = $pageNumber;
     $pagerData['total_pages'] = ceil($category->getNumberThreads() / $perPage);
     $c = new Criteria();
     $c->add("category_id", $categoryId);
     $c->add("site_id", $site->getSiteId());
     $c->addOrderDescending("sticky");
     if ($sort == "start") {
         $c->addOrderDescending("thread_id");
     } else {
         //$c->addOrderDescending("last_post_id", "NULLS LAST"); // sorry, requires postgresql 8.3?
         $c->addOrderDescending('COALESCE(last_post_id, 0)');
         $c->addOrderDescending("thread_id");
     }
     $c->setLimit($perPage, $offset);
     $threads = DB_ForumThreadPeer::instance()->select($c);
     $runData->contextAdd("pagerData", $pagerData);
     $runData->contextAdd("category", $category);
     $runData->contextAdd("threads", $threads);
     $runData->contextAdd("threadsCount", count($threads));
     $runData->contextAdd("sortStart", $sort == "start");
 }