/** * Public: Save new comment into database * * Returns id of new comment */ public function save() { // Email address validation tests are NOT handled here as different workflows may have different rules for auto validation $app = App::getInstance(); // If an update if ($this->pk && $this->fields[$this->pk]->getValue()) { return parent::save(); } $this->setIp($app['env']['REMOTE_ADDR']); $this->setUseragent($app['env']['HTTP_USER_AGENT']); $this->setReferer($app['env']['HTTP_REFERER']); if (!$this->getUser()) { // check key $key_check = $app['akismet']->keyCheck($app->getOption('akismet_api_key', ''), $app->getOption('base_url')); if ($key_check == false) { throw new \FelixOnline\Exceptions\InternalException('Akismet key is invalid'); } // check spam using akismet $check = $app['akismet']->check(array('permalink' => $this->getArticle()->getURL(), 'comment_type' => 'comment', 'comment_author' => $this->fields['name']->getValue(), 'comment_content' => $this->getComment(), 'comment_author_email' => $this->getEmail(), 'user_ip' => $this->getIp(), 'user_agent' => $this->getUseragent(), 'referrer' => $this->getReferer())); // check for akismet errors if (!is_null($app['akismet']->getError())) { throw new \FelixOnline\Exceptions\InternalException($app['akismet']->getError()); } if ($check == true) { // if comment is spam $this->setActive(0); $this->setPending(0); $this->setSpam(1); } else { // Not spam $this->setActive(1); $this->setPending(1); $this->setSpam(0); } } else { $this->setActive(1); $this->setPending(0); $this->setSpam(0); } parent::save(); if (!$this->getSpam()) { // Send emails if (!$this->getUser()) { $log_entry = new \FelixOnline\Core\AkismetLog(); $log_entry->setCommentId($this)->setAction('check')->setIsSpam($check)->setError($app['akismet']->getError())->save(); // If pending comment if (!$this->getSpam() && $this->getPending() && $this->getActive()) { $this->emailComment(); } } } return $this->getId(); // return new comment id }