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();
 }
$trackbacks = new TrackBacks();
// create teh trackback object
$now = new Timestamp();
$trackback = new Trackback($url, $title, $articleId, $excerpt, $blogName, $now->getTimestamp());
// throw the event in case somebody is listening to it!
$pm->notifyEvent(EVENT_PRE_TRACKBACK_ADD, array("trackback" => &$trackback));
$result = $trackbacks->addTrackBack($trackback);
if (!$result) {
    trackbackLog("There was an error saving the trackback!");
}
// throw the post event too...
$pm->notifyEvent(EVENT_POST_TRACKBACK_ADD, array("trackback" => &$trackback));
// result
$result = '<?xml version="1.0" encoding="iso-8859-1"?>';
$result .= '<response>';
$result .= '<error>0</error>';
$result .= '</response>';
// notify the user that a new trackback has been received, if the article was
// configured to receive notifications
// but first make sure, the trackback was not removed by some plugins like validatetrackback...
if ($trackbacks->getArticleTrackback($trackback->getId())) {
    $notifier = new ArticleNotifications();
    $notifier->notifyUsers($article->getId(), $blogInfo);
}
// clear the blog cache
CacheControl::resetBlogCache($article->getBlog());
// return the result
print $result;
trackbackLog("Sending response: {$result}");
trackbackLog("** End");
die;
 /**
  * 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;
 }
Example #4
0
    }
    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);
    MoblogLogger::log("Post was successfully added to the database.");
}
 /**
  * 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;
 }
 /**
  * Carries out the action
  */
 function perform()
 {
     // need to check the ip of the client
     $clientIp = Client::getIp();
     // fetch the same article again so that we can have all the comments from
     // the database, plus this last one
     $articles = new Articles();
     $article = $articles->getBlogArticle($this->_articleId, $this->_blogInfo->getId());
     // check if the user wanted to receive comments for this article
     // or not...
     if ($article->getCommentsEnabled() == false) {
         $this->_view = new ErrorView($this->_blogInfo);
         $this->_view->setValue("message", "Comments have been disabled for this article.");
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_LOADED, array("article" => &$article));
     // we have already checked all the data, so we are sure that everything's in place
     $comments = new ArticleComments();
     $comment = new UserComment($this->_articleId, $this->_parentId, $this->_commentTopic, $this->_commentText, null, $this->_userName, $this->_userEmail, $this->_userUrl, $clientIp);
     // check if there is already a comment with the same text, topic and made from the same
     // IP already in the database because if so, then we will not add the comment that
     // the user is trying to add (a reload button mistake, perhaps?)
     if (!$comments->getIdenticalComment($this->_commentTopic, $this->_commentText, $this->_articleId, $this->_parentId, $this->_userName, $this->_userEmail, $this->_userUrl, $clientIp)) {
         // fire an event
         $this->notifyEvent(EVENT_PRE_COMMENT_ADD, array("comment" => &$comment));
         if (!$comments->addComment($comment)) {
             // show an error message if problems
             $this->_view = new ErrorView($this->_blogInfo);
             $this->_view->setValue("message", "error_adding_comment");
             $this->setCommonData();
             return false;
         }
     }
     // finally, check if there was any user who wanted to be notified of new comments
     // to this post...
     $notifier = new ArticleNotifications();
     $notifier->notifyUsers($article->getId(), $this->_blogInfo);
     // fire the post event...
     $this->notifyEvent(EVENT_POST_COMMENT_ADD, array("comment" => &$comment));
     //
     // clear caches. This should be done in a more granular way, because right now
     // we're either removing *all* of them or none. I guess we should only remove the
     // cache whose identifier corresponds with the blog and article that we just removed,
     // but let's leave it as it is for the time being...
     //
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     // clean up the request, there's a parameter called 'userName' also used by
     // ViewArticleAction but that doesn't have the same meaning so we better remove it
     // before it's too late! We also need to add a new request commentUserName to replace
     // original userName, in case developer need it in filter or event plugin.
     $request = HttpVars::getRequest();
     $request["commentUserName"] = $request["userName"];
     $request["userName"] = "";
     HttpVars::setRequest($request);
     // forward the action to ViewArticleAction
     return BlogController::setForwardAction("ViewArticle");
 }