public function build($runData) { $site = $runData->getTemp("site"); $fsettings = $site->getForumSettings(); if (!$fsettings) { throw new ProcessException(_("Forum not activated (yet).")); } $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->addOrderAscending("sort_index"); $groups = DB_ForumGroupPeer::instance()->select($c); $catout = array(); $catout2 = array(); foreach ($groups as $group) { $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->addOrderAscending("sort_index"); $c->add("group_id", $group->getGroupId()); $categories = DB_ForumCategoryPeer::instance()->select($c); $catout[$group->getGroupId()] = $categories; foreach ($categories as $cat) { $catout2[] = $cat->getFieldValuesArray(); } } $defaultPermissions = $fsettings->getPermissions(); $runData->contextAdd("groups", $groups); $runData->contextAdd("categories", $catout); $runData->ajaxResponseAdd("categories", $catout2); $runData->contextAdd("defaultPermissions", $defaultPermissions); }
public function build($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); // get groups and categories $c = new Criteria(); $c->add("site_id", $site->getSiteId()); if (!$pl->getParameterValue("hidden")) { $c->add("visible", true); $runData->contextAdd("hidden", true); } $c->addOrderAscending("sort_index"); $groups = DB_ForumGroupPeer::instance()->select($c); $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->addOrderAscending("sort_index"); $categories = DB_ForumCategoryPeer::instance()->select($c); // now mangle the categories and put into array // - in order to avoid several queries $cats = array(); foreach ($categories as $category) { $cats[$category->getGroupId()][] = $category; } $runData->contextAdd("groups", $groups); $runData->contextAdd("catarray", $cats); }
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(); }
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 build($runData) { $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $categoryId = $pl->getParameterValue("c"); if ($categoryId == null || !is_numeric($categoryId)) { throw new ProcessException(_("No forum category has been specified.")); } // check for suggested title $sTitle = $pl->getParameterValue("title"); $c = new Criteria(); $c->add("category_id", $categoryId); $c->add("site_id", $site->getSiteId()); $category = DB_ForumCategoryPeer::instance()->selectOne($c); if ($category == null) { throw new ProcessException(_("No forum category has been specified.")); } WDPermissionManager::instance()->hasForumPermission('new_thread', $runData->getUser(), $category); // keep the session - i.e. put an object into session storage not to delete it!!! $runData->sessionAdd("keep", true); $this->category = $category; $runData->contextAdd("category", $category); $userId = $runData->getUserId(); if ($userId == null) { $userString = $runData->createIpString(); $runData->contextAdd("anonymousString", $userString); } if ($sTitle) { $runData->contextAdd("title", $sTitle); } }
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); }
public function build($runData) { // get all groups and categories, prepare them in a suitable form $site = $runData->getTemp("site"); $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->addOrderAscending("sort_index"); $groups = DB_ForumGroupPeer::instance()->select($c); $g0 = array(); $c0 = array(); $gcount = 0; foreach ($groups as $group) { $grow = array(); $grow['name'] = $group->getName(); $grow['description'] = $group->getDescription(); $grow['group_id'] = $group->getGroupId(); $grow['visible'] = $group->getVisible(); $g0[$gcount] = $grow; // now get categories... $c0[$gcount] = array(); $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->addOrderAscending("sort_index"); $c->add("group_id", $group->getGroupId()); $categories = DB_ForumCategoryPeer::instance()->select($c); $ccount = 0; foreach ($categories as $cat) { $crow = array(); $crow['name'] = $cat->getName(); $crow['description'] = $cat->getDescription(); $crow['category_id'] = $cat->getCategoryId(); $crow['posts'] = $cat->getNumberPosts(); $crow['number_threads'] = $cat->getNumberThreads(); $crow['permissions'] = $cat->getPermissions(); $crow['max_nest_level'] = $cat->getMaxNestLevel(); $c0[$gcount][$ccount] = $crow; $ccount++; } $gcount++; } $runData->ajaxResponseAdd("groups", $g0); $runData->ajaxResponseAdd("categories", $c0); //get default nesting $fs = $site->getForumSettings(); $runData->ajaxResponseAdd("defaultNesting", $fs->getMaxNestLevel()); }
public function build($runData) { $site = $runData->getTemp("site"); // get forum groups $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("visible", true); $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("cats", $res); }
public function getForumCategory() { if (is_array($this->prefetched)) { if (in_array('forum_category', $this->prefetched)) { if (in_array('forum_thread', $this->prefetchedObjects)) { return $this->prefetchedObjects['forum_category']; } else { $obj = new DB_ForumCategory($this->sourceRow); $obj->setNew(false); $this->prefetchedObjects['forum_category'] = $obj; return $obj; } } } return DB_ForumCategoryPeer::instance()->selectByPrimaryKey($this->getCategoryId()); }
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 cloneSite($site, $siteProperties, $attrs = array()) { $db = Database::connection(); $db->begin(); /* * Hopefully attrs contains a set of parameters that determine * the behoviour of the duplicatior. */ $nsite = clone $site; $nsite->setNew(true); $nsite->setSiteId(null); $nsite->setUnixName($siteProperties['unixname']); if (isset($siteProperties['name'])) { $nsite->setName($siteProperties['name']); } if (isset($siteProperties['subtitle'])) { $nsite->setSubtitle($siteProperties['subtitle']); } if (isset($siteProperties['description'])) { $nsite->setDescription($siteProperties['description']); } if (array_key_exists('private', $siteProperties)) { if ($siteProperties['private']) { $nsite->setPrivate(true); } else { $nsite->setPrivate(false); } } $nsite->setCustomDomain(null); $nsite->save(); /* Super settings. */ // site_super_settings $superSettings = $site->getSuperSettings(); $superSettings->setNew(true); $superSettings->setSiteId($nsite->getSiteId()); $superSettings->save(); /* Site settings. */ $settings = $site->getSettings(); $settings->setNew(true); $settings->setSiteId($nsite->getSiteId()); $settings->save(); /* Now handle site owner. */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $c->add('founder', true); $owner = DB_AdminPeer::instance()->selectOne($c); $this->owner = $owner; $admin = new DB_Admin(); $admin->setSiteId($nsite->getSiteId()); $admin->setUserId($owner->getUserId()); $admin->setFounder(true); // will be nonremovable ;-) $admin->save(); $member = new DB_Member(); $member->setSiteId($nsite->getSiteId()); $member->setUserId($owner->getUserId()); $member->setDateJoined(new ODate()); $member->save(); /* Theme(s). */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $themes = DB_ThemePeer::instance()->select($c); $themeMap = array(); $nthemes = array(); foreach ($themes as $theme) { $ntheme = clone $theme; $ntheme->setNew(true); $ntheme->setSiteId($nsite->getSiteId()); $ntheme->setThemeId(null); $ntheme->save(); $themeMap[$theme->getThemeId()] = $ntheme->getThemeId(); $nthemes[] = $ntheme; } foreach ($nthemes as $ntheme) { if ($ntheme->getExtendsThemeId() && isset($themeMap[$ntheme->getExtendsThemeId()])) { $ntheme->setExtendsThemeId($themeMap[$ntheme->getExtendsThemeId()]); $ntheme->save(); } } // get all categories from the site $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $categories = DB_CategoryPeer::instance()->select($c); foreach ($categories as $cat) { if (!in_array($cat->getName(), $this->excludedCategories)) { $ncategory = $this->duplicateCategory($cat, $nsite); /* Check if is using a custom theme. */ if ($ncategory->getThemeId() && isset($themeMap[$ncategory->getThemeId()])) { $ncategory->setThemeId($themeMap[$ncategory->getThemeId()]); $ncategory->save(); } if ($ncategory->getTemplateId()) { $ncategory->setTemplateId($this->pageMap[$ncategory->getTemplateId()]); $ncategory->save(); } } } /* Recompile WHOLE site. */ $od = new Outdater(); $od->recompileWholeSite($nsite); /* Index. */ $ind = Indexer::instance(); $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $pages = DB_PagePeer::instance()->select($c); foreach ($pages as $p) { $ind->indexPage($p); } /* Handle forum too. */ $fs = $site->getForumSettings(); if ($fs) { $fs->setNew(true); $fs->setSiteId($nsite->getSiteId()); $fs->save(); /* Copy existing structure. */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $groups = DB_ForumGroupPeer::instance()->select($c); foreach ($groups as $group) { $ngroup = clone $group; $ngroup->setNew(true); $ngroup->setGroupId(null); $ngroup->setSiteId($nsite->getSiteId()); $ngroup->save(); $c = new Criteria(); $c->add('group_id', $group->getGroupId()); $categories = DB_ForumCategoryPeer::instance()->select($c); foreach ($categories as $category) { $ncategory = clone $category; $ncategory->setNew(true); $ncategory->setCategoryId(null); $ncategory->setNumberPosts(0); $ncategory->setNumberThreads(0); $ncategory->setLastPostId(null); $ncategory->setSiteId($nsite->getSiteId()); $ncategory->setGroupId($ngroup->getGroupId()); $ncategory->save(); } } } /* Copy ALL files from the filesystem. */ $srcDir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName(); $destDir = WIKIDOT_ROOT . "/web/files--sites/" . $nsite->getUnixName(); $cmd = 'cp -r ' . escapeshellarg($srcDir) . ' ' . escapeshellarg($destDir); exec($cmd); /* Copy file objects. */ $c = new Criteria(); $c->add('site_id', $site->getSiteId()); $files = DB_FilePeer::instance()->select($c); foreach ($files as $file) { $nfile = clone $file; $nfile->setSiteId($nsite->getSiteId()); $nfile->setNew(true); $nfile->setFileId(null); $nfile->setSiteId($nsite->getSiteId()); /* Map to a new page objects. */ $pageId = $this->pageMap[$file->getPageId()]; $nfile->setPageId($pageId); $nfile->save(); } $db->commit(); return $nsite; }
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); } }
public function saveForumPermissionsEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $siteId = $site->getSiteId(); $json = new JSONService(SERVICES_JSON_LOOSE_TYPE); $cats = $json->decode($pl->getParameterValue("categories")); $db = Database::connection(); $db->begin(); /* for each category * - get a category from database * - check if permissions has changed * - if changed: update */ foreach ($cats as $cat) { $categoryId = $cat['category_id']; $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("category_id", $cat['category_id']); $ca = DB_ForumCategoryPeer::instance()->selectOne($c); if ($cat == null) { throw new ProcessException("Invalid category."); } //validate permstring $permstring = $cat['permissions']; $p2 = explode(";", $permstring); foreach ($p2 as $perm) { if ($permstring && preg_match("/^[tpes]:[armo]{0,4}\$/", $perm) == 0) { throw new ProcessException(_("Error saving permissions - invalid internal format. Please try again and contact admins if the problem repeats.")); } } if ($ca->getPermissions() !== $cat['permissions']) { $ca->setPermissions($cat['permissions']); $ca->save(); } } $defaultPermissions = $pl->getParameterValue("default_permissions"); $p2 = explode(";", $defaultPermissions); foreach ($p2 as $perm) { if (preg_match("/^[tpes]:[armo]{0,4}\$/", $perm) == 0) { throw new ProcessException(_("Error saving permissions - invalid internal format. Please try again and contact admins if the problem repeats.")); } } $fSettings = $site->getForumSettings(); if ($fSettings->getPermissions() !== $defaultPermissions) { $fSettings->setPermissions($defaultPermissions); $fSettings->save(); } $db->commit(); if (GlobalProperties::$UI_SLEEP) { sleep(1); } }
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); }
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); } }
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"); }