Services_Akismet
[ class tree: Services_Akismet ] [ index: Services_Akismet ] [ all elements ]

File: Akismet.php

Source Location: /Services_Akismet-1.0.1/Akismet.php

Classes:

Services_Akismet
Class to use Akismet API from PHP

Page Details:

Services_Akismet is a package to use Akismet spam-filtering from PHP

This package provides an object-oriented interface to the Akismet REST API. Akismet is used to detect and to filter spam comments posted on weblogs. Though the use of Akismet is not specific to Wordpress, you will need a Wordpress API key from http://wordpress.com to use this package.

Akismet is free for personal use and a license may be purchased for commercial or high-volume applications.

This package is derived from the miPHP Akismet class written by Bret Kuhns for use in PHP 4. This package requires PHP 5.2.1.

Example usage:

  1.  /**
  2.   * Handling user-posted comments
  3.   */
  4.  
  5.  $comment = new Services_Akismet_Comment();
  6.  $comment->setAuthor('Test Author');
  7.  $comment->setAuthorEmail('test@example.com');
  8.  $comment->setAuthorUri('http://example.com/');
  9.  $comment->setContent('Hello, World!');
  10.  
  11.  try {
  12.      $apiKey 'AABBCCDDEEFF';
  13.      $akismet = new Services_Akismet('http://blog.example.com/'$apiKey);
  14.      if ($akismet->isSpam($comment)) {
  15.          // rather than simply ignoring the spam comment, it is recommended
  16.          // to save the comment and mark it as spam in case the comment is a
  17.          // false positive.
  18.      else {
  19.          // save comment as normal comment
  20.      }
  21.  catch (Services_Akismet_InvalidApiKeyException $keyException{
  22.      echo 'Invalid API key!';
  23.  catch (Services_Akismet_CommunicationException $comException{
  24.      echo 'Error communicating with Akismet API server: ' .
  25.          $comException->getMessage();
  26.  catch (Services_Akismet_InvalidCommentException $commentException{
  27.      echo 'Specified comment is missing one or more required fields.' .
  28.          $commentException->getMessage();
  29.  }
  30.  
  31.  /**
  32.   * Submitting a comment as known spam
  33.   */
  34.  
  35.  $comment = new Services_Akismet_Comment();
  36.  $comment->setAuthor('Test Author');
  37.  $comment->setAuthorEmail('test@example.com');
  38.  $comment->setAuthorUri('http://example.com/');
  39.  $comment->setContent('Hello, World!');
  40.  
  41.  try {
  42.      $apiKey 'AABBCCDDEEFF';
  43.      $akismet = new Services_Akismet('http://blog.example.com/'$apiKey);
  44.      $akismet->submitSpam($comment);
  45.  catch (Services_Akismet_InvalidApiKeyException $keyException{
  46.      echo 'Invalid API key!';
  47.  catch (Services_Akismet_CommunicationException $comException{
  48.      echo 'Error communicating with Akismet API server: ' .
  49.          $comException->getMessage();
  50.  catch (Services_Akismet_InvalidCommentException $commentException{
  51.      echo 'Specified comment is missing one or more required fields.' .
  52.          $commentException->getMessage();
  53.  }
  54.  
  55.  /**
  56.   * Submitting a comment as a false positive
  57.   */
  58.  
  59.  $comment = new Services_Akismet_Comment();
  60.  $comment->setAuthor('Test Author');
  61.  $comment->setAuthorEmail('test@example.com');
  62.  $comment->setAuthorUri('http://example.com/');
  63.  $comment->setContent('Hello, World!');
  64.  
  65.  try {
  66.      $apiKey 'AABBCCDDEEFF';
  67.      $akismet = new Services_Akismet('http://blog.example.com/'$apiKey);
  68.      $akismet->submitFalsePositive($comment);
  69.  catch (Services_Akismet_InvalidApiKeyException $keyException{
  70.      echo 'Invalid API key!';
  71.  catch (Services_Akismet_CommunicationException $comException{
  72.      echo 'Error communicating with Akismet API server: ' .
  73.          $comException->getMessage();
  74.  catch (Services_Akismet_InvalidCommentException $commentException{
  75.      echo 'Specified comment is missing one or more required fields.' .
  76.          $commentException->getMessage();
  77.  }

PHP version 5

LICENSE:

Copyright (c) 2007-2008 Bret Kuhns, silverorange

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Includes:

require_once('Services/Akismet/Comment.php') [line 143]
Comment class definition.
require_once('Services/Akismet/HttpClient.php') [line 148]
Simple HTTP client for accessing the Akismet API.
require_once('Services/Akismet/InvalidApiKeyException.php') [line 153]
Exception thrown when an invalid API key is used.

Documentation generated on Mon, 11 Mar 2019 15:21:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.