Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public function customThemeSaveEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $themeId = $pl->getParameterValue("themeId");
     $name = trim($pl->getParameterValue("name"));
     $parentThemeId = $pl->getParameterValue("parentTheme");
     $code = trim($pl->getParameterValue("code"));
     $pageName = trim($pl->getParameterValue("cssImportPage"));
     $useSideBar = false;
     $useTopBar = false;
     if ($pl->getParameterValue("useSideBar")) {
         $useSideBar = true;
     }
     if ($pl->getParameterValue("useTopBar")) {
         $useTopBar = true;
     }
     if ($name == '') {
         throw new ProcessException(_("Theme name must be given."), "form_error");
     }
     if (strlen8($name) > 30) {
         throw new ProcessException(_("Theme name should not be longer than 30 characters."), "form_error");
     }
     if (strlen($code) > 50000) {
         throw new ProcessException(_("CSS code seems to be to long."), "form_error");
     }
     $parentTheme = DB_ThemePeer::instance()->selectByPrimaryKey($parentThemeId);
     if ($parentTheme == null) {
         throw new ProcessException(_("Parent theme can not be found."), "form_error");
     }
     if ($themeId == null) {
         // check if theme name is unique among custom themes for this site
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("name", $name);
         $th = DB_ThemePeer::instance()->selectOne($c);
         if ($th) {
             throw new ProcessException(_("Theme with this name already exists within this site."), "form_error");
         }
     }
     $db = Database::connection();
     $db->begin();
     if ($themeId) {
         // theme already exists
         $theme = DB_ThemePeer::instance()->selectByPrimaryKey($themeId);
         if ($theme == null || $theme->getSiteId() !== $site->getSiteId()) {
             throw new ProcessException(_("Error selecting theme."), "wrong_theme");
         }
     } else {
         // new theme
         $theme = new DB_Theme();
         $theme->setCustom(true);
         $theme->setSiteId($site->getSiteId());
     }
     $unixName = WDStringUtils::toUnixName($name);
     $theme->setName($name);
     $theme->setSyncPageName($pageName);
     $theme->setExtendsThemeId($parentThemeId);
     if ($unixName != $theme->getUnixName()) {
         $nameChanged = true;
         $oldName = $theme->getUnixName();
     }
     $theme->setUnixName($unixName);
     $theme->setUseSideBar($useSideBar);
     $theme->setUseTopBar($useTopBar);
     if ($nameChanged && $oldName != '') {
         $cmd = "rm -r " . escapeshellarg($site->getLocalFilesPath() . "/theme/" . $oldName);
         exec($cmd);
     }
     // handle code now
     $dir = WIKIDOT_ROOT . "/web/files--sites/" . $site->getUnixName() . "/theme/" . $unixName;
     mkdirfull($dir);
     file_put_contents($dir . "/style.css", $code);
     $theme->setRevisionNumber($theme->getRevisionNumber() + 1);
     $theme->save();
     $outdater = new Outdater();
     $outdater->themeEvent("theme_save", $theme);
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }