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;
 }
 /**
  * @private
  *
  * returns the id of the post or 'false' if it couldn't be saved
  */
 function _savePostData($article)
 {
     $status = $this->_postStatus;
     $articles = new Articles();
     $article->setFields($this->_getArticleCustomFields());
     // notifiy about this event
     $this->notifyEvent(EVENT_PRE_POST_ADD, array("article" => &$article));
     // in case the post is already in the db
     if ($this->_postId != "") {
         $article->setId($this->_postId);
         $artId = $this->_postId;
         $postSavedOk = $articles->updateArticle($article);
         if ($postSavedOk) {
             $artId = $this->_postId;
         } else {
             $artId = false;
         }
     } else {
         $artId = $articles->addArticle($article);
     }
     return $artId;
 }
 function _addPost($data, $_debug)
 {
     if ($data["title"] == NULL) {
         $data["title"] = "No Title Entered.";
     }
     if ($data["text"] == NULL) {
         $data["text"] = "No Body Entered.";
     }
     if ($data["category"] == NULL) {
         $data["category"] = 1;
     }
     if ($data["user_id"] == NULL) {
         $data["user_id"] = 1;
     }
     if ($data["blog_id"] == NULL) {
         $data["blog_id"] = 1;
     }
     if ($data["status"] == NULL) {
         $data["status"] = POST_STATUS_PUBLISHED;
     }
     if ($data["comments"] == NULL) {
         $data["comments"] = true;
     }
     $articles = new Articles();
     // verify that article does not exist in database
     $artss = $articles->getBlogArticles($data["blog_id"]);
     $exists = 0;
     foreach ($artss as $art) {
         if ($art->getTopic() == $data["title"]) {
             $exists = $art->getId();
             break;
         }
     }
     /*
     $exists = $articles->getBlogArticleByTitle( 
     			TextFilter::urlize($data["title"]) ,
     			$data["blog_id"], 
     			true, -1 -1 -1, POST_STATUS_PUBLISHED );
     
     if (!$exists) 
     {
     	$exists = $articles->getBlogArticleByTitle( 
     			TextFilter::urlize($data["title"]) ,
     			$data["blog_id"], 
     			true, -1 -1 -1, POST_STATUS_DRAFT );
     }
     */
     if (!$exists) {
         // verify that desired post id does not exist.  Otherwise, create new id.
         if (!$articles->getUserArticle($data["id"])) {
             $post_id = $data["id"];
         }
         if ($_debug) {
             print "--- --- adding post " . $data["title"] . " to db.<br />\n\r";
         }
         $cat[0] = $data["category"];
         $article = new Article($data["title"], $data["text"], $cat, $data["user_id"], $data["blog_id"], $data["status"], 0);
         if ($data["date"]) {
             $article->setDate($data["date"]);
         }
         if ($post_id) {
             $article->setId($post_id);
         }
         $article->setCommentsEnabled($data["comments"]);
         $artId = $articles->addArticle($article);
         $this->_stats["posts"]["write"]++;
         // remap comments to $artId
         if ($this->_container["comments"]) {
             foreach ($this->_t_container["comments"] as $comment => $val) {
                 if ($this->container["comments"][$comment]["article_id"] == $data["id"] || $val["article_id"] == NULL) {
                     $this->_container["comments"][$comment]["article_id"] = $artId;
                     if ($_debug) {
                         print "--- --- remapping comment entry #" . $comment . " to proper article id<br />\n\r";
                     }
                 }
             }
         }
     } else {
         $artId = $exists;
         if ($_debug) {
             print "--- --- post already exists, aborting operation.<br />\n\r";
         }
     }
     return $artId;
 }
Пример #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;
 }
 function perform()
 {
     $status = POST_STATUS_DRAFT;
     $articles = new Articles();
     $postText = Textfilter::xhtmlize($this->_postText) . POST_EXTENDED_TEXT_MODIFIER . Textfilter::xhtmlize($this->_postExtendedText);
     $article = new Article($this->_postTopic, $postText, $this->_postCategories, $this->_userInfo->getId(), $this->_blogInfo->getId(), $status, 0, array(), $this->_postSlug);
     // set also the date before it's too late
     $article->setDateObject($this->_postTimestamp);
     $article->setCommentsEnabled($this->_commentsEnabled);
     // prepare the custom fields
     $fields = array();
     if (is_array($this->_customFields)) {
         foreach ($this->_customFields as $fieldId => $fieldValue) {
             // 3 of those parameters are not really need when creating a new object... it's enough that
             // we know the field definition id.
             $customField = new CustomFieldValue($fieldId, $fieldValue, "", -1, "", $artId, $this->_blogInfo->getId(), -1);
             array_push($fields, $customField);
         }
         $article->setFields($fields);
     }
     // in case the post is already in the db
     if ($this->_postId != "") {
         $article->setId($this->_postId);
         $postSavedOk = $articles->updateArticle($article);
         if ($postSavedOk) {
             $artId = $this->_postId;
         } else {
             $artId = false;
         }
     } else {
         $artId = $articles->addArticle($article);
     }
     // once we have built the object, we can add it to the database
     $this->_view = new AdminXmlView($this->_blogInfo, "response");
     $this->_view->setValue("method", "saveXmlDraft");
     if ($artId) {
         $this->_view->setValue("result", $artId);
     } else {
         $this->_view->setValue("result", "0");
     }
     return true;
 }
Пример #6
0
    if ($curItem < $numItems) {
        $markup .= "<br/><br/>";
    }
    MoblogLogger::log("Adding markup {$markup}");
    $postBody .= $markup;
    $postBody = TextFilter::autoP(trim($postBody));
    $resNames .= $resource->getDescription();
}
// add the article
$articles = new Articles();
$article = new Article($request->getTopic(), $postBody, array($category->getId()), $userInfo->getId(), $blogInfo->getId(), POST_STATUS_PUBLISHED, 0);
$article->setDateObject(new Timestamp());
// enable or disable comments by default depending on the current config
$commentsEnabled = $blogSettings->getValue("comments_enabled");
$article->setCommentsEnabled($commentsEnabled);
$result = $articles->addArticle($article);
// add an article notification
$notifications = new ArticleNotifications();
$notifications->addNotification($result, $blogInfo->getId(), $userInfo->getId());
// reset the cache in case it is enabled
CacheControl::resetBlogCache($blogInfo->getId());
if (!$result) {
    $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Error", "There was an error adding the post to the database.");
    MoblogLogger::log("There was an error adding the post to the database.");
} else {
    $responseBody = "Post was successfully added to the database with topic '" . $request->getTopic() . "\n\n";
    if (count($request->getAttachments()) > 0) {
        $responseBody .= "The following attachments have been added:\n\n";
        $responseBody .= $resNames;
    }
    $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Success", $responseBody);
 /**
  * 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;
 }