public function execute()
 {
     $this->getResponse()->addHeader('Content-type', 'application/json');
     if ($comment_id = $this->getRequest()->post('id', 0, waRequest::TYPE_INT)) {
         $comment_model = new blogCommentModel();
         $comment = $comment_model->getById($comment_id);
         if (!$comment) {
             throw new waException(_w('Comment not found'), 404);
         }
         $post_model = new blogPostModel();
         if (!($post = $post_model->getBlogPost(array('id' => $comment['post_id'], 'blog_id' => $comment['blog_id'])))) {
             throw new waException(_w('Post not found'), 404);
         }
         $user_id = $this->getUser()->getId();
         $rights = blogHelper::checkRights($comment['blog_id'], $user_id, blogRightConfig::RIGHT_READ_WRITE);
         if ($rights == blogRightConfig::RIGHT_READ_WRITE && $user_id != $post['contact_id']) {
             throw new waRightsException(_w('Access denied'), 403);
         }
         $status = $this->getRequest()->post('status', blogCommentModel::STATUS_DELETED);
         if ($status != blogCommentModel::STATUS_DELETED) {
             $status = blogCommentModel::STATUS_PUBLISHED;
         }
         $changed = $comment_model->updateById($comment_id, array('status' => $status));
         $count = $comment_model->getCount($comment['blog_id'], $comment['post_id']);
         if ($changed) {
             if ($status == blogCommentModel::STATUS_DELETED) {
                 $this->log('comment_delete', 1);
             } else {
                 $this->log('comment_restore', 1);
             }
         }
         $this->response = array('count_str' => $count . " " . _w('comment', 'comments', $count), 'status' => $status, 'changed' => $changed);
     }
 }
 public function execute()
 {
     $comment_id = (int) waRequest::post('spam');
     $comment_model = new blogCommentModel();
     $comment = $comment_model->getById($comment_id);
     $this->response['status'] = null;
     if ($comment) {
         $comment_model->updateById($comment_id, array('akismet_spam' => 1, 'status' => blogCommentModel::STATUS_DELETED));
         $this->response['status'] = blogCommentModel::STATUS_DELETED;
         $blog_plugin = wa()->getPlugin('akismet');
         $akismet = new Akismet(wa()->getRouting()->getUrl('blog', array(), true), $blog_plugin->getSettingValue('api_key'));
         $akismet->setCommentAuthor($comment['name']);
         $akismet->setCommentAuthorEmail($comment['email']);
         $akismet->setCommentContent($comment['text']);
         if (!waSystemConfig::isDebug() && $blog_plugin->getSettingValue('send_spam')) {
             $akismet->submitSpam();
         }
     }
 }
 public function execute()
 {
     $id = $this->post('id', true);
     if (!is_array($id)) {
         if (strpos($id, ',') !== false) {
             $id = array_map('intval', explode(',', $id));
         } else {
             $id = array($id);
         }
     }
     $user_id = wa()->getUser()->getId();
     $comment_model = new blogCommentModel();
     $post_model = new blogPostModel();
     $comments = $comment_model->getByField('id', $id, 'id');
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[] = $comment['post_id'];
     }
     $post_ids = array_unique($post_ids);
     $posts = $post_model->getByField('id', $post_ids, 'id');
     $available = array();
     foreach ($comments as $comment) {
         try {
             $rights = blogHelper::checkRights($comment['blog_id'], $user_id, blogRightConfig::RIGHT_READ_WRITE);
         } catch (Exception $e) {
             continue;
         }
         if ($rights == blogRightConfig::RIGHT_READ_WRITE && $user_id != $posts[$comment['post_id']]['contact_id']) {
             continue;
         }
         if ($comment['status'] == blogCommentModel::STATUS_DELETED) {
             continue;
         }
         $available[] = $comment['id'];
     }
     $comment_model->updateById($available, array('status' => blogCommentModel::STATUS_DELETED));
     $this->response = true;
 }