/** * 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; }
function _fetchCommonData() { $this->_postText = trim(Textfilter::xhtmlize($this->_request->getValue("postText"))); $this->_postExtendedText = trim(Textfilter::xhtmlize($this->_request->getValue("postExtendedText"))); $this->_postTopic = trim(Textfilter::xhtmlize(Textfilter::filterAllHTML($this->_request->getValue("postTopic")))); $this->_postCategories = $this->_request->getValue("postCategories"); $this->_postSlug = trim(Textfilter::filterAllHTML($this->_request->getValue("postSlug"))); $this->_postStatus = $this->_request->getValue("postStatus"); $this->_sendNotification = $this->_request->getValue("sendNotification"); $this->_sendTrackbacks = $this->_request->getValue("sendTrackbacks"); $this->_sendPings = $this->_request->getValue("sendPings"); $this->_postId = $this->_request->getValue("postId"); $this->_commentsEnabled = $this->_request->getValue("commentsEnabled"); $this->_trackbackUrls = $this->_request->getValue("trackbackUrls"); // fetch the custom fields $this->_customFields = $this->_request->getValue("customField"); // fetch the timestamp that the post will have $this->_fetchPostDateInformation(); }
/** * Carries out the specified action */ function perform() { $this->_fetchCommonData(); $this->_postId = $this->_request->getValue("postId"); $this->_previewPost = $this->_request->getValue("previewPost"); $this->_addPost = $this->_request->getValue("addPost"); $this->_saveDraft = $this->_request->getValue("isDraft"); // we know for sure that the information is correct so we can now add // the post to the database $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(), $this->_postStatus, 0, array(), $this->_postSlug); // set also the date before it's too late $article->setDateObject($this->_postTimestamp); $article->setCommentsEnabled($this->_commentsEnabled); // save the article to the db $artId = $this->_savePostData($article); // once we have built the object, we can add it to the database if ($artId) { $this->_view = new AdminPostsListView($this->_blogInfo); //$article->setId( $artId ); $message = $this->_locale->tr("post_added_ok"); // train the filter BayesianFilterCore::trainWithArticle($article); // add the article notification if requested to do so if ($this->_sendNotification) { $artNotifications = new ArticleNotifications(); $artNotifications->addNotification($artId, $this->_blogInfo->getId(), $this->_userInfo->getId()); $message .= " " . $this->_locale->tr("send_notifications_ok"); } // we only have to send trackback pings if the article was published // otherwise there is no need to... $article->setId($artId); if ($article->getStatus() == POST_STATUS_PUBLISHED) { // get the output from the xmlrpc pings but only if the user decided to do so! if ($this->_sendPings) { $pingsOutput = $this->sendXmlRpcPings(); $message .= "<br/><br/>" . $pingsOutput; } // and now check what to do with the trackbacks if ($this->_sendTrackbacks) { // get the links from the text of the post $postLinks = StringUtils::getLinks(stripslashes($article->getText())); // get the real trackback links from trackbackUrls $trackbackLinks = array(); foreach (explode("\r\n", $this->_trackbackUrls) as $host) { trim($host); if ($host != "" && $host != "\r\n" && $host != "\r" && $host != "\n") { array_push($trackbackLinks, $host); } } // if no links, there is nothing to do if (count($postLinks) == 0 && count($trackbackLinks) == 0) { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_no_trackback_links_sent")); } else { $this->_view = new AdminTemplatedView($this->_blogInfo, "sendtrackbacks"); $this->_view->setValue("post", $article); $this->_view->setValue("postLinks", $postLinks); $this->_view->setValue("trackbackLinks", $trackbackLinks); } } $this->_view->setSuccessMessage($message); $this->notifyEvent(EVENT_POST_POST_ADD, array("article" => &$article)); // empty the cache used by this blog CacheControl::resetBlogCache($this->_blogInfo->getId()); } else { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setSuccessMessage($this->_locale->tr("post_added_not_published")); $this->notifyEvent(EVENT_POST_POST_ADD, array("article" => &$article)); } } else { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_adding_post")); } $this->setCommonData(); // better to return true if everything fine return true; }