public function post() { $app = JFactory::getApplication(); $my = $this->plugin->getUser(); $config = EasyBlogHelper::getConfig(); //$acl = EasyBlogACLHelper::getRuleSet(); $acl = EB::acl(); $post = $app->input->post->getArray(); if (empty($acl->rules->allow_comment) && (empty($my->id) && !$config->get('main_allowguestcomment'))) { $this->plugin->setResponse($this->getErrorResponse(500, JText::_('COM_EASYBLOG_NO_PERMISSION_TO_POST_COMMENT'))); } $isModerated = false; $parentId = isset($post['parent_id']) ? $post['parent_id'] : 0; $commentDepth = isset($post['comment_depth']) ? $post['comment_depth'] : 0; $blogId = isset($post['id']) ? $post['id'] : 0; $subscribeBlog = isset($post['subscribe-to-blog']) ? true : false; if (!$blogId) { $this->plugin->setResponse($this->getErrorResponse(404, 'Invalid Blog')); } // @task: Cleanup posted values. array_walk($post, array($this, '_trim')); array_walk($post, array($this, '_revertValue')); if (!$config->get('comment_require_email') && !isset($post['esemail'])) { $post['esemail'] = ''; } // @task: Run some validation tests on the posted values. if (!$this->_validateFields($post)) { $this->plugin->setResponse($this->getErrorResponse(500, $this->err[0])); } // @task: Akismet detection service. if ($config->get('comment_akismet')) { $data = array('author' => $post['esname'], 'email' => $post['esname'], 'website' => JURI::root(), 'body' => $post['comment'], 'permalink' => EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $post['id'])); if (EasyBlogHelper::getHelper('Akismet')->isSpam($data)) { $this->plugin->setResponse($this->getErrorResponse(500, JText::_('COM_EASYBLOG_SPAM_DETECTED_IN_COMMENT'))); } } // @task: Retrieve the comments model $model = EasyBlogHelper::getModel('Comment'); // @task: Retrieve the comment's table $comment = EasyBlogHelper::table('Comment'); // We need to rename the esname and esemail back to name and email. $post['post_id'] = $post['id']; $post['name'] = $post['esname']; $post['email'] = $post['esemail']; unset($post['id']); unset($post['esname']); unset($post['esemail']); // @task: Bind posted values into the table. $comment->bindPost($post); // @task: Process registrations $registerUser = isset($post['esregister']) ? true : false; $fullname = isset($post['name']) ? $post['name'] : ''; $username = isset($post['esusername']) ? $post['esusername'] : ''; $email = $post['email']; $message = ''; $newUserId = 0; // @task: Process registrations if necessary if ($registerUser && $my->id <= 0) { $state = $this->processRegistrations($post, $username, $email, $ajax); if (!is_numeric($state)) { $this->plugin->setResponse($this->getErrorResponse(500, $state)); } $newUserId = $state; } $totalComments = empty($post['totalComment']) ? 1 : $post['totalComment']; //$date = EasyBlogHelper::getDate(); $date = EasyBlogDate::getDate(); $comment->set('created', $date->toMySQL()); $comment->set('modified', $date->toMySQL()); $comment->set('published', 1); $comment->set('parent_id', $parentId); $comment->set('sent', 0); $comment->set('created_by', $my->id); // @rule: Update the user's id if they have just registered earlier. if ($newUserId != 0) { $comment->set('created_by', $newUserId); } // @rule: Update publish status if the comment requires moderation if ($config->get('comment_moderatecomment') == 1 || $my->id == 0 && $config->get('comment_moderateguestcomment') == 1) { $comment->set('published', EBLOG_COMMENT_STATUS_MODERATED); $isModerated = true; } $blog = EasyBlogHelper::table('Blog'); $blog->load($blogId); // If moderation for author is disabled, ensure that the comment is published. // If the author is the owner of the blog, it should never be moderated. if (!$config->get('comment_moderateauthorcomment') && $blog->created_by == $my->id) { $comment->set('published', 1); $isModerated = false; } if (!$comment->store()) { $this->plugin->setResponse($this->getErrorResponse(500, 'There was a problem saving the comment')); } // @rule: Process subscription for blog automatically when the user submits a new comment and wants to subscribe to the blog. if ($subscribeBlog && $config->get('main_subscription') && $blog->subscription) { $isSubscribed = false; $userId = $my->id; $blogModel = EasyblogHelper::getModel('Blog'); if ($userId == 0) { $sid = $blogModel->isBlogSubscribedEmail($blog->id, $email); if (empty($sid)) { $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, '', $fullname); } } else { $sid = $blogModel->isBlogSubscribedUser($blog->id, $userId, $email); if (!empty($sid)) { // @task: User found, update the email address $blogModel->updateBlogSubscriptionEmail($sid, $userId, $email); } else { $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, $userId, $fullname); } } } $row = $comment; $creator = EasyBlogHelper::table('Profile'); $creator->load($my->id); $row->poster = $creator; $row->comment = nl2br($row->comment); $row->comment = EasyBlogComment::parseBBCode($row->comment); $row->depth = is_null($commentDepth) ? '0' : $commentDepth; $row->likesAuthor = ''; // @rule: Process notifications $comment->processEmails($isModerated, $blog); //update the sent flag to sent $comment->updateSent(); // @TODO - Move this to a map comment function $item = new CommentSimpleSchema(); $item->commentid = $comment->id; $item->postid = $comment->post_id; $item->title = $comment->title; $item->text = EasyBlogComment::parseBBCode($comment->comment); $item->textplain = strip_tags(EasyBlogComment::parseBBCode($comment->comment)); $item->created_date = $comment->created; $item->created_date_elapsed = EasyBlogDate::getLapsedTime($comment->created); $item->updated_date = $comment->modified; // Author $item->author->name = isset($comment->poster->nickname) ? $comment->poster->nickname : $comment->name; $item->author->photo = isset($comment->poster->avatar) ? $comment->poster->avatar : 'default_blogger.png'; $item->author->photo = JURI::root() . 'components/com_easyblog/assets/images/' . $item->author->photo; $item->author->email = $comment->email; $item->author->website = isset($comment->poster->url) ? $comment->poster->url : $comment->url; $this->plugin->setResponse($item); }