Exemplo n.º 1
0
 public static function instance()
 {
     if (self::$instance == null) {
         self::$instance = new Indexer();
     }
     return self::$instance;
 }
Exemplo n.º 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);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 public function deletePostEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $postId = $pl->getParameterValue("postId");
     if ($postId == null || !is_numeric($postId)) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $db = Database::connection();
     $db->begin();
     $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId);
     if ($post == null || $post->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $thread = $post->getForumThread();
     $category = $thread->getForumCategory();
     try {
         WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
     } catch (Exception $e) {
         throw new WDPermissionException(_("Sorry, you are not allowed to delete posts. Only site administrators and moderators are the ones who can."));
     }
     $c = new Criteria();
     $c->add("parent_id", $postId);
     $toDelete = array();
     $chposts = DB_ForumPostPeer::instance()->select($c);
     while ($chposts && count($chposts) > 0) {
         $toDelete = array_merge($toDelete, $chposts);
         $c = new Criteria();
         foreach ($chposts as $f) {
             $c->addOr("parent_id", $f->getPostId());
         }
         $chposts = DB_ForumPostPeer::instance()->select($c);
     }
     DB_ForumPostPeer::instance()->deleteByPrimaryKey($post->getPostId());
     foreach ($toDelete as $f) {
         DB_ForumPostPeer::instance()->deleteByPrimaryKey($f->getPostId());
     }
     // now recalculate a few things...
     $thread->calculateNumberPosts();
     $thread->findLastPost();
     $thread->save();
     $category->calculateNumberPosts();
     $category->findLastPost();
     $category->save();
     // outdate
     $o = new Outdater();
     $o->forumEvent("thread_save", $thread);
     // index thread
     Indexer::instance()->indexThread($thread);
     EventLogger::instance()->logPostDelete($thread, $post->getTitle());
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Exemplo n.º 5
0
 public function indexPage($page)
 {
     Indexer::instance()->indexPage($page);
 }