当前位置: 首页>>代码示例>>PHP>>正文


PHP Akismet类代码示例

本文整理汇总了PHP中Akismet的典型用法代码示例。如果您正苦于以下问题:PHP Akismet类的具体用法?PHP Akismet怎么用?PHP Akismet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Akismet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: detect_spam

 /**
  * 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);
         }
     }
 }
开发者ID:hunter2814,项目名称:reason_package,代码行数:28,代码来源:akismet.php

示例2: filterMessage

 /**
  * 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;
 }
开发者ID:ItsHaden,项目名称:epicLanBootstrap,代码行数:45,代码来源:akismet.php

示例3: validate

	/**
	 * 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;
	}
开发者ID:Jobar87,项目名称:fabrik,代码行数:35,代码来源:akismet.php

示例4: buildAkismet

 /**
  * 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;
 }
开发者ID:vanilla,项目名称:addons,代码行数:15,代码来源:class.akismet.plugin.php

示例5: register

 /**
  * 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');
 }
开发者ID:nickurt,项目名称:laravel-akismet,代码行数:16,代码来源:ServiceProvider.php

示例6: doModel

 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;
     }
 }
开发者ID:oanav,项目名称:closetshare,代码行数:51,代码来源:spamnbots.php

示例7: Akismet

 /**
  * @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;
 }
开发者ID:nilsen,项目名称:addons,代码行数:19,代码来源:class.akismet.plugin.php

示例8: check

 /**
  * 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));
                     }
                 }
             }
         }
     }
 }
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:42,代码来源:class.akismet-cli.php

示例9: akismet_create_topic

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'));
    }
}
开发者ID:valek0972,项目名称:hackits,代码行数:60,代码来源:Subs-Akismet.php

示例10: HandleGuestStore

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);
}
开发者ID:ansgar,项目名称:pmguest,代码行数:34,代码来源:guest.php

示例11: validate

 /**
  * 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;
 }
开发者ID:jfquestiaux,项目名称:fabrik,代码行数:26,代码来源:akismet.php

示例12: rules

 /**
  * 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}/'];
 }
开发者ID:Antoine07,项目名称:student,代码行数:14,代码来源:CommentFormRequest.php

示例13: beforeSave

 /**
  * 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';
     }
 }
开发者ID:atkrad,项目名称:akismet,代码行数:18,代码来源:AkismetBehavior.php

示例14: execute

 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();
         }
     }
 }
开发者ID:cjmaximal,项目名称:webasyst-framework,代码行数:19,代码来源:blogAkismetPluginBackend.controller.php

示例15: check

 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;
 }
开发者ID:Naldo100,项目名称:k2-v3-dev-build,代码行数:55,代码来源:captcha.php


注:本文中的Akismet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。