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;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the data, we already know it's valid and that we can trust it!
     $this->_categoryName = Textfilter::filterAllHTML($this->_request->getValue("categoryName"));
     $this->_categoryUrl = $this->_request->getValue("categoryUrl");
     $this->_categoryInMainPage = Textfilter::checkboxToBoolean($this->_request->getValue("categoryInMainPage"));
     $this->_categoryDescription = Textfilter::filterAllHTML($this->_request->getValue("categoryDescription"));
     $this->_properties = $this->_request->getValue("properties");
     // create the object...
     $categories = new ArticleCategories();
     $category = new ArticleCategory($this->_categoryName, $this->_categoryUrl, $this->_blogInfo->getId(), $this->_categoryInMainPage, $this->_categoryDescription, 0, $this->_properties);
     // fire the pre event...
     $this->notifyEvent(EVENT_PRE_CATEGORY_ADD, array("category" => &$category));
     // once we have built the object, we can add it to the database!
     if ($categories->addArticleCategory($category)) {
         // if everything went fine, transfer the execution flow to the action that
         // lists all the article categories... without forgetting that we should let the
         // next class know that we actually added a category alongside a message
         // and the category that we just added!
         $this->_view = new AdminArticleCategoriesListView($this->_blogInfo);
         $this->_view->setSuccess(true);
         $this->_view->setSuccessMessage($this->_locale->pr("category_added_ok", $category->getName()));
         // fire the post event
         $this->notifyEvent(EVENT_POST_CATEGORY_ADD, array("category" => &$category));
         // clear the cache if everything went fine
         CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
         $this->setCommonData();
     } else {
         // if there was an error, we should say so... as well as not changing the view since
         // we're going back to the original view where we can add the category
         $this->_view->setError(true);
         $this->_view->setErrorMessage($this->_locale->tr("error_adding_article_category"));
         $this->setCommonData(true);
     }
     // better to return true if everything fine
     return true;
 }
 function _addCategory($data, $_debug)
 {
     if ($data["name"] == NULL) {
         $data["name"] = "Category";
     }
     if ($data["url"] == NULL) {
         $data["url"] = "";
     }
     if ($data["blog_id"] == NULL) {
         $data["blog_id"] = 1;
     }
     if ($data["mainpage"] == NULL) {
         $data["mainpage"] = 1;
     }
     $cat = new ArticleCategory($data["name"], $data["url"], $data["blog_id"], $data["mainpage"]);
     $cats = new ArticleCategories();
     if (!($cat_id = $cats->getCategoryByName(TextFilter::urlize($data["name"]), $data["blog_id"]))) {
         $cat_id = $cats->addArticleCategory($cat);
         if ($_debug) {
             print "--- --- category " . $data["name"] . " added with id:  " . $cat_id . "<br />\n\r";
         }
         $this->_stats["categories"]["write"]++;
     } else {
         if ($_debug) {
             print "--- --- category " . $data["name"] . " already exists with id:  " . $cat_id->getId() . "<br />\n\r";
         }
         $cat_id = $cat_id->getId();
     }
     // remap posts' category attribute to the correct ids.
     foreach ($this->_t_container["posts"] as $post => $val) {
         if ($val["category"] == $data["id"] || $val["category"] == NULL && $this->_container["posts"][$post]["blog_id"] == $data["blog_id"]) {
             if ($_debug) {
                 print "--- --- --- remapping post entry #" . $post . " to proper category id<br />\n\r";
             }
             $this->_container["posts"][$post]["category"] = $cat_id;
         }
     }
     return $cat_id;
 }
예제 #4
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;
 }