Example #1
0
 /**
  * Passes form content to the Akismet API. If spam is detected, sends an error message back to the user.
  */
 public function detect_spam()
 {
     $form_contents = '';
     foreach ($this->disco_form->get_values() as $k => $v) {
         if (is_array($v)) {
             $form_contents .= implode($v, ' ') . ' ';
         } else {
             // don't include hidden elements which contain objects as values
             if (!(get_class($this->disco_form->get_element($k)) == 'hiddenType' && substr($v, 0, 3) == 'id_')) {
                 $form_contents .= $v . ' ';
             }
         }
     }
     $akismet_api_key = constant("AKISMET_API_KEY");
     if (!empty($akismet_api_key)) {
         $url = carl_construct_link();
         //$akismet = new Akismet($url, $akismet_api_key, $is_test=1); // for testing
         $akismet = new Akismet($url, $akismet_api_key);
         $akismet->setCommentContent($form_contents);
         //$akismet->setCommentAuthor('viagra-test-123'); // for testing
         if ($akismet->isCommentSpam()) {
             $this->disco_form->set_error(NULL, 'Spam detected in this submission. If this message was made in error, please contact an administrator.', $element_must_exist = false);
         }
     }
 }
Example #2
0
 /**
  * The function for processing a message to see if it might be SPAM
  *       returns:
  *         0 if the message is SPAM
  *         1 if the message might be SPAM (it will be marked for moderation)
  *         2 if the message is not SPAM
  *
  * @param string $author Author field from the posting
  * @param string $email Email field from the posting
  * @param string $website Website field from the posting
  * @param string $body The text of the comment
  * @param string $imageLink A link to the album/image on which the post was made
  * @param string $ip the IP address of the comment poster
  * 
  * @return int
  */
 function filterMessage($author, $email, $website, $body, $imageLink, $ip)
 {
     $commentData = array('author' => $author, 'email' => $email, 'website' => $website, 'body' => $body, 'permalink' => $imageLink);
     $zp_galUrl = FULLWEBPATH;
     // Sets the webpath for the Akismet server
     $zp_akismetKey = getOption('Akismet_key');
     $forgive = getOption('Forgiving');
     $die = 2;
     // good comment until proven bad
     $akismet = new Akismet($zp_galUrl, $zp_akismetKey, $commentData);
     if ($akismet->errorsExist()) {
         // TODO: Add more improved error handling (maybe)
         // echo "Couldn't connected to Akismet server!";
         // print_r ($akismet->getErrors());
         $die = 1;
         // mark for moderation if we can't check for Spam
     } else {
         if ($akismet->isSpam()) {
             // Message is spam according to Akismet
             // echo 'Spam detected';
             // echo "bad message.";
             $die = $forgive;
         } else {
             // Message is not spam according to Akismet
             // echo "spam filter is true. good message.";
         }
     }
     return $die;
 }
 function testIsSpam()
 {
     $this->akismet->commentUserIp = "113.91.127.32";
     $this->akismet->commentAuthor = "office 2010 download";
     $this->assertTrue(isset($this->akismet));
     $this->assertTrue($this->akismet->isSpam());
 }
Example #4
0
	/**
	 * validate the elements data against the rule
	 * @param string data to check
	 * @param object element model
	 * @param int plugin sequence ref
	 * @return bol true if validation passes, false if fails
	 */

	function validate($data, &$elementModel, $c)
	{
		$params = $this->getParams();
		$user = JFactory::getUser();
		if ($params->get('akismet-key') != '')
		{
			$username = $user->get('username') != '' ? $user->get('username') : $this->_randomSring();
			$email = $user->get('email') != '' ? $user->get('email') : $this->_randomSring().'@'.$this->_randomSring().'com';
			require_once(JPATH_COMPONENT.DS.'plugins'.DS.'validationrule'.DS.'akismet'.DS.'akismet.class.php');
			$akismet_comment = array (
															'author' => $username,
															'email' => $user->get('email'),
															'website' => JURI::base(),
															'body' => $data
			);
			$akismet = new Akismet(JURI::base(), $params->get('akismet-key'), $akismet_comment);
			if ($akismet->errorsExist()) {
				JError::raiseNotice( JText::_("Couldn't connected to Akismet server!"));
			} else {

				if ($akismet->isSpam()) {
					return false;
				}
			}
		}
		return true;
	}
Example #5
0
 /**
  * Build an Akismet object.
  *
  * @param string $key Authentication key.
  * @param string $server Remote URL.
  * @return Akismet
  */
 private static function buildAkismet($key, $server = false)
 {
     $Akismet = new Akismet(Gdn::request()->url('/', true), $key);
     if ($server) {
         $Akismet->setAkismetServer($server);
     }
     return $Akismet;
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('nickurt\\Akismet\\Akismet', function ($app) {
         $config = $app['config']->get('akismet');
         $akismet = new Akismet();
         $akismet->setApiKey($config['api_key']);
         $akismet->setBlogUrl($config['blog_url']);
         return $akismet;
     });
     $this->app->alias('nickurt\\Akismet\\Akismet', 'Akismet');
 }
Example #7
0
 function doModel()
 {
     switch ($this->action) {
         case 'spamNbots':
             // calling the spam and bots view
             $akismet_key = osc_akismet_key();
             $akismet_status = 3;
             if ($akismet_key != '') {
                 require_once osc_lib_path() . 'Akismet.class.php';
                 $akismet_obj = new Akismet(osc_base_url(), $akismet_key);
                 $akismet_status = 2;
                 if ($akismet_obj->isKeyValid()) {
                     $akismet_status = 1;
                 }
             }
             View::newInstance()->_exportVariableToView('akismet_status', $akismet_status);
             $this->doView('settings/spamNbots.php');
             break;
         case 'akismet_post':
             // updating spam and bots option
             osc_csrf_check();
             $updated = 0;
             $akismetKey = Params::getParam('akismetKey');
             $akismetKey = trim($akismetKey);
             $updated = osc_set_preference('akismetKey', $akismetKey);
             if ($akismetKey == '') {
                 osc_add_flash_info_message(_m('Your Akismet key has been cleared'), 'admin');
             } else {
                 osc_add_flash_ok_message(_m('Your Akismet key has been updated'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=spamNbots');
             break;
         case 'recaptcha_post':
             // updating spam and bots option
             osc_csrf_check();
             $iUpdated = 0;
             $recaptchaPrivKey = Params::getParam('recaptchaPrivKey');
             $recaptchaPrivKey = trim($recaptchaPrivKey);
             $recaptchaPubKey = Params::getParam('recaptchaPubKey');
             $recaptchaPubKey = trim($recaptchaPubKey);
             $iUpdated += osc_set_preference('recaptchaPrivKey', $recaptchaPrivKey);
             $iUpdated += osc_set_preference('recaptchaPubKey', $recaptchaPubKey);
             if ($recaptchaPubKey == '') {
                 osc_add_flash_info_message(_m('Your reCAPTCHA key has been cleared'), 'admin');
             } else {
                 osc_add_flash_ok_message(_m('Your reCAPTCHA key has been updated'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=spamNbots');
             break;
     }
 }
Example #8
0
 /**
  * @return Akismet
  */
 public static function Akismet()
 {
     static $Akismet;
     if (!$Akismet) {
         $Key = C('Plugins.Akismet.Key', C('Plugins.Akismet.MasterKey'));
         if (!$Key) {
             return NULL;
         }
         $Akismet = new Akismet(Gdn::Request()->Url('/', TRUE), $Key);
         $Server = C('Plugins.Akismet.Server');
         if ($Server) {
             $Akismet->setAkismetServer($Server);
         }
     }
     return $Akismet;
 }
 /**
  * Checks one or more comments against the Akismet API.
  *
  * ## OPTIONS
  * <comment_id>...
  * : The ID(s) of the comment(s) to check.
  *
  * [--noaction]
  * : Don't change the status of the comment. Just report what Akismet thinks it is.
  *
  * ## EXAMPLES
  *
  *     wp akismet check 12345
  *
  * @alias comment-check
  */
 public function check($args, $assoc_args)
 {
     foreach ($args as $comment_id) {
         if (isset($assoc_args['noaction'])) {
             // Check the comment, but don't reclassify it.
             $api_response = Akismet::check_db_comment($comment_id, 'wp-cli');
         } else {
             $api_response = Akismet::recheck_comment($comment_id, 'wp-cli');
         }
         if ('true' === $api_response) {
             WP_CLI::line(sprintf(__("Comment #%d is spam.", 'akismet'), $comment_id));
         } else {
             if ('false' === $api_response) {
                 WP_CLI::line(sprintf(__("Comment #%d is not spam.", 'akismet'), $comment_id));
             } else {
                 if (false === $api_response) {
                     WP_CLI::error(__("Failed to connect to Akismet.", 'akismet'));
                 } else {
                     if (is_wp_error($api_response)) {
                         WP_CLI::warning(sprintf(__("Comment #%d could not be checked.", 'akismet'), $comment_id));
                     }
                 }
             }
         }
     }
 }
 function __construct($comment)
 {
     $ini = eZINI::instance('akismet.ini');
     $blogURL = $ini->variable('SiteSettings', 'BlogURL');
     $apiKey = $ini->variable('AccountSettings', 'APIKey');
     parent::__construct($blogURL, $apiKey);
     if (isset($comment['permalink'])) {
         parent::setPermalink($comment['permalink']);
     }
     if ($comment['type']) {
         parent::setCommentType($comment['type']);
     }
     if (isset($comment['author'])) {
         parent::setCommentAuthor($comment['author']);
     } else {
         parent::setCommentAuthor('');
     }
     if (isset($comment['email'])) {
         parent::setCommentAuthorEmail($comment['email']);
     }
     if ($comment['website']) {
         parent::setCommentAuthorURL($comment['website']);
     }
     if ($comment['body']) {
         parent::setCommentContent($comment['body']);
     }
 }
Example #11
0
function akismet_create_topic($msg_options, $topic_options, $poster_options)
{
    global $modSettings, $scripturl, $smcFunc, $sourcedir;
    require $sourcedir . '/Akismet.class.php';
    // If the subject is 'akismet-test-123', then mark it as spam (this is a test)
    if ($msg_options['subject'] == 'akismet-test-123') {
        $spam = true;
    } else {
        // If the API key has been set
        if (isset($modSettings['akismetAPIKey']) && $modSettings['akismetAPIKey'] != "") {
            // Set up the Akismet class
            $akismet = new Akismet($scripturl, $modSettings['akismetAPIKey']);
            $akismet->setAuthor($poster_options['name']);
            $akismet->setAuthorEmail($poster_options['email']);
            //$akismet->setCommentAuthorURL(""); -- URL's not used in SMF.
            $akismet->setContent($msg_options['body']);
            if (!empty($topic_options['id'])) {
                $akismet->setPermalink($scripturl . '?topic=' . $topicOptions['id']);
            }
            $akismet->setType('smf-post');
            // Now, the moment of truth... Send the post to Akismet
            $akismet_return = $akismet->isSpam();
            // Was the server down?
            if ($akismet_return === 'conn_error') {
                // Assume it's not spam. We log an error to the error log later
                $spam = false;
                // Log it!
                if (empty($modSettings['akismetNoLog'])) {
                    log_error(sprintf($txt['akismet_cant_connect2'], $_POST['guestname'], $scripturl . '?topic=' . $topic . (isset($_REQUEST['msg']) ? '.msg' . $_REQUEST['msg'] : '')));
                }
            } elseif ($akismet_return === true) {
                // Oh, the horror! Someone posted spam to your forum!
                $spam = true;
            } else {
                $spam = false;
            }
        } else {
            // No API key, assume it isn't spam
            $spam = false;
        }
    }
    if ($spam) {
        // Mark the message as spam and unapprove the post. Post moderation is a big help here. :)
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}topics
			SET spam = 1,
				approved = 0,
				unapproved_posts = 1
			WHERE id_topic = {int:id_topic}', array('id_topic' => $topic_options['id']));
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}messages
			SET approved = 0
			WHERE id_msg = {int:id_msg}', array('id_msg' => $msg_options['id']));
        // Increase spam count
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}settings
			SET value = value + 1
			WHERE variable = {string:akismetCaughtSpam}', array('akismetCaughtSpam' => 'akismetCaughtSpam'));
    }
}
Example #12
0
function HandleGuestStore($pagename, $auth)
{
    global $wpcom_api_key, $wpcom_home;
    $akismet = new Akismet($wpcom_home, $wpcom_api_key);
    $akismet->setCommentAuthor($_POST['name']);
    $akismet->setCommentAuthorEmail($_POST['email']);
    $akismet->setCommentAuthorURL($_POST['url']);
    $akismet->setCommentContent($_POST['comment']);
    $itemurl = $pagename . date("Ymd") . "-" . uniqid();
    $akismet->setPermalink($itemurl);
    $page['name'] = $itemurl;
    $page['text'] = "----\n";
    $page['text'] .= strlen($_POST['name']) > 0 ? $_POST['name'] : "Unbekannt";
    if (strlen($_POST['email']) > 0) {
        $page['text'] .= " [[&#9993;->mailto:";
        $page['text'] .= $_POST['email'];
        $page['text'] .= "]]";
    }
    if (strlen($_POST['url']) > 0) {
        $page['text'] .= " [[&#10138;->";
        $page['text'] .= substr($_POST['url'], 0, 4) == "http" ? $_POST['url'] : "http://" . $_POST['url'];
        $page['text'] .= "]]";
    }
    $page['text'] .= " schrieb am ";
    $page['text'] .= date("d.m.Y");
    $page['text'] .= ":\n\n";
    $page['text'] .= $_POST['comment'];
    $page['text'] .= $akismet->isCommentSpam() ? "(:spam: true:)" : "(:spam: false:)";
    $page['time'] = $Now;
    $page['host'] = $_SERVER['REMOTE_ADDR'];
    $page['agent'] = @$_SERVER['HTTP_USER_AGENT'];
    UpdatePage($page['name'], $page, $page);
    HandleBrowse($pagename);
}
Example #13
0
 /**
  * Validate the elements data against the rule
  *
  * @param   string  $data           To check
  * @param   int     $repeatCounter  Repeat group counter
  *
  * @return  bool  true if validation passes, false if fails
  */
 public function validate($data, $repeatCounter)
 {
     $params = $this->getParams();
     if ($params->get('akismet-key') != '') {
         $username = $this->user->get('username') != '' ? $this->user->get('username') : $this->_randomSring();
         require_once JPATH_COMPONENT . '/plugins/validationrule/akismet/libs/akismet.class.php';
         $akismet_comment = array('author' => $username, 'email' => $this->user->get('email'), 'website' => JURI::base(), 'body' => $data);
         $akismet = new Akismet(JURI::base(), $params->get('akismet-key'), $akismet_comment);
         if ($akismet->errorsExist()) {
             throw new RuntimeException("Couldn't connected to Akismet server!");
         } else {
             if ($akismet->isSpam()) {
                 return false;
             }
         }
     }
     return true;
 }
Example #14
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $input = $this->all();
     // service Aksimet checked content and email
     \Akismet::setCommentContent($input['content'])->setCommentAuthorEmail($input['email']);
     $input['spam'] = \Akismet::isSpam() ? 1 : 0;
     $this->replace($input);
     return ['email' => 'email|required', 'content' => 'required', 'post_id' => 'integer', 'published_at' => 'regex:/[0-9]{4}\\-[0-9]{2}\\-[0-9]{2} [0-9]{2}\\:[0-9]{2}\\:[0-9]{2}/'];
 }
Example #15
0
 /**
  * beforeSave is called before a model is saved. Returning false from a beforeSave callback
  * will abort the save operation.
  *
  * @param Model $model Model using this behavior
  * @param array $options Options passed from Model::save().
  *
  * @return mixed|void
  */
 public function beforeSave(\Model $model, $options = array())
 {
     parent::beforeSave($model);
     $request = new CakeRequest();
     $data = ['blog' => urlencode(Configure::read('General.site_url')), 'user_ip' => urlencode($model->data[$model->alias]['author_ip']), 'user_agent' => urlencode($model->data[$model->alias]['agent']), 'referrer' => urlencode($request->referer()), 'permalink' => urlencode($request->referer()), 'comment_type' => urlencode('comment'), 'comment_author' => urlencode($model->data[$model->alias]['author']), 'comment_author_email' => urlencode($model->data[$model->alias]['author_email']), 'comment_author_url' => urlencode($model->data[$model->alias]['author_url']), 'comment_content' => urlencode($model->data[$model->alias]['content'])];
     if (Akismet::isSpam($data, Configure::read('Akismet.api_key'))) {
         $model->data[$model->alias]['status'] = 'spam';
     }
 }
 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();
         }
     }
 }
Example #17
0
 public static function check($input, &$model)
 {
     $application = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_k2');
     $user = JFactory::getUser();
     // Google reCAPTCHA
     if ($params->get('antispam') == 'recaptcha' || $params->get('antispam') == 'both') {
         if ($user->guest || $params->get('recaptchaForRegistered')) {
             $data = array();
             $data['secret'] = $params->get('recaptcha_private_key');
             $data['remoteip'] = $_SERVER["REMOTE_ADDR"];
             $data['response'] = $application->input->post->get('g-recaptcha-response', '', 'raw');
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify?' . http_build_query($data));
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $response = curl_exec($ch);
             $error = curl_error($ch);
             curl_close($ch);
             if ($response === false) {
                 $model->setError($error);
                 return false;
             }
             $json = json_decode($response);
             if (!$json->success) {
                 $model->setError(JText::_('K2_WE_COULD_NOT_VERIFY_THAT_YOU_ARE_HUMAN'));
                 return false;
             }
         }
     }
     // Akismet
     if ($params->get('antispam') == 'akismet' || $params->get('antispam') == 'both') {
         if ($user->guest || $params->get('akismetForRegistered')) {
             if ($params->get('akismetApiKey')) {
                 require_once JPATH_ADMINISTRATOR . 'components/com_k2/classes/akismet.class.php';
                 $akismetApiKey = $params->get('akismetApiKey');
                 $akismet = new Akismet(JURI::root(false), $akismetApiKey);
                 $akismet->setCommentAuthor($input['name']);
                 $akismet->setCommentAuthorEmail($input['email']);
                 $akismet->setCommentAuthorURL($input['url']);
                 $akismet->setCommentContent($input['text']);
                 $akismet->setPermalink(JURI::root(false) . 'index.php?option=com_k2&view=item&id=' . $input['itemId']);
                 try {
                     if ($akismet->isCommentSpam()) {
                         $model->setError(JText::_('K2_SPAM_ATTEMPT_HAS_BEEN_DETECTED_THE_COMMENT_HAS_BEEN_REJECTED'));
                         return false;
                     }
                 } catch (Exception $e) {
                     $model->setError($e->getMessage());
                     return false;
                 }
             }
         }
     }
     return true;
 }
 public static function get_api_key()
 {
     if (is_callable(array('Akismet', 'get_api_key'))) {
         // Akismet v3.0+
         return (bool) Akismet::get_api_key();
     }
     if (function_exists('akismet_get_key')) {
         return (bool) akismet_get_key();
     }
     return false;
 }
Example #19
0
function flamingo_akismet_is_active()
{
    if (is_callable(array('Akismet', 'get_api_key'))) {
        // Akismet v3.0+
        return (bool) Akismet::get_api_key();
    }
    if (function_exists('akismet_get_key')) {
        return (bool) akismet_get_key();
    }
    return false;
}
Example #20
0
 /**
 		Akismet key verification
 			@return boolean
 			@param $key string
 			@public
 	**/
 static function verify($key)
 {
     $response = Web::http('GET http://rest.akismet.com/1.1/verify-key', http_build_query(array('key' => $key, 'blog' => 'http://' . $_SERVER['SERVER_NAME'])));
     if (preg_match('/invalid/i', $response)) {
         trigger_error(self::TEXT_VerifyFail);
         self::$key = NULL;
     } else {
         self::$key = $key;
     }
     return self::$key;
 }
 protected function is_akismet_available()
 {
     if (!class_exists('Akismet')) {
         return false;
     }
     $api_key = Akismet::get_api_key();
     if (empty($api_key)) {
         return false;
     }
     return true;
 }
Example #22
0
 /**
  * Function: create
  * Attempts to create a comment using the passed information. If the Akismet API key is present, it will check it.
  *
  * Parameters:
  *     $body - The comment.
  *     $author - The name of the commenter.
  *     $url - The commenter's website.
  *     $email - The commenter's email.
  *     $post - The <Post> they're commenting on.
  *     $parent - The <Comment> they're replying to.
  *     $notify - Notification on follow-up comments.
  *     $type - The type of comment. Optional, used for trackbacks/pingbacks.
  */
 static function create($body, $author, $url, $email, $post, $parent, $notify, $type = null)
 {
     if (!self::user_can($post->id) and !in_array($type, array("trackback", "pingback"))) {
         return;
     }
     $config = Config::current();
     $route = Route::current();
     $visitor = Visitor::current();
     if (!$type) {
         $status = $post->user_id == $visitor->id ? "approved" : $config->default_comment_status;
         $type = "comment";
     } else {
         $status = $type;
     }
     if (!empty($config->akismet_api_key)) {
         $akismet = new Akismet($config->url, $config->akismet_api_key);
         $akismet->setCommentContent($body);
         $akismet->setCommentAuthor($author);
         $akismet->setCommentAuthorURL($url);
         $akismet->setCommentAuthorEmail($email);
         $akismet->setPermalink($post->url());
         $akismet->setCommentType($type);
         $akismet->setReferrer($_SERVER['HTTP_REFERER']);
         $akismet->setUserIP($_SERVER['REMOTE_ADDR']);
         if ($akismet->isCommentSpam()) {
             self::add($body, $author, $url, $email, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], "spam", $post->id, $visitor->id, $parent, $notify);
             error(__("Spam Comment"), __("Your comment has been marked as spam. It has to be reviewed and/or approved by an admin.", "comments"));
         } else {
             $comment = self::add($body, $author, $url, $email, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $status, $post->id, $visitor->id, $parent, $notify);
             fallback($_SESSION['comments'], array());
             $_SESSION['comments'][] = $comment->id;
             if (isset($_POST['ajax'])) {
                 exit("{ \"comment_id\": \"" . $comment->id . "\", \"comment_timestamp\": \"" . $comment->created_at . "\" }");
             }
             Flash::notice(__("Comment added."), $post->url() . "#comments");
         }
     } else {
         $comment = self::add($body, $author, $url, $email, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $status, $post->id, $visitor->id, $parent, $notify);
         fallback($_SESSION['comments'], array());
         $_SESSION['comments'][] = $comment->id;
         if (isset($_POST['ajax'])) {
             exit("{ \"comment_id\": \"" . $comment->id . "\", \"comment_timestamp\": \"" . $comment->created_at . "\" }");
         }
         Flash::notice(__("Comment added."), $post->url() . "#comment");
     }
 }
Example #23
0
function spamurai_content_verify($pObject, $pParamHash)
{
    global $gBitUser, $gBitSystem;
    // hardcode limit spamurai to BitBlogPost and BitUser. more enterprising person can write some cool admin config.
    // for now, these are the limits cause doing everything is slow and produces many false positives for content with limited text
    if ($gBitSystem->isPackageActive('spamurai') && !$gBitUser->hasPermission('p_spamurai_moderate') && (is_a($pObject, 'LibertyComment') || is_a($pObject, 'BitBlogPost') || is_a($pObject, 'BitUser'))) {
        $akismet = new Akismet(BOARDS_PKG_URI, $gBitSystem->getConfig('spamurai_api_key'));
        if (!empty($pParamHash) && !empty($akismet)) {
            $userInfo = $gBitUser->getUserInfo(array('user_id' => $pParamHash['user_id']));
            $akismet->setCommentAuthor($userInfo['real_name'] . $userInfo['login']);
            $akismet->setCommentAuthorEmail($userInfo['email']);
            $checkTitle = '';
            if (!empty($pParamHash['title'])) {
                $checkTitle .= $pParamHash['title'];
            }
            if (!empty($pParamHash['comment_title'])) {
                $checkTitle .= $pParamHash['comment_title'];
            }
            $checkString = '';
            if (!empty($pParamHash['edit'])) {
                $checkString .= $pParamHash['edit'];
            }
            if (!empty($pParamHash['comment_data'])) {
                $checkString .= $pParamHash['comment_data'];
            }
            if (!empty($checkString) || !empty($checkTitle)) {
                $akismet->setCommentContent($checkTitle . $checkString);
                if ($akismet->isCommentSpam()) {
                    if ($gBitUser->isRegistered()) {
                        bit_error_log('SPAM ' . $pObject->getContentType() . ' for user ' . $userInfo['user_id']);
                    }
                    $insertSql = "INSERT INTO " . BIT_DB_PREFIX . "spamurai_log (user_id, email, subject, data, posted_date, ip) VALUES ( ?, ?, ?, ?, ?, ? )";
                    $bindVars = array($pParamHash['user_id'], $userInfo['email'], substr($checkTitle, 0, 255), $checkString, time(), $_SERVER['REMOTE_ADDR']);
                    $gBitSystem->mDb->query($insertSql, $bindVars);
                    $pObject->mErrors['spam'] = "This comment has been blocked as spam";
                }
            }
        }
    }
}
 public function commentValidate($comment)
 {
     $result = null;
     if (!$comment['contact_id'] && ($api_key = $this->getSettingValue('api_key')) && class_exists('Akismet')) {
         $url = wa()->getRouteUrl('blog', array(), true);
         $post_url = null;
         if (isset($comment['post_data'])) {
             $post_url = blogPost::getUrl($comment['post_data']);
             if (is_array($post_url)) {
                 $post_url = array_shift($post_url);
             }
         }
         $akismet = new Akismet($url, $api_key);
         $akismet->setCommentAuthor($comment['name']);
         $akismet->setCommentAuthorEmail($comment['email']);
         //$akismet->setCommentAuthorURL($comment['site']);
         $akismet->setCommentContent($comment['text']);
         if ($post_url) {
             $akismet->setPermalink($post_url);
         }
         if ($akismet->isCommentSpam()) {
             $result = array('text' => _wp('According to Akismet.com, your comment very much looks like spam, thus will not be published. Please rewrite your comment. Sorry for the inconvenience.'));
         }
     }
     return $result;
 }
 public function action_admin_moderate_comments($action, $comments, $handler)
 {
     $false_negatives = 0;
     $false_positives = 0;
     $provider = Options::get('habariakismet__provider');
     $endpoint = $provider == 'Akismet' ? self::SERVER_AKISMET : self::SERVER_TYPEPAD;
     $a = new Akismet(Site::get_url('habari'), Options::get('habariakismet__api_key'));
     $a->setAkismetServer($endpoint);
     foreach ($comments as $comment) {
         switch ($action) {
             case 'spam':
                 if ($comment->status == Comment::STATUS_APPROVED || $comment->status == Comment::STATUS_UNAPPROVED) {
                     $a->setCommentAuthor($comment->name);
                     $a->setCommentAuthorEmail($comment->email);
                     $a->setCommentAuthorURL($comment->url);
                     $a->setCommentContent($comment->content);
                     $a->submitSpam();
                     $false_negatives++;
                 }
                 break;
             case 'approved':
                 if ($comment->status == Comment::STATUS_SPAM) {
                     $a->setCommentAuthor($comment->name);
                     $a->setCommentAuthorEmail($comment->email);
                     $a->setCommentAuthorURL($comment->url);
                     $a->setCommentContent($comment->content);
                     $a->submitHam();
                     $false_positives++;
                 }
                 break;
         }
     }
     if ($false_negatives) {
         Session::notice(_t('Reported %d false negatives to %s.', array($false_negatives, $provider)));
     }
     if ($false_positives) {
         Session::notice(_t('Reported %d false positives to %s.', array($false_positives, $provider)));
     }
 }
 /**
  * check if a comment is spam through Akismet
  *
  * @param mixed $data Data passed to this action
  * @return bool TRUE if comment is spam else FALSE
  */
 public function perform($data = FALSE)
 {
     include_once JAPA_BASE_DIR . 'modules/common/includes/Akismet.class.php';
     $akismet = new Akismet($data['url'], $data['key']);
     $akismet->setCommentAuthor($data['user']['name']);
     $akismet->setCommentAuthorEmail($data['user']['email']);
     $akismet->setCommentAuthorURL($data['user']['url']);
     $akismet->setCommentContent($data['user']['comment']);
     $akismet->setPermalink($data['permaLink']);
     return $akismet->isCommentSpam();
 }
Example #27
0
 /**
  * @param ContactFormRequest $request
  * @return \Illuminate\Http\RedirectResponse
  *
  * PAGE CONTACT - SEND MESSAGE
  */
 public function sendContact(ContactFormRequest $request)
 {
     $messageMain = $request->input('message');
     $email = $request->input('email');
     \Akismet::setCommentContent($request->input('message'))->setCommentAuthorEmail($request->input('email'))->setCommentAuthorUrl($request->url());
     if (\Akismet::isSpam()) {
         return redirect()->back()->with('error', 'Message considéré comme du spam ! Merci d\'envoyer un message sans intentions commerciales');
     } else {
         Mail::send('emails.email', compact('messageMain', 'email'), function ($message) use($request) {
             $message->from('*****@*****.**', 'Laravel');
             $message->to('*****@*****.**')->cc('*****@*****.**');
         });
         return redirect()->back()->with('message', 'Message envoyé');
     }
 }
Example #28
0
 function onSubmit($vals)
 {
     $ak = appconf('akismet_key');
     if ($ak) {
         loader_import('siteblog.Akismet');
         $comment = array('author' => $vals['name'], 'email' => $vals['email'], 'website' => $vals['url'], 'body' => $vals['body'], 'permalink' => site_url() . '/index/siteblog-post-action/id.' . $vals['post'] . '/title.' . siteblog_filter_link_title($title), 'user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT']);
         $akismet = new Akismet(site_url(), $ak, $comment);
         if (!$akismet->errorsExist()) {
             // no errors
             if ($akismet->isSpam()) {
                 // akismet says spam
                 $title = db_shift('select subject from siteblog_post where id = ?', $vals['post']);
                 db_execute('insert into siteblog_akismet values (null, ?, now(), ?, ?, ?, ?, ?, ?)', $vals['post'], $comment['author'], $comment['email'], $comment['website'], $comment['user_ip'], $comment['user_agent'], $comment['body']);
                 header('Location: ' . site_prefix() . '/index/siteblog-post-action/id.' . $vals['post'] . '/title.' . siteblog_filter_link_title($title));
                 exit;
             }
         }
     }
     if (!empty($vals['post'])) {
         $res = db_execute('insert into siteblog_comment (id, child_of_post, body, date, author, email, url, ip) values (null, ?, ?, now(), ?, ?, ?, ?)', $vals['post'], $vals['body'], $vals['name'], $vals['email'], $vals['url'], $_SERVER['REMOTE_ADDR']);
         if (!$res) {
             die(db_error());
         }
         $id = db_lastid();
     } else {
         $res = db_execute('update siteblog_comment set body = ?, author = ?, email = ?, url = ? where id = ?', $vals['body'], $vals['name'], $vals['email'], $vals['url'], $vals['_key']);
         if (!$res) {
             die(db_error());
         }
         $id = $vals['_key'];
         $vals['post'] = db_shift('select child_of_post from siteblog_comment where id = ?', $vals['_key']);
     }
     $title = db_shift('select subject from siteblog_post where id = ?', $vals['post']);
     header('Location: ' . site_prefix() . '/index/siteblog-post-action/id.' . $vals['post'] . '/title.' . siteblog_filter_link_title($title) . '#siteblog-comment-' . $id);
     exit;
 }
Example #29
0
 public function isSpam()
 {
     require APP . 'Plugin' . DS . 'Comment' . DS . 'Vendor' . DS . 'akismet.php';
     App::uses('Akismet', 'Vendor');
     $akismet = new Akismet(Configure::read('Plugin.Comment.akismet.site'), Configure::read('Plugin.Comment.akismet.key'));
     $akismet->setCommentAuthor($this->data['Comment']['username']);
     $akismet->setCommentAuthorEmail($this->data['Comment']['mail']);
     $akismet->setCommentContent($this->data['Comment']["content"]);
     $akismet->setUserIP($this->data['Comment']['ip']);
     return $akismet->isCommentSpam();
 }
 function checkSpam($api, $blogUrl, $name, $email, $url, $comment, &$msgA)
 {
     require_once JPATH_COMPONENT . DS . 'assets' . DS . 'akismet' . DS . 'Akismet.class.php';
     $akismet = new Akismet($blogUrl, $api);
     $akismet->setCommentAuthor($name);
     $akismet->setCommentAuthorEmail($email);
     $akismet->setCommentAuthorURL($url);
     $akismet->setCommentContent($comment);
     if ($akismet->isKeyValid()) {
     } else {
         $msgA = 'Akismet: Key is invalid';
     }
     //trigger_error("Akismet: ".$akismet->isCommentSpam(),E_USER_WARNING);
     return $akismet->isCommentSpam();
 }