function perform()
 {
     // fetch the validated data
     $this->_blogName = Textfilter::filterAllHTML($this->_request->getValue("blogName"));
     $this->_ownerId = $this->_request->getValue("blogOwner");
     $this->_blogProperties = $this->_request->getValue("properties");
     // check that the user really exists
     $users = new Users();
     $userInfo = $users->getUserInfoFromId($this->_ownerId);
     if (!$userInfo) {
         $this->_view = new AdminCreateBlogView($this->_blogInfo);
         $this->_form->setFieldValidationStatus("blogOwner", false);
         $this->setCommonData(true);
         return false;
     }
     // now that we have validated the data, we can proceed to create the user, making
     // sure that it doesn't already exists
     $blogs = new Blogs();
     $blog = new BlogInfo($this->_blogName, $this->_ownerId, "", "");
     $blog->setProperties($this->_blogProperties);
     $this->notifyEvent(EVENT_PRE_BLOG_ADD, array("blog" => &$blog));
     $newBlogId = $blogs->addBlog($blog);
     if (!$newBlogId) {
         $this->_view = new AdminCreateBlogView($this->_blogInfo);
         $this->_form->setFieldValidationStatus("blogName", false);
         $this->setCommonData();
         return false;
     }
     // add a default category and a default post
     $articleCategories = new ArticleCategories();
     $articleCategory = new ArticleCategory("General", "", $newBlogId, true);
     $catId = $articleCategories->addArticleCategory($articleCategory);
     $config =& Config::getConfig();
     $locale =& Locales::getLocale($config->getValue("default_locale"));
     $articleTopic = $locale->tr("register_default_article_topic");
     $articleText = $locale->tr("register_default_article_text");
     $article = new Article($articleTopic, $articleText, array($catId), $this->_ownerId, $newBlogId, POST_STATUS_PUBLISHED, 0, array(), "welcome");
     $t = new Timestamp();
     $article->setDateObject($t);
     $articles = new Articles();
     $articles->addArticle($article);
     // and inform everyone that everything went ok
     $this->notifyEvent(EVENT_POST_BLOG_ADD, array("blog" => &$blog));
     $this->_view = new AdminSiteBlogsListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("blog_added_ok", $blog->getBlog()));
     $this->setCommonData();
     return true;
 }
 function _addJournal($data, $_debug)
 {
     // blog, $owner, $about, $settings, $id = -1      * <li>locale</li>
     if ($data["name"] == NULL) {
         $data["name"] = "Journal";
     }
     if ($data["owner"] == NULL) {
         $data["owner"] = 1;
     }
     if ($data["about"] == NULL) {
         $data["about"] = "About...";
     }
     // if ($data["blog_id"]	== NULL)  $data["blog_id"]	= NULL;
     /*
     				Individual Blog Settings have been disabled in favor of using the
     				BlogSettings::_setDefaults() method to generate preferences based
     				on admin settings.
     	if ($data["locale"]   	== NULL)  $data["locale"]	= "EN_UK";
     				if ($data["template"] 	== NULL)  $data["template"] 	= "blueish";
     				if ($data["show_more"]	== NULL)  $data["show_more"]	= 0;
     				if ($data["threshold"]	== NULL)  $data["threshold"]	= 50;
     				if ($data["recent"]	== NULL)  $data["recent"]	= 10;
     				if ($data["xmlrpc"]	== NULL)  $data["xmlrpc"]	= 0;
     				if ($data["htmlarea"]	== NULL)  $data["htmlarea"]	= 1;
     				if ($data["comments"]	== NULL)  $data["comments"]	= 1;
     				if ($data["order"]	== NULL)  $data["order"]	= 1;
     */
     $blogs = new Blogs();
     if ($data["blog_id"]) {
         $blog = $blogs->getBlogInfoByName(TextFilter::urlize($data["name"]));
         if ($blog) {
             if ($blog->getId() == $data["blog_id"]) {
                 if ($_debug) {
                     print "--- --- blog " . $blog->getBlog() . " already exists at the proper id (" . $blog->getId() . ").  next entry.<br />\n\r";
                 }
                 return $blog->getId();
             } else {
                 if ($_debug) {
                     print "--- --- blog " . $blog->getBlog() . " already exists, but at a new id (" . $blog->getId() . ").  skip to remap.<br />\n\r";
                 }
                 $blog_id = $blog->getId();
             }
         }
     }
     if (!$blog_id) {
         $blog = new BlogInfo($data["name"], $data["owner"], $data["about"], "", $data["blog_id"]);
         $blog_id = $blogs->addBlog($blog);
         if ($_debug) {
             print "--- blog " . $blog->getBlog() . " created at a new id (" . $blog_id . ").  proceed to remap.<br />\n\r";
         }
         $this->_stats["blogs"]["write"]++;
     }
     // remap categories
     foreach ($this->_t_container["categories"] as $category => $val) {
         if ($val["blog_id"] == $data["blog_id"] || $val["blog_id"] == NULL) {
             if ($_debug) {
                 print "--- --- --- remapping category #" . $category . " to the proper blog id.<br />\n\r";
             }
             $this->_container["categories"][$category]["blog_id"] = $blog_id;
         }
     }
     // remap articles
     foreach ($this->_t_container["posts"] as $post => $val) {
         if ($val["blog_id"] == $data["blog_id"] || $val["blog_id"] == NULL) {
             if ($_debug) {
                 print "--- --- --- remapping post #" . $post . " to the proper blog id.<br />\n\r";
             }
             $this->_container["posts"][$post]["blog_id"] = $blog_id;
         }
     }
     return $blog_id;
 }
示例#3
0
 function perform()
 {
     // retrieve the values from the view
     $this->_blogName = $this->_request->getValue("blogName");
     $this->_ownerId = $this->_request->getValue("ownerid");
     $this->_blogProperties = $this->_request->getValue("properties");
     $this->_blogTemplate = $this->_request->getValue("blogTemplate");
     $this->_blogLocale = $this->_request->getValue("blogLocale");
     // configure the blog
     $blogs = new Blogs();
     $blog = new BlogInfo($this->_blogName, $this->_ownerId, "", "");
     $blog->setProperties($this->_blogProperties);
     $blog->setStatus(BLOG_STATUS_ACTIVE);
     $blogSettings = $blog->getSettings();
     $blogSettings->setValue("locale", $this->_blogLocale);
     $blogSettings->setValue("template", $this->_blogTemplate);
     $blog->setSettings($blogSettings);
     // and now save it to the database
     $newblogId = $blogs->addBlog($blog);
     if (!$newblogId) {
         $this->_view = new WizardView("step4");
         $this->_view->setValue("siteLocales", Locales::getLocales());
         $ts = new TemplateSets();
         $this->_view->setValue("siteTemplates", $ts->getGlobalTemplateSets());
         $this->_view->setErrorMessage("There was an error creating the new blog");
         $this->setCommonData(true);
         return false;
     }
     // if the blog was created, we can add some basic information
     // add a category
     $articleCategories = new ArticleCategories();
     $articleCategory = new ArticleCategory("General", "", $newblogId, true);
     $catId = $articleCategories->addArticleCategory($articleCategory);
     // load the right locale
     $locale =& Locales::getLocale($this->_blogLocale);
     // and load the right text
     $articleTopic = $locale->tr("register_default_article_topic");
     $articleText = $locale->tr("register_default_article_text");
     $article = new Article($articleTopic, $articleText, array($catId), $this->_ownerId, $newblogId, POST_STATUS_PUBLISHED, 0, array(), "welcome");
     $t = new Timestamp();
     $article->setDateObject($t);
     $articles = new Articles();
     $articles->addArticle($article);
     // save a few things in the default configuration
     $config =& Config::getConfig();
     // default blog id
     $config->saveValue("default_blog_id", (int) $newblogId);
     // default locale
     $config->saveValue("default_locale", $this->_blogLocale);
     // and finally, the default template
     $config->saveValue("default_template", $this->_blogTemplate);
     //
     // detect wether we have GD available and set the blog to use it
     //
     if (GdDetector::detectGd()) {
         $config->saveValue("thumbnail_method", "gd");
         $message = "GD has been detected and set as the backend for dealing with images.";
     } else {
         $pathToConvert = $config->getValue("path_to_convert");
         if ($pathToConvert) {
             $config->saveValue("thumbnail_method", "imagemagick");
             $message = "ImageMagick has been detected and set as the backend for dealing with images.";
         } else {
             // nothing was found, so we'll have to do away with the 'null' resizer...
             $config->saveValue("thumbnail_method", "null");
             $message = "Neither GD nor ImageMagick have been detected in this host so it will not be possible to generate thumbnails from images.";
         }
     }
     $this->_view = new WizardView("step5");
     $this->_view->setValue("message", $message);
     return true;
 }
 /**
  * create the blog
  */
 function createBlog($userId)
 {
     $this->blogName = stripslashes($this->_request->getValue("blogName"));
     $this->blogLocale = $this->_request->getValue("blogLocale");
     $this->templateId = $this->_request->getValue("templateId");
     // get the default locale configured for the site
     $blogs = new Blogs();
     $blogInfo = new BlogInfo($this->blogName, $userId, "", "");
     if ($this->need_confirm == 1) {
         $blogInfo->setStatus(BLOG_STATUS_UNCONFIRMED);
     } else {
         $blogInfo->setStatus(BLOG_STATUS_ACTIVE);
     }
     $locale = Locales::getLocale($this->blogLocale);
     $blogInfo->setLocale($locale);
     $blogInfo->setTemplate($this->templateId);
     $newblogId = $blogs->addBlog($blogInfo);
     if (!$newblogId) {
         $this->_view = new SummaryView("registererror");
         $this->_view->setErrorMessage($this->_locale->tr("error_creating_blog"));
         return false;
     }
     // get info about the blog
     $blogInfo = $blogs->getBlogInfo($newblogId);
     $this->_blogInfo = $blogInfo;
     // if the blog was created, we can add some basic information
     // add a category
     $articleCategories = new ArticleCategories();
     $articleCategory = new ArticleCategory($locale->tr("register_default_category"), "", $newblogId, true);
     $catId = $articleCategories->addArticleCategory($articleCategory);
     // add an article based on that category
     $articleTopic = $locale->tr("register_default_article_topic");
     $articleText = $locale->tr("register_default_article_text");
     $article = new Article($articleTopic, $articleText, array($catId), $userId, $newblogId, POST_STATUS_PUBLISHED, 0, array(), "welcome");
     $article->setDateObject(new Timestamp());
     // set it to the current date
     $article->setCommentsEnabled(true);
     // enable comments
     $articles = new Articles();
     $articles->addArticle($article);
     return true;
 }