silverstripe / akismet
Akismet 防垃圾邮件模块用于 Silverstripe
Requires
- php: ^7.4 || ^8.0
- silverstripe/cms: ^4.0
- silverstripe/framework: ^4.10
- silverstripe/spamprotection: ^3.0
- tijsverkoyen/akismet: 1.1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.0
- 5.x-dev
- 4.x-dev
- 4.5.x-dev
- 4.5.1
- 4.5.0
- 4.5.0-rc1
- 4.5.0-beta1
- 4.4.x-dev
- 4.4.0
- 4.4.0-rc1
- 4.4.0-beta1
- 4.3.x-dev
- 4.3.0
- 4.3.0-rc1
- 4.3.0-beta1
- 4.2.x-dev
- 4.2.0
- 4.2.0-rc1
- 4.2.0-beta1
- 4.1.x-dev
- 4.1.0
- 4.1.0-rc1
- 4.1.0-beta1
- 4.0.x-dev
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 4.0.0-beta1
- 3.2.x-dev
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.x-dev
- 3.1.0
- 3.0.x-dev
- dev-master
This package is auto-updated.
Last update: 2024-09-05 00:25:26 UTC
README
使用 Akismet 为 Silverstripe 提供简单的垃圾邮件过滤器
另外,请报告任何您遇到的问题,因为这有助于我们所有人!
请参阅模块历史记录
致谢和作者
- Damian Mooyman - https://github.com/tractorcow/silverstripe-akismet
- 对 Tijs Verkoyen 的 Akismet API 包装器表示感谢 - https://github.com/tijsverkoyen/Akismet
要求
- Silverstripe ^4 || ^5
- Silverstripe SpamProtection 模块 - https://github.com/silverstripe/silverstripe-spamprotection
- Tijs Verkoyen 的 Akismet API 包装器 - https://github.com/tijsverkoyen/Akismet
注意:对于 Silverstripe 4.x 兼容版本,请使用 4.x 版本。
安装说明
此模块可以轻松安装在任何已开发的网站上
- 您可以使用以下方式使用 Composer 进行安装
composer require silverstripe/akismet
AkismetSpamProtector
被自动分配为默认的垃圾邮件保护类。
- 从 akismet.com 获取 API 密钥,并通过以下任一方式设置到网站上。
config.yml
--- Name: myspamprotection --- SilverStripe\Akismet\AkismetSpamProtector: api_key: 5555dddd55d5d
_config.php
use SilverStripe\Akismet\AkismetSpamProtector; AkismetSpamProtector::singleton()->setApiKey('5555dddd55d5d');
.env
SS_AKISMET_API_KEY="5555dddd55d5d"
如果您想通过 siteconfig(作为密码字段)配置您的 akismet 密钥,您可以将包含的扩展添加到 SiteConfig
mysite/_config/settings.yml
SilverStripe\SiteConfig\SiteConfig: extensions: - SilverStripe\Akismet\Config\AkismetConfig
定义的 API 密钥的优先级
请注意,上述各种方式中定义的 API 密钥值将按照以下顺序优先:
- 通过
AkismetSpamProtector::singleton()->setApiKey()
分配给单例的值 - 在 YAML 或 _config.php 文件中定义的配置值,使用
Config::modify()->set(...)
- 在环境变量中定义的值 .env
测试
默认情况下,对具有 ADMIN 权限的用户禁用垃圾邮件保护。还可以选择禁用所有登录用户的垃圾邮件保护。为了测试目的暂时禁用此功能,您可以在您的开发环境中按以下方式修改这些选项
use SilverStripe\Akismet\AkismetSpamProtector; use SilverStripe\Control\Director; use SilverStripe\Core\Config\Config; if (!Director::isLive()) { Config::modify()->remove(AkismetSpamProtector::class, 'bypass_permission'); Config::modify()->remove(AkismetSpamProtector::class, 'bypass_members'); }
为了检查您的表单是否正确阻止垃圾邮件,您始终可以将 'viagra-test-123' 设置为作者,Akismet 总会将此标记为垃圾邮件。
评论
如果您正在使用评论模块,您可以通过将 CommentSpamProtection
扩展添加到 CommentingController
来快速设置 Akismet 过滤这些评论。
config.yml
SilverStripe\Comments\Controllers\CommentingController: extensions: - CommentSpamProtection
如有必要,您还可以将垃圾邮件评论标记为保存到数据库。这将仍然显示垃圾邮件拒绝通知,但垃圾邮件评论现在将在后端中可供审核。要启用此功能,请将以下内容添加到您的配置中。
config.yml
# Allows spam posts to be saved for review if necessary SilverStripe\Akismet\AkismetSpamProtector: save_spam: true
自定义表单使用
为了在您的自定义表单中启用垃圾邮件保护,请使用字段名称映射到 Akismet 字段调用 enableSpamProtection 方法
$form = new Form($this, 'Form', $fields, $actions, $validator);
$form->enableSpamProtection(array(
'mapping' => array(
'Name' => 'authorName',
'Email' => 'authorMail',
'Comments' => 'body'
)
)
);
针对欧盟用户的注意事项
由于 Akismet 的工作方式(向第三方发送消息、作者和其他信息),在某些国家,在验证之前通知并获得用户的同意在法律上是必要的。
为了创建一个用于此字段的复选框样式授权提示,请设置以下配置选项
config.yml
SilverStripe\Akismet\AkismetSpamProtector: require_confirmation: true
_config.php
Config::modify()->set(AkismetSpamProtector::class, 'require_confirmation', true);