Example #1
0
 public function validatePost(PostWillBeSaved $event)
 {
     $post = $event->post;
     if ($post->exists || $post->user->groups()->count()) {
         return;
     }
     $akismet = new Akismet($this->settings->get('akismet.api_key'), Core::url());
     $isSpam = $akismet->isSpam($post->content, $post->user->username, $post->user->email, null, 'comment');
     if ($isSpam) {
         $post->hide();
         $this->savingPost = $post;
         CommentPost::saved(function (CommentPost $post) {
             if ($post !== $this->savingPost) {
                 return;
             }
             $report = new Report();
             $report->post_id = $post->id;
             $report->reporter = 'Akismet';
             $report->reason = 'spam';
             $report->time = time();
             $report->save();
             $this->savingPost = null;
         });
     }
 }
Example #2
0
 public function init()
 {
     if (!$this->_akismet instanceof AkismetAPI) {
         $akismet = new AkismetAPI($this->apiKey, Url::base(true));
         if (!$akismet->verifyKey()) {
             throw new \yii\base\InvalidConfigException('Invalid Akismet API key.');
         }
         $this->_akismet = $akismet;
     }
 }
Example #3
0
 public function validatePost(PostWillBeSaved $event)
 {
     $post = $event->post;
     if ($post->exists || $post->user->groups()->count()) {
         return;
     }
     $akismet = new Akismet($this->settings->get('akismet.api_key'), Core::url());
     $isSpam = $akismet->isSpam($post->content, $post->user->username, $post->user->email, null, 'comment');
     if ($isSpam) {
         $post->is_approved = false;
         // TODO:
         // $post->is_spam = true;
         $post->afterSave(function ($post) {
             $flag = new Flag();
             $flag->post_id = $post->id;
             $flag->type = 'akismet';
             $flag->time = time();
             $flag->save();
         });
     }
 }
Example #4
0
 /**
  * Validates the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // validate required fields
         $this->frm->getField('site_title')->isFilled(BL::err('FieldIsRequired'));
         // date & time
         $this->frm->getField('time_format')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('date_format_short')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('date_format_long')->isFilled(BL::err('FieldIsRequired'));
         // number
         $this->frm->getField('number_format')->isFilled(BL::err('FieldIsRequired'));
         // akismet key may be filled in
         if ($this->needsAkismet && $this->frm->getField('akismet_key')->isFilled()) {
             // key has changed
             if ($this->frm->getField('akismet_key')->getValue() != $this->get('fork.settings')->get('Core', 'akismet_key', null)) {
                 // create instance
                 $akismet = new Akismet($this->frm->getField('akismet_key')->getValue(), SITE_URL);
                 // invalid key
                 if (!$akismet->verifyKey()) {
                     $this->frm->getField('akismet_key')->setError(BL::err('InvalidAPIKey'));
                 }
             }
         }
         // domains filled in
         if ($this->frm->getField('site_domains')->isFilled()) {
             // split on newlines
             $domains = explode("\n", trim($this->frm->getField('site_domains')->getValue()));
             // loop domains
             foreach ($domains as $domain) {
                 // strip funky stuff
                 $domain = trim(str_replace(array('www.', 'http://', 'https://'), '', $domain));
                 // invalid URL
                 if (!\SpoonFilter::isURL('http://' . $domain)) {
                     // set error
                     $this->frm->getField('site_domains')->setError(BL::err('InvalidDomain'));
                     // stop looping domains
                     break;
                 }
             }
         }
         if ($this->frm->getField('ckfinder_image_max_width')->isFilled()) {
             $this->frm->getField('ckfinder_image_max_width')->isInteger(BL::err('InvalidInteger'));
         }
         if ($this->frm->getField('ckfinder_image_max_height')->isFilled()) {
             $this->frm->getField('ckfinder_image_max_height')->isInteger(BL::err('InvalidInteger'));
         }
         // no errors ?
         if ($this->frm->isCorrect()) {
             // general settings
             $this->get('fork.settings')->set('Core', 'site_title_' . BL::getWorkingLanguage(), $this->frm->getField('site_title')->getValue());
             $this->get('fork.settings')->set('Core', 'site_html_header', $this->frm->getField('site_html_header')->getValue());
             $this->get('fork.settings')->set('Core', 'site_start_of_body_scripts', $this->frm->getField('site_start_of_body_scripts')->getValue());
             $this->get('fork.settings')->set('Core', 'site_html_footer', $this->frm->getField('site_html_footer')->getValue());
             // facebook settings
             $this->get('fork.settings')->set('Core', 'facebook_admin_ids', $this->frm->getField('facebook_admin_ids')->isFilled() ? $this->frm->getField('facebook_admin_ids')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'facebook_app_id', $this->frm->getField('facebook_application_id')->isFilled() ? $this->frm->getField('facebook_application_id')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'facebook_app_secret', $this->frm->getField('facebook_application_secret')->isFilled() ? $this->frm->getField('facebook_application_secret')->getValue() : null);
             // twitter settings
             /** @var \SpoonFormText $txtTwitterSiteName */
             $txtTwitterSiteName = $this->frm->getField('twitter_site_name');
             if ($txtTwitterSiteName->isFilled()) {
                 $this->get('fork.settings')->set('Core', 'twitter_site_name', '@' . ltrim($txtTwitterSiteName->getValue(), '@'));
             }
             // ckfinder settings
             $this->get('fork.settings')->set('Core', 'ckfinder_license_name', $this->frm->getField('ckfinder_license_name')->isFilled() ? $this->frm->getField('ckfinder_license_name')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'ckfinder_license_key', $this->frm->getField('ckfinder_license_key')->isFilled() ? $this->frm->getField('ckfinder_license_key')->getValue() : null);
             $this->get('fork.settings')->set('Core', 'ckfinder_image_max_width', $this->frm->getField('ckfinder_image_max_width')->isFilled() ? $this->frm->getField('ckfinder_image_max_width')->getValue() : 1600);
             $this->get('fork.settings')->set('Core', 'ckfinder_image_max_height', $this->frm->getField('ckfinder_image_max_height')->isFilled() ? $this->frm->getField('ckfinder_image_max_height')->getValue() : 1200);
             // api keys
             $this->get('fork.settings')->set('Core', 'fork_api_public_key', $this->frm->getField('fork_api_public_key')->getValue());
             $this->get('fork.settings')->set('Core', 'fork_api_private_key', $this->frm->getField('fork_api_private_key')->getValue());
             if ($this->needsAkismet) {
                 $this->get('fork.settings')->set('Core', 'akismet_key', $this->frm->getField('akismet_key')->getValue());
             }
             if ($this->needsGoogleMaps) {
                 $this->get('fork.settings')->set('Core', 'google_maps_key', $this->frm->getField('google_maps_key')->getValue());
             }
             // date & time formats
             $this->get('fork.settings')->set('Core', 'time_format', $this->frm->getField('time_format')->getValue());
             $this->get('fork.settings')->set('Core', 'date_format_short', $this->frm->getField('date_format_short')->getValue());
             $this->get('fork.settings')->set('Core', 'date_format_long', $this->frm->getField('date_format_long')->getValue());
             // date & time formats
             $this->get('fork.settings')->set('Core', 'number_format', $this->frm->getField('number_format')->getValue());
             // before we save the languages, we need to ensure that each language actually exists and may be chosen.
             $languages = array(SITE_DEFAULT_LANGUAGE);
             $activeLanguages = array_unique(array_merge($languages, $this->frm->getField('active_languages')->getValue()));
             $redirectLanguages = array_unique(array_merge($languages, $this->frm->getField('redirect_languages')->getValue()));
             // cleanup redirect-languages, by removing the values that aren't present in the active languages
             $redirectLanguages = array_intersect($redirectLanguages, $activeLanguages);
             // save active languages
             $this->get('fork.settings')->set('Core', 'active_languages', $activeLanguages);
             $this->get('fork.settings')->set('Core', 'redirect_languages', $redirectLanguages);
             // domains may not contain www, http or https. Therefor we must loop and create the list of domains.
             $siteDomains = array();
             // domains filled in
             if ($this->frm->getField('site_domains')->isFilled()) {
                 // split on newlines
                 $domains = explode("\n", trim($this->frm->getField('site_domains')->getValue()));
                 // loop domains
                 foreach ($domains as $domain) {
                     // strip funky stuff
                     $siteDomains[] = trim(str_replace(array('www.', 'http://', 'https://'), '', $domain));
                 }
             }
             // save domains
             $this->get('fork.settings')->set('Core', 'site_domains', $siteDomains);
             $this->get('fork.settings')->set('Core', 'show_cookie_bar', $this->frm->getField('show_cookie_bar')->getChecked());
             // assign report
             $this->tpl->assign('report', true);
             $this->tpl->assign('reportMessage', BL::msg('Saved'));
         }
     }
 }
Example #5
0
 /**
  * General method to check if something is spam
  *
  * @param string $content   The content that was submitted.
  * @param string $permaLink The permanent location of the entry the comment was submitted to.
  * @param string $author    Commenter's name.
  * @param string $email     Commenter's email address.
  * @param string $URL       Commenter's URL.
  * @param string $type      May be blank, comment, trackback, pingback, or a made up value like "registration".
  * @return bool|string Will return a boolean, except when we can't decide the status
  *                          (unknown will be returned in that case)
  */
 public static function isSpam($content, $permaLink, $author = null, $email = null, $URL = null, $type = 'comment')
 {
     // get some settings
     $akismetKey = self::get('fork.settings')->get('Core', 'akismet_key');
     // invalid key, so we can't detect spam
     if ($akismetKey === '') {
         return false;
     }
     // create new instance
     $akismet = new Akismet($akismetKey, SITE_URL);
     // set properties
     $akismet->setTimeOut(10);
     $akismet->setUserAgent('Fork CMS/' . FORK_VERSION);
     // try it, to decide if the item is spam
     try {
         // check with Akismet if the item is spam
         return $akismet->isSpam($content, $author, $email, $URL, $permaLink, $type);
     } catch (\Exception $e) {
         // in debug mode we want to see exceptions, otherwise the fallback will be triggered
         if (self::getContainer()->getParameter('kernel.debug')) {
             throw $e;
         }
         // return unknown status
         return 'unknown';
     }
 }
Example #6
0
 /**
  * Submit spam, his call is for submitting comments that weren't marked as spam but should have been.
  *
  * @param string $userIp    IP address of the comment submitter.
  * @param string $userAgent User agent information.
  * @param string $content   The content that was submitted.
  * @param string $author    Submitted name with the comment.
  * @param string $email     Submitted email address.
  * @param string $url       Commenter URL.
  * @param string $permalink The permanent location of the entry the comment was submitted to.
  * @param string $type      May be blank, comment, trackback, pingback, or a made up value like "registration".
  * @param string $referrer  The content of the HTTP_REFERER header should be sent here.
  * @param array  $others    Other data (the variables from $_SERVER).
  * @return bool If everything went fine true will be returned, otherwise an exception will be triggered.
  */
 public static function submitSpam($userIp, $userAgent, $content, $author = null, $email = null, $url = null, $permalink = null, $type = null, $referrer = null, $others = null)
 {
     $akismetKey = self::get('fork.settings')->get('Core', 'akismet_key');
     // no key, so we can't detect spam
     if ($akismetKey === '') {
         return false;
     }
     $akismet = new Akismet($akismetKey, SITE_URL);
     $akismet->setTimeOut(10);
     $akismet->setUserAgent('Fork CMS/2.1');
     // try it to decide it the item is spam
     try {
         // check with Akismet if the item is spam
         return $akismet->submitSpam($userIp, $userAgent, $content, $author, $email, $url, $permalink, $type, $referrer, $others);
     } catch (Exception $e) {
         if (BackendModel::getContainer()->getParameter('kernel.debug')) {
             throw $e;
         }
     }
     return false;
 }
Example #7
0
<?php

//require
require_once '../../../autoload.php';
require_once 'config.php';
use TijsVerkoyen\Akismet\Akismet;
// create instance
$akismet = new Akismet(APIKEY, URL);
$response = $akismet->verifyKey();
//$response = $akismet->isSpam('Nice one. Thanks', 'Joris', '*****@*****.**', '', null, 'comment');
//$response = $akismet->submitHam(
//	'Great portal! <a href="http://key-west-florida-fishing-charters.6xyotd.us/ " rel="nofollow">Key west florida fishing charters</a><a href="http://kates-playground-videos.6xyotd.us/ " rel="nofollow">Kates playground videos</a><a href="http://karaoke-norah-jones.6xyotd.us/ " rel="nofollow">Karaoke norah jones</a><a href="http://kiera-knightly-naked.6xyotd.us/ " rel="nofollow">Kiera knightly naked</a><a href="http://kelli-fox.6xyotd.us/ " rel="nofollow">Kelli fox</a><a href="http://ky-farm-bureau.6xyotd.us/ " rel="nofollow">Ky farm bureau</a><a href="http://kari-gold.6xyotd.us/ " rel="nofollow">Kari gold</a><a href="http://julie-gibson-diaspora.6xyotd.us/ " rel="nofollow">Julie gibson diaspora</a><a href="http://keely-net.6xyotd.us/ " rel="nofollow">Keely net</a><a href="http://kellie-pickler-t**s.6xyotd.us/ " rel="nofollow">Kellie pickler t**s</a><a href="http://korean-central-news-agency.6xyotd.us/ " rel="nofollow">Korean central news agency</a><a href="http://kings-quest-3-walkthru.6xyotd.us/ " rel="nofollow">King&#8217;s quest 3 walkthru</a><a href="http://kennels-in-hilton-head.6xyotd.us/ " rel="nofollow">Kennels in hilton head</a><a href="http://kentucky-tv-stations.6xyotd.us/ " rel="nofollow">Kentucky tv stations</a><a href="http://kauffman-foundation.6xyotd.us/ " rel="nofollow">Kauffman foundation</a><a href="http://jungle-diaper-cakes.6xyotd.us/ " rel="nofollow">Jungle diaper cakes</a><a href="http://kimba-the-white-lion.6xyotd.us/ " rel="nofollow">Kimba the white lion</a><a href="http://julie-harris.6xyotd.us/ " rel="nofollow">Julie harris</a><a href="http://kona-hi.6xyotd.us/ " rel="nofollow">Kona hi</a><a href="http://kids-cowboy-boots.6xyotd.us/ " rel="nofollow">Kids cowboy boots</a><a href="http://kimora-simmons.6xyotd.us/ " rel="nofollow">Kimora simmons</a><a href="http://kermit-the-frog.6xyotd.us/ " rel="nofollow">Kermit the frog</a><a href="http://justin-nozuka.6xyotd.us/ " rel="nofollow">Justin nozuka</a><a href="http://katie-james-actress.6xyotd.us/ " rel="nofollow">Katie james actress</a><a href="http://king-neptune.6xyotd.us/ " rel="nofollow">King neptune</a> yefvo',
//	'ofqqn',
//	'*****@*****.**'
//);
//output
ob_start();
var_dump($response);