2017 © Pedro PelĂĄez
 

module zf2-akismet-module

ZF2 module that provides an Akismet service and validator

image

netglue/zf2-akismet-module

ZF2 module that provides an Akismet service and validator

  • Tuesday, June 17, 2014
  • by netglue
  • Repository
  • 1 Watchers
  • 1 Stars
  • 15,251 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

ZF2 Akismet Service Module

Abandoned

If you're still using ZF and need this, it's not going anywhere, but it's also not going to receive any maintenance either. Akismet is still useful - you might want to check out gsteel/akismet which is a pretty easy to use standalone client that's well tested
 That way you can implement your own validators and just consume the api client!, (*1)

Intro

A straightforward ZF2 module that provides a service for using the Akismet API and a handy validator you can attach to your form elements., (*2)

Current Status

Mostly tested with exception of submitting ham and spam, though there's no reason why these wouldn't work fine as far as I can see., (*3)

Install

Install via composer with netglue/zf2-akismet-module then enable in your application.config.php with the module name NetglueAkismet, (*4)

Add your Akismet ApiKey to local autoloaded config like this:, (*5)

return array(
    'netglue_akismet' => array(
        'apiKey' => 'YourApiKey',
    ),
);

There are more options to setup defaults. Look at config/module.config.php for a full list., (*6)

Akismet Service

The Akismet service, once the module is loaded should be accessible from the main service locator with the name 'NetglueAkismet\Service\AkismetService'. It also has a shorter alias 'AkismetService', (*7)

Basic usage of the service goes like this:, (*8)

$service = $this->getServiceLocator()->get('AkismetService');
$result = $service->isSpam($contentToCheck, $authorEmail, $commentType, $additionalParams);

Not all of the parameters are required and all of them can be passed into the $additionalParams array making sure that the keys match up with whatever is expected by the API. You can find docs for it here: comment-check docs, (*9)

Validator

The validator is registered through the ValidatorManager by the Module as it depends on a service instance. Providing your form elements are created using the form element manager/factory stuff the validator should be ready to go - this is important. You must be intialising your form with $formElementManager->get('My\Form\Name'); in order for the validator to be properly initialised., (*10)

For example, set up your input filter config like this:, (*11)

public function getInputFilterSpecification() {
    return array(
        'myNameFormElement' => array(
            'required' => true,
            'filters' => array(
                array('name' => 'Zend\Filter\StringTrim'),
            ),
        ),
        'emailFormElement' => array(
            'required' => true,
            'filters' => array(
                array('name' => 'Zend\Filter\StringToLower'),
                array('name' => 'Zend\Filter\StringTrim'),
            ),
        ),
        'comment' => array(
            'required' => true,
            'filters' => array(
                array('name' => 'Zend\Filter\StringTrim'),
            ),
            'validators' => array(
                array(
                    'name' => 'AkismetValidator', // Or 'NetglueAkismet\Validator\Akismet'
                    'options' => array(
                        'comment_type' => 'comment', // Or 'contact-form' or something else, or leave it to the service configured default
                        'context_map' => array(
                            'emailFormElement' => 'comment_author_email',
                            'myNameFormElement' => 'comment_author',
                        ),
                    ),
                ),
            ),
        ),
    );
}

Tests

The tests are pretty good I think, but submitHam and submitSpam aren't tested yet., (*12)

To run the tests, CD to the module directory and issue php composer.phar install to download all the dependencies; copy phpunit.xml.dist to phpunit.xml. By default the network tests are disabled. To run those too, comment out or delete the exclude directive in the phpunit.xml and make sure you setup a valid api key in test/config/local.php., (*13)

The Versions

17/06 2014

dev-master

9999999-dev https://github.com/netglue/ZF2-Akismet-Module

ZF2 module that provides an Akismet service and validator

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 module akismet netglue

17/06 2014

0.1.1

0.1.1.0 https://github.com/netglue/ZF2-Akismet-Module

ZF2 module that provides an Akismet service and validator

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 module akismet netglue

17/06 2014

dev-develop

dev-develop https://github.com/netglue/ZF2-Akismet-Module

ZF2 module that provides an Akismet service and validator

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 module akismet netglue

13/03 2014

0.1.0

0.1.0.0 https://github.com/netglue/ZF2-Akismet-Module

ZF2 module that provides an Akismet service and validator

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 module akismet netglue