devfactory / mollom
Mollom for laravel 4
2.0.0
2015-07-09 15:23 UTC
Requires
- php: >=5.4.0
- illuminate/support: 5.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- guzzlehttp/guzzle: ~5.0
- illuminate/http: 5.*
- mockery/mockery: 0.7.2
README
Mollom for laravel 4.2
##如何设置
更新composer.json
文件
{ "require": { "devfactory/mollom": "1.0.5" } }
并在终端运行composer update
以下载文件。
更新app.php
文件,位于app/config
目录
'providers' => array( 'Devfactory\Mollom\MollomServiceProvider', ),
alias => array( 'Mollom' => 'Devfactory\Mollom\Facades\Mollom', ),
##配置
php artisan config:publish devfactory/mollom
<?php return array( /* |-------------------------------------------------------------------------- | Mollom dev Mode |-------------------------------------------------------------------------- | | When the dev mode is enabled the package will use the dev.mollom.com api | */ 'dev' => false, /* |-------------------------------------------------------------------------- | Mollom Public Key |-------------------------------------------------------------------------- | | This key is used to comminicate with the mollom api | https://mollom.com/user/xxxx/site-manager | */ 'mollom_public_key' => '', /* |-------------------------------------------------------------------------- | Mollom private Key |-------------------------------------------------------------------------- | | This key is used to comminicate with the mollom api | https://mollom.com/user/xxxx/site-manager | */ 'mollom_private_key' => '', /* | List of ISO 639-1 language codes supported by Mollom. | | If your application has a predefined list of ISO 639-1 languages already, | intersect your list with this via strtok($langcode, '-'). | | example : en */ 'mollom_languages_expected' => '', );
##如何在blade中使用验证码,添加以下代码
{{ Mollom::captcha('cpachaID') }} {{ Form::text('capchaInput') }}
并且为了验证用户输入的数据,只需将mollom
添加到数组验证规则中。
$rules = array( 'capchaInput' => 'required|mollom:cpachaID' ); $validator = Validator::make(Input::all(), $rules); if($validator -> fails()) { return Redirect::back() -> withErrors($validator); }
##如何检查评论垃圾邮件 此方法将联系mollom来检查内容
$comment = array( 'title' => 'comment title', 'body' => 'body comment', 'name' => 'authorName', 'mail' => 'authorEmail' ); try { $result = Mollom::comment($comment); } catch (\Devfactory\Mollom\Exceptions\UnknownSpamClassificationException $e) { //Mollom return anothor value } catch (\Devfactory\Mollom\Exceptions\SystemUnavailableException $e) { // Unable to contact mollom }
并返回
'ham' //Is not a spam 'spam' //Is a spam 'unsure' //Not sure you should display a captcha