Example #1
0
 public function build($runData)
 {
     $c = new Criteria();
     $c->add("site_id", $runData->getTemp("site")->getSiteId());
     $c->addJoin("user_id", "ozone_user.user_id");
     $pl = $runData->getParameterList();
     $from = $pl->getParameterValue("group", "MODULE");
     $showSince = $pl->getParameterValue("showSince", "MODULE");
     if ($showSince == "no" || $showSince == "false" || $showSince == "get lost") {
         $showSince = false;
     } else {
         $showSince = true;
     }
     if ($pl->getParameterType("from") == "MODULE") {
         $from = $pl->getParameterValue("from");
     }
     if ($from !== "admins" && $from !== "moderators") {
         $from = null;
     }
     if ($from === "admins") {
         $mems = DB_AdminPeer::instance()->select($c);
     } elseif ($from === "moderators") {
         $mems = DB_ModeratorPeer::instance()->select($c);
     } else {
         $mems = DB_MemberPeer::instance()->select($c);
     }
     if (count($mems) > 0) {
         $runData->contextAdd("from", $from);
         $runData->contextAdd("memberships", $mems);
         $runData->contextAdd("showSince", $showSince);
     }
 }
Example #2
0
 private function canSetBlock($user, $page)
 {
     if ($user && ($user->getSuperAdmin() || $user->getSuperModerator())) {
         return true;
     }
     if (!$user) {
         return false;
     }
     // still nothing. check if moderator of "pages".
     $c = new Criteria();
     $c->add("site_id", $page->getSiteId());
     $c->add("user_id", $user->getUserId());
     $rel = DB_ModeratorPeer::instance()->selectOne($c);
     if ($rel && strpos($rel->getPermissions(), 'p') !== false) {
         return true;
     }
     // still nothing. check if admin.
     $c = new Criteria();
     $c->add("site_id", $page->getSiteId());
     $c->add("user_id", $user->getUserId());
     $rel = DB_AdminPeer::instance()->selectOne($c);
     if ($rel) {
         return true;
     }
     return false;
 }
 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();
 }
Example #4
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $userId = $pl->getParameterValue("user_id");
     $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($userId);
     $avatarUri = '/common--images/avatars/' . floor($userId / 1000) . '/' . $userId . '/a48.png';
     $runData->contextAdd("user", $user);
     $runData->contextAdd("avatarUri", $avatarUri);
     // find the possible role in this site
     $site = $runData->getTemp("site");
     $siteId = $site->getSiteId();
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->add("site_id", $siteId);
     $mem = DB_MemberPeer::instance()->selectOne($c);
     if ($mem != null) {
         $runData->contextAdd("member", $mem);
         // also check for other roles: admin & moderator
         if (DB_AdminPeer::instance()->selectOne($c) != null) {
             $runData->contextAdd("role", "admin");
         } elseif (DB_AdminPeer::instance()->selectOne($c) != null) {
             $runData->contextAdd("role", "moderator");
         }
     }
     $runData->contextAdd("uu", $runData->getUser());
     $runData->contextAdd('karmaLevel', $user->getKarmaLevel());
 }
 public function build($runData)
 {
     $userId = $runData->getUserId();
     // get all membership - criteria with join ;-) wooo!
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->addJoin("site_id", "site.site_id");
     $c->add("site.deleted", true);
     $mems = DB_AdminPeer::instance()->select($c);
     if (count($mems) > 0) {
         $runData->contextAdd("admins", $mems);
     }
     // get the sites
     $sites = array();
     foreach ($mems as $m) {
         $s = $m->getSite();
         $sites[$s->getSiteId()] = $s->getFieldValuesArray();
         // original unix name...
         $un = $s->getUnixName();
         $un = explode('..del..', $un);
         $un = $un[0];
         $sites[$s->getSiteId()]['unix_name'] = $un;
     }
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $runData->contextAdd('sitesData', $json->encode($sites));
 }
 public function build($runData)
 {
     // get all the members
     $c = new Criteria();
     $c->add("site_id", $runData->getTemp("site")->getSiteId());
     $c->addJoin("user_id", "ozone_user.user_id");
     $c->addOrderAscending("ozone_user.nick_name");
     $mems = DB_AdminPeer::instance()->select($c);
     if (count($mems) > 0) {
         $runData->contextAdd("admins", $mems);
     }
 }
Example #7
0
 public function build($runData)
 {
     $userId = $runData->getUserId();
     // get all membership - criteria with join ;-) wooo!
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->addJoin("site_id", "site.site_id");
     $c->add("site.deleted", false);
     $mems = DB_AdminPeer::instance()->select($c);
     if (count($mems) > 0) {
         $runData->contextAdd("admins", $mems);
     }
 }
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $postId = $pl->getParameterValue("postId", "AMODULE");
     $user = $runData->getUser();
     $site = $runData->getTemp("site");
     if ($postId == null || !is_numeric($postId)) {
         throw new ProcessException(_("No post specified."), "no_post");
     }
     $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId);
     if ($post == null || $post->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("No post specified."), "no_post");
     }
     $category = $post->getForumThread()->getCategory();
     WDPermissionManager::instance()->hasForumPermission('edit_post', $runData->getUser(), $category, null, $post);
     // check if thread blocked
     $thread = $post->getForumThread();
     if ($thread->getBlocked()) {
         // check if moderator or admin
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("user_id", $user->getUserId());
         $rel = DB_ModeratorPeer::instance()->selectOne($c);
         if (!$rel || strpos($rel->getPermissions(), 'f') == false) {
             $rel = DB_AdminPeer::instance()->selectOne($c);
             if (!$rel) {
                 throw new WDPermissionException(_("Sorry, this thread is blocked. Nobody can add new posts nor edit existing ones."));
             }
         }
     }
     // OK for now...
     // keep the session - i.e. put an object into session storage not to delete it!!!
     $runData->sessionAdd("keep", true);
     $runData->contextAdd("post", $post);
     $runData->ajaxResponseAdd("postId", $postId);
     $userId = $runData->getUserId();
     if ($userId == null) {
         $userString = $runData->createIpString();
         $runData->contextAdd("anonymousString", $userString);
     }
 }
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $runData->contextAdd("site", $site);
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("site_id", $site->getSiteId());
     $c->add("founder", true);
     $rel = DB_AdminPeer::instance()->selectOne($c);
     if ($rel) {
         $runData->contextAdd('allowed', true);
     } else {
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("founder", true);
         $f = DB_AdminPeer::instance()->selectOne($c);
         $founder = DB_OzoneUserPeer::instance()->selectByPrimaryKey($f->getUserId());
         $runData->contextAdd('founder', $founder);
     }
 }
Example #10
0
 public function render($runData)
 {
     $user = $runData->getTemp("user");
     $site = $runData->getTemp("site");
     // check if site admin
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->add("user_id", $user->getUserId());
     $admin = DB_AdminPeer::instance()->selectOne($c);
     if ($admin == null) {
         return _("Sorry, you are not allowed to view this feed.");
     }
     $key = "adminnotificationsfeed.." . $site->getSiteId();
     $mc = OZONE::$memcache;
     $out = $mc->get($key);
     if ($out) {
         return $out;
     }
     $out = parent::render($runData);
     $mc->set($key, $out, 0, 3600);
     return $out;
 }
Example #11
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();
 }
Example #12
0
 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;
 }
Example #13
0
 public function saveThreadMetaEvent($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $title = $pl->getParameterValue("title");
     $description = $pl->getParameterValue("description");
     // validate
     $errors = array();
     if ($title == '') {
         $errors['title'] = _("Thread title can not be empty.");
     }
     if (strlen8($title) > 128) {
         $errors['title'] = _("Thread title should not be longer than 128 characters.");
     }
     if (strlen($description) > 1000) {
         $errors['description'] = _("Thread description should not be longer than 1000 characters.");
     }
     if (count($errors) > 0) {
         $runData->ajaxResponseAdd("formErrors", $errors);
         throw new ProcessException("Form errors", "form_errors");
     }
     $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->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. Meta information can not be edited."));
             }
         }
     }
     $category = $thread->getCategory();
     WDPermissionManager::instance()->hasForumPermission('edit_thread', $runData->getUser(), $category, $thread);
     $changed = false;
     $title = trim($title);
     $description = trim($description);
     if ($title !== $thread->getTitle()) {
         $changed = true;
         $thread->setTitle($title);
     }
     if ($description !== $thread->getDescription()) {
         $changed = true;
         $thread->setDescription($description);
     }
     if ($changed) {
         $thread->save();
         EventLogger::instance()->logSaveThreadMeta($thread);
     }
     $o = new Outdater();
     $o->forumEvent("thread_save", $thread);
     // index thread
     Indexer::instance()->indexThread($thread);
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Example #14
0
 /**
  * Changes the "unix name" of the site and effectively its URL address.
  *
  * @param unknown_type $runData
  */
 public function renameSiteEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $unixName = trim($pl->getParameterValue('unixName'));
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("site_id", $site->getSiteId());
     $c->add("founder", true);
     $rel = DB_AdminPeer::instance()->selectOne($c);
     if (!$rel) {
         throw new ProcessException(_("Sorry, you have no permissions to change URL of this site."));
     }
     $db = Database::connection();
     $db->begin();
     $oldUnixName = $site->getUnixName();
     // validate unix name
     $errors = array();
     if ($unixName == $site->getUnixName()) {
         $errors['unixname'] = _('The new and current addresses are the same.');
     } elseif ($unixName === null || strlen($unixName) < 3 || strlen(WDStringUtils::toUnixName($unixName)) < 3) {
         $errors['unixname'] = _("Web address must be present and should be at least 3 characters long.");
     } elseif (strlen($unixName) > 30) {
         $errors['unixname'] = _("Web address name should not be longer than 30 characters.");
     } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.');
     } elseif (preg_match("/\\-\\-/", $unixName) !== 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.');
     } else {
         $unixName = WDStringUtils::toUnixName($unixName);
         if (!$runData->getUser()->getSuperAdmin()) {
             //	handle forbidden names
             $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf'));
             foreach ($forbiddenUnixNames as $f) {
                 if (preg_match($f, $unixName) > 0) {
                     $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.');
                 }
             }
         }
         // check if the domain is not taken.
         $c = new Criteria();
         $c->add("unix_name", $unixName);
         $ss = DB_SitePeer::instance()->selectOne($c);
         if ($ss) {
             $errors['unixname'] = _('Sorry, this web address is already used by another site.');
         }
     }
     if (isset($errors['unixname'])) {
         throw new ProcessException($errors['unixname']);
     }
     // remove some data.
     $c = new Criteria();
     $c->add('site_id', $site->getSiteId());
     // now clear cache!
     $keys = array();
     $keys[] = 'site..' . $site->getUnixName();
     $keys[] = 'site_cd..' . $site->getCustomDomain();
     $mc = OZONE::$memcache;
     foreach ($keys as $k) {
         $mc->delete($k);
     }
     $outdater = new Outdater();
     $outdater->siteEvent('delete', $site);
     $outdater->siteEvent('sitewide_change', $site);
     // change site name!!!
     $site->setUnixName($unixName);
     $site->save();
     // remove custom domain link
     // rename the files
     @rename(WIKIDOT_ROOT . '/web/files--sites/' . $oldUnixName, WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName());
     // delete custom domain link
     if ($site->getCustomDomain()) {
         @unlink(WIKIDOT_ROOT . '/web/custom--domains/' . $site->getCustomDomain());
         symlink(WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName(), WIKIDOT_ROOT . '/web/custom--domains/' . $site->getCustomDomain());
     }
     $db->commit();
     $runData->ajaxResponseAdd("unixName", $site->getUnixName());
 }
Example #15
0
 public function getSitesMasterLeft($user)
 {
     $us = $user->getSettings();
     if (!$us->getMaxSitesMaster() || $user->getSuperAdmin()) {
         return null;
         // unlimited
     }
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->addJoin("site_id", "site.site_id");
     $c->add('founder', true);
     $c->add("site.deleted", false);
     $ac = DB_AdminPeer::instance()->selectCount($c);
     return max(array(0, $us->getMaxSitesMaster() - $ac));
 }
 public function restoreSiteEvent($runData)
 {
     $pl = $runData->getParameterList();
     $siteId = $pl->getParameterValue('siteId');
     $unixName = trim($pl->getParameterValue('unixName'));
     $c = new Criteria();
     $c->add('site_id', $siteId);
     $c->add('deleted', true);
     $site = DB_SitePeer::instance()->selectOne($c);
     if (!$site) {
         throw new ProcessException(_('Error selecting a site to restore.'));
     }
     // check if allowed
     $user = $runData->getUser();
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("site_id", $site->getSiteId());
     $c->add("founder", true);
     $rel = DB_AdminPeer::instance()->selectOne($c);
     if (!$rel) {
         throw new ProcessException(_("Sorry, you have no permissions to restore this site."));
     }
     $db = Database::connection();
     $db->begin();
     // validate unix name
     $errors = array();
     if ($unixName === null || strlen($unixName) < 3 || strlen(WDStringUtils::toUnixName($unixName)) < 3) {
         $errors['unixname'] = _("Web address must be present and should be at least 3 characters long.");
     } elseif (strlen($unixName) > 30) {
         $errors['unixname'] = _("Web address name should not be longer than 30 characters.");
     } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.');
     } elseif (preg_match("/\\-\\-/", $unixName) !== 0) {
         $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.');
     } else {
         $unixName = WDStringUtils::toUnixName($unixName);
         if (!$runData->getUser()->getSuperAdmin()) {
             //	handle forbidden names
             $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf'));
             foreach ($forbiddenUnixNames as $f) {
                 if (preg_match($f, $unixName) > 0) {
                     $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.');
                 }
             }
         }
         // check if the domain is not taken.
         $c = new Criteria();
         $c->add("unix_name", $unixName);
         $ss = DB_SitePeer::instance()->selectOne($c);
         if ($ss) {
             $errors['unixname'] = _('Sorry, this web address is already used by another site.');
         }
     }
     if (isset($errors['unixname'])) {
         throw new ProcessException($errors['unixname']);
     }
     $oldUnixName = $site->getUnixName();
     $oldLocalPath = $site->getLocalFilesPath();
     $site->setUnixName($unixName);
     // 	rename the files
     mkdirfull(dirname($site->getLocalFilesPath()));
     @rename($oldLocalPath, $site->getLocalFilesPath());
     $site->setDeleted(false);
     $site->setCustomDomain(null);
     $site->save();
     $db->commit();
     $runData->ajaxResponseAdd('unixName', $site->getUnixName());
 }
 public function removeAdminEvent($runData)
 {
     $userId = $runData->getParameterList()->getParameterValue("user_id");
     $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($userId);
     if ($user == null) {
         throw new ProcessException("Error");
     }
     $siteId = $runData->getTemp("site")->getSiteId();
     $site = $runData->getTemp("site");
     // check if IS an admin
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->add("site_id", $siteId);
     $admin = DB_AdminPeer::instance()->selectOne($c);
     if ($admin && $admin->getFounder()) {
         throw new ProcessException(_("The original founder of the site can not be removed."), "founder_nonremovable");
     }
     if ($admin == null) {
         $runData->ajaxResponseAdd("status", "not_already");
         $runData->ajaxResponseAdd("message", _("This user is not an administator any more."));
         $db->commit();
         return;
     }
     if ($userId === $runData->getUserId()) {
         $runData->ajaxResponseAdd("status", "not_yourself");
         $runData->ajaxResponseAdd("message", _("You can not remove yourself from site admins."));
         $db->commit();
         return;
     }
     $c2 = new Criteria();
     $c2->add("site_id", $siteId);
     $acount = DB_AdminPeer::instance()->selectCount($c2);
     if ($acount == 1) {
         // BUT this meand "yourself"
         $runData->ajaxResponseAdd("status", "last_admin");
         $runData->ajaxResponseAdd("message", _("You can not remove the last admin."));
         $db->commit();
         return;
     }
     DB_AdminPeer::instance()->delete($c);
     // and create a notification too...
     NotificationMaker::instance()->removedFromAdmins($site, $user);
     $db->commit();
 }
Example #18
0
 public function saveEvent($runData)
 {
     $params = $runData->getParameterList()->asArray();
     $ids = array();
     foreach ($params as $param_key => $param_val) {
         $m = array();
         if (preg_match(';^nick_name_([new0-9]+)$;', $param_key, $m)) {
             $ids[] = $m[1];
         }
     }
     foreach ($ids as $id) {
         $nick_name = $params["nick_name_{$id}"];
         $password = $params["password_{$id}"];
         $admin = $params["admin_{$id}"] ? true : false;
         $mod = $params["mod_{$id}"] ? true : false;
         $site = $runData->getTemp('site');
         if ($nick_name) {
             if ($id = 1 * $id) {
                 $u = DB_OzoneUserPeer::instance()->selectByPrimaryKey($id);
             } else {
                 $u = null;
             }
             $next = false;
             if (!$u) {
                 $u = new DB_OzoneUser();
                 if (!$password) {
                     $next = true;
                 }
                 $u->save();
                 $m = new DB_Member();
                 $m->setUserId($u->getUserId());
                 $m->setSiteId($site->getSiteId());
                 $m->save();
             }
             if (!$next) {
                 $u->setName($nick_name);
                 $u->setEmail($nick_name);
                 $u->setNickName($nick_name);
                 $u->setUnixName(WDStringUtils::toUnixName($nick_name));
                 if ($password) {
                     $u->setPassword(md5($password));
                 }
                 $u->save();
                 if ($admin) {
                     if (!WDPermissionManager::hasPermission('manage_site', $u, $site)) {
                         $a = new DB_Admin();
                         $a->setUserId($u->getUserId());
                         $a->setSiteId($site->getSiteId());
                         $a->save();
                     }
                 } else {
                     // ! $admin
                     $c = new Criteria();
                     $c->add('site_id', $site->getSiteId());
                     $c->add('user_id', $u->getUserId());
                     DB_AdminPeer::instance()->delete($c);
                 }
                 if ($mod) {
                     if (!WDPermissionManager::hasPermission('moderate_site', $u, $site)) {
                         $m = new DB_Moderator();
                         $m->setUserId($u->getUserId());
                         $m->setSiteId($site->getSiteId());
                         $m->save();
                     }
                 } else {
                     // ! $mod
                     $c = new Criteria();
                     $c->add('site_id', $site->getSiteId());
                     $c->add('user_id', $u->getUserId());
                     DB_ModeratorPeer::instance()->delete($c);
                 }
             }
         }
     }
 }