$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 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"); }