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) { $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) { $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) { // 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 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 getForumGroup() { return DB_ForumGroupPeer::instance()->selectByPrimaryKey($this->getGroupId()); }
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 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); } }
public function createPageDiscussionThreadEvent($runData) { // ok, the page has no discussion yet... but check it! $site = $runData->getTemp("site"); $pl = $runData->getParameterList(); $pageId = $pl->getParameterValue("page_id"); $page = DB_PagePeer::instance()->selectByPrimaryKey($pageId); if ($page == null || $page->getSiteId() != $site->getSiteId()) { throw new ProcessException(_("Page does not exist."), "no_page"); } $db = Database::connection(); $db->begin(); $c = new Criteria(); $c->add("page_id", $pageId); $c->add("site_id", $site->getSiteId()); $thread = DB_ForumThreadPeer::instance()->selectOne($c); if ($thread) { // thread exists! which means it could have been created meanwhile! // simply return the thread it now. $runData->ajaxResponseAdd("thread_id", $thread->getThreadId()); $runData->ajaxResponseAdd("thread_unix_title", $thread->getUnixifiedTitle()); $db->commit(); return; } // thread does not exist. check if category with page discussions exist. $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($pageId); $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(); $runData->ajaxResponseAdd("thread_id", $thread->getThreadId()); $runData->ajaxResponseAdd("thread_unix_title", $thread->getUnixifiedTitle()); $o = new Outdater(); $o->forumEvent("thread_save", $thread); $db->commit(); }