Coder Social home page Coder Social logo

laravel-akismet's Introduction

Laravel Akismet

Build Status Total Downloads Latest Stable Version MIT Licensed

Installation

Install this package with composer:

composer require nickurt/laravel-akismet

Copy the config files for the api

php artisan vendor:publish --provider="nickurt\Akismet\ServiceProvider" --tag="config"

Configuration

The Akismet information can be set with environment values in the .env file (or directly in the config/akismet.php file)

AKISMET_APIKEY=MY_UNIQUE_APIKEY
AKISMET_BLOGURL=https://my-custom-blogurl.dev

Examples

Validation Rule

You can use a hidden-field akismet in your Form-Request to validate if the request is valid

// FormRequest ...

public function rules()
{
    return [
        'akismet' => [new \nickurt\Akismet\Rules\AkismetRule(
            request()->input('email'), request()->input('name')
        )]
    ];
}

// Manually ...

$validator = validator()->make(['akismet' => 'akismet'], ['akismet' => [new \nickurt\Akismet\Rules\AkismetRule(
    request()->input('email'), request()->input('name')
)]]);

The AkismetRule requires a email and name parameter to validate the request.

Events

You can listen to the IsSpam, ReportSpam and ReportHam events, e.g. if you want to log all the IsSpam-requests in your application

IsSpam Event

This event will be fired when the request contains spam nickurt\Akismet\Events\IsSpam

ReportSpam Event

This event will be fired when you succesfully reported spam nickurt\Akismet\Events\ReportSpam

ReportHam Event

This event will be fired when you succesfully reported ham nickurt\Akismet\Events\ReportHam

Custom Implementation

Validate Key
if( \Akismet::validateKey() ) {
    // valid
} else {
    // invalid
}
Set CommentAuthor Information
\Akismet::setCommentAuthor("John Doe")
    ->setCommentAuthorUrl("https://www.google.com")
    ->setCommentContent("It's me, John!")
    ->setCommentType('registration');
    // etc
    
// or
\Akismet::fill([
    'comment_author' => 'John Doe',
    'comment_author_url' => 'https://www.google.com',
    'comment_content' => 'It's me, John!'
]);
// etc
Is it Spam?
if( \Akismet::isSpam() ) {
    // yes, i'm spam!
}
Submit Spam (missed spam)
if( \Akismet::reportSpam() ) {
    // yes, thanks!
}
Submit Ham (false positives)
if( \Akismet::reportHam() ) {
    // yes, thanks!
}

Tests

composer test

laravel-akismet's People

Contributors

dependabot-preview[bot] avatar edalzell avatar greut avatar laravel-shift avatar nickurt avatar simonfranz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-akismet's Issues

Refactor getResponseData

I would like to save the data that's submitted to check for the spam report but at the moment it's private function. It would be nice to add a toArray() function which would return an array of data that will be sent to check the spam report.

Throw exception on invalid API call

In combination with #6 it would have been useful to get the error straight away by the app throwing an exception, that way can quickly spot/catch invalid API calls to akismet.

Dependencies errors when trying to install

Greetings, I'm getting these composer errors when trying to install on Laravel 5.2

Problem 1
- Installation request for nickurt/laravel-akismet ^0.0.1 -> satisfiable by nickurt/laravel-akismet[0.0.1].
- Conclusion: remove guzzlehttp/guzzle 6.1.1

- Conclusion: don't install guzzlehttp/guzzle 6.1.1
- nickurt/laravel-akismet 0.0.1 requires guzzlehttp/guzzle 5.* -> satisfiable by guzzlehttp/guzzle[5.0.0, 5.0.1, 5.0.2, 5.0.3, 5.1.0,

5.2.0, 5.3.0].
- Can only install one of: guzzlehttp/guzzle[5.0.0, 6.1.1].
- Can only install one of: guzzlehttp/guzzle[5.0.1, 6.1.1].
- Can only install one of: guzzlehttp/guzzle[5.0.2, 6.1.1].
- Can only install one of: guzzlehttp/guzzle[5.0.3, 6.1.1].
- Can only install one of: guzzlehttp/guzzle[5.1.0, 6.1.1].
- Can only install one of: guzzlehttp/guzzle[5.2.0, 6.1.1].
- Can only install one of: guzzlehttp/guzzle[5.3.0, 6.1.1].
- Installation request for guzzlehttp/guzzle == 6.1.1.0 -> satisfiable by guzzlehttp/guzzle[6.1.1].

Guzzle Exception error

Error: Call to undefined method GuzzleHttp\Exception\ConnectException::getResponse()

/Users/erin/Development/akismet/vendor/nickurt/laravel-akismet/src/Akismet.php:131
/Users/erin/Development/akismet/vendor/nickurt/laravel-akismet/src/Akismet.php:105

The code that causes this is the isSpam here: `return $this->akismetApi->fill($this->akismetData())->isSpam();'

validateKey function not exist

installed 1.0.0 on laravel 5.3.

getting error on validating key:
Call to undefined method nickurt\Akismet\Facade::validateKey()

Tag

Can this be tagged at 0.0.1? Bit scared about using this in production without a tag... :-)

Null values issue

I've just been debugging an issue for a while before realizing that it's submitting blog as null and erroring with:

"Missing required field: blog."

All of the values that are being submitted as null should be empty strings otherwise akismet won't process the request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.