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;
 }
 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']);
     }
 }
Beispiel #3
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);
         }
     }
 }
Beispiel #4
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'] .= " [[✉->mailto:";
        $page['text'] .= $_POST['email'];
        $page['text'] .= "]]";
    }
    if (strlen($_POST['url']) > 0) {
        $page['text'] .= " [[➚->";
        $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);
}
 /**
  * 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}/'];
 }
 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();
 }
 /**
  * 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();
 }
 /**
  * @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é');
     }
 }
 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();
 }
Beispiel #10
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");
     }
 }
Beispiel #11
0
function q_isspam($q)
{
    if (get_option('q_filter_spam') == 'TRUE') {
        global $current_user;
        get_currentuserinfo();
        $akismet = new Akismet(get_bloginfo('wpurl'), get_option('q_wpcomAPIkey'));
        $akismet->setCommentAuthor($current_user->user_login);
        $akismet->setCommentAuthorEmail($current_user->user_email);
        $akismet->setCommentAuthorURL($current_user->user_url);
        $akismet->setCommentContent($q);
        if ($akismet->isCommentSpam()) {
            return true;
        } else {
            return false;
        }
    }
}
Beispiel #12
0
 public function queryAkismet($author, $textDiff, $permalink)
 {
     global $wgMWAkismetKey;
     global $wgMWAkismetURL;
     // First check to see if the config settings are set
     if ($wgMWAkismetKey == '' || $wgMWAkismetURL == '') {
         echo "Akismet key and url must be set.  Instructions for getting a key are here: <a href=\"http://faq.wordpress.com/2005/10/19/api-key/\">API key FAQ on Wordpress.com</a>";
         die;
     }
     $akismet = new Akismet($wgMWAkismetURL, $wgMWAkismetKey);
     $akismet->setCommentAuthor($author);
     $akismet->setCommentAuthorEmail("");
     $akismet->setCommentAuthorURL("");
     $akismet->setCommentContent($textDiff);
     $akismet->setPermalink($permalink);
     $isSpam = $akismet->isCommentSpam();
     return $isSpam;
 }
Beispiel #13
0
 /**
  * This event check spam in comments, posts and other contents for modules
  * 
  * @param array All params to check (blogurl, name, email, url, text, permalink)
  * @return bool
  */
 public function eventRmcommonCheckPostSpam($params)
 {
     $config = RMFunctions::get()->plugin_settings('akismet', true);
     if ($config['key'] == '') {
         return;
     }
     extract($params);
     $akismet = new Akismet($blogurl, $config['key']);
     $akismet->setCommentAuthor($name);
     $akismet->setCommentAuthorEmail($email);
     $akismet->setCommentAuthorURL($url);
     $akismet->setCommentContent($text);
     $akismet->setPermalink($permalink);
     $akismet->setUserIP($_SERVER['REMOTE_ADDR']);
     if ($akismet->isCommentSpam()) {
         return false;
     }
     return true;
 }
 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();
         }
     }
 }
Beispiel #15
0
function akismet_scan($Data, $Setup, $Config)
{
    if (empty($Setup['_APIKey'])) {
        return false;
    }
    include_once WP_PLUGIN_DIR . '/db-toolkit/data_form/processors/akismet/Akismet.class.php';
    $WordPressAPIKey = $Setup['_APIKey'];
    $MyBlogURL = get_bloginfo('url');
    $akismet = new Akismet($MyBlogURL, $WordPressAPIKey);
    $akismet->setCommentAuthor($Data[$Setup['_Name']]);
    $akismet->setCommentAuthorEmail($Data[$Setup['_Email']]);
    $akismet->setCommentAuthorURL($Data[$Setup['_URL']]);
    $akismet->setCommentContent($Data[$Setup['_Text']]);
    $akismet->setUserIP($_SERVER['REMOTE_ADDR']);
    if ($akismet->isCommentSpam()) {
        return true;
    } else {
        return false;
    }
    return false;
}
Beispiel #16
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";
                }
            }
        }
    }
}
Beispiel #17
0
 /**
  * Use Akismet to check comment data for spam
  *
  * @param array $data
  * @return array Data with spam field set
  */
 function isSpam(&$data)
 {
     $apiKey = Configure::read('AppSettings.wordpress_api_key');
     if (empty($apiKey)) {
         return false;
     }
     try {
         App::import('Vendor', 'akismet');
         $siteUrl = 'http://' . getenv('SERVER_NAME');
         $akismet = new Akismet($siteUrl, $apiKey);
         $akismet->setCommentAuthor($data[$this->name]['name']);
         $akismet->setCommentAuthorEmail($data[$this->name]['email']);
         $akismet->setCommentAuthorURL($data[$this->name]['url']);
         $akismet->setCommentContent($data[$this->name]['content']);
         $akismet->setPermalink($data['Post']['permalink']);
         if ($akismet->isCommentSpam()) {
             return true;
         }
     } catch (Exception $e) {
         $this->log('Akismet not reachable!');
     }
     return false;
 }
Beispiel #18
0
 /**
  * Use Akismet to check comment data for spam
  *
  * @param array $data
  * @return bool
  */
 function isSpam(&$data)
 {
     $apiKey = Configure::read('Wildflower.settings.wordpress_api_key');
     if (empty($apiKey)) {
         return false;
     }
     try {
         App::import('Vendor', 'akismet');
         $siteUrl = Configure::read('Wildflower.fullSiteUrl');
         $akismet = new Akismet($siteUrl, $apiKey);
         $akismet->setCommentAuthor($data[$this->name]['name']);
         $akismet->setCommentAuthorEmail($data[$this->name]['email']);
         $akismet->setCommentAuthorURL($data[$this->name]['url']);
         $akismet->setCommentContent($data[$this->name]['content']);
         $akismet->setPermalink($data['Post']['permalink']);
         if ($akismet->isCommentSpam()) {
             return true;
         }
     } catch (Exception $e) {
         trigger_error('Akismet not reachable: ' . $e->message);
     }
     return false;
 }
Beispiel #19
0
 protected function getAkismet($invoker)
 {
     $request = sfContext::getInstance()->getRequest();
     $api_key = sfConfig::get('app_akismet_api_key');
     if (empty($api_key)) {
         return false;
     }
     $akismet = new Akismet($request->getUriPrefix() . $request->getRelativeUrlRoot(), $api_key);
     $data = $invoker->getAkismetData();
     // Set values
     if (!empty($data['author_name'])) {
         $akismet->setCommentAuthor($data['author_name']);
     } else {
         return true;
     }
     if (!empty($data['author_email'])) {
         $akismet->setCommentAuthorEmail($data['author_email']);
     }
     if (!empty($data['author_url'])) {
         $akismet->setCommentAuthorURL($data['author_url']);
     }
     if (!empty($data['content'])) {
         $akismet->setCommentContent($data['content']);
     } else {
         return true;
     }
     if (!empty($data['permalink'])) {
         $akismet->setPermalink($data['permalink']);
     }
     if (!empty($data['referrer'])) {
         $akismet->setReferer($data['referrer']);
     }
     if (!empty($data['user_ip'])) {
         $akismet->setUserIp($data['user_ip']);
     }
     return $akismet;
 }
Beispiel #20
0
function sl_is_spam($email, $content = null, $optional = array())
{
    $optargs = array('ip' => 'setUserIP', 'nickname' => 'setCommentAuthor', 'permalink' => 'setPermalink', 'referrer' => 'setReferrer', 'type' => 'setCommentType');
    $akismet = new Akismet(AKISMET_URL, AKISMET_KEY);
    $akismet->setCommentAuthorEmail($email);
    if (!empty($content)) {
        $akismet->setCommentContent($content);
    }
    // User-agent, IP, and referrer are automatically set by the Akismet class, but can be overriden
    foreach ($optional as $optarg => $val) {
        if (in_array($optarg, $optargs)) {
            $akismet->{$optargs[$optarg]}($val);
        }
    }
    try {
        $isSpam = $akismet->isCommentSpam();
    } catch (Exception $e) {
        $isSpam = false;
        error_log('Akismet exception: ', $e->getMessage(), "\n");
    }
    return $isSpam;
}
Beispiel #21
0
 /**
  * Akismet Operations
  *
  * Send a message to check for spam.  If the message is flagged as spam, true is returned.
  *
  * @param string|array $data The message to check
  *
  * @return bool True if the message is flagged as spam, false if not
  */
 public static function akismet($data)
 {
     global $cache, $config, $db, $user;
     if (!$config['asacp_enable'] || !$config['asacp_akismet_enable'] || !$config['asacp_akismet_key']) {
         return false;
     }
     if ($user->data['is_registered']) {
         if ($user->data['user_posts'] > $config['asacp_akismet_post_limit'] && $config['asacp_akismet_post_limit'] > 0) {
             return false;
         }
     }
     // else the user is a guest
     if (!class_exists('Akismet')) {
         global $phpbb_root_path, $phpEx;
         include $phpbb_root_path . 'antispam/Akismet.class.' . $phpEx;
     }
     $akismet = new Akismet($config['asacp_akismet_domain'], $config['asacp_akismet_key']);
     $akismet->setUserIP($user->ip);
     $akismet->setCommentType('comment');
     $akismet->setCommentAuthor($user->data['username']);
     $akismet->setCommentAuthorEmail($user->data['user_email']);
     $akismet->setCommentContent((string) $data);
     return $akismet->isCommentSpam() ? true : false;
 }
Beispiel #22
0
function akismet_showpage()
{
    global $main_smarty, $the_template, $current_user, $db;
    force_authentication();
    $canIhaveAccess = 0;
    $canIhaveAccess = $canIhaveAccess + checklevel('god');
    if ($canIhaveAccess == 1) {
        if (phpnum() >= 5) {
            include_once akismet_lib_path . 'Akismet.class_5.php';
        } else {
            include_once akismet_lib_path . 'Akismet.class_4.php';
        }
        $navwhere['text1'] = 'Akismet';
        $navwhere['link1'] = URL_akismet;
        define('pagename', 'akismet');
        $main_smarty->assign('pagename', pagename);
        define('modulename', 'akismet');
        $main_smarty->assign('modulename', modulename);
        if (isset($_REQUEST['view'])) {
            $view = sanitize($_REQUEST['view'], 3);
        } else {
            $view = '';
        }
        if ($view == '') {
            $wordpress_key = get_misc_data('wordpress_key');
            if ($wordpress_key == '') {
                header('Location: ' . URL_akismet . '&view=manageKey');
            }
            $spam_links = get_misc_data('spam_links');
            if ($spam_links != '') {
                $spam_links = unserialize(get_misc_data('spam_links'));
            } else {
                $spam_links = array();
            }
            $main_smarty->assign('spam_links', $spam_links);
            $main_smarty->assign('spam_links_count', count($spam_links));
            $spam_comments = get_misc_data('spam_comments');
            if ($spam_comments != '') {
                $spam_comments = unserialize(get_misc_data('spam_comments'));
            } else {
                $spam_comments = array();
            }
            $main_smarty->assign('spam_comments', $spam_comments);
            $main_smarty->assign('spam_comments_count', count($spam_comments));
            $main_smarty = do_sidebar($main_smarty, $navwhere);
            $main_smarty->assign('posttitle', " / " . $main_smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel'));
            $main_smarty->assign('tpl_center', akismet_tpl_path . 'main');
            $main_smarty->display($template_dir . '/admin/admin.tpl');
        }
        if ($view == 'manageKey') {
            $wordpress_key = get_misc_data('wordpress_key');
            $main_smarty->assign('wordpress_key', $wordpress_key);
            $main_smarty = do_sidebar($main_smarty, $navwhere);
            $main_smarty->assign('posttitle', " / " . $main_smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel'));
            $main_smarty->assign('tpl_center', akismet_tpl_path . 'manageKey');
            $main_smarty->display($template_dir . '/admin/admin.tpl');
        }
        if ($view == 'updateKey') {
            if (isset($_REQUEST['key'])) {
                $wordpress_key = sanitize($_REQUEST['key'], 3);
            } else {
                $wordpress_key = '';
            }
            misc_data_update('wordpress_key', $wordpress_key);
            header('Location: ' . URL_akismet);
        }
        if ($view == 'manageSpam') {
            $spam_links = get_misc_data('spam_links');
            if ($spam_links != '') {
                $spam_links = unserialize(get_misc_data('spam_links'));
            } else {
                $spam_links = array();
            }
            if (count($spam_links) > 0) {
                $sql = "SELECT " . table_links . ".* FROM " . table_links . " WHERE ";
                $sql .= 'link_id IN (' . implode(',', $spam_links) . ')';
                $link_data = $db->get_results($sql);
                $main_smarty->assign('link_data', object_2_array($link_data));
            } else {
                header('Location: ' . URL_akismet);
            }
            $main_smarty = do_sidebar($main_smarty, $navwhere);
            $main_smarty->assign('posttitle', " / " . $main_smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel'));
            $main_smarty->assign('tpl_center', akismet_tpl_path . 'manageSpam');
            $main_smarty->display($template_dir . '/admin/admin.tpl');
        }
        if ($view == 'manageSettings') {
            $main_smarty = do_sidebar($main_smarty, $navwhere);
            $main_smarty->assign('posttitle', " / " . $main_smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel'));
            $main_smarty->assign('tpl_center', akismet_tpl_path . 'manageSettings');
            $main_smarty->display($template_dir . '/admin/admin.tpl');
        }
        /*
        if($view == 'isSpam'){
        	if(isset($_REQUEST['link_id'])){$link_id = sanitize($_REQUEST['link_id'], 3);}else{$link_id='';}
        
        	$spam_links = get_misc_data('spam_links');
        	$spam_links = unserialize(get_misc_data('spam_links'));
        
        	unset($spam_links[$link_id]);
        	misc_data_update('spam_links', serialize($spam_links));
        
        	$link = new Link;
        	$link->id = $link_id;
        	$link->read(FALSE);
        	$link->status = 'discard';
        	$link->store();
        
        	header('Location: ' . URL_akismet . '&view=manageSpam');
        }
        
        if($view == 'isNotSpam'){
        	if(isset($_REQUEST['link_id'])){$link_id = sanitize($_REQUEST['link_id'], 3);}else{$link_id='';}
        
        	$spam_links = get_misc_data('spam_links');
        	$spam_links = unserialize(get_misc_data('spam_links'));
        
        	unset($spam_links[$link_id]);
        	misc_data_update('spam_links', serialize($spam_links));
        
        	$link = new Link;
        	$link->id = $link_id;
        	$link->read(FALSE);
        	$link->status = 'queued';
        	$link->store();
        
        	header('Location: ' . URL_akismet . '&view=manageSpam');
        }
        
        if($view == 'addSpam'){
        
        	$spam_links[1] = 1;
        	misc_data_update('spam_links', serialize($spam_links));
        	header('Location: ' . URL_akismet . '&view=manageSpam');
        
        }
        */
        if ($view == 'manageSpamcomments') {
            $spam_comments = get_misc_data('spam_comments');
            if ($spam_comments != '') {
                $spam_comments = unserialize(get_misc_data('spam_comments'));
            } else {
                $spam_comments = array();
            }
            if (count($spam_comments) > 0) {
                $sql = "SELECT * FROM " . table_prefix . "spam_comments WHERE ";
                $sql .= 'linkid IN (' . implode(',', $spam_comments) . ')';
                $link_data = $db->get_results($sql);
                $user_cmt = new User();
                $user_cmt_link = new Link();
                $spam_output .= ' <form name="bulk_moderate" action="' . URL_akismet_isSpamcomment . '&action=bulkmod" method="post">';
                $spam_output .= "<table>";
                $spam_output .= "<tr><th>Author</th><th>Body</th><th>this is spam</th><th>this is NOT spam</th></tr>";
                if ($link_data) {
                    foreach ($link_data as $spam_cmts) {
                        $user_cmt->id = $spam_cmts->userid;
                        $user_cmt->read();
                        $user_name = $user_cmt->username;
                        $user_cmt_link->id = $spam_cmts->linkid;
                        $user_cmt_link->read();
                        $spam_output .= "<tr>";
                        $spam_output .= "<td>" . $user_name . "</td>";
                        $spam_output .= "<td>" . save_text_to_html($spam_cmts->cmt_content) . "</td>";
                        $spam_output .= '<td><center><input type="radio" name="spamcomment[' . $spam_cmts->auto_id . ']" id="spamcomment-' . $spam_cmts->auto_id . '" value="spamcomment"></center></td>';
                        $spam_output .= '<td><center><input type="radio" name="spamcomment[' . $spam_cmts->auto_id . ']" id="spamcomment-' . $spam_cmts->auto_id . '" value="notspamcomment"></center></td>';
                        $spam_output .= "</tr>";
                    }
                }
                $spam_output .= "</table>";
                $spam_output .= '<p align="right"><input type="submit" name="submit" value="Change Status" class="log2" /></p>';
                $spam_output .= "</form>";
                $main_smarty->assign('spam_output', $spam_output);
                $main_smarty->assign('link_data', object_2_array($link_data));
            } else {
                header('Location: ' . URL_akismet);
            }
            $main_smarty = do_sidebar($main_smarty, $navwhere);
            $main_smarty->assign('posttitle', " / " . $main_smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel'));
            $main_smarty->assign('tpl_center', akismet_tpl_path . 'manageSpamcomments');
            $main_smarty->display($the_template . '/pligg.tpl');
        }
        if ($view == 'isSpam') {
            if ($_GET['action'] == "bulkmod") {
                if (isset($_POST['submit'])) {
                    $spam = array();
                    foreach ($_POST["spam"] as $k => $v) {
                        $spam[intval($k)] = $v;
                    }
                    foreach ($spam as $key => $value) {
                        if ($value == "spam") {
                            if (isset($key)) {
                                $link_id = sanitize($key, 3);
                            } else {
                                $link_id = '';
                            }
                            $spam_links = get_misc_data('spam_links');
                            $spam_links = unserialize(get_misc_data('spam_links'));
                            $key = array_search($link_id, $spam_links);
                            unset($spam_links[$key]);
                            misc_data_update('spam_links', serialize($spam_links));
                            $link = new Link();
                            $link->id = $link_id;
                            $link->read();
                            $link->status = 'discard';
                            $link->store();
                            $user = new User();
                            $user->id = $link->author;
                            $user->read();
                            $akismet = new Akismet(my_base_url . my_pligg_base, get_misc_data('wordpress_key'));
                            $akismet->setCommentAuthor($user->username);
                            $akismet->setCommentAuthorEmail($user->email);
                            $akismet->setCommentAuthorURL($link->url);
                            $akismet->setCommentContent($link->content);
                            $akismet->setPermalink(getmyurl('story', $link->id));
                            $akismet->submitSpam();
                        } elseif ($value == "notspam") {
                            if (isset($key)) {
                                $link_id = sanitize($key, 3);
                            } else {
                                $link_id = '';
                            }
                            $spam_links = get_misc_data('spam_links');
                            $spam_links = unserialize(get_misc_data('spam_links'));
                            $key = array_search($link_id, $spam_links);
                            unset($spam_links[$key]);
                            misc_data_update('spam_links', serialize($spam_links));
                            $link = new Link();
                            $link->id = $link_id;
                            $link->read(FALSE);
                            $link->status = 'queued';
                            $link->store();
                            $user = new User();
                            $user->id = $link->author;
                            $user->read();
                            $akismet = new Akismet(my_base_url . my_pligg_base, get_misc_data('wordpress_key'));
                            $akismet->setCommentAuthor($user->username);
                            $akismet->setCommentAuthorEmail($user->email);
                            $akismet->setCommentAuthorURL($link->url);
                            $akismet->setCommentContent($link->content);
                            $akismet->setPermalink(getmyurl('story', $link->id));
                            $akismet->submitHam();
                        }
                    }
                }
            }
            header('Location: ' . URL_akismet . '&view=manageSpam');
        }
        if ($view == 'isSpamcomment') {
            if ($_GET['action'] == "bulkmod") {
                if (isset($_POST['submit'])) {
                    $spamcomment = array();
                    foreach ($_POST["spamcomment"] as $k => $v) {
                        $spamcomment[intval($k)] = $v;
                    }
                    foreach ($spamcomment as $key => $value) {
                        if ($value == "spamcomment") {
                            if (isset($key)) {
                                $link_id = sanitize($key, 3);
                            } else {
                                $link_id = '';
                            }
                            global $db;
                            $spam_comments = get_misc_data('spam_comments');
                            $spam_comments = unserialize(get_misc_data('spam_comments'));
                            $key = array_search($link_id, $spam_comments);
                            unset($spam_comments[$key]);
                            $sql_result = "Select * from " . table_prefix . "spam_comments where auto_id=" . $link_id;
                            $result_arr = $db->get_results($sql_result);
                            if ($result_arr) {
                                foreach ($result_arr as $result_arr_comments) {
                                    $link = new Link();
                                    $link->id = $result_arr_comments->linkid;
                                    $link->read();
                                    $user = new User();
                                    $user->id = $result_arr_comments->userid;
                                    $user->read();
                                    $akismet = new Akismet(my_base_url . my_pligg_base, get_misc_data('wordpress_key'));
                                    $akismet->setCommentAuthor($user->username);
                                    $akismet->setCommentAuthorEmail($user->email);
                                    $akismet->setCommentAuthorURL($link->url);
                                    $akismet->setCommentContent($result_arr_comments->cmt_content);
                                    $akismet->setPermalink(getmyurl('story', $link->id));
                                    $akismet->submitSpam();
                                }
                            }
                            misc_data_update('spam_comments', serialize($spam_comments));
                            $db->query(' Delete from ' . table_prefix . 'spam_comments where auto_id=' . $link_id);
                        } elseif ($value == "notspamcomment") {
                            if (isset($key)) {
                                $link_id = sanitize($key, 3);
                            } else {
                                $link_id = '';
                            }
                            global $db;
                            $spam_comments = get_misc_data('spam_comments');
                            $spam_comments = unserialize(get_misc_data('spam_comments'));
                            $key = array_search($link_id, $spam_comments);
                            unset($spam_comments[$key]);
                            $sql_result = " Select * from " . table_prefix . "spam_comments where auto_id={$link_id}";
                            $result_arr = $db->get_results($sql_result);
                            if ($result_arr) {
                                foreach ($result_arr as $result_arr_comments) {
                                    $link = new Link();
                                    $link->id = $result_arr_comments->linkid;
                                    $link->read();
                                    $user = new User();
                                    $user->id = $result_arr_comments->userid;
                                    $user->read();
                                    $akismet = new Akismet(my_base_url . my_pligg_base, get_misc_data('wordpress_key'));
                                    $akismet->setCommentAuthor($user->username);
                                    $akismet->setCommentAuthorEmail($user->email);
                                    $akismet->setCommentAuthorURL($link->url);
                                    $akismet->setCommentContent($result_arr_comments->cmt_content);
                                    $akismet->setPermalink(getmyurl('story', $link->id));
                                    $akismet->submitHam();
                                    $sql = "INSERT INTO " . table_comments . " (comment_parent, comment_user_id, comment_link_id , comment_date, comment_randkey, comment_content) VALUES ({$result_arr_comments->cmt_parent}, {$result_arr_comments->userid}, {$result_arr_comments->linkid}, now(), '{$result_arr_comments->cmt_rand}', '{$result_arr_comments->cmt_content}')";
                                    $db->query($sql);
                                }
                            }
                            misc_data_update('spam_comments', serialize($spam_comments));
                            $sql_delete = ' Delete from ' . table_prefix . 'spam_comments where auto_id=' . $link_id;
                            $db->query($sql_delete);
                            $link->adjust_comment(1);
                            $link->store();
                        }
                    }
                }
                header('Location: ' . URL_akismet . '&view=manageSpamcomments');
            }
        }
    }
}
Beispiel #23
0
 /**
  * Check if comment is spam using Akismet.
  *
  * @param Comment $comment The Comment object
  * @param string $api_key The Akismet API key
  *
  * @return void
  *
  * @since 2.0
  */
 public function akismet($comment, $api_key = '')
 {
     // load akismet class
     $this->app->loader->register('Akismet', 'libraries:akismet/akismet.php');
     // check comment
     $akismet = new Akismet(JURI::root(), $api_key);
     $akismet->setCommentAuthor($comment->author);
     $akismet->setCommentAuthorEmail($comment->email);
     $akismet->setCommentAuthorURL($comment->url);
     $akismet->setCommentContent($comment->content);
     // set state
     if ($akismet->isCommentSpam()) {
         $comment->state = Comment::STATE_SPAM;
     }
 }
Beispiel #24
0
        public function add_comment()
        {

            if(!osc_comments_enabled()) {
                return 7;
            }

            $aItem  = $this->prepareDataForFunction('add_comment');


            $authorName     = trim(strip_tags($aItem['authorName']));
            $authorEmail    = trim(strip_tags($aItem['authorEmail']));
            $body           = trim(strip_tags($aItem['body']));
            $title          = trim(strip_tags($aItem['title']));
            $itemId         = $aItem['id'];
            $userId         = $aItem['userId'];
            $status_num     = -1;

            $banned = osc_is_banned(trim(strip_tags($aItem['authorEmail'])));
            if($banned==1 || $banned==2) {
                Session::newInstance()->_setForm('commentAuthorName', $authorName);
                Session::newInstance()->_setForm('commentTitle', $title);
                Session::newInstance()->_setForm('commentBody', $body);
                Session::newInstance()->_setForm('commentAuthorEmail', $authorEmail);
                return 5;
            }

            $item = $this->manager->findByPrimaryKey($itemId);
            View::newInstance()->_exportVariableToView('item', $item);
            $itemURL = osc_item_url();
            $itemURL = '<a href="'.$itemURL.'" >'.$itemURL.'</a>';

            Params::setParam('itemURL', $itemURL);

            if(osc_reg_user_post_comments() && !osc_is_web_user_logged_in()) {
                Session::newInstance()->_setForm('commentAuthorName', $authorName);
                Session::newInstance()->_setForm('commentTitle', $title);
                Session::newInstance()->_setForm('commentBody', $body);
                return 6;
            }

            if( !preg_match('|^.*?@.{2,}\..{2,3}$|', $authorEmail)) {
                Session::newInstance()->_setForm('commentAuthorName', $authorName);
                Session::newInstance()->_setForm('commentTitle', $title);
                Session::newInstance()->_setForm('commentBody', $body);
                return 3;
            }

            if( ($body == '') ) {
                Session::newInstance()->_setForm('commentAuthorName', $authorName);
                Session::newInstance()->_setForm('commentAuthorEmail', $authorEmail);
                Session::newInstance()->_setForm('commentTitle', $title);
                return 4;
            }

            $num_moderate_comments = osc_moderate_comments();
            if($userId==null) {
                $num_comments = 0;
            } else {
                $user         = User::newInstance()->findByPrimaryKey($userId);
                $num_comments = $user['i_comments'];
            }

            if ($num_moderate_comments == -1 || ($num_moderate_comments != 0 && $num_comments >= $num_moderate_comments)) {
                $status     = 'ACTIVE';
                $status_num = 2;
            } else {
                $status     = 'INACTIVE';
                $status_num = 1;
            }

            if (osc_akismet_key()) {
                require_once LIB_PATH . 'Akismet.class.php';
                $akismet = new Akismet(osc_base_url(), osc_akismet_key());
                $akismet->setCommentAuthor($authorName);
                $akismet->setCommentAuthorEmail($authorEmail);
                $akismet->setCommentContent($body);
                $akismet->setPermalink($itemURL);

                $status = $akismet->isCommentSpam() ? 'SPAM' : $status;
                if($status == 'SPAM') {
                    $status_num = 5;
                }
            }

            $mComments = ItemComment::newInstance();
            $aComment  = array('dt_pub_date'    => date('Y-m-d H:i:s')
                              ,'fk_i_item_id'   => $itemId
                              ,'s_author_name'  => $authorName
                              ,'s_author_email' => $authorEmail
                              ,'s_title'        => $title
                              ,'s_body'         => $body
                              ,'b_active'       => ($status=='ACTIVE' ? 1 : 0)
                              ,'b_enabled'      => 1
                              ,'fk_i_user_id'   => $userId);

            osc_run_hook('before_add_comment', $aComment);

            if( $mComments->insert($aComment) ) {
                $commentID = $mComments->dao->insertedId();
                if($status_num == 2 && $userId != null) { // COMMENT IS ACTIVE
                    $user = User::newInstance()->findByPrimaryKey($userId);
                    if( $user ) {
                        User::newInstance()->update( array( 'i_comments' => $user['i_comments'] + 1)
                                                    ,array( 'pk_i_id'    => $user['pk_i_id'] ) );
                    }
                }

                //Notify admin
                if ( osc_notify_new_comment() ) {
                    osc_run_hook('hook_email_new_comment_admin', $aItem);
                }

                //Notify user
                if ( osc_notify_new_comment_user() ) {
                    osc_run_hook('hook_email_new_comment_user', $aItem);
                }

                osc_run_hook( 'add_comment', $commentID );

                return $status_num;
            }

            return -1;
        }
Beispiel #25
0
 /**
  * Check to see if the content being passed is considered as SPAM.
  *
  * @return bool TRUE is spam, FALSE if it isn't.
  */
 private function _isSpam()
 {
     if (Phpfox::getUserParam('core.is_spam_free')) {
         return false;
     }
     if (!Phpfox::getParam('core.enable_spam_check')) {
         return false;
     }
     if (Phpfox::isUser() && Phpfox::getUserBy('total_spam') > Phpfox::getParam('core.auto_deny_items')) {
         $this->_aParams['is_spam'] = true;
         return true;
     }
     $sUrl = Phpfox::getParam('core.akismet_url');
     $sPassword = Phpfox::getParam('core.akismet_password');
     if (empty($sUrl) || empty($sPassword)) {
         return false;
     }
     $sAkismet = PHPFOX_DIR_LIB . 'akismet' . PHPFOX_DS . 'Akismet.class.php';
     if (file_exists($sAkismet)) {
         require_once $sAkismet;
         $oAkismet = new Akismet($sUrl, $sPassword);
         if (Phpfox::isUser()) {
             $oAkismet->setCommentAuthor(Phpfox::getUserBy('full_name'));
             $oAkismet->setCommentAuthorEmail(Phpfox::getUserBy('email'));
         } else {
             if (isset($this->_aParams['user'])) {
                 $oAkismet->setCommentAuthor($this->_aParams['user']);
             }
             if (isset($this->_aParams['email'])) {
                 $oAkismet->setCommentAuthorEmail($this->_aParams['email']);
             }
         }
         if (isset($this->_aParams['url'])) {
             $oAkismet->setCommentAuthorURL($this->_aParams['url']);
         }
         if (isset($this->_aParams['link'])) {
             $oAkismet->setPermalink($this->_aParams['link']);
         }
         if (isset($this->_aParams['content'])) {
             $oAkismet->setCommentContent($this->_aParams['content']);
         }
         if (($this->_aParams['is_spam'] = $oAkismet->isCommentSpam()) === true) {
             Phpfox_Database::instance()->updateCounter('user', 'total_spam', 'user_id', Phpfox::getUserId());
         }
         return $this->_aParams['is_spam'];
     }
     return false;
 }
Beispiel #26
0
     require_once $this->direktori_kiss . '/classAkismet.php';
     foreach ($_POST['pilihan'] as $id_komentar) {
         $id_komen = $this->filter($id_komentar);
         # Jangan tampilkan komentar dari konten yang bersangkutan
         $proses = $this->db->perbarui('komentar', "aktif = 0", "id = '{$id_komentar}'");
         if ($proses) {
             # Ambil data komentar
             $komen_spam = $this->db->ambil('komentar', 'komentar, nama, email, situs', "id = '{$id_komentar}'");
             # Proses dengan Akismet (submit ke server Akismet sebagai SPAM)
             $akismet = new Akismet($this->alamat, $this->data_utama['wordpress_key']);
             $akismet->setCommentAuthor($komen_spam['nama']);
             $akismet->setCommentAuthorEmail($komen_spam['email']);
             if (!empty($komen_spam['situs'])) {
                 $akismet->setCommentAuthorURL($komen_spam['situs']);
             }
             $akismet->setCommentContent($komen_spam['komentar']);
             $akismet->submitSpam();
         }
     }
     $komen .= 'Komentar telah ditandai sebagai SPAM';
 } elseif (isset($_POST['hapus']) and !empty($_POST['pilihan'])) {
     $num = 0;
     foreach ($_POST['pilihan'] as $id_komentar) {
         $id_komentar = $this->filter($id_komentar);
         $proses = $this->db->hapus('komentar', "id = '{$id_komentar}'");
         $num++;
     }
     $konten .= $proses ? 'Menghapus ' . $num . ' komentar' : 'Gagal menghapus komentar';
 }
 # Tampilkan tabel komentar
 # Pertama-tama set dahulu variable pagination
Beispiel #27
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;
 }
Beispiel #28
0
 function comment()
 {
     $mainframe = JFactory::getApplication();
     jimport('joomla.mail.helper');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $params = K2HelperUtilities::getParams('com_k2');
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     JLoader::register('Services_JSON', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php');
     $json = new Services_JSON();
     $response = new JObject();
     //Get item
     $item = JTable::getInstance('K2Item', 'Table');
     $item->load(JRequest::getInt('itemID'));
     //Get category
     $category = JTable::getInstance('K2Category', 'Table');
     $category->load($item->catid);
     //Access check
     if (K2_JVERSION != '15') {
         if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($category->access, $user->getAuthorisedViewLevels())) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
     } else {
         if ($item->access > $user->get('aid', 0) || $category->access > $user->get('aid', 0)) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
     }
     //Published check
     if (!$item->published || $item->trash) {
         JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
     }
     if (!$category->published || $category->trash) {
         JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
     }
     //Check permissions
     if ($params->get('comments') == '2' && $user->id > 0 && K2HelperPermissions::canAddComment($item->catid) || $params->get('comments') == '1') {
         // If new antispam settings are not saved, show a message to the comments form and stop the comment submission
         $antispamProtection = $params->get('antispam', null);
         if ($antispamProtection === null || ($antispamProtection == 'recaptcha' || $antispamProtection == 'both') && !$params->get('recaptcha_private_key') || ($antispamProtection == 'akismet' || $antispamProtection == 'both') && !$params->get('akismetApiKey')) {
             $response->message = JText::_('K2_ANTISPAM_SETTINGS_ERROR');
             echo $json->encode($response);
             $mainframe->close();
         }
         $row = JTable::getInstance('K2Comment', 'Table');
         if (!$row->bind(JRequest::get('post'))) {
             $response->message = $row->getError();
             echo $json->encode($response);
             $mainframe->close();
         }
         $row->commentText = JRequest::getString('commentText', '', 'default');
         $row->commentText = strip_tags($row->commentText);
         //Strip a tags since all urls will be converted to links automatically on runtime.
         //Additionaly strip tables to avoid layout issues.
         //Also strip all attributes except src, alt and title.
         //$filter	= new JFilterInput(array('a', 'table'), array('src', 'alt', 'title'), 1);
         //$row->commentText = $filter->clean( $row->commentText );
         //Clean vars
         $filter = JFilterInput::getInstance();
         $row->userName = $filter->clean($row->userName, 'username');
         if ($row->commentURL && preg_match('/^((http|https|ftp):\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,6}((:[0-9]{1,5})?\\/.*)?$/i', $row->commentURL)) {
             $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $row->commentURL);
             $url = str_replace(';//', '://', $url);
             if ($url != '') {
                 $url = !strstr($url, '://') ? 'http://' . $url : $url;
                 $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
                 $row->commentURL = $url;
             }
         } else {
             $row->commentURL = '';
         }
         $datenow = JFactory::getDate();
         $row->commentDate = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql();
         if (!$user->guest) {
             $row->userID = $user->id;
             $row->commentEmail = $user->email;
             $row->userName = $user->name;
         }
         $userName = trim($row->userName);
         $commentEmail = trim($row->commentEmail);
         $commentText = trim($row->commentText);
         $commentURL = trim($row->commentURL);
         if (empty($userName) || $userName == JText::_('K2_ENTER_YOUR_NAME') || empty($commentText) || $commentText == JText::_('K2_ENTER_YOUR_MESSAGE_HERE') || empty($commentEmail) || $commentEmail == JText::_('K2_ENTER_YOUR_EMAIL_ADDRESS')) {
             $response->message = JText::_('K2_YOU_NEED_TO_FILL_IN_ALL_REQUIRED_FIELDS');
             echo $json->encode($response);
             $mainframe->close();
         }
         if (!JMailHelper::isEmailAddress($commentEmail)) {
             $response->message = JText::_('K2_INVALID_EMAIL_ADDRESS');
             echo $json->encode($response);
             $mainframe->close();
         }
         if ($user->guest) {
             $db = JFactory::getDBO();
             $query = "SELECT COUNT(*) FROM #__users WHERE name=" . $db->Quote($userName) . " OR email=" . $db->Quote($commentEmail);
             $db->setQuery($query);
             $result = $db->loadresult();
             if ($result > 0) {
                 $response->message = JText::_('K2_THE_NAME_OR_EMAIL_ADDRESS_YOU_TYPED_IS_ALREADY_IN_USE');
                 echo $json->encode($response);
                 $mainframe->close();
             }
         }
         // Google reCAPTCHA
         if ($params->get('antispam') == 'recaptcha' || $params->get('antispam') == 'both') {
             if ($user->guest || $params->get('recaptchaForRegistered', 1)) {
                 if (!function_exists('_recaptcha_qsencode')) {
                     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'recaptchalib.php';
                 }
                 $privatekey = $params->get('recaptcha_private_key');
                 $recaptcha_challenge_field = isset($_POST["recaptcha_challenge_field"]) ? $_POST["recaptcha_challenge_field"] : '';
                 $recaptcha_response_field = isset($_POST["recaptcha_response_field"]) ? $_POST["recaptcha_response_field"] : '';
                 $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field, $recaptcha_response_field);
                 if (!$resp->is_valid) {
                     $response->message = JText::_('K2_THE_WORDS_YOU_TYPED_DID_NOT_MATCH_THE_ONES_DISPLAYED_PLEASE_TRY_AGAIN');
                     echo $json->encode($response);
                     $mainframe->close();
                 }
             }
         }
         // Akismet
         if ($params->get('antispam') == 'akismet' || $params->get('antispam') == 'both') {
             if ($user->guest || $params->get('akismetForRegistered', 1)) {
                 if ($params->get('akismetApiKey')) {
                     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'akismet.class.php';
                     $akismetApiKey = $params->get('akismetApiKey');
                     $akismet = new Akismet(JURI::root(false), $akismetApiKey);
                     $akismet->setCommentAuthor($userName);
                     $akismet->setCommentAuthorEmail($commentEmail);
                     $akismet->setCommentAuthorURL($commentURL);
                     $akismet->setCommentContent($commentText);
                     $akismet->setPermalink(JURI::root(false) . 'index.php?option=com_k2&view=item&id=' . JRequest::getInt('itemID'));
                     try {
                         if ($akismet->isCommentSpam()) {
                             $response->message = JText::_('K2_SPAM_ATTEMPT_HAS_BEEN_DETECTED_THE_COMMENT_HAS_BEEN_REJECTED');
                             echo $json->encode($response);
                             $mainframe->close();
                         }
                     } catch (Exception $e) {
                         $response->message = $e->getMessage();
                         echo $json->encode($response);
                         $mainframe->close();
                     }
                 }
             }
         }
         if ($commentURL == JText::_('K2_ENTER_YOUR_SITE_URL') || $commentURL == "") {
             $row->commentURL = NULL;
         } else {
             if (substr($commentURL, 0, 7) != 'http://') {
                 $row->commentURL = 'http://' . $commentURL;
             }
         }
         if ($params->get('commentsPublishing')) {
             $row->published = 1;
         } else {
             $row->published = 0;
             // Auto publish comments for users with administrative permissions
             if (K2_JVERSION != '15') {
                 if ($user->authorise('core.admin')) {
                     $row->published = 1;
                 }
             } else {
                 if ($user->gid > 23) {
                     $row->published = 1;
                 }
             }
         }
         if (!$row->store()) {
             $response->message = $row->getError();
             echo $json->encode($response);
             $mainframe->close();
         }
         if ($row->published) {
             $caching = K2_JVERSION == '30' ? $config->get('caching') : $config->getValue('config.caching');
             if ($caching && $user->guest) {
                 $response->message = JText::_('K2_THANK_YOU_YOUR_COMMENT_WILL_BE_PUBLISHED_SHORTLY');
                 echo $json->encode($response);
             } else {
                 $response->message = JText::_('K2_COMMENT_ADDED_REFRESHING_PAGE');
                 $response->refresh = 1;
                 echo $json->encode($response);
             }
         } else {
             $response->message = JText::_('K2_COMMENT_ADDED_AND_WAITING_FOR_APPROVAL');
             echo $json->encode($response);
         }
     }
     $mainframe->close();
 }
Beispiel #29
0
 function report_ham($c)
 {
     $spam = $this->db->quick_query('SELECT * FROM %pspam WHERE spam_id=%d', $c);
     if (!$spam) {
         return $this->message('Spam Control', 'There is no such spam comment.', 'Continue', '/index.php?a=spam_control');
     }
     if ($this->user['user_level'] == USER_CONTRIBUTOR) {
         $user = null;
         if ($spam['spam_type'] == COMMENT_BLOG) {
             $user = $this->db->quick_query('SELECT post_user FROM %blogposts WHERE post_id=%d', $spam['spam_post']);
         } else {
             if ($spam['spam_type'] == COMMENT_GALLERY) {
                 $user = $this->db->quick_query('SELECT photo_user FROM %pphotogallery WHERE photo_id=%d', $spam['spam_post']);
             } else {
                 if ($spam['spam_type'] == COMMENT_FILE) {
                     $user = $this->db->quick_query('SELECT file_user FROM %pfilelist WHERE file_id=%d', $spam['spam_post']);
                 }
             }
         }
         if (!$user) {
             return $this->error('Access Denied: You do not own the entry you are trying to report.');
         }
     }
     $svars = json_decode($spam['spam_server'], true);
     // Setup and deliver the information to flag this comment as legit with Akismet.
     require_once 'lib/akismet.php';
     $akismet = new Akismet($this->settings['site_address'], $this->settings['wordpress_api_key'], $this->version);
     $akismet->setCommentAuthor($spam['spam_author']);
     $akismet->setCommentAuthorURL($spam['spam_url']);
     $akismet->setCommentContent($spam['spam_message']);
     $akismet->setUserIP($spam['spam_ip']);
     $akismet->setReferrer($svars['HTTP_REFERER']);
     $akismet->setUserAgent($svars['HTTP_USER_AGENT']);
     $akismet->setCommentType('comment');
     $akismet->submitHam();
     $q = $spam['spam_post'];
     $author = $spam['spam_user'];
     $author_name = $spam['spam_author'];
     $message = $spam['spam_message'];
     $url = $spam['spam_url'];
     $time = $spam['spam_date'];
     $ip = $spam['spam_ip'];
     $type = $spam['spam_type'];
     $this->settings['spam_count']--;
     $this->settings['ham_count']++;
     $this->save_settings();
     $this->db->dbquery("INSERT INTO %pblogcomments\n\t\t   (comment_post, comment_user, comment_author, comment_message, comment_date, comment_ip, comment_type)\n\t\t   VALUES ( %d, %d, '%s', '%s', %d, '%s', %d)", $q, $author, $author_name, $message, $time, $ip, $type);
     if ($type == COMMENT_BLOG) {
         $this->db->dbquery('UPDATE %pblogposts SET post_comment_count=post_comment_count+1 WHERE post_id=%d', $q);
     } elseif ($type == COMMENT_GALLERY) {
         $this->db->dbquery('UPDATE %pphotogallery SET photo_comment_count=photo_comment_count+1 WHERE photo_id=%d', $q);
     } elseif ($type == COMMENT_FILE) {
         $this->db->dbquery('UPDATE %pfilelist SET file_comment_count=file_comment_count+1 WHERE file_id=%d', $q);
     }
     $this->db->dbquery('DELETE FROM %pspam WHERE spam_id=%d', $c);
     return $this->message('Spam Control', 'Comment has been posted and Akismet notified of a false positive.', 'Continue', $this->settings['site_address'] . 'index.php?a=spam_control');
 }
         $db->sql_freeresult($result);
         if ($post) {
             if (!class_exists('Akismet')) {
                 global $phpbb_root_path, $phpEx;
                 include $phpbb_root_path . 'antispam/Akismet.class.' . $phpEx;
             }
             $post['decoded_text'] = $post['post_text'];
             decode_message($post['decoded_text'], $post['bbcode_uid']);
             $akismet = new Akismet($config['asacp_akismet_domain'], $config['asacp_akismet_key']);
             $akismet->setUserIP($post['poster_ip']);
             $akismet->setReferrer('');
             $akismet->setCommentUserAgent('');
             $akismet->setCommentType('comment');
             $akismet->setCommentAuthor($user_row['username']);
             $akismet->setCommentAuthorEmail($user_row['user_email']);
             $akismet->setCommentContent($post['decoded_text']);
             $akismet->submitSpam();
         }
     }
     trigger_error(sprintf($user->lang['ASACP_BAN_COMPLETE'], append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=viewprofile&amp;u={$user_id}")));
 } else {
     if (isset($_REQUEST['confirm_key']) && $error) {
         // Hack to fix the confirm_box if we need to come back to it because of an error
         unset($_REQUEST['confirm_key']);
     }
     // Build the ban actions string
     $user->add_lang('mods/acp_asacp');
     $ban_actions = array();
     if ($config['asacp_ocban_username']) {
         $ban_actions[] = $user->lang['ASACP_BAN_USERNAME'];
     }