/**
  * show the contents of the view
  */
 function render()
 {
     // load the comments and throw the correct event
     $comments = new ArticleComments();
     $postComments = $comments->getPostComments($this->_article->getId(), COMMENT_ORDER_NEWEST_FIRST, $this->_commentStatus, $this->_page, DEFAULT_ITEMS_PER_PAGE);
     $this->notifyEvent(EVENT_COMMENTS_LOADED, array("comments", &$postComments));
     // number of comments
     $numPostComments = $comments->getNumPostComments($this->_article->getId(), $this->_commentStatus);
     if ($this->_commentStatus > -1) {
         $pagerUrl = "?op=editComments&articleId=" . $this->_article->getId() . "&showStatus=" . $this->_commentStatus . "&page=";
     } else {
         $pagerUrl = "?op=editComments&articleId=" . $this->_article->getId() . "&page=";
     }
     // calculate the pager url
     $pager = new Pager($pagerUrl, $this->_page, $numPostComments, DEFAULT_ITEMS_PER_PAGE);
     // get a list with all the different comment status
     $statusList = ArticleCommentStatus::getStatusList(true);
     // and pass all the information to the templates
     $this->setValue("comments", $postComments);
     $this->setValue("commentstatus", $statusList);
     $this->setValue("currentstatus", $this->_commentStatus);
     // pass the pager to the view
     $this->setValue("pager", $pager);
     +$this->setValue("post", $this->_article);
     parent::render();
 }
 function perform()
 {
     // fetch the data and make some arrangements if needed
     $this->_parentId = $this->_request->getValue("parentId");
     $this->_articleId = $this->_request->getValue("articleId");
     if ($this->_parentId < 0 || $this->_parentId == "") {
         $this->_parentId = 0;
     }
     // check if comments are enabled
     $blogSettings = $this->_blogInfo->getSettings();
     if (!$blogSettings->getValue("comments_enabled")) {
         $this->_view = new ErrorView($this->_blogInfo, "error_comments_not_enabled");
         $this->setCommonData();
         return false;
     }
     // fetch the article
     $blogs = new Blogs();
     $articles = new Articles();
     $article = $articles->getBlogArticle($this->_articleId, $this->_blogInfo->getId());
     // if there was a problem fetching the article, we give an error and quit
     if ($article == false) {
         $this->_view = new ErrorView($this->_blogInfo);
         $this->_view->setValue("message", "error_fetching_article");
         $this->setCommonData();
         return false;
     }
     $this->_view = new BlogView($this->_blogInfo, "commentarticle", SMARTY_VIEW_CACHE_CHECK, array("articleId" => $this->_articleId, "parentId" => $this->_parentId));
     // do nothing if the view was already cached
     if ($this->_view->isCached()) {
         return true;
     }
     // fetch the comments so far
     $comments = new ArticleComments();
     $postComments = $comments->getPostComments($article->getId());
     if ($this->_parentId > 0) {
         // get a pre-set string for the subject field, for those users interested
         $comment = $comments->getPostComment($article->getId(), $this->_parentId);
         // create the string
         if ($comment) {
             $replyString = $this->_locale->tr("reply_string") . $comment->getTopic();
             $this->_view->setValue("comment", $comment);
         }
     }
     // if everything's fine, we set up the article object for the view
     $this->_view->setValue("post", $article);
     $this->_view->setValue("parentId", $this->_parentId);
     $this->_view->setValue("comments", $postComments);
     $this->_view->setValue("postcomments", $postComments);
     $this->_view->setValue("topic", $replyString);
     $this->setCommonData();
     // and return everything normal
     return true;
 }
 function _addComment($data, $_debug)
 {
     if ($data["article_id"] == NULL) {
         $data["article_id"] = 1;
     }
     if ($data["parent_id"] == NULL) {
         $data["parent_id"] = 0;
     }
     if ($data["topic"] == NULL) {
         $data["topic"] = "No Topic";
     }
     if ($data["text"] == NULL) {
         $data["text"] = "No Comment";
     }
     if ($data["date"] == NULL) {
         $data["date"] = now();
     }
     if ($data["user_name"] == NULL) {
         $data["user_name"] = "";
     }
     if ($data["user_email"] == NULL) {
         $data["user_email"] = "";
     }
     if ($data["user_url"] == NULL) {
         $data["user_url"] = "";
     }
     if ($data["client_ip"] == NULL) {
         $data["client_ip"] = "0.0.0.0";
     }
     $coms = new ArticleComments();
     $com = $coms->getPostComments($data["article_id"]);
     if ($com) {
         foreach ($com as $artcom) {
             if ($artcom->getText() == $data["text"]) {
                 if ($_debug) {
                     print "--- --- comment already exists, abort.<br />\n\r";
                 }
                 return $artcom->getId();
             }
         }
     }
     //(article_id, `topic`, `text`, `date`, user_email, user_url, user_name, client_ip)
     $com = new UserComment($data["article_id"], $data["parent_id"], $data["topic"], $data["text"], $data["date"], $data["user_name"], $data["user_email"], $data["user_url"], $data["client_ip"]);
     $comments = new ArticleComments();
     $comment_id = $comments->addComment($com);
     $this->_stats["comments"]["write"]++;
     return $comment_id;
 }
 /**
  * Returns an array of UserComment objects, with all the comments that have been received for
  * this article.
  *
  * @param onlyActive return only those comments that are not marked as spam
  * @return An array of UserComment objects.
  * @see UserComment
  */
 function getComments($onlyActive = true)
 {
     // load the comments if they haven't been loaded yet
     if ($this->_comments == null) {
         $userComments = new ArticleComments();
         $blogSettings = $this->_blogInfo->getSettings();
         $this->setComments($userComments->getPostComments($this->getId(), $blogSettings->getValue('comments_order'), COMMENT_STATUS_ALL));
     }
     // if we only want to return the active ones, then we have to loop through
     // the array once more
     if ($onlyActive) {
         $comments = array();
         foreach ($this->_comments as $comment) {
             if ($comment->getStatus() == COMMENT_STATUS_NONSPAM) {
                 $comments[] = $comment;
             }
         }
     } else {
         $comments = $this->_comments;
     }
     return $comments;
 }