示例#1
0
 /**
  * Setup Akismet
  *
  * @param array $options
  * @return Zend_Service_Akismet
  */
 protected function _setupService($options)
 {
     if (!isset($options['apiKey'])) {
         $message = 'option "apiKey" not found for Service_Akismet';
         throw new Robo47_Application_Resource_Exception($message);
     }
     if (!isset($options['blog'])) {
         $message = 'option "blog" not found for Service_Akismet';
         throw new Robo47_Application_Resource_Exception($message);
     }
     $akismet = new Zend_Service_Akismet($options['apiKey'], $options['blog']);
     if (isset($options['charset'])) {
         $akismet->setCharset($options['charset']);
     }
     if (isset($options['userAgent'])) {
         $akismet->setUserAgent($options['userAgent']);
     }
     if (isset($options['port'])) {
         // casting needed because of is_int in Zend_Service_Akismet::setPort
         $akismet->setPort((int) $options['port']);
     }
     if (isset($options['registryKey'])) {
         Zend_Registry::set($options['registryKey'], $akismet);
     }
     return $akismet;
 }
示例#2
0
 function actionSpam($id, $action)
 {
     $where = 'id = ' . intval($id);
     $row = $this->fetchRow($where);
     if ($row == null) {
         return 'Id invalid : ' . $id;
     }
     $data = Zend_Json::decode($row['fields']);
     Zend_Debug::dump($data);
     $akismet = new Zend_Service_Akismet($this->akismet_api, $this->akismet_blog);
     switch ($action) {
         case "spam":
             /* C'est un spam */
             $akismet->submitSpam($data);
             $data['spam'] = true;
             break;
         case 'ham':
             $akismet->submitHam($data);
             $data['spam'] = false;
             break;
         case 'isspam':
             $data['spam'] = $akismet->isSpam($data);
             break;
     }
     $maj = array('spam' => $data['spam'], 'fields' => Zend_Json::encode($data));
     $ret = $this->update($maj, $where);
     if ($ret == 1) {
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /** 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);
     }
 }
示例#4
0
 public static function isSpam($name, $url, $message)
 {
     if ($this->chkTrigger($message)) {
         return true;
     } else {
         //  Verifica se é SPAM
         $akismet = new Zend_Service_Akismet(self::API_KEY, self::BLOG);
         $data = array('user_ip' => $_SERVER["REMOTE_ADDR"], 'user_agent' => $_SERVER["HTTP_USER_AGENT"], 'comment_type' => 'comment', 'comment_author' => $name, 'comment_author_url' => $url, 'comment_content' => $message);
         return $akismet->isSpam($data);
     }
 }
 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;
     }
 }
示例#6
0
 public function isSpam($params)
 {
     if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     } elseif (isset($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER['REMOTE_ADDR'];
     } else {
         $ip = '';
     }
     if (isset($_SERVER['HTTP_USER_AGENT'])) {
         $userAgent = (string) $_SERVER['HTTP_USER_AGENT'];
     } else {
         $userAgent = '';
     }
     if (isset($_SERVER['HTTP_REFERER'])) {
         $referrer = (string) $_SERVER['HTTP_REFERER'];
     } else {
         $referrer = '';
     }
     $params['user_ip'] = $ip;
     $params['user_agent'] = $userAgent;
     if ($referrer != '') {
         $params['referrer'] = $referrer;
     }
     return parent::isSpam($params);
 }
 public function checkSpam()
 {
     $wordPressAPIKey = get_option('commenting_wpapi_key');
     if (!empty($wordPressAPIKey)) {
         $ak = new Zend_Service_Akismet($wordPressAPIKey, WEB_ROOT);
         $data = $this->getAkismetData();
         try {
             $this->is_spam = $ak->isSpam($data);
         } catch (Exception $e) {
             $this->is_spam = 1;
         }
     } else {
         //if not using Akismet, assume only registered users are commenting
         $this->is_spam = 0;
     }
 }
示例#8
0
 /** Add the complaint
  * @access public
  * @param array $data
  * @return integer
  */
 public function addComplaint(array $data)
 {
     if (!empty($data['csrf'])) {
         unset($data['csrf']);
     }
     if (empty($data['comment_date'])) {
         $data['comment_date'] = $this->timeCreation();
         $data['created'] = $this->timeCreation();
     }
     if (empty($data['createdBy'])) {
         $data['createdBy'] = $this->getUserNumber();
     }
     if (empty($data['updatedBy'])) {
         $data['updatedBy'] = $this->getUserNumber();
     }
     if (empty($data['user_ip'])) {
         $data['user_ip'] = Zend_Controller_Front::getInstance()->getRequest()->getClientIp();
     }
     if (empty($data['user_agent'])) {
         $useragent = new Zend_Http_UserAgent();
         $data['user_agent'] = $useragent->getUserAgent();
     }
     if ($this->_akismet->isSpam($data)) {
         $data['comment_approved'] = self::SPAM;
     } else {
         $data['comment_approved'] = self::NOTSPAM;
     }
     return parent::insert($data);
 }
 public function articleAction()
 {
     if ($this->_getParam('id', false)) {
         $news = new News();
         $this->view->news = $news->getStory($this->_getParam('id'));
         $comments = new Comments();
         $this->view->comments = $comments->getCommentsNews($this->_getParam('id'));
         $form = new CommentFindForm();
         $form->submit->setLabel('Add a new comment');
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 $data = array();
                 $data['comment_findID'] = $this->_getParam('id');
                 $data['user_ip'] = $form->getValue('comment_author_IP');
                 $data['user_agent'] = $form->getValue('comment_agent');
                 $data['comment_type'] = 'newscomment';
                 $data['comment_author'] = $form->getValue('comment_author');
                 $data['comment_author_email'] = $form->getValue('comment_author_email');
                 $data['comment_content'] = $form->getValue('comment_content');
                 $data['comment_date'] = $this->getTimeForForms();
                 $data['user_id'] = $this->getIdentityForForms();
                 $config = Zend_Registry::get('config');
                 $akismetkey = $config->webservice->akismetkey;
                 $akismet = new Zend_Service_Akismet($akismetkey, 'http://www.finds.org.uk');
                 if ($akismet->isSpam($data)) {
                     $data['comment_approved'] = 'spam';
                 } else {
                     $data['comment_approved'] = 'moderation';
                 }
                 $comments = new Comments();
                 $insert = $comments->insert($data);
                 $this->_flashMessenger->addMessage('Your comment has been entered and will appear shortly!');
                 $this->_redirect('/news/stories/article/id/' . $this->_getParam('id'));
                 $this->_request->setMethod('GET');
             } else {
                 $this->_flashMessenger->addMessage('There are problems with your comment submission');
                 $form->populate($formData);
             }
         }
     } else {
         throw new Exception('No parameter on the url string');
     }
 }
 public function setUp()
 {
     $this->akismet = new Zend_Service_Akismet('somebogusapikey', 'http://framework.zend.com/wiki/');
     $adapter = new Zend_Http_Client_Adapter_Test();
     $client = new Zend_Http_Client(null, array('adapter' => $adapter));
     $this->adapter = $adapter;
     Zend_Service_Akismet::setHttpClient($client);
     $this->comment = array('user_ip' => '71.161.221.76', 'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1)', 'comment_type' => 'comment', 'comment_content' => 'spam check');
 }
示例#11
0
 protected function _post($host, $path, array $params)
 {
     if ($this->_type == self::TYPE_TYPEPAD) {
         $caller = $this->_getCallerMethod();
         if (strtolower($caller) == 'verifykey') {
             $host = self::TYPEPAD_API_URL;
         } else {
             $host = $this->getApiKey() . '.' . self::TYPEPAD_API_URL;
         }
     }
     return parent::_post($host, $path, $params);
 }
示例#12
0
 public function commentAction()
 {
     $label = $this->_getParam('label');
     if ($label === null) {
         throw new Zend_Exception('No label specified in PostsController::commentAction()');
     }
     $postManager = new Post();
     $post = $postManager->fetchRow(array('label = ?' => $label, 'is_active = ?' => 1));
     if ($post === null) {
         throw new Zend_Exception('No post found with that label in PostsController::commentAction()');
     }
     $this->view->post = $post;
     // form
     $form = new Zend_Form($this->_commentForm);
     $form->setAction('/posts/' . $post->label . '/comment');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $config = Zend_Registry::get('config');
             $akismet = new Zend_Service_Akismet($config->akismet->key, 'http://codecaine.co.za');
             $akismetData = array('user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'permalink' => 'http://codecaine.co.za/posts/' . $post->label, 'comment_type' => 'comment', 'comment_author' => $_POST['name'], 'comment_author_email' => $_POST['email'], 'comment_author_url' => $_POST['website'], 'comment_content' => $_POST['text']);
             if ($akismet->isSpam($akismetData)) {
                 $this->_redirect('/spam');
             }
             $commentManager = new Comment();
             $data = $_POST;
             unset($data['submit']);
             $data['post_id'] = $post->id;
             $data['posted_at'] = new Zend_Db_Expr('NOW()');
             $id = $commentManager->insert($data);
             $this->_redirect('/posts/' . $post->label . '#comment-' . $id);
         }
     }
     // description
     $this->view->metaDescription = 'Post your comments on ' . $post->title;
     // set title
     $this->_title($post->title);
 }
示例#13
0
 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")));
     }
 }
示例#14
0
 private function check_is_spam(array $info)
 {
     global $prefs, $user;
     if ($prefs['comments_akismet_filter'] != 'y') {
         return false;
     }
     if ($user && $prefs['comments_akismet_check_users'] != 'y') {
         return false;
     }
     try {
         $tikilib = TikiLib::lib('tiki');
         $url = $tikilib->tikiUrl();
         $akismet = new Zend_Service_Akismet($prefs['comments_akismet_apikey'], $url);
         return $akismet->isSpam(array('user_ip' => $tikilib->get_ip_address(), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'comment_type' => 'comment', 'comment_author' => $info['author'], 'comment_author_email' => $info['email'], 'comment_author_url' => $info['website'], 'comment_content' => $info['content']));
     } catch (Exception $e) {
         TikiLib::lib('errorreport')->report(tr('Cannot perform spam check: %0', $e->getMessage()));
         return false;
     }
 }
示例#15
0
 protected function _checkAkismet($content, array $extraParams, Zend_Controller_Request_Http $request)
 {
     $options = XenForo_Application::getOptions();
     $visitor = XenForo_Visitor::getInstance();
     $result = self::RESULT_ALLOWED;
     if ($options->akismetKey) {
         $akismetParams = array('user_ip' => $request->getClientIp(false), 'user_agent' => $request->getServer('HTTP_USER_AGENT', 'Unknown'), 'referrer' => $request->getServer('HTTP_REFERER'), 'comment_type' => 'comment', 'comment_author' => $visitor['username'], 'comment_author_email' => $visitor['email'], 'comment_author_url' => $visitor['homepage'], 'comment_content' => $content);
         if (isset($extraParams['permalink'])) {
             $akismetParams['permalink'] = $extraParams['permalink'];
         }
         $akismet = new Zend_Service_Akismet($options->akismetKey, $options->boardUrl);
         try {
             $this->_checkParams['akismetIsSpam'] = $akismet->isSpam($akismetParams);
             $this->_checkParams['akismet'] = $akismetParams;
             if ($this->_checkParams['akismetIsSpam']) {
                 $result = self::RESULT_MODERATED;
                 $this->_resultDetails[] = array('phrase' => 'akismet_matched');
             }
         } catch (Zend_Http_Exception $e) {
         } catch (Zend_Service_Exception $e) {
         }
     }
     return $result;
 }
 public function updateApprovedAction()
 {
     $wordPressAPIKey = get_option('commenting_wpapi_key');
     $commentIds = $_POST['ids'];
     $status = $_POST['approved'];
     $table = $this->_helper->db->getTable();
     if (!$commentIds) {
         return;
     }
     foreach ($commentIds as $commentId) {
         $comment = $table->find($commentId);
         $comment->approved = $status;
         //if approved, it isn't spam
         if ($status == 1 && $comment->is_spam == 1) {
             $comment->is_spam = 0;
             $ak = new Zend_Service_Akismet($wordPressAPIKey, WEB_ROOT);
             $data = $comment->getAkismetData();
             try {
                 $ak->submitHam($data);
                 $response = array('status' => 'ok');
                 $comment->save();
             } catch (Exception $e) {
                 _log($e->getMessage());
                 $response = array('status' => 'fail', 'message' => $e->getMessage());
             }
         } else {
             try {
                 $comment->save();
                 $response = array('status' => 'ok');
             } catch (Exception $e) {
                 $response = array('status' => 'fail', 'message' => $e->getMessage());
                 _log($e->getMessage());
             }
         }
     }
     $this->_helper->json($response);
 }
示例#17
0
 public function responseAction()
 {
     $id = $this->_request->getParam('id', 0);
     if (!$id) {
         $this->_redirect('/ads/categories-list/');
     }
     $ads = new Ads();
     $ad = $ads->find($id)->current();
     if (!$ad) {
         $this->_redirect('/ads/categories-list/');
     }
     $form = new AdsResponseForm();
     $form->getSubForm('ads_responses')->getElement('ad_id')->setValue($id);
     if (Standart_Main::buttonPressed('doResponse')) {
         if ($form->isValid($_POST)) {
             $values = $form->getValues();
             $akismetData = array('user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'comment_type' => 'comment', 'comment_author' => $values['ads_responses']['name'], 'comment_author_email' => $values['ads_responses']['email'], 'comment_content' => $values['ads_responses']['content']);
             $akismet = new Zend_Service_Akismet(Zend_Registry::get('config')->akismet->apiKey, Zend_Registry::get('config')->host->default);
             if ($akismet->isSpam($akismetData)) {
                 $values['ads_responses']['is_spam'] = 1;
                 $this->view->message(Standart_Main::translate('adsResponseIsSpam'), 'error');
             }
             $adsResponses = new Ads_Responses();
             $adsResponses->insert($values['ads_responses']);
             $this->_redirect('/ads/response/id/' . $id . '/');
         } else {
             $this->view->message(Standart_Main::translate('invalidFormData'), 'error');
         }
     }
     $this->view->form = $form;
 }