/** Verify the akismet key * @access public * @return boolean * @throws Zend_Exception */ public function verifyKey() { if ($this->_akismet->verifyKey($this->_akismetKey)) { return true; } else { throw new Zend_Exception('Akismet key failed validation', 500); } }
public function onSubmit(array $data = array()) { unset($data['enabled']); $apiKey = @$data['key']; $blog = @$data['url']; try { $akismet = new Zend_Service_Akismet($apiKey, $blog); $akismet->verifyKey(); $this->_data = $data; return true; } catch (Exception $e) { $this->getForm()->addError('Test failed: ' . $e->getMessage()); return false; } }
public function indexAction() { if ($this->_request->isPost()) { if ($this->input->hasInvalid()) { $missing = ""; $notalnum = ""; $message = ""; foreach ($this->input->getInvalid() as $key => $value) { if (isset($value["isEmpty"])) { $missing .= $key . ","; } if (isset($value["notAlnum"])) { $notalnum .= $key . ","; } } if ($missing) { $message .= "Following are required {$missing} \n"; } if ($notalnum) { $message .= "Following are alpha numeric only {$notalnum}"; } throw new Zend_Service_Exception(Zend_Json::encode(array("error" => $message))); } if (!$this->_helper->csrf->isValidToken($this->token)) { throw new Zend_Service_Exception(Zend_Json::encode(array("error" => 'Token validation failed'))); } if ($this->config->antispam) { switch ($this->config->antispam) { case "typepad": $spam = new Zend_Service_TypePadAntiSpam($this->config->typepad->key, "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); break; case "akismet": $spam = new Zend_Service_Akismet($this->config->akismet->key, "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); break; } if (isset($spam)) { if ($spam->verifyKey()) { $params = array(); $params["user_ip"] = $_SERVER['REMOTE_ADDR']; $params["user_agent"] = $_SERVER['HTTP_USER_AGENT']; $params["referrer"] = $_SERVER['HTTP_REFERER']; $params["comment_type"] = "email"; $params["comment_author"] = $this->name; $params["comment_author_email"] = $this->email; $params["comment_content"] = $this->message; if ($spam->isSpam($params)) { throw new Zend_Service_Exception(Zend_Json::encode(array("error" => 'Message failed due to spam'))); } } } } $mail = new Zend_Mail(); $mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64); $mail->setBodyText($this->subject); $mail->setFrom($this->email, $this->name); $emails = explode(",", $this->to); $validator = new Zend_Validate_EmailAddress(); foreach ($emails as $value) { if ($validator->isValid($value)) { $mail->addTo($value); } } $mail->setSubject($this->subject); $mail->setBodyText($this->message); $mail->setBodyHtml($this->message); try { $mail->send(); } catch (Exception $e) { throw new Zend_Service_Exception(Zend_Json::encode(array("error" => 'Mail send was not successful'))); } $this->getResponse()->setBody(Zend_Json::encode(array("success" => "Message succesfully sent"))); } }