function render() { // check if there is a notification for the article set up by this user if ($this->_article) { $notifications = new ArticleNotifications(); $userNotification = $notifications->getUserArticleNotification($this->_article->getId(), $this->_blogInfo->getId(), $this->_userInfo->getId()); // decide wether or not we should notify the user based on what we've just // fetched from the database if ($userNotification) { $this->setValue("sendNotification", true); } else { $this->setValue("sendNotification", false); } // set information about the post itself into the view $this->setValue("postTopic", $this->_article->getTopic()); $this->setValue("postText", preg_replace('/&/', '&', $this->_article->getIntroText())); $this->setValue("postExtendedText", preg_replace('/&/', '&', $this->_article->getExtendedText())); $this->setValue("postSlug", $this->_article->getPostSlug()); $this->setValue("postId", $this->_article->getId()); if ($this->_article->getCommentsEnabled()) { $commentsEnabled = true; } else { $commentsEnabled = false; } $this->setValue("postCommentsEnabled", $commentsEnabled); $this->setValue("postCategories", $this->_article->getCategoryIds()); $this->setValue("postStatus", $this->_article->getStatus()); // we need to play a bit with the values of the fields, as the editpost.template page is // expecting them in a bit different way than if we just do an $article->getFields() $customFieldValues = $this->_article->getFields(); $customField = array(); foreach ($customFieldValues as $fieldValue) { $customField[$fieldValue->getFieldId()] = $fieldValue->getValue(); } $this->setValue("customField", $customField); // related to the date $postDate = $this->_article->getDateObject(); $this->setValue("postYear", $postDate->getYear()); $this->setValue("postMonth", $postDate->getMonth()); $this->setValue("postDay", $postDate->getDay()); $this->setValue("postHour", $postDate->getHour()); $this->setValue("postMinutes", $postDate->getMinutes()); } // let our parent class do the rest... parent::render(); }
/** * Carries out the specified action */ function perform() { // fetch the data $this->_fetchCommonData(); $this->_postId = $this->_request->getValue("postId"); // fetch the old post $articles = new Articles(); $post = $articles->getBlogArticle($this->_postId, $this->_blogInfo->getId()); // there must be something wrong if we can't fetch the post that we are trying to update... if (!$post) { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_fetching_post")); $this->setCommonData(); return false; } // if we got it, update some fields $post->setTopic(stripslashes($this->_postTopic)); $postText = $this->_postText . POST_EXTENDED_TEXT_MODIFIER . $this->_postExtendedText; $post->setText(stripslashes($postText)); $post->setCategoryIds($this->_postCategories); $post->setStatus($this->_postStatus); $post->setDateObject($this->_postTimestamp); $post->setCommentsEnabled($this->_commentsEnabled); $post->setPostSlug($this->_postSlug); // 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, "", $post->getId(), $this->_blogInfo->getId(), -1); array_push($fields, $customField); } $post->setFields($fields); } // fire the pre event $this->notifyEvent(EVENT_PRE_POST_UPDATE, array("article" => &$post)); // and finally save the post to the database if (!$articles->updateArticle($post)) { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_updating_post")); $this->setCommonData(); return false; } // clean up the cache CacheControl::resetBlogCache($this->_blogInfo->getId()); // create the definitive view $this->_view = new AdminPostsListView($this->_blogInfo); // show a message saying that the post was updated $message = $this->_locale->pr("post_updated_ok", $post->getTopic()); // check if there was a previous notification $notifications = new ArticleNotifications(); $artNotification = $notifications->getUserArticleNotification($this->_postId, $this->_blogInfo->getId(), $this->_userInfo->getId()); // check if we have to add or remove a notification if ($this->_sendNotification) { if (!$artNotification) { // if there wasn't one and now we want it, we have to add it $notifications->addNotification($this->_postId, $this->_blogInfo->getId(), $this->_userInfo->getId()); $message .= " " . $this->_locale->tr("notification_added"); } } else { // if we don't want notifications, then we have to check if there is one since we // should remove it if ($artNotification) { $notifications->deleteNotification($this->_postId, $this->_blogInfo->getId(), $this->_userInfo->getId()); $message .= " " . $this->_locale->tr("notification_removed"); } } // if the "send xmlrpc pings" checkbox was enabled, do something about it... if ($post->getStatus() == POST_STATUS_PUBLISHED) { // get the links from the text of the post $postLinks = StringUtils::getLinks(stripslashes($post->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 ($this->_sendPings) { $message .= "<br/><br/>" . $this->sendXmlRpcPings(); } // and now check what to do with the trackbacks if ($this->_sendTrackbacks) { // 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"); // get the links from the text of the post $this->_view->setValue("post", $post); $this->_view->setValue("postLinks", $postLinks); $this->_view->setValue("trackbackLinks", $trackbackLinks); } } } // show the message $this->_view->setSuccessMessage($message); // and fire the post event $this->notifyEvent(EVENT_POST_POST_UPDATE, array("article" => &$post)); $this->setCommonData(); return true; }