示例#1
0
 public function activateForumEvent($runData)
 {
     $site = $runData->getTemp("site");
     $db = Database::connection();
     $db->begin();
     // copy forum settings from template
     $c = new Criteria();
     $c->add("unix_name", "template-" . $site->getLanguage());
     $templateSite = DB_SitePeer::instance()->selectOne($c);
     $fs = $templateSite->getForumSettings();
     $fs->setNew(true);
     $fs->setSiteId($site->getSiteId());
     $fs->save();
     // create extra categories? no.
     // copy pages
     $d = new Duplicator();
     $d->setOwner($runData->getUser());
     // copy "forum" category
     $fc = DB_CategoryPeer::instance()->selectByName("forum", $templateSite->getSiteId());
     $d->duplicateCategory($fc, $site);
     // recompile category.
     $od = new Outdater();
     $od->recompileCategory(DB_CategoryPeer::instance()->selectByName("forum", $site->getSiteId()));
     // create a "Hidden" forum group and "Deleted" category
     $group = new DB_ForumGroup();
     $group->setSiteId($site->getSiteId());
     $group->setName("Hidden");
     $group->setVisible(false);
     $group->save();
     $del = new DB_ForumCategory();
     $del->setSiteId($site->getSiteId());
     $del->setName(_("Deleted threads"));
     $del->setDescription(_("Deleted forum discussions should go here."));
     $del->setPermissions("t:;p:;e:;s:");
     $del->setGroupId($group->getGroupId());
     $del->save();
     $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());
     $category->setGroupId($group->getGroupId());
     $category->save();
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
示例#2
0
 public function createSiteEvent($runData)
 {
     WDPermissionManager::instance()->canBecomeAdmin($runData->getUser());
     $pl = $runData->getParameterList();
     $name = trim($pl->getParameterValue("name"));
     $unixName = trim($pl->getParameterValue("unixname"));
     $tagline = trim($pl->getParameterValue("tagline"));
     $templateId = $pl->getParameterValue("template");
     $private = (bool) $pl->getParameterValue("private");
     // validate form data:
     $errors = array();
     if (strlen($name) < 1) {
         $errors['name'] = _("Site name must be present.");
     } elseif (strlen8($name) > 30) {
         $errors['name'] = _("Site name should not be longer than 30 characters.");
     }
     // site unix name *************
     if ($unixName === null || strlen($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.');
         }
     }
     // template
     if (!$templateId) {
         $errors['template'] = _('Please choose a template for your site');
     }
     if (strlen8($tagline) > 50) {
         $errors['tagline'] = _("Tagline should not be longer than 50 characters");
     }
     // TOS
     if (!$pl->getParameterValue("tos")) {
         $errors['tos'] = _("Please read and agree to the Terms of Service.");
     }
     if (count($errors) > 0) {
         $runData->ajaxResponseAdd("formErrors", $errors);
         throw new ProcessException("Form errors", "form_errors");
     }
     // and now... CREATE THE SITE!!!!!!!!!!!!!!!!
     $dup = new Duplicator();
     $dup->setOwner($runData->getUser());
     $db = Database::connection();
     $db->begin();
     $templateSite = DB_SitePeer::instance()->selectByPrimaryKey($templateId);
     if (!preg_match(';^template\\-;', $templateSite->getUnixName())) {
         throw new ProcessException('Error');
     }
     $site = new DB_Site();
     $site->setName($name);
     $site->setSubtitle($tagline);
     $site->setUnixName($unixName);
     $site->setLanguage($templateSite->getLanguage());
     $site->setDateCreated(new ODate());
     $site->setPrivate($private);
     if ($private) {
         // change file flag too
         $flagDir = WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName() . '/flags';
         $flagFile = $flagDir . '/private';
         mkdirfull($flagDir);
         //just to make sure
         if (!file_exists($flagFile)) {
             file_put_contents($flagFile, "private");
         }
     }
     $site->save();
     $dup->addExcludedCategory("forum");
     // should be initialized independently
     $dup->addExcludedCategory("profile");
     $dup->duplicateSite($templateSite, $site);
     // index the site too
     $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);
     }
     $db->commit();
     // clear captcha code
     $runData->sessionDel("captchaCode");
     $runData->ajaxResponseAdd("siteUnixName", $unixName);
 }
示例#3
0
 public function finalizeEvent($runData, $skipEvcode = false)
 {
     // get the form data
     $pl = $runData->getParameterList();
     if (!$skipEvcode) {
         $evcode = $pl->getParameterValue("evcode", "AMODULE");
         //check if the email vercode is correct
         $evcode2 = $runData->sessionGet('evcode');
         if ($evcode !== $evcode2) {
             throw new ProcessException(_("Invalid email verification code."), "invalid_code");
         }
     }
     $data = $runData->sessionGet("ca_data");
     $name = $data['name'];
     $email = $data['email'];
     $password = $data['password'];
     $lang = $data['language'];
     $db = Database::connection();
     $db->begin();
     // check again if email and nick are not duplicate!
     $c = new Criteria();
     $c->add("lower(email)", strtolower($email));
     $u = DB_OzoneUserPeer::instance()->selectOne($c);
     if ($u != null) {
         $runData->resetSession();
         throw new ProcessException(_("A user with this email already exists. Must have been created meanwhile... " . "Unfortunately you have to repeat the whole procedure. :-("), "user_exists");
     }
     $unixified = WDStringUtils::toUnixName($name);
     $c = new Criteria();
     $c->add("unix_name", $unixified);
     $u = DB_OzoneUserPeer::instance()->selectOne($c);
     if ($u != null) {
         $runData->resetSession();
         throw new ProcessException(_("A user with this name (or very similar) already exists. Must have been created meanwhile... " . "Unfortunately you have to repeat the whole procedure. :-("), "user_exists");
     }
     // add new user!!!
     $nuser = new DB_OzoneUser();
     /* email as the username!!! */
     $nuser->setName($email);
     $nuser->setEmail($email);
     $nuser->setPassword(md5($password));
     $nuser->setNickName($name);
     $nuser->setUnixName($unixified);
     $nuser->setLanguage($lang);
     $date = new ODate();
     $nuser->setRegisteredDate($date);
     $nuser->setLastLogin($date);
     $nuser->save();
     // profile
     $profile = new DB_Profile();
     $profile->setUserId($nuser->getUserId());
     $profile->save();
     $us = new DB_UserSettings();
     $us->setUserId($nuser->getUserId());
     $us->save();
     // profile page
     $c = new Criteria();
     $c->add("unix_name", "profiles");
     $nsite = DB_SitePeer::instance()->selectOne($c);
     $ncategory = DB_CategoryPeer::instance()->selectByName('profile', $nsite->getSiteId());
     $dup = new Duplicator();
     $dup->setOwner($nuser);
     $dup->duplicatePage(DB_PagePeer::instance()->selectByName($nsite->getSiteId(), 'template:profile'), $nsite, $ncategory, 'profile:' . $nuser->getUnixName());
     $page = DB_PagePeer::instance()->selectByName($nsite->getSiteId(), 'profile:' . $nuser->getUnixName());
     $ou = new Outdater();
     $ou->pageEvent('new_page', $page);
     $db->commit();
     /* Handle originalUrl. */
     $originalUrl = $runData->sessionGet('loginOriginalUrl');
     if ($originalUrl) {
         $runData->ajaxResponseAdd('originalUrl', $originalUrl);
         if ($runData->sessionGet('loginOriginalUrlForce')) {
             $runData->ajaxResponseAdd('originalUrlForce', true);
         }
     }
     // reset session etc.
     $runData->resetSession();
     $runData->getSession()->setUserId($nuser->getUserId());
     setcookie("welcome", $nuser->getUserId(), time() + 10000000, "/", GlobalProperties::$SESSION_COOKIE_DOMAIN);
     setcookie(GlobalProperties::$SESSION_COOKIE_NAME_IE, $runData->getSessionId(), null, "/");
 }