/** * Carries out the specified action */ function perform() { //print_r($_REQUEST); // fetch all the information that we need for the dummy Article object $this->_fetchCommonData(); // and now, create a harmless Article object with it $postText = Textfilter::xhtmlize($this->_postText) . POST_EXTENDED_TEXT_MODIFIER . Textfilter::xhtmlize($this->_postExtendedText); // create the main object $article = new Article($this->_postTopic, $postText, $this->_postCategories, $this->_userInfo->getId(), $this->_blogInfo->getId(), $status, 0, array(), $this->_postSlug); // and a few more properties that we need to know about $this->_fetchPostDateInformation(); $article->setDateObject($this->_postTimestamp); // we will not allow comments because it wouldn't work! $article->setCommentsEnabled(false); $article->setFields($this->_getArticleCustomFields()); // the next two fields are also required in order to show an article $article->setUserInfo($this->_userInfo); $article->setBlogInfo($this->_blogInfo); $article->setCategories($this->_loadArticleCategories($this->_postCategories)); // and now trick the ViewArticleView class into thinking that we're showing // a real article just fetched from the database (even though it makes no difference // to the class itself whence the article came from :) // the 'random' parameter in the array is to provide the view with a random view id // every time that we run the preview, otherwise when caching is enabled we would always be // getting the same page!! $this->_view = new ViewArticleView($this->_blogInfo, array('random' => md5(time()))); $this->_view->setArticle($article); //$this->setCommonData(); 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; }