public function build($runData) { $site = $runData->getTemp("site"); $runData->contextAdd("site", $site); // now select themes $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->add("custom", true); $c->add("abstract", false); $c->addOrderAscending("name"); $themes = DB_ThemePeer::instance()->select($c); $runData->contextAdd("themes", $themes); }
public function build($runData) { $pl = $runData->getParameterList(); $url = $pl->getParameterValue('url'); $siteId = $pl->getParameterValue('siteId'); if ($siteId && is_numeric($siteId)) { $site = DB_SitePeer::instance()->selectByPrimaryKey($siteId); } if (!$site) { throw new ProcessException(_('Invalid site')); } $runData->setLanguage($site->getLanguage()); $GLOBALS['lang'] = $site->getLanguage(); // and for gettext too: $lang = $site->getLanguage(); switch ($lang) { case 'pl': $glang = "pl_PL"; break; case 'en': $glang = "en_US"; break; } putenv("LANG={$glang}"); putenv("LANGUAGE={$glang}"); setlocale(LC_ALL, $glang . '.UTF-8'); // Set the text domain as 'messages' $gdomain = 'messages'; bindtextdomain($gdomain, WIKIDOT_ROOT . '/locale'); textdomain($gdomain); $themeId = $pl->getParameterValue('themeId'); if ($themeId && is_numeric($themeId)) { $theme = DB_ThemePeer::instance()->selectByPrimaryKey($themeId); } if (!$theme) { throw new ProcessException(_('Invalid theme')); } $runData->contextAdd('site', $site); $runData->contextAdd('theme', $theme); $runData->contextAdd('url', $url); $seed = CryptUtils::generateSeed(4); // put seed into session! $runData->sessionStart(); $runData->sessionAdd("login_seed", $seed); $runData->contextAdd("key", CryptUtils::modulus()); $runData->contextAdd("seed", $seed); // clear welcome cookie? if ($pl->getParameterValue("clearwelcome")) { $runData->contextAdd('reset', true); } }
public function getStyleUrls() { if ($this->getExtendsThemeId()) { // get parent theme $parent = DB_ThemePeer::instance()->selectByPrimaryKey($this->getExtendsThemeId()); if ($parent == null) { throw new ProcessException("FATAL ERROR: Theme not found."); } $files = $parent->getStyleUrls(); } else { $files = array(); } $files[] = $this->getStyleUrl(); return $files; }
public function build($runData) { $site = $runData->getTemp("site"); $runData->contextAdd("site", $site); // get all categories for the site $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->addOrderAscending("replace(name, '_', '00000000')"); $categories = DB_CategoryPeer::instance()->select($c); $runData->contextAdd("categories", $categories); // also prepare categories to put into javascript... $cats2 = array(); foreach ($categories as $category) { $arr = $category->getFieldValuesArray(); // change themes to conform to variants structure if ($arr['theme_id']) { $theme = DB_ThemePeer::instance()->selectByPrimaryKey($category->getThemeId()); if ($theme->getVariantOfThemeId() != null) { $arr['theme_id'] = $theme->getVariantOfThemeId(); $arr['variant_theme_id'] = $theme->getThemeId(); $arr['theme_external_url'] = $category->getThemeExternalUrl(); } } $cats2[] = $arr; } $runData->ajaxResponseAdd("categories", $cats2); // now select themes $c = new Criteria(); /*$c->add("custom", false); $c->add("abstract", false); $c->addOrderAscending("name");*/ $q = "SELECT * from theme WHERE " . "abstract = FALSE AND variant_of_theme_id IS NULL " . "AND (custom = FALSE" . " OR (custom = TRUE AND site_id='" . $site->getSiteId() . "')" . ") " . "ORDER BY custom, sort_index, replace(name, '_', '00000000');"; $c->setExplicitQuery($q); $themes = DB_ThemePeer::instance()->select($c); $runData->contextAdd("themes", $themes); // get theme variants too $c = new Criteria(); $q = "SELECT * FROM theme WHERE variant_of_theme_id IS NOT NULL ORDER BY name"; $c->setExplicitQuery($q); $variants = DB_ThemePeer::instance()->select($c); $variantsArray = array(); foreach ($variants as $v) { $variantsArray[$v->getVariantOfThemeId()][] = $v; } $runData->contextAdd("variantsArray", $variantsArray); }
protected function getExternalTheme($url) { if (!$url) { return null; } $t = new DB_Theme(); $t->setExternalUrl($url); /* Get base theme. */ $c = new Criteria(); $c->add('name', 'Base'); $c->add('custom', false); $baseTheme = DB_ThemePeer::instance()->selectOne($c); $t->setExtendsThemeId($baseTheme->getThemeId()); $t->setThemeId($baseTheme->getThemeId()); // needed sometime return $t; }
public function build($runData) { $site = $runData->getTemp("site"); $runData->contextAdd("site", $site); // get all categories for the site $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $c->addOrderAscending("replace(name, '_', '00000000')"); $categories = DB_CategoryPeer::instance()->select($c); $runData->contextAdd("categories", $categories); // also prepare categories to put into javascript... $cats2 = array(); foreach ($categories as $category) { $cats2[] = $category->getFieldValuesArray(); } $runData->ajaxResponseAdd("categories", $cats2); // now select themes $c = new Criteria(); $c->addOrderAscending("name"); $themes = DB_ThemePeer::instance()->select($c); $runData->contextAdd("themes", $themes); }
public function build($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $runData->contextAdd("site", $site); // now select themes that can be extended $c = new Criteria(); $c->add("custom", false); $c->addOrderAscending("sort_index"); $c->addOrderAscending("name"); $themes = DB_ThemePeer::instance()->select($c); $runData->contextAdd("exthemes", $themes); $themeId = $pl->getParameterValue("themeId"); if ($themeId && is_numeric($themeId)) { $theme = DB_ThemePeer::instance()->selectByPrimaryKey($themeId); if ($theme == null || $theme->getSiteId() !== $site->getSiteId()) { throw new ProcessException(_("Error selecting theme."), "wrong_theme"); } $runData->contextAdd("theme", $theme); $dir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/theme/" . $theme->getUnixName(); $code = file_get_contents($dir . "/style.css"); $runData->contextAdd("code", $code); } }
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 customThemeDeleteEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $themeId = $pl->getParameterValue("themeId"); $theme = DB_ThemePeer::instance()->selectByPrimaryKey($themeId); if ($theme == null || $theme->getSiteId() !== $site->getSiteId()) { throw new ProcessException(_("Error selecting theme."), "wrong_theme"); } $db = Database::connection(); $db->begin(); // now check if theme is used by pages (categories) $c = new Criteria(); $c->add("theme_id", $theme->getThemeId()); $c->add("site_id", $site->getSiteId()); $cats = DB_CategoryPeer::instance()->select($c); if (count($cats) > 0) { throw new ProcessException(_("This theme can not be deleted because there are still pages that use it. Please check themes assigned to particular categories."), "can_not_delete"); } // ok, delete now! DB_ThemePeer::instance()->deleteByPrimaryKey($theme->getThemeId()); $cmd = "rm -r " . escapeshellarg($site->getLocalFilesPath() . "/theme/" . $theme->getUnixName()); exec($cmd); $db->commit(); }