本文整理汇总了PHP中Akismet::setUserAgent方法的典型用法代码示例。如果您正苦于以下问题:PHP Akismet::setUserAgent方法的具体用法?PHP Akismet::setUserAgent怎么用?PHP Akismet::setUserAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Akismet
的用法示例。
在下文中一共展示了Akismet::setUserAgent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isSpam
/**
* 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[optional] $author Commenters name.
* @param string[optional] $email Commenters email address.
* @param string[optional] $URL Commenters URL.
* @param string[optional] $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::getModuleSetting('core', 'akismet_key');
// invalid key, so we can't detect spam
if ($akismetKey === '') {
return false;
}
// require the class
require_once PATH_LIBRARY . '/external/akismet.php';
// 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 (SPOON_DEBUG) {
throw $e;
}
// return unknown status
return 'unknown';
}
// when everything fails
return false;
}
示例2: Akismet
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');
}
示例3: submitSpam
/**
* Submit spam, his call is for submitting comments that weren't marked as spam but should have been.
*
* @return bool If everything went fine true will be returned, otherwise an exception will be triggered.
* @param string $userIp IP address of the comment submitter.
* @param string $userAgent User agent information.
* @param string[optional] $content The content that was submitted.
* @param string[optional] $author Submitted name with the comment.
* @param string[optional] $email Submitted email address.
* @param string[optional] $url Commenter URL.
* @param string[optional] $permalink The permanent location of the entry the comment was submitted to.
* @param string[optional] $type May be blank, comment, trackback, pingback, or a made up value like "registration".
* @param string[optional] $referrer The content of the HTTP_REFERER header should be sent here.
* @param array[optional] $others Other data (the variables from $_SERVER).
*/
public static function submitSpam($userIp, $userAgent, $content, $author = null, $email = null, $url = null, $permalink = null, $type = null, $referrer = null, $others = null)
{
// get some settings
$akismetKey = self::getModuleSetting('core', 'akismet_key');
// invalid key, so we can't detect spam
if ($akismetKey === '') {
return false;
}
// require the class
require_once PATH_LIBRARY . '/external/akismet.php';
// create new instance
$akismet = new Akismet($akismetKey, SITE_URL);
// set properties
$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 = null, $email = null, $url = null, $permalink = null, $type = null, $referrer = null, $others = null);
} catch (Exception $e) {
// in debug mode we want to see exceptions, otherwise the fallback will be triggered
if (SPOON_DEBUG) {
throw $e;
}
}
// when everything fails
return false;
}